BsBlendState.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 Render system pipeline state that allows you to modify how an object is rendered.
  53. * More exactly this state allows to you to control how is a rendered
  54. * object blended with any previously renderer objects.
  55. *
  56. * @note Blend states are immutable. Thread safe.
  57. */
  58. class BS_CORE_EXPORT BlendState : public Resource
  59. {
  60. public:
  61. virtual ~BlendState() {}
  62. /**
  63. * @brief Alpha to coverage allows you to perform blending without needing to worry about order of
  64. * rendering like regular blending does. It requires multi-sampling to be active in order to
  65. * work, and you need to supply an alpha texture that determines object transparency.
  66. *
  67. * Blending is then performed by only using sub-samples covered by the alpha texture for the current
  68. * pixel and combining them with sub-samples previously stored.
  69. *
  70. * Be aware this is a limited technique only useful for certain situations. Unless you are having performance
  71. * problems use regular blending.
  72. */
  73. bool getAlphaToCoverageEnabled() const { return mData.alphaToCoverageEnable; }
  74. /**
  75. * @brief When not set, only the first render target blend descriptor will be used for all
  76. * render targets. If set each render target will use its own blend descriptor.
  77. */
  78. bool getIndependantBlendEnable() const { return mData.independantBlendEnable; }
  79. /**
  80. * @brief Queries is blending enabled for the specified render target. Blending
  81. * allows you to combine the color from current and previous pixel based on
  82. * some value.
  83. */
  84. bool getBlendEnabled(UINT32 renderTargetIdx) const;
  85. /**
  86. * @brief Determines what should the source blend factor be. This value determines
  87. * what will the color being generated currently be multiplied by.
  88. */
  89. BlendFactor getSrcBlend(UINT32 renderTargetIdx) const;
  90. /**
  91. * @brief Determines what should the destination blend factor be. This value determines
  92. * what will the color already in render target be multiplied by.
  93. */
  94. BlendFactor getDstBlend(UINT32 renderTargetIdx) const;
  95. /**
  96. * @brief Determines how are source and destination colors combined (after they are multiplied
  97. * by their respective blend factors).
  98. */
  99. BlendOperation getBlendOperation(UINT32 renderTargetIdx) const;
  100. /**
  101. * @brief Determines what should the alpha source blend factor be. This value determines
  102. * what will the alpha value being generated currently be multiplied by.
  103. */
  104. BlendFactor getAlphaSrcBlend(UINT32 renderTargetIdx) const;
  105. /**
  106. * @brief Determines what should the alpha destination blend factor be. This value determines
  107. * what will the alpha value already in render target be multiplied by.
  108. */
  109. BlendFactor getAlphaDstBlend(UINT32 renderTargetIdx) const;
  110. /**
  111. * @brief Determines how are source and destination alpha values combined (after they are multiplied
  112. * by their respective blend factors).
  113. */
  114. BlendOperation getAlphaBlendOperation(UINT32 renderTargetIdx) const;
  115. /**
  116. * @brief Render target write mask allows to choose which pixel components should the pixel shader
  117. * output.
  118. *
  119. * Only the first four bits are used. First bit representing red, second green, third blue and
  120. * fourth alpha value. Set bits means pixel shader will output those channels.
  121. */
  122. UINT8 getRenderTargetWriteMask(UINT32 renderTargetIdx) const;
  123. /**
  124. * @brief Creates a new blend state using the specified blend state description structure.
  125. */
  126. static HBlendState create(const BLEND_STATE_DESC& desc);
  127. /**
  128. * @brief Returns the default blend state that you may use
  129. * when no other is available.
  130. */
  131. static const BlendStatePtr& getDefault();
  132. protected:
  133. friend class RenderStateManager;
  134. /**
  135. * @brief Initializes the blend state. Must be called right after construction.
  136. */
  137. virtual void initialize(const BLEND_STATE_DESC& desc);
  138. BLEND_STATE_DESC mData;
  139. /************************************************************************/
  140. /* RTTI */
  141. /************************************************************************/
  142. public:
  143. friend class BlendStateRTTI;
  144. static RTTITypeBase* getRTTIStatic();
  145. virtual RTTITypeBase* getRTTI() const;
  146. };
  147. }