BsDepthStencilState.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 Render system pipeline state that allows you to modify how an object is rendered.
  47. * More exactly this state allows to you to control how are depth and stencil buffers
  48. * modified upon rendering.
  49. *
  50. * @note Depth stencil states are immutable. Thread safe.
  51. */
  52. class BS_CORE_EXPORT DepthStencilState : public Resource
  53. {
  54. public:
  55. virtual ~DepthStencilState() {}
  56. /**
  57. * @brief If enabled, any pixel about to be written will be tested against the depth value
  58. * currently in the buffer. If the depth test passes (depending on the set value
  59. * and chosen depth comparison function), that pixel is written and depth is
  60. * updated (if depth write is enabled).
  61. */
  62. bool getDepthReadEnable() const { return mData.depthReadEnable; }
  63. /**
  64. * @brief If enabled rendering pixels will update the depth buffer value.
  65. */
  66. bool getDepthWriteEnable() const { return mData.depthWriteEnable; }
  67. /**
  68. * @brief Determines what operation should the renderer use when comparing previous and
  69. * current depth value. If the operation passes, pixel with the current depth
  70. * value will be considered visible.
  71. */
  72. CompareFunction getDepthComparisonFunc() const { return mData.depthComparisonFunc; }
  73. /**
  74. * @brief If true then stencil buffer will also be updated when a pixel is written, and
  75. * pixels will be tested against the stencil buffer before rendering.
  76. */
  77. bool getStencilEnable() const { return mData.stencilEnable; }
  78. /**
  79. * @brief Mask to apply to any value read from the stencil buffer, before applying the
  80. * stencil comparison function.
  81. */
  82. UINT8 getStencilReadMask() const { return mData.stencilReadMask; }
  83. /**
  84. * @brief Mask to apply to any value about to be written in the stencil buffer.
  85. */
  86. UINT8 getStencilWriteMask() const { return mData.stencilWriteMask; }
  87. /**
  88. * @brief Operation that happens when stencil comparison function fails on a front facing polygon.
  89. */
  90. StencilOperation getStencilFrontFailOp() const { return mData.frontStencilFailOp; }
  91. /**
  92. * @brief Operation that happens when stencil comparison function passes but depth test fails
  93. * on a front facing polygon.
  94. */
  95. StencilOperation getStencilFrontZFailOp() const { return mData.frontStencilZFailOp; }
  96. /**
  97. * @brief Operation that happens when stencil comparison function passes on a front facing polygon.
  98. */
  99. StencilOperation getStencilFrontPassOp() const { return mData.frontStencilPassOp; }
  100. /**
  101. * @brief Stencil comparison function used for front facing polygons. Stencil buffer will be modified according
  102. * to previously set stencil operations depending whether this comparison passes or fails.
  103. */
  104. CompareFunction getStencilFrontCompFunc() const { return mData.frontStencilComparisonFunc; }
  105. /**
  106. * @brief Operation that happens when stencil comparison function fails on a back facing polygon.
  107. */
  108. StencilOperation getStencilBackFailOp() const { return mData.backStencilFailOp; }
  109. /**
  110. * @brief Operation that happens when stencil comparison function passes but depth test fails
  111. * on a back facing polygon.
  112. */
  113. StencilOperation getStencilBackZFailOp() const { return mData.backStencilZFailOp; }
  114. /**
  115. * @brief Operation that happens when stencil comparison function passes on a back facing polygon.
  116. */
  117. StencilOperation getStencilBackPassOp() const { return mData.backStencilPassOp; }
  118. /**
  119. * @brief Stencil comparison function used for back facing polygons. Stencil buffer will be modified according
  120. * to previously set stencil operations depending whether this comparison passes or fails.
  121. */
  122. CompareFunction getStencilBackCompFunc() const { return mData.backStencilComparisonFunc; }
  123. /**
  124. * @brief Creates a new depth stencil state using the specified depth stencil state description structure.
  125. */
  126. static HDepthStencilState create(const DEPTH_STENCIL_STATE_DESC& desc);
  127. /**
  128. * @brief Returns the default depth stencil state that you may use when no other is available.
  129. */
  130. static const DepthStencilStatePtr& getDefault();
  131. protected:
  132. friend class RenderStateManager;
  133. virtual void initialize(const DEPTH_STENCIL_STATE_DESC& desc);
  134. DEPTH_STENCIL_STATE_DESC mData;
  135. /************************************************************************/
  136. /* RTTI */
  137. /************************************************************************/
  138. public:
  139. friend class DepthStencilStateRTTI;
  140. static RTTITypeBase* getRTTIStatic();
  141. virtual RTTITypeBase* getRTTI() const;
  142. };
  143. }