BsDepthStencilState.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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, UINT32 id)
  31. : mProperties(desc), mId(id)
  32. {
  33. }
  34. DepthStencilStateCore::~DepthStencilStateCore()
  35. {
  36. }
  37. void DepthStencilStateCore::initialize()
  38. {
  39. // Since we cache states it's possible this object was already initialized
  40. // (i.e. multiple sim-states can share a single core-state)
  41. if (isInitialized())
  42. return;
  43. createInternal();
  44. CoreObjectCore::initialize();
  45. }
  46. const DepthStencilProperties& DepthStencilStateCore::getProperties() const
  47. {
  48. return mProperties;
  49. }
  50. const SPtr<DepthStencilStateCore>& DepthStencilStateCore::getDefault()
  51. {
  52. return RenderStateCoreManager::instance().getDefaultDepthStencilState();
  53. }
  54. DepthStencilState::DepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc)
  55. :mProperties(desc)
  56. {
  57. }
  58. DepthStencilState::~DepthStencilState()
  59. {
  60. }
  61. SPtr<DepthStencilStateCore> DepthStencilState::getCore() const
  62. {
  63. return std::static_pointer_cast<DepthStencilStateCore>(mCoreSpecific);
  64. }
  65. SPtr<CoreObjectCore> DepthStencilState::createCore() const
  66. {
  67. return RenderStateCoreManager::instance()._createDepthStencilState(mProperties.mData);
  68. }
  69. const DepthStencilStatePtr& DepthStencilState::getDefault()
  70. {
  71. return RenderStateManager::instance().getDefaultDepthStencilState();
  72. }
  73. const DepthStencilProperties& DepthStencilState::getProperties() const
  74. {
  75. return mProperties;
  76. }
  77. DepthStencilStatePtr DepthStencilState::create(const DEPTH_STENCIL_STATE_DESC& desc)
  78. {
  79. return RenderStateManager::instance().createDepthStencilState(desc);
  80. }
  81. UINT64 DepthStencilState::generateHash(const DEPTH_STENCIL_STATE_DESC& desc)
  82. {
  83. size_t hash = 0;
  84. hash_combine(hash, desc.depthReadEnable);
  85. hash_combine(hash, desc.depthWriteEnable);
  86. hash_combine(hash, (UINT32)desc.depthComparisonFunc);
  87. hash_combine(hash, desc.stencilEnable);
  88. hash_combine(hash, desc.stencilReadMask);
  89. hash_combine(hash, desc.stencilWriteMask);
  90. hash_combine(hash, (UINT32)desc.frontStencilFailOp);
  91. hash_combine(hash, (UINT32)desc.frontStencilZFailOp);
  92. hash_combine(hash, (UINT32)desc.frontStencilPassOp);
  93. hash_combine(hash, (UINT32)desc.frontStencilComparisonFunc);
  94. hash_combine(hash, (UINT32)desc.backStencilFailOp);
  95. hash_combine(hash, (UINT32)desc.backStencilZFailOp);
  96. hash_combine(hash, (UINT32)desc.backStencilPassOp);
  97. hash_combine(hash, (UINT32)desc.backStencilComparisonFunc);
  98. return (UINT64)hash;
  99. }
  100. /************************************************************************/
  101. /* RTTI */
  102. /************************************************************************/
  103. RTTITypeBase* DepthStencilState::getRTTIStatic()
  104. {
  105. return DepthStencilStateRTTI::instance();
  106. }
  107. RTTITypeBase* DepthStencilState::getRTTI() const
  108. {
  109. return DepthStencilState::getRTTIStatic();
  110. }
  111. }