BsDepthStencilState.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #include "BsDepthStencilState.h"
  2. #include "BsRenderStateManager.h"
  3. #include "BsRenderAPI.h"
  4. #include "BsDepthStencilStateRTTI.h"
  5. #include "BsException.h"
  6. #include "BsResources.h"
  7. namespace BansheeEngine
  8. {
  9. bool DEPTH_STENCIL_STATE_DESC::operator == (const DEPTH_STENCIL_STATE_DESC& rhs) const
  10. {
  11. return depthReadEnable == rhs.depthReadEnable &&
  12. depthWriteEnable == rhs.depthWriteEnable &&
  13. depthComparisonFunc == rhs.depthComparisonFunc &&
  14. stencilEnable == rhs.stencilEnable &&
  15. stencilReadMask == rhs.stencilReadMask &&
  16. stencilWriteMask == rhs.stencilWriteMask &&
  17. frontStencilFailOp == rhs.frontStencilFailOp &&
  18. frontStencilZFailOp == rhs.frontStencilZFailOp &&
  19. frontStencilPassOp == rhs.frontStencilPassOp &&
  20. frontStencilComparisonFunc == rhs.frontStencilComparisonFunc &&
  21. backStencilFailOp == rhs.backStencilFailOp &&
  22. backStencilZFailOp == rhs.backStencilZFailOp &&
  23. backStencilPassOp == rhs.backStencilPassOp &&
  24. backStencilComparisonFunc == rhs.backStencilComparisonFunc;
  25. }
  26. DepthStencilProperties::DepthStencilProperties(const DEPTH_STENCIL_STATE_DESC& desc)
  27. :mData(desc), mHash(DepthStencilState::generateHash(desc))
  28. {
  29. }
  30. DepthStencilStateCore::DepthStencilStateCore(const DEPTH_STENCIL_STATE_DESC& desc)
  31. : mProperties(desc)
  32. {
  33. }
  34. DepthStencilStateCore::~DepthStencilStateCore()
  35. {
  36. RenderStateCoreManager::instance().notifyDepthStencilStateDestroyed(mProperties.mData);
  37. }
  38. const DepthStencilProperties& DepthStencilStateCore::getProperties() const
  39. {
  40. return mProperties;
  41. }
  42. const SPtr<DepthStencilStateCore>& DepthStencilStateCore::getDefault()
  43. {
  44. return RenderStateCoreManager::instance().getDefaultDepthStencilState();
  45. }
  46. DepthStencilState::DepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc)
  47. :mProperties(desc)
  48. {
  49. }
  50. DepthStencilState::~DepthStencilState()
  51. {
  52. RenderStateManager::instance().notifyDepthStencilStateDestroyed(mProperties.mData);
  53. }
  54. SPtr<DepthStencilStateCore> DepthStencilState::getCore() const
  55. {
  56. return std::static_pointer_cast<DepthStencilStateCore>(mCoreSpecific);
  57. }
  58. SPtr<CoreObjectCore> DepthStencilState::createCore() const
  59. {
  60. return RenderStateCoreManager::instance().createDepthStencilStateInternal(mProperties.mData);
  61. }
  62. const DepthStencilStatePtr& DepthStencilState::getDefault()
  63. {
  64. return RenderStateManager::instance().getDefaultDepthStencilState();
  65. }
  66. const DepthStencilProperties& DepthStencilState::getProperties() const
  67. {
  68. return mProperties;
  69. }
  70. DepthStencilStatePtr DepthStencilState::create(const DEPTH_STENCIL_STATE_DESC& desc)
  71. {
  72. return RenderStateManager::instance().createDepthStencilState(desc);
  73. }
  74. UINT64 DepthStencilState::generateHash(const DEPTH_STENCIL_STATE_DESC& desc)
  75. {
  76. size_t hash = 0;
  77. hash_combine(hash, desc.depthReadEnable);
  78. hash_combine(hash, desc.depthWriteEnable);
  79. hash_combine(hash, (UINT32)desc.depthComparisonFunc);
  80. hash_combine(hash, desc.stencilEnable);
  81. hash_combine(hash, desc.stencilReadMask);
  82. hash_combine(hash, desc.stencilWriteMask);
  83. hash_combine(hash, (UINT32)desc.frontStencilFailOp);
  84. hash_combine(hash, (UINT32)desc.frontStencilZFailOp);
  85. hash_combine(hash, (UINT32)desc.frontStencilPassOp);
  86. hash_combine(hash, (UINT32)desc.frontStencilComparisonFunc);
  87. hash_combine(hash, (UINT32)desc.backStencilFailOp);
  88. hash_combine(hash, (UINT32)desc.backStencilZFailOp);
  89. hash_combine(hash, (UINT32)desc.backStencilPassOp);
  90. hash_combine(hash, (UINT32)desc.backStencilComparisonFunc);
  91. return (UINT64)hash;
  92. }
  93. /************************************************************************/
  94. /* RTTI */
  95. /************************************************************************/
  96. RTTITypeBase* DepthStencilState::getRTTIStatic()
  97. {
  98. return DepthStencilStateRTTI::instance();
  99. }
  100. RTTITypeBase* DepthStencilState::getRTTI() const
  101. {
  102. return DepthStencilState::getRTTIStatic();
  103. }
  104. }