BsD3D11DepthStencilState.cpp 2.6 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. D3D11DepthStencilStateCore::D3D11DepthStencilStateCore(const DEPTH_STENCIL_STATE_DESC& desc)
  9. :DepthStencilStateCore(desc), mDepthStencilState(nullptr)
  10. { }
  11. D3D11DepthStencilStateCore::~D3D11DepthStencilStateCore()
  12. {
  13. }
  14. void D3D11DepthStencilStateCore::initialize()
  15. {
  16. D3D11_DEPTH_STENCIL_DESC depthStencilState;
  17. ZeroMemory(&depthStencilState, sizeof(D3D11_DEPTH_STENCIL_DESC));
  18. depthStencilState.BackFace.StencilPassOp = D3D11Mappings::get(mProperties.getStencilBackPassOp());
  19. depthStencilState.BackFace.StencilFailOp = D3D11Mappings::get(mProperties.getStencilBackFailOp());
  20. depthStencilState.BackFace.StencilDepthFailOp = D3D11Mappings::get(mProperties.getStencilBackZFailOp());
  21. depthStencilState.BackFace.StencilFunc = D3D11Mappings::get(mProperties.getStencilBackCompFunc());
  22. depthStencilState.FrontFace.StencilPassOp = D3D11Mappings::get(mProperties.getStencilFrontPassOp());
  23. depthStencilState.FrontFace.StencilFailOp = D3D11Mappings::get(mProperties.getStencilFrontFailOp());
  24. depthStencilState.FrontFace.StencilDepthFailOp = D3D11Mappings::get(mProperties.getStencilFrontZFailOp());
  25. depthStencilState.FrontFace.StencilFunc = D3D11Mappings::get(mProperties.getStencilFrontCompFunc());
  26. depthStencilState.DepthEnable = mProperties.getDepthReadEnable();
  27. depthStencilState.DepthWriteMask = mProperties.getDepthWriteEnable() ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
  28. depthStencilState.DepthFunc = D3D11Mappings::get(mProperties.getDepthComparisonFunc());
  29. depthStencilState.StencilEnable = mProperties.getStencilEnable();
  30. depthStencilState.StencilReadMask = mProperties.getStencilReadMask();
  31. depthStencilState.StencilWriteMask = mProperties.getStencilWriteMask();
  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. DepthStencilStateCore::initialize();
  42. }
  43. void D3D11DepthStencilStateCore::destroy()
  44. {
  45. SAFE_RELEASE(mDepthStencilState);
  46. BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_DepthStencilState);
  47. DepthStencilStateCore::destroy();
  48. }
  49. }