BsRasterizerState.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsIReflectable.h"
  4. #include "BsCoreObject.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Structure that describes pipeline rasterizer state. Used for initializing
  9. * a RasterizerState.
  10. *
  11. * @see RasterizerState
  12. */
  13. struct BS_CORE_EXPORT RASTERIZER_STATE_DESC
  14. {
  15. RASTERIZER_STATE_DESC()
  16. : polygonMode(PM_SOLID)
  17. , cullMode(CULL_COUNTERCLOCKWISE)
  18. , depthBias(0)
  19. , depthBiasClamp(0.0f)
  20. , slopeScaledDepthBias(0.0f)
  21. , depthClipEnable(true)
  22. , scissorEnable(false)
  23. , multisampleEnable(true)
  24. , antialiasedLineEnable(false)
  25. { }
  26. PolygonMode polygonMode;
  27. CullingMode cullMode;
  28. float depthBias;
  29. float depthBiasClamp;
  30. float slopeScaledDepthBias;
  31. bool depthClipEnable;
  32. bool scissorEnable;
  33. bool multisampleEnable;
  34. bool antialiasedLineEnable;
  35. };
  36. /**
  37. * @brief Information about a rasterizer state.
  38. */
  39. class BS_CORE_EXPORT RasterizerProperties
  40. {
  41. public:
  42. RasterizerProperties(const RASTERIZER_STATE_DESC& desc);
  43. /**
  44. * @brief Polygon mode allows you to draw polygons as solid objects or as wireframe by
  45. * just drawing their edges.
  46. */
  47. PolygonMode getPolygonMode() const { return mData.polygonMode; }
  48. /**
  49. * @brief Sets vertex winding order. Faces that contain vertices with this order will
  50. * be culled and not rasterized. Used primarily for saving cycles by not rendering
  51. * backfacing faces.
  52. */
  53. CullingMode getCullMode() const { return mData.cullMode; }
  54. /**
  55. * @brief Represents a constant depth bias that will offset the depth values of new pixels
  56. * by the specified amount.
  57. *
  58. * @note This is useful if you want to avoid z fighting for objects at the same or similar depth.
  59. */
  60. float getDepthBias() const { return mData.depthBias; }
  61. /**
  62. * @brief Maximum depth bias value.
  63. */
  64. float getDepthBiasClamp() const { return mData.depthBiasClamp; }
  65. /**
  66. * @brief Represents a dynamic depth bias that increases as the slope of the rendered polygons
  67. * surface increases. Resulting value offsets depth values of new pixels. This offset will
  68. * be added on top of the constant depth bias.
  69. *
  70. * @note This is useful if you want to avoid z fighting for objects at the same or similar depth.
  71. */
  72. float getSlopeScaledDepthBias() const { return mData.slopeScaledDepthBias; }
  73. /**
  74. * @brief If true, clipping of polygons past the far Z plane is enabled. This ensures proper
  75. * Z ordering for polygons outside of valid depth range (otherwise they all have the same
  76. * depth). It can be useful to disable if you are performing stencil operations that count on
  77. * objects having a front and a back (like stencil shadow) and don't want to clip the back.
  78. */
  79. bool getDepthClipEnable() const { return mData.depthClipEnable; }
  80. /**
  81. * @brief Scissor rectangle allows you to cull all pixels outside of the scissor rectangle.
  82. *
  83. * @see RenderAPICore::setScissorRect
  84. */
  85. bool getScissorEnable() const { return mData.scissorEnable; }
  86. /**
  87. * @brief Determines how are samples in multi-sample render targets handled.
  88. * If disabled all samples in the render target will be written the same value,
  89. * and if enabled each sample will be generated separately.
  90. *
  91. * @note In order to get an antialiased image you need to both enable this option and use
  92. * a MSAA render target.
  93. */
  94. bool getMultisampleEnable() const { return mData.multisampleEnable; }
  95. /**
  96. * @brief Determines should the lines be antialiased. This is separate from multi-sample
  97. * antialiasing setting as lines can be antialiased without multi-sampling.
  98. *
  99. * @note This setting is usually ignored if MSAA is used, as that provides sufficient antialiasing.
  100. */
  101. bool getAntialiasedLineEnable() const { return mData.antialiasedLineEnable; }
  102. protected:
  103. friend class RasterizerState;
  104. friend class RasterizerStateRTTI;
  105. RASTERIZER_STATE_DESC mData;
  106. };
  107. /**
  108. * @brief Core thread version of a rasterizer state.
  109. *
  110. * @see RasterizerState
  111. *
  112. * @note Core thread.
  113. */
  114. class BS_CORE_EXPORT RasterizerStateCore : public CoreObjectCore
  115. {
  116. public:
  117. virtual ~RasterizerStateCore() {}
  118. /**
  119. * @brief Returns information about the rasterizer state.
  120. */
  121. const RasterizerProperties& getProperties() const;
  122. /**
  123. * @brief Returns the default rasterizer state.
  124. */
  125. static const SPtr<RasterizerStateCore>& getDefault();
  126. protected:
  127. friend class RenderStateCoreManager;
  128. RasterizerStateCore(const RASTERIZER_STATE_DESC& desc);
  129. RasterizerProperties mProperties;
  130. };
  131. /**
  132. * @brief Render system pipeline state that allows you to modify how an object is rasterized.
  133. * i.e. how are polygons converted to pixels.
  134. *
  135. * @note Rasterizer states are immutable. Sim thread only.
  136. */
  137. class BS_CORE_EXPORT RasterizerState : public IReflectable, public CoreObject
  138. {
  139. public:
  140. virtual ~RasterizerState() {}
  141. /**
  142. * @brief Returns information about the rasterizer state.
  143. */
  144. const RasterizerProperties& getProperties() const;
  145. /**
  146. * @brief Retrieves a core implementation of the rasterizer state usable only from the
  147. * core thread.
  148. */
  149. SPtr<RasterizerStateCore> getCore() const;
  150. /**
  151. * @brief Creates a new rasterizer state using the specified rasterizer state descriptor structure.
  152. */
  153. static RasterizerStatePtr create(const RASTERIZER_STATE_DESC& desc);
  154. /**
  155. * @brief Returns the default rasterizer state.
  156. */
  157. static const RasterizerStatePtr& getDefault();
  158. protected:
  159. friend class RenderStateManager;
  160. RasterizerState(const RASTERIZER_STATE_DESC& desc);
  161. /**
  162. * @copydoc CoreObjectCore::createCore
  163. */
  164. SPtr<CoreObjectCore> createCore() const;
  165. RasterizerProperties mProperties;
  166. /************************************************************************/
  167. /* RTTI */
  168. /************************************************************************/
  169. public:
  170. friend class RasterizerStateRTTI;
  171. static RTTITypeBase* getRTTIStatic();
  172. virtual RTTITypeBase* getRTTI() const;
  173. };
  174. }