BsD3D11BlendState.cpp 2.1 KB

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