BsDepthStencilState.h 7.2 KB

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