BsD3D11DepthStencilState.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "BsD3D11DepthStencilState.h"
  2. #include "BsD3D11Device.h"
  3. #include "BsD3D11RenderSystem.h"
  4. #include "BsD3D11Mappings.h"
  5. #include "BsRenderStats.h"
  6. namespace BansheeEngine
  7. {
  8. D3D11DepthStencilState::D3D11DepthStencilState()
  9. :mDepthStencilState(nullptr)
  10. { }
  11. D3D11DepthStencilState::~D3D11DepthStencilState()
  12. {
  13. }
  14. void D3D11DepthStencilState::initialize_internal()
  15. {
  16. D3D11_DEPTH_STENCIL_DESC depthStencilState;
  17. ZeroMemory(&depthStencilState, sizeof(D3D11_DEPTH_STENCIL_DESC));
  18. depthStencilState.BackFace.StencilPassOp = D3D11Mappings::get(mData.backStencilPassOp);
  19. depthStencilState.BackFace.StencilFailOp = D3D11Mappings::get(mData.backStencilFailOp);
  20. depthStencilState.BackFace.StencilDepthFailOp = D3D11Mappings::get(mData.backStencilZFailOp);
  21. depthStencilState.BackFace.StencilFunc = D3D11Mappings::get(mData.backStencilComparisonFunc);
  22. depthStencilState.FrontFace.StencilPassOp = D3D11Mappings::get(mData.frontStencilPassOp);
  23. depthStencilState.FrontFace.StencilFailOp = D3D11Mappings::get(mData.frontStencilFailOp);
  24. depthStencilState.FrontFace.StencilDepthFailOp = D3D11Mappings::get(mData.frontStencilZFailOp);
  25. depthStencilState.FrontFace.StencilFunc = D3D11Mappings::get(mData.frontStencilComparisonFunc);
  26. depthStencilState.DepthEnable = mData.depthReadEnable;
  27. depthStencilState.DepthWriteMask = mData.depthWriteEnable ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
  28. depthStencilState.DepthFunc = D3D11Mappings::get(mData.depthComparisonFunc);
  29. depthStencilState.StencilEnable = mData.stencilEnable;
  30. depthStencilState.StencilReadMask = mData.stencilReadMask;
  31. depthStencilState.StencilWriteMask = mData.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. BS_EXCEPT(RenderingAPIException, "Cannot create depth stencil state.\nError Description:" + errorDescription);
  39. }
  40. BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_DepthStencilState);
  41. DepthStencilState::initialize_internal();
  42. }
  43. void D3D11DepthStencilState::destroy_internal()
  44. {
  45. SAFE_RELEASE(mDepthStencilState);
  46. BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_DepthStencilState);
  47. DepthStencilState::destroy_internal();
  48. }
  49. }