CmD3D11DepthStencilState.cpp 2.3 KB

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