BsRasterizerState.h 5.9 KB

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