BsDepthStencilState.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsResource.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Descriptor structured used for initializing DepthStencilState.
  8. *
  9. * @see DepthStencilState
  10. */
  11. struct BS_CORE_EXPORT DEPTH_STENCIL_STATE_DESC
  12. {
  13. DEPTH_STENCIL_STATE_DESC()
  14. : depthReadEnable(true)
  15. , depthWriteEnable(true)
  16. , depthComparisonFunc(CMPF_LESS)
  17. , stencilEnable(false)
  18. , stencilReadMask(0xFF)
  19. , stencilWriteMask(0xFF)
  20. , frontStencilFailOp(SOP_KEEP)
  21. , frontStencilZFailOp(SOP_KEEP)
  22. , frontStencilPassOp(SOP_KEEP)
  23. , frontStencilComparisonFunc(CMPF_ALWAYS_PASS)
  24. , backStencilFailOp(SOP_KEEP)
  25. , backStencilZFailOp(SOP_KEEP)
  26. , backStencilPassOp(SOP_KEEP)
  27. , backStencilComparisonFunc(CMPF_ALWAYS_PASS)
  28. { }
  29. bool depthReadEnable;
  30. bool depthWriteEnable;
  31. CompareFunction depthComparisonFunc;
  32. bool stencilEnable;
  33. UINT8 stencilReadMask;
  34. UINT8 stencilWriteMask;
  35. StencilOperation frontStencilFailOp;
  36. StencilOperation frontStencilZFailOp;
  37. StencilOperation frontStencilPassOp;
  38. CompareFunction frontStencilComparisonFunc;
  39. StencilOperation backStencilFailOp;
  40. StencilOperation backStencilZFailOp;
  41. StencilOperation backStencilPassOp;
  42. CompareFunction backStencilComparisonFunc;
  43. };
  44. BS_ALLOW_MEMCPY_SERIALIZATION(DEPTH_STENCIL_STATE_DESC);
  45. /**
  46. * @brief Information about a depth stencil state.
  47. */
  48. class BS_CORE_EXPORT DepthStencilProperties
  49. {
  50. public:
  51. DepthStencilProperties(const DEPTH_STENCIL_STATE_DESC& desc);
  52. /**
  53. * @brief If enabled, any pixel about to be written will be tested against the depth value
  54. * currently in the buffer. If the depth test passes (depending on the set value
  55. * and chosen depth comparison function), that pixel is written and depth is
  56. * updated (if depth write is enabled).
  57. */
  58. bool getDepthReadEnable() const { return mData.depthReadEnable; }
  59. /**
  60. * @brief If enabled rendering pixels will update the depth buffer value.
  61. */
  62. bool getDepthWriteEnable() const { return mData.depthWriteEnable; }
  63. /**
  64. * @brief Determines what operation should the renderer use when comparing previous and
  65. * current depth value. If the operation passes, pixel with the current depth
  66. * value will be considered visible.
  67. */
  68. CompareFunction getDepthComparisonFunc() const { return mData.depthComparisonFunc; }
  69. /**
  70. * @brief If true then stencil buffer will also be updated when a pixel is written, and
  71. * pixels will be tested against the stencil buffer before rendering.
  72. */
  73. bool getStencilEnable() const { return mData.stencilEnable; }
  74. /**
  75. * @brief Mask to apply to any value read from the stencil buffer, before applying the
  76. * stencil comparison function.
  77. */
  78. UINT8 getStencilReadMask() const { return mData.stencilReadMask; }
  79. /**
  80. * @brief Mask to apply to any value about to be written in the stencil buffer.
  81. */
  82. UINT8 getStencilWriteMask() const { return mData.stencilWriteMask; }
  83. /**
  84. * @brief Operation that happens when stencil comparison function fails on a front facing polygon.
  85. */
  86. StencilOperation getStencilFrontFailOp() const { return mData.frontStencilFailOp; }
  87. /**
  88. * @brief Operation that happens when stencil comparison function passes but depth test fails
  89. * on a front facing polygon.
  90. */
  91. StencilOperation getStencilFrontZFailOp() const { return mData.frontStencilZFailOp; }
  92. /**
  93. * @brief Operation that happens when stencil comparison function passes on a front facing polygon.
  94. */
  95. StencilOperation getStencilFrontPassOp() const { return mData.frontStencilPassOp; }
  96. /**
  97. * @brief Stencil comparison function used for front facing polygons. Stencil buffer will be modified according
  98. * to previously set stencil operations depending whether this comparison passes or fails.
  99. */
  100. CompareFunction getStencilFrontCompFunc() const { return mData.frontStencilComparisonFunc; }
  101. /**
  102. * @brief Operation that happens when stencil comparison function fails on a back facing polygon.
  103. */
  104. StencilOperation getStencilBackFailOp() const { return mData.backStencilFailOp; }
  105. /**
  106. * @brief Operation that happens when stencil comparison function passes but depth test fails
  107. * on a back facing polygon.
  108. */
  109. StencilOperation getStencilBackZFailOp() const { return mData.backStencilZFailOp; }
  110. /**
  111. * @brief Operation that happens when stencil comparison function passes on a back facing polygon.
  112. */
  113. StencilOperation getStencilBackPassOp() const { return mData.backStencilPassOp; }
  114. /**
  115. * @brief Stencil comparison function used for back facing polygons. Stencil buffer will be modified according
  116. * to previously set stencil operations depending whether this comparison passes or fails.
  117. */
  118. CompareFunction getStencilBackCompFunc() const { return mData.backStencilComparisonFunc; }
  119. protected:
  120. friend class DepthStencilState;
  121. friend class DepthStencilStateRTTI;
  122. DEPTH_STENCIL_STATE_DESC mData;
  123. };
  124. /**
  125. * @brief Core thread version of the depth stencil state.
  126. *
  127. * @see DepthStencilState
  128. *
  129. * @note Core thread.
  130. */
  131. class BS_CORE_EXPORT DepthStencilStateCore : public CoreObjectCore
  132. {
  133. public:
  134. virtual ~DepthStencilStateCore() {}
  135. /**
  136. * @brief Returns information about the depth stencil state.
  137. */
  138. const DepthStencilProperties& getProperties() const;
  139. /**
  140. * @brief Returns the default depth stencil state that you may use when no other is available.
  141. */
  142. static const SPtr<DepthStencilStateCore>& getDefault();
  143. protected:
  144. friend class RenderStateCoreManager;
  145. DepthStencilStateCore(const DEPTH_STENCIL_STATE_DESC& desc);
  146. DepthStencilProperties mProperties;
  147. };
  148. /**
  149. * @brief Render system pipeline state that allows you to modify how an object is rendered.
  150. * More exactly this state allows to you to control how are depth and stencil buffers
  151. * modified upon rendering.
  152. *
  153. * @note Depth stencil states are immutable. Sim thread only.
  154. */
  155. class BS_CORE_EXPORT DepthStencilState : public Resource
  156. {
  157. public:
  158. virtual ~DepthStencilState() {}
  159. /**
  160. * @brief Returns information about the depth stencil state.
  161. */
  162. const DepthStencilProperties& getProperties() const;
  163. /**
  164. * @brief Retrieves a core implementation of a sampler state usable only from the
  165. * core thread.
  166. */
  167. SPtr<DepthStencilStateCore> getCore() const;
  168. /**
  169. * @brief Creates a new depth stencil state using the specified depth stencil state description structure.
  170. */
  171. static HDepthStencilState create(const DEPTH_STENCIL_STATE_DESC& desc);
  172. /**
  173. * @brief Returns the default depth stencil state that you may use when no other is available.
  174. */
  175. static const DepthStencilStatePtr& getDefault();
  176. protected:
  177. friend class RenderStateManager;
  178. DepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc);
  179. /**
  180. * @copydoc CoreObjectCore::createCore
  181. */
  182. SPtr<CoreObjectCore> createCore() const;
  183. DepthStencilProperties mProperties;
  184. /************************************************************************/
  185. /* RTTI */
  186. /************************************************************************/
  187. public:
  188. friend class DepthStencilStateRTTI;
  189. static RTTITypeBase* getRTTIStatic();
  190. virtual RTTITypeBase* getRTTI() const;
  191. };
  192. }