CmD3D11DepthStencilState.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "CmD3D11DepthStencilState.h"
  2. #include "CmD3D11Device.h"
  3. #include "CmD3D11RenderSystem.h"
  4. #include "CmD3D11Mappings.h"
  5. namespace CamelotEngine
  6. {
  7. D3D11DepthStencilState::D3D11DepthStencilState()
  8. :mDepthStencilState(nullptr)
  9. { }
  10. D3D11DepthStencilState::~D3D11DepthStencilState()
  11. {
  12. SAFE_RELEASE(mDepthStencilState);
  13. }
  14. void D3D11DepthStencilState::initialize(const DEPTH_STENCIL_STATE_DESC& desc)
  15. {
  16. D3D11_DEPTH_STENCIL_DESC depthStencilState;
  17. ZeroMemory(&depthStencilState, sizeof(D3D11_DEPTH_STENCIL_DESC));
  18. depthStencilState.BackFace.StencilPassOp = D3D11Mappings::get(desc.backStencilPassOp);
  19. depthStencilState.BackFace.StencilFailOp = D3D11Mappings::get(desc.backStencilFailOp);
  20. depthStencilState.BackFace.StencilDepthFailOp = D3D11Mappings::get(desc.backStencilZFailOp);
  21. depthStencilState.BackFace.StencilFunc = D3D11Mappings::get(desc.backStencilComparisonFunc);
  22. depthStencilState.FrontFace.StencilPassOp = D3D11Mappings::get(desc.frontStencilPassOp);
  23. depthStencilState.FrontFace.StencilFailOp = D3D11Mappings::get(desc.frontStencilFailOp);
  24. depthStencilState.FrontFace.StencilDepthFailOp = D3D11Mappings::get(desc.frontStencilZFailOp);
  25. depthStencilState.FrontFace.StencilFunc = D3D11Mappings::get(desc.frontStencilComparisonFunc);
  26. depthStencilState.DepthEnable = desc.depthReadEnable;
  27. depthStencilState.DepthWriteMask = desc.depthWriteEnable ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
  28. depthStencilState.DepthFunc = D3D11Mappings::get(desc.depthComparisonFunc);
  29. depthStencilState.StencilEnable = desc.stencilEnable;
  30. depthStencilState.StencilReadMask = desc.stencilReadMask;
  31. depthStencilState.StencilWriteMask = desc.stencilWriteMask;
  32. D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
  33. D3D11Device& device = rs->getPrimaryDevice();
  34. HRESULT hr = device.getD3D11Device()->CreateDepthStencilState(&depthStencilState, &mDepthStencilState);
  35. if(FAILED(hr) || device.hasError())
  36. {
  37. String errorDescription = device.getErrorDescription();
  38. CM_EXCEPT(RenderingAPIException, "Cannot create depth stencil state.\nError Description:" + errorDescription);
  39. }
  40. }
  41. }