BsBlendState.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsResource.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Structure that describes blend states for a single render
  8. * target. Used internally by BLEND_STATE_DESC for initializing a BlendState.
  9. *
  10. * @see BLEND_STATE_DESC
  11. * @see BlendState
  12. */
  13. struct BS_CORE_EXPORT RENDER_TARGET_BLEND_STATE_DESC
  14. {
  15. RENDER_TARGET_BLEND_STATE_DESC()
  16. : blendEnable(false)
  17. , srcBlend(BF_ONE)
  18. , dstBlend(BF_ZERO)
  19. , blendOp(BO_ADD)
  20. , srcBlendAlpha(BF_ONE)
  21. , dstBlendAlpha(BF_ZERO)
  22. , blendOpAlpha(BO_ADD)
  23. , renderTargetWriteMask(0xFF)
  24. { }
  25. bool blendEnable;
  26. BlendFactor srcBlend;
  27. BlendFactor dstBlend;
  28. BlendOperation blendOp;
  29. BlendFactor srcBlendAlpha;
  30. BlendFactor dstBlendAlpha;
  31. BlendOperation blendOpAlpha;
  32. // Enable write to RGBA channels separately by setting first four bits (0 - R, 1 - G, 2 - B, 3 - A)
  33. UINT8 renderTargetWriteMask;
  34. };
  35. /**
  36. * @brief Structure that describes render pipeline blend states. Used for initializing
  37. * BlendState.
  38. *
  39. * @see BlendState.
  40. */
  41. struct BS_CORE_EXPORT BLEND_STATE_DESC
  42. {
  43. BLEND_STATE_DESC()
  44. : alphaToCoverageEnable(false)
  45. , independantBlendEnable(false)
  46. { }
  47. bool alphaToCoverageEnable;
  48. bool independantBlendEnable;
  49. RENDER_TARGET_BLEND_STATE_DESC renderTargetDesc[BS_MAX_MULTIPLE_RENDER_TARGETS];
  50. };
  51. /**
  52. * @brief Information about a blend state.
  53. */
  54. class BS_CORE_EXPORT BlendProperties
  55. {
  56. public:
  57. BlendProperties(const BLEND_STATE_DESC& desc);
  58. /**
  59. * @brief Alpha to coverage allows you to perform blending without needing to worry about order of
  60. * rendering like regular blending does. It requires multi-sampling to be active in order to
  61. * work, and you need to supply an alpha texture that determines object transparency.
  62. *
  63. * Blending is then performed by only using sub-samples covered by the alpha texture for the current
  64. * pixel and combining them with sub-samples previously stored.
  65. *
  66. * Be aware this is a limited technique only useful for certain situations. Unless you are having performance
  67. * problems use regular blending.
  68. */
  69. bool getAlphaToCoverageEnabled() const { return mData.alphaToCoverageEnable; }
  70. /**
  71. * @brief When not set, only the first render target blend descriptor will be used for all
  72. * render targets. If set each render target will use its own blend descriptor.
  73. */
  74. bool getIndependantBlendEnable() const { return mData.independantBlendEnable; }
  75. /**
  76. * @brief Queries is blending enabled for the specified render target. Blending
  77. * allows you to combine the color from current and previous pixel based on
  78. * some value.
  79. */
  80. bool getBlendEnabled(UINT32 renderTargetIdx) const;
  81. /**
  82. * @brief Determines what should the source blend factor be. This value determines
  83. * what will the color being generated currently be multiplied by.
  84. */
  85. BlendFactor getSrcBlend(UINT32 renderTargetIdx) const;
  86. /**
  87. * @brief Determines what should the destination blend factor be. This value determines
  88. * what will the color already in render target be multiplied by.
  89. */
  90. BlendFactor getDstBlend(UINT32 renderTargetIdx) const;
  91. /**
  92. * @brief Determines how are source and destination colors combined (after they are multiplied
  93. * by their respective blend factors).
  94. */
  95. BlendOperation getBlendOperation(UINT32 renderTargetIdx) const;
  96. /**
  97. * @brief Determines what should the alpha source blend factor be. This value determines
  98. * what will the alpha value being generated currently be multiplied by.
  99. */
  100. BlendFactor getAlphaSrcBlend(UINT32 renderTargetIdx) const;
  101. /**
  102. * @brief Determines what should the alpha destination blend factor be. This value determines
  103. * what will the alpha value already in render target be multiplied by.
  104. */
  105. BlendFactor getAlphaDstBlend(UINT32 renderTargetIdx) const;
  106. /**
  107. * @brief Determines how are source and destination alpha values combined (after they are multiplied
  108. * by their respective blend factors).
  109. */
  110. BlendOperation getAlphaBlendOperation(UINT32 renderTargetIdx) const;
  111. /**
  112. * @brief Render target write mask allows to choose which pixel components should the pixel shader
  113. * output.
  114. *
  115. * Only the first four bits are used. First bit representing red, second green, third blue and
  116. * fourth alpha value. Set bits means pixel shader will output those channels.
  117. */
  118. UINT8 getRenderTargetWriteMask(UINT32 renderTargetIdx) const;
  119. protected:
  120. friend class BlendState;
  121. friend class BlendStateRTTI;
  122. BLEND_STATE_DESC mData;
  123. };
  124. /**
  125. * @brief Core thread version of a blend state.
  126. *
  127. * @see BlendState
  128. *
  129. * @note Core thread.
  130. */
  131. class BS_CORE_EXPORT BlendStateCore : public CoreObjectCore
  132. {
  133. public:
  134. virtual ~BlendStateCore() {}
  135. /**
  136. * @brief Returns information about the blend state.
  137. */
  138. const BlendProperties& getProperties() const;
  139. /**
  140. * @brief Returns the default blend state that you may use
  141. * when no other is available.
  142. */
  143. static const SPtr<BlendStateCore>& getDefault();
  144. protected:
  145. friend class RenderStateCoreManager;
  146. BlendStateCore(const BLEND_STATE_DESC& desc);
  147. BlendProperties mProperties;
  148. };
  149. /**
  150. * @brief Render system pipeline state that allows you to modify how an object is rendered.
  151. * More exactly this state allows to you to control how is a rendered
  152. * object blended with any previously renderer objects.
  153. *
  154. * @note Blend states are immutable. Sim thread only.
  155. */
  156. class BS_CORE_EXPORT BlendState : public IReflectable, public CoreObject
  157. {
  158. public:
  159. virtual ~BlendState() {}
  160. /**
  161. * @brief Returns information about a blend state.
  162. */
  163. const BlendProperties& getProperties() const;
  164. /**
  165. * @brief Retrieves a core implementation of the sampler state usable only from the
  166. * core thread.
  167. */
  168. SPtr<BlendStateCore> getCore() const;
  169. /**
  170. * @brief Creates a new blend state using the specified blend state description structure.
  171. */
  172. static BlendStatePtr create(const BLEND_STATE_DESC& desc);
  173. /**
  174. * @brief Returns the default blend state that you may use
  175. * when no other is available.
  176. */
  177. static const BlendStatePtr& getDefault();
  178. protected:
  179. friend class RenderStateManager;
  180. BlendState(const BLEND_STATE_DESC& desc);
  181. /**
  182. * @copydoc CoreObjectCore::createCore
  183. */
  184. SPtr<CoreObjectCore> createCore() const;
  185. BlendProperties mProperties;
  186. /************************************************************************/
  187. /* RTTI */
  188. /************************************************************************/
  189. public:
  190. friend class BlendStateRTTI;
  191. static RTTITypeBase* getRTTIStatic();
  192. virtual RTTITypeBase* getRTTI() const;
  193. };
  194. }