CmRasterizerState.h 4.9 KB

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