BsD3D11BlendState.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsD3D11BlendState.h"
  4. #include "BsD3D11Mappings.h"
  5. #include "BsD3D11RenderAPI.h"
  6. #include "BsD3D11Device.h"
  7. #include "Profiling/BsRenderStats.h"
  8. namespace bs { namespace ct
  9. {
  10. D3D11BlendState::D3D11BlendState(const BLEND_STATE_DESC& desc, UINT32 id)
  11. :BlendState(desc, id), mBlendState(nullptr)
  12. { }
  13. D3D11BlendState::~D3D11BlendState()
  14. {
  15. SAFE_RELEASE(mBlendState);
  16. BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_BlendState);
  17. }
  18. void D3D11BlendState::createInternal()
  19. {
  20. D3D11_BLEND_DESC blendStateDesc;
  21. ZeroMemory(&blendStateDesc, sizeof(D3D11_BLEND_DESC));
  22. blendStateDesc.AlphaToCoverageEnable = mProperties.getAlphaToCoverageEnabled();
  23. blendStateDesc.IndependentBlendEnable = mProperties.getIndependantBlendEnable();
  24. for(UINT32 i = 0; i < BS_MAX_MULTIPLE_RENDER_TARGETS; i++)
  25. {
  26. blendStateDesc.RenderTarget[i].BlendEnable = mProperties.getBlendEnabled(i);
  27. blendStateDesc.RenderTarget[i].BlendOp = D3D11Mappings::get(mProperties.getBlendOperation(i));
  28. blendStateDesc.RenderTarget[i].BlendOpAlpha = D3D11Mappings::get(mProperties.getAlphaBlendOperation(i));
  29. blendStateDesc.RenderTarget[i].DestBlend = D3D11Mappings::get(mProperties.getDstBlend(i));
  30. blendStateDesc.RenderTarget[i].DestBlendAlpha = D3D11Mappings::get(mProperties.getAlphaDstBlend(i));
  31. blendStateDesc.RenderTarget[i].RenderTargetWriteMask = 0xf & (mProperties.getRenderTargetWriteMask(i)); // Mask out all but last 4 bits
  32. blendStateDesc.RenderTarget[i].SrcBlend = D3D11Mappings::get(mProperties.getSrcBlend(i));
  33. blendStateDesc.RenderTarget[i].SrcBlendAlpha = D3D11Mappings::get(mProperties.getAlphaSrcBlend(i));
  34. }
  35. D3D11RenderAPI* rs = static_cast<D3D11RenderAPI*>(RenderAPI::instancePtr());
  36. D3D11Device& device = rs->getPrimaryDevice();
  37. HRESULT hr = device.getD3D11Device()->CreateBlendState(&blendStateDesc, &mBlendState);
  38. if(FAILED(hr) || device.hasError())
  39. {
  40. String errorDescription = device.getErrorDescription();
  41. BS_EXCEPT(RenderingAPIException, "Cannot create blend state.\nError Description:" + errorDescription);
  42. }
  43. BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_BlendState);
  44. BlendState::createInternal();
  45. }
  46. }}