CmD3D11BlendState.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "CmD3D11BlendState.h"
  2. #include "CmD3D11Mappings.h"
  3. #include "CmD3D11RenderSystem.h"
  4. #include "CmD3D11Device.h"
  5. namespace CamelotFramework
  6. {
  7. D3D11BlendState::D3D11BlendState()
  8. :mBlendState(nullptr)
  9. { }
  10. D3D11BlendState::~D3D11BlendState()
  11. {
  12. }
  13. void D3D11BlendState::initialize_internal()
  14. {
  15. D3D11_BLEND_DESC blendStateDesc;
  16. ZeroMemory(&blendStateDesc, sizeof(D3D11_BLEND_DESC));
  17. blendStateDesc.AlphaToCoverageEnable = mData.alphaToCoverageEnable;
  18. blendStateDesc.IndependentBlendEnable = mData.independantBlendEnable;
  19. for(UINT32 i = 0; i < CM_MAX_MULTIPLE_RENDER_TARGETS; i++)
  20. {
  21. blendStateDesc.RenderTarget[i].BlendEnable = mData.renderTargetDesc[i].blendEnable;
  22. blendStateDesc.RenderTarget[i].BlendOp = D3D11Mappings::get(mData.renderTargetDesc[i].blendOp);
  23. blendStateDesc.RenderTarget[i].BlendOpAlpha = D3D11Mappings::get(mData.renderTargetDesc[i].blendOpAlpha);
  24. blendStateDesc.RenderTarget[i].DestBlend = D3D11Mappings::get(mData.renderTargetDesc[i].dstBlend);
  25. blendStateDesc.RenderTarget[i].DestBlendAlpha = D3D11Mappings::get(mData.renderTargetDesc[i].dstBlendAlpha);
  26. blendStateDesc.RenderTarget[i].RenderTargetWriteMask = 0xf & mData.renderTargetDesc[i].renderTargetWriteMask; // Mask out all but last 4 bits
  27. blendStateDesc.RenderTarget[i].SrcBlend = D3D11Mappings::get(mData.renderTargetDesc[i].srcBlend);
  28. blendStateDesc.RenderTarget[i].SrcBlendAlpha = D3D11Mappings::get(mData.renderTargetDesc[i].srcBlendAlpha);
  29. }
  30. D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
  31. D3D11Device& device = rs->getPrimaryDevice();
  32. HRESULT hr = device.getD3D11Device()->CreateBlendState(&blendStateDesc, &mBlendState);
  33. if(FAILED(hr) || device.hasError())
  34. {
  35. String errorDescription = device.getErrorDescription();
  36. CM_EXCEPT(RenderingAPIException, "Cannot create blend state.\nError Description:" + errorDescription);
  37. }
  38. BlendState::initialize_internal();
  39. }
  40. void D3D11BlendState::destroy_internal()
  41. {
  42. SAFE_RELEASE(mBlendState);
  43. BlendState::destroy_internal();
  44. }
  45. }