BsD3D11BlendState.cpp 2.2 KB

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