SDL_blendmode.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * \file SDL_blendmode.h
  20. *
  21. * Header file declaring the SDL_BlendMode enumeration
  22. */
  23. #ifndef SDL_blendmode_h_
  24. #define SDL_blendmode_h_
  25. #include <SDL3/SDL_begin_code.h>
  26. /* Set up for C function definitions, even when using C++ */
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /**
  31. * An enumeration of blend modes used in drawing operations.
  32. *
  33. * Note that additional values may be obtained from SDL_ComposeCustomBlendMode.
  34. *
  35. * \sa SDL_ComposeCustomBlendMode
  36. *
  37. * \since This enum is available since SDL 3.0.0.
  38. */
  39. typedef enum SDL_BlendMode
  40. {
  41. SDL_BLENDMODE_NONE = 0x00000000, /**< no blending
  42. dstRGBA = srcRGBA */
  43. SDL_BLENDMODE_BLEND = 0x00000001, /**< alpha blending
  44. dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA))
  45. dstA = srcA + (dstA * (1-srcA)) */
  46. SDL_BLENDMODE_ADD = 0x00000002, /**< additive blending
  47. dstRGB = (srcRGB * srcA) + dstRGB
  48. dstA = dstA */
  49. SDL_BLENDMODE_MOD = 0x00000004, /**< color modulate
  50. dstRGB = srcRGB * dstRGB
  51. dstA = dstA */
  52. SDL_BLENDMODE_MUL = 0x00000008, /**< color multiply
  53. dstRGB = (srcRGB * dstRGB) + (dstRGB * (1-srcA))
  54. dstA = dstA */
  55. SDL_BLENDMODE_INVALID = 0x7FFFFFFF
  56. /* Additional custom blend modes can be returned by SDL_ComposeCustomBlendMode() */
  57. } SDL_BlendMode;
  58. /**
  59. * The blend operation used when combining source and destination pixel components.
  60. *
  61. * \since This enum is available since SDL 3.0.0.
  62. */
  63. typedef enum SDL_BlendOperation
  64. {
  65. SDL_BLENDOPERATION_ADD = 0x1, /**< dst + src: supported by all renderers */
  66. SDL_BLENDOPERATION_SUBTRACT = 0x2, /**< src - dst : supported by D3D9, D3D11, OpenGL, OpenGLES */
  67. SDL_BLENDOPERATION_REV_SUBTRACT = 0x3, /**< dst - src : supported by D3D9, D3D11, OpenGL, OpenGLES */
  68. SDL_BLENDOPERATION_MINIMUM = 0x4, /**< min(dst, src) : supported by D3D9, D3D11 */
  69. SDL_BLENDOPERATION_MAXIMUM = 0x5 /**< max(dst, src) : supported by D3D9, D3D11 */
  70. } SDL_BlendOperation;
  71. /**
  72. * The normalized factor used to multiply pixel components.
  73. *
  74. * The blend factors are multiplied with the pixels from a drawing
  75. * operation (src) and the pixels from the render target (dst) before
  76. * the blend operation. The comma-separated factors listed above are always
  77. * applied in the component order red, green, blue, and alpha.
  78. *
  79. * \since This enum is available since SDL 3.0.0.
  80. */
  81. typedef enum SDL_BlendFactor
  82. {
  83. SDL_BLENDFACTOR_ZERO = 0x1, /**< 0, 0, 0, 0 */
  84. SDL_BLENDFACTOR_ONE = 0x2, /**< 1, 1, 1, 1 */
  85. SDL_BLENDFACTOR_SRC_COLOR = 0x3, /**< srcR, srcG, srcB, srcA */
  86. SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR = 0x4, /**< 1-srcR, 1-srcG, 1-srcB, 1-srcA */
  87. SDL_BLENDFACTOR_SRC_ALPHA = 0x5, /**< srcA, srcA, srcA, srcA */
  88. SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA = 0x6, /**< 1-srcA, 1-srcA, 1-srcA, 1-srcA */
  89. SDL_BLENDFACTOR_DST_COLOR = 0x7, /**< dstR, dstG, dstB, dstA */
  90. SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR = 0x8, /**< 1-dstR, 1-dstG, 1-dstB, 1-dstA */
  91. SDL_BLENDFACTOR_DST_ALPHA = 0x9, /**< dstA, dstA, dstA, dstA */
  92. SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA = 0xA /**< 1-dstA, 1-dstA, 1-dstA, 1-dstA */
  93. } SDL_BlendFactor;
  94. /**
  95. * Compose a custom blend mode for renderers.
  96. *
  97. * The functions SDL_SetRenderDrawBlendMode and SDL_SetTextureBlendMode accept
  98. * the SDL_BlendMode returned by this function if the renderer supports it.
  99. *
  100. * A blend mode controls how the pixels from a drawing operation (source) get
  101. * combined with the pixels from the render target (destination). First, the
  102. * components of the source and destination pixels get multiplied with their
  103. * blend factors. Then, the blend operation takes the two products and
  104. * calculates the result that will get stored in the render target.
  105. *
  106. * Expressed in pseudocode, it would look like this:
  107. *
  108. * ```c
  109. * dstRGB = colorOperation(srcRGB * srcColorFactor, dstRGB * dstColorFactor);
  110. * dstA = alphaOperation(srcA * srcAlphaFactor, dstA * dstAlphaFactor);
  111. * ```
  112. *
  113. * Where the functions `colorOperation(src, dst)` and `alphaOperation(src,
  114. * dst)` can return one of the following:
  115. *
  116. * - `src + dst`
  117. * - `src - dst`
  118. * - `dst - src`
  119. * - `min(src, dst)`
  120. * - `max(src, dst)`
  121. *
  122. * The red, green, and blue components are always multiplied with the first,
  123. * second, and third components of the SDL_BlendFactor, respectively. The
  124. * fourth component is not used.
  125. *
  126. * The alpha component is always multiplied with the fourth component of the
  127. * SDL_BlendFactor. The other components are not used in the alpha
  128. * calculation.
  129. *
  130. * Support for these blend modes varies for each renderer. To check if a
  131. * specific SDL_BlendMode is supported, create a renderer and pass it to
  132. * either SDL_SetRenderDrawBlendMode or SDL_SetTextureBlendMode. They will
  133. * return with an error if the blend mode is not supported.
  134. *
  135. * This list describes the support of custom blend modes for each renderer in
  136. * SDL 2.0.6. All renderers support the four blend modes listed in the
  137. * SDL_BlendMode enumeration.
  138. *
  139. * - **direct3d**: Supports all operations with all factors. However, some
  140. * factors produce unexpected results with `SDL_BLENDOPERATION_MINIMUM` and
  141. * `SDL_BLENDOPERATION_MAXIMUM`.
  142. * - **direct3d11**: Same as Direct3D 9.
  143. * - **opengl**: Supports the `SDL_BLENDOPERATION_ADD` operation with all
  144. * factors. OpenGL versions 1.1, 1.2, and 1.3 do not work correctly with SDL
  145. * 2.0.6.
  146. * - **opengles**: Supports the `SDL_BLENDOPERATION_ADD` operation with all
  147. * factors. Color and alpha factors need to be the same. OpenGL ES 1
  148. * implementation specific: May also support `SDL_BLENDOPERATION_SUBTRACT`
  149. * and `SDL_BLENDOPERATION_REV_SUBTRACT`. May support color and alpha
  150. * operations being different from each other. May support color and alpha
  151. * factors being different from each other.
  152. * - **opengles2**: Supports the `SDL_BLENDOPERATION_ADD`,
  153. * `SDL_BLENDOPERATION_SUBTRACT`, `SDL_BLENDOPERATION_REV_SUBTRACT`
  154. * operations with all factors.
  155. * - **psp**: No custom blend mode support.
  156. * - **software**: No custom blend mode support.
  157. *
  158. * Some renderers do not provide an alpha component for the default render
  159. * target. The `SDL_BLENDFACTOR_DST_ALPHA` and
  160. * `SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA` factors do not have an effect in this
  161. * case.
  162. *
  163. * \param srcColorFactor the SDL_BlendFactor applied to the red, green, and
  164. * blue components of the source pixels
  165. * \param dstColorFactor the SDL_BlendFactor applied to the red, green, and
  166. * blue components of the destination pixels
  167. * \param colorOperation the SDL_BlendOperation used to combine the red,
  168. * green, and blue components of the source and
  169. * destination pixels
  170. * \param srcAlphaFactor the SDL_BlendFactor applied to the alpha component of
  171. * the source pixels
  172. * \param dstAlphaFactor the SDL_BlendFactor applied to the alpha component of
  173. * the destination pixels
  174. * \param alphaOperation the SDL_BlendOperation used to combine the alpha
  175. * component of the source and destination pixels
  176. * \returns an SDL_BlendMode that represents the chosen factors and
  177. * operations.
  178. *
  179. * \since This function is available since SDL 3.0.0.
  180. *
  181. * \sa SDL_SetRenderDrawBlendMode
  182. * \sa SDL_GetRenderDrawBlendMode
  183. * \sa SDL_SetTextureBlendMode
  184. * \sa SDL_GetTextureBlendMode
  185. */
  186. extern DECLSPEC SDL_BlendMode SDLCALL SDL_ComposeCustomBlendMode(SDL_BlendFactor srcColorFactor,
  187. SDL_BlendFactor dstColorFactor,
  188. SDL_BlendOperation colorOperation,
  189. SDL_BlendFactor srcAlphaFactor,
  190. SDL_BlendFactor dstAlphaFactor,
  191. SDL_BlendOperation alphaOperation);
  192. /* Ends C function definitions when using C++ */
  193. #ifdef __cplusplus
  194. }
  195. #endif
  196. #include <SDL3/SDL_close_code.h>
  197. #endif /* SDL_blendmode_h_ */