BsD3D11DepthStencilState.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsD3D11DepthStencilState.h"
  4. #include "BsD3D11Device.h"
  5. #include "BsD3D11RenderAPI.h"
  6. #include "BsD3D11Mappings.h"
  7. #include "Profiling/BsRenderStats.h"
  8. namespace bs { namespace ct
  9. {
  10. D3D11DepthStencilState::D3D11DepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc, UINT32 id)
  11. :DepthStencilState(desc, id), mDepthStencilState(nullptr)
  12. { }
  13. D3D11DepthStencilState::~D3D11DepthStencilState()
  14. {
  15. SAFE_RELEASE(mDepthStencilState);
  16. BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_DepthStencilState);
  17. }
  18. void D3D11DepthStencilState::createInternal()
  19. {
  20. D3D11_DEPTH_STENCIL_DESC depthStencilState;
  21. ZeroMemory(&depthStencilState, sizeof(D3D11_DEPTH_STENCIL_DESC));
  22. bool depthEnable = mProperties.getDepthWriteEnable() || mProperties.getDepthReadEnable();
  23. CompareFunction compareFunc;
  24. if (mProperties.getDepthReadEnable())
  25. compareFunc = mProperties.getDepthComparisonFunc();
  26. else
  27. compareFunc = CMPF_ALWAYS_PASS;
  28. depthStencilState.BackFace.StencilPassOp = D3D11Mappings::get(mProperties.getStencilBackPassOp());
  29. depthStencilState.BackFace.StencilFailOp = D3D11Mappings::get(mProperties.getStencilBackFailOp());
  30. depthStencilState.BackFace.StencilDepthFailOp = D3D11Mappings::get(mProperties.getStencilBackZFailOp());
  31. depthStencilState.BackFace.StencilFunc = D3D11Mappings::get(mProperties.getStencilBackCompFunc());
  32. depthStencilState.FrontFace.StencilPassOp = D3D11Mappings::get(mProperties.getStencilFrontPassOp());
  33. depthStencilState.FrontFace.StencilFailOp = D3D11Mappings::get(mProperties.getStencilFrontFailOp());
  34. depthStencilState.FrontFace.StencilDepthFailOp = D3D11Mappings::get(mProperties.getStencilFrontZFailOp());
  35. depthStencilState.FrontFace.StencilFunc = D3D11Mappings::get(mProperties.getStencilFrontCompFunc());
  36. depthStencilState.DepthEnable = depthEnable;
  37. depthStencilState.DepthWriteMask = mProperties.getDepthWriteEnable() ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
  38. depthStencilState.DepthFunc = D3D11Mappings::get(compareFunc);
  39. depthStencilState.StencilEnable = mProperties.getStencilEnable();
  40. depthStencilState.StencilReadMask = mProperties.getStencilReadMask();
  41. depthStencilState.StencilWriteMask = mProperties.getStencilWriteMask();
  42. D3D11RenderAPI* rs = static_cast<D3D11RenderAPI*>(RenderAPI::instancePtr());
  43. D3D11Device& device = rs->getPrimaryDevice();
  44. HRESULT hr = device.getD3D11Device()->CreateDepthStencilState(&depthStencilState, &mDepthStencilState);
  45. if(FAILED(hr) || device.hasError())
  46. {
  47. String errorDescription = device.getErrorDescription();
  48. BS_EXCEPT(RenderingAPIException, "Cannot create depth stencil state.\nError Description:" + errorDescription);
  49. }
  50. BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_DepthStencilState);
  51. DepthStencilState::createInternal();
  52. }
  53. }}