BsD3D11DepthStencilState.cpp 2.8 KB

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