BsD3D11DepthStencilState.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "BsD3D11DepthStencilState.h"
  2. #include "BsD3D11Device.h"
  3. #include "BsD3D11RenderAPI.h"
  4. #include "BsD3D11Mappings.h"
  5. #include "BsRenderStats.h"
  6. namespace BansheeEngine
  7. {
  8. D3D11DepthStencilStateCore::D3D11DepthStencilStateCore(const DEPTH_STENCIL_STATE_DESC& desc, UINT32 id)
  9. :DepthStencilStateCore(desc, id), mDepthStencilState(nullptr)
  10. { }
  11. D3D11DepthStencilStateCore::~D3D11DepthStencilStateCore()
  12. {
  13. SAFE_RELEASE(mDepthStencilState);
  14. BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_DepthStencilState);
  15. }
  16. void D3D11DepthStencilStateCore::createInternal()
  17. {
  18. D3D11_DEPTH_STENCIL_DESC depthStencilState;
  19. ZeroMemory(&depthStencilState, sizeof(D3D11_DEPTH_STENCIL_DESC));
  20. depthStencilState.BackFace.StencilPassOp = D3D11Mappings::get(mProperties.getStencilBackPassOp());
  21. depthStencilState.BackFace.StencilFailOp = D3D11Mappings::get(mProperties.getStencilBackFailOp());
  22. depthStencilState.BackFace.StencilDepthFailOp = D3D11Mappings::get(mProperties.getStencilBackZFailOp());
  23. depthStencilState.BackFace.StencilFunc = D3D11Mappings::get(mProperties.getStencilBackCompFunc());
  24. depthStencilState.FrontFace.StencilPassOp = D3D11Mappings::get(mProperties.getStencilFrontPassOp());
  25. depthStencilState.FrontFace.StencilFailOp = D3D11Mappings::get(mProperties.getStencilFrontFailOp());
  26. depthStencilState.FrontFace.StencilDepthFailOp = D3D11Mappings::get(mProperties.getStencilFrontZFailOp());
  27. depthStencilState.FrontFace.StencilFunc = D3D11Mappings::get(mProperties.getStencilFrontCompFunc());
  28. depthStencilState.DepthEnable = mProperties.getDepthReadEnable();
  29. depthStencilState.DepthWriteMask = mProperties.getDepthWriteEnable() ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
  30. depthStencilState.DepthFunc = D3D11Mappings::get(mProperties.getDepthComparisonFunc());
  31. depthStencilState.StencilEnable = mProperties.getStencilEnable();
  32. depthStencilState.StencilReadMask = mProperties.getStencilReadMask();
  33. depthStencilState.StencilWriteMask = mProperties.getStencilWriteMask();
  34. D3D11RenderAPI* rs = static_cast<D3D11RenderAPI*>(RenderAPICore::instancePtr());
  35. D3D11Device& device = rs->getPrimaryDevice();
  36. HRESULT hr = device.getD3D11Device()->CreateDepthStencilState(&depthStencilState, &mDepthStencilState);
  37. if(FAILED(hr) || device.hasError())
  38. {
  39. String errorDescription = device.getErrorDescription();
  40. BS_EXCEPT(RenderingAPIException, "Cannot create depth stencil state.\nError Description:" + errorDescription);
  41. }
  42. BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_DepthStencilState);
  43. DepthStencilStateCore::createInternal();
  44. }
  45. }