BsRasterizerState.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 Render system pipeline state that allows you to modify how an object is rasterized.
  37. * i.e. how are polygons converted to pixels.
  38. *
  39. * @note Rasterizer states are immutable. Thread safe.
  40. */
  41. class BS_CORE_EXPORT RasterizerState : public Resource
  42. {
  43. public:
  44. virtual ~RasterizerState() {}
  45. /**
  46. * @brief Polygon mode allows you to draw polygons as solid objects or as wireframe by
  47. * just drawing their edges.
  48. */
  49. PolygonMode getPolygonMode() const { return mData.polygonMode; }
  50. /**
  51. * @brief Sets vertex winding order. Faces that contain vertices with this order will
  52. * be culled and not rasterized. Used primarily for saving cycles by not rendering
  53. * backfacing faces.
  54. */
  55. CullingMode getCullMode() const { return mData.cullMode; }
  56. /**
  57. * @brief Represents a constant depth bias that will offset the depth values of new pixels
  58. * by the specified amount.
  59. *
  60. * @note This is useful if you want to avoid z fighting for objects at the same or similar depth.
  61. */
  62. int getDepthBias() const { return mData.depthBias; }
  63. /**
  64. * @brief Maximum depth bias value.
  65. */
  66. float getDepthBiasClamp() const { return mData.depthBiasClamp; }
  67. /**
  68. * @brief Represents a dynamic depth bias that increases as the slope of the rendered polygons
  69. * surface increases. Resulting value offsets depth values of new pixels. This offset will
  70. * be added on top of the constant depth bias.
  71. *
  72. * @note This is useful if you want to avoid z fighting for objects at the same or similar depth.
  73. */
  74. float getSlopeScaledDepthBias() const { return mData.slopeScaledDepthBias; }
  75. /**
  76. * @brief If true, clipping of polygons past the far Z plane is enabled. This ensures proper
  77. * Z ordering for polygons outside of valid depth range (otherwise they all have the same
  78. * depth). It can be useful to disable if you are performing stencil operations that count on
  79. * objects having a front and a back (like stencil shadow) and don't want to clip the back.
  80. */
  81. bool getDepthClipEnable() const { return mData.depthClipEnable; }
  82. /**
  83. * @brief Scissor rectangle allows you to cull all pixels outside of the scissor rectangle.
  84. *
  85. * @see RenderSystem::setScissorRect
  86. */
  87. bool getScissorEnable() const { return mData.scissorEnable; }
  88. /**
  89. * @brief Determines how are samples in multi-sample render targets handled.
  90. * If disabled all samples in the render target will be written the same value,
  91. * and if enabled each sample will be generated separately.
  92. *
  93. * @note In order to get an antialiased image you need to both enable this option and use
  94. * a MSAA render target.
  95. */
  96. bool getMultisampleEnable() const { return mData.multisampleEnable; }
  97. /**
  98. * @brief Determines should the lines be antialiased. This is separate from multi-sample
  99. * antialiasing setting as lines can be antialiased without multi-sampling.
  100. *
  101. * @note This setting is usually ignored if MSAA is used, as that provides sufficient antialiasing.
  102. */
  103. bool getAntialiasedLineEnable() const { return mData.antialiasedLineEnable; }
  104. /**
  105. * @brief Creates a new rasterizer state using the specified rasterizer state descriptor structure.
  106. */
  107. static HRasterizerState create(const RASTERIZER_STATE_DESC& desc);
  108. /**
  109. * @brief Returns the default rasterizer state.
  110. */
  111. static const RasterizerStatePtr& getDefault();
  112. protected:
  113. friend class RenderStateManager;
  114. /**
  115. * @brief Initializes the rasterizer state. Must be called right after construction.
  116. */
  117. virtual void initialize(const RASTERIZER_STATE_DESC& desc);
  118. RASTERIZER_STATE_DESC mData;
  119. /************************************************************************/
  120. /* RTTI */
  121. /************************************************************************/
  122. public:
  123. friend class RasterizerStateRTTI;
  124. static RTTITypeBase* getRTTIStatic();
  125. virtual RTTITypeBase* getRTTI() const;
  126. };
  127. }