🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
8.8 KiB

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
  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 "begin_code.h"
  26. /* Set up for C function definitions, even when using C++ */
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /**
  31. * \brief The blend mode used in SDL_RenderCopy() and drawing operations.
  32. */
  33. typedef enum
  34. {
  35. SDL_BLENDMODE_NONE = 0x00000000, /**< no blending
  36. dstRGBA = srcRGBA */
  37. SDL_BLENDMODE_BLEND = 0x00000001, /**< alpha blending
  38. dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA))
  39. dstA = srcA + (dstA * (1-srcA)) */
  40. SDL_BLENDMODE_ADD = 0x00000002, /**< additive blending
  41. dstRGB = (srcRGB * srcA) + dstRGB
  42. dstA = dstA */
  43. SDL_BLENDMODE_MOD = 0x00000004, /**< color modulate
  44. dstRGB = srcRGB * dstRGB
  45. dstA = dstA */
  46. SDL_BLENDMODE_MUL = 0x00000008, /**< color multiply
  47. dstRGB = (srcRGB * dstRGB) + (dstRGB * (1-srcA))
  48. dstA = (srcA * dstA) + (dstA * (1-srcA)) */
  49. SDL_BLENDMODE_INVALID = 0x7FFFFFFF
  50. /* Additional custom blend modes can be returned by SDL_ComposeCustomBlendMode() */
  51. } SDL_BlendMode;
  52. /**
  53. * \brief The blend operation used when combining source and destination pixel components
  54. */
  55. typedef enum
  56. {
  57. SDL_BLENDOPERATION_ADD = 0x1, /**< dst + src: supported by all renderers */
  58. SDL_BLENDOPERATION_SUBTRACT = 0x2, /**< dst - src : supported by D3D9, D3D11, OpenGL, OpenGLES */
  59. SDL_BLENDOPERATION_REV_SUBTRACT = 0x3, /**< src - dst : supported by D3D9, D3D11, OpenGL, OpenGLES */
  60. SDL_BLENDOPERATION_MINIMUM = 0x4, /**< min(dst, src) : supported by D3D9, D3D11 */
  61. SDL_BLENDOPERATION_MAXIMUM = 0x5 /**< max(dst, src) : supported by D3D9, D3D11 */
  62. } SDL_BlendOperation;
  63. /**
  64. * \brief The normalized factor used to multiply pixel components
  65. */
  66. typedef enum
  67. {
  68. SDL_BLENDFACTOR_ZERO = 0x1, /**< 0, 0, 0, 0 */
  69. SDL_BLENDFACTOR_ONE = 0x2, /**< 1, 1, 1, 1 */
  70. SDL_BLENDFACTOR_SRC_COLOR = 0x3, /**< srcR, srcG, srcB, srcA */
  71. SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR = 0x4, /**< 1-srcR, 1-srcG, 1-srcB, 1-srcA */
  72. SDL_BLENDFACTOR_SRC_ALPHA = 0x5, /**< srcA, srcA, srcA, srcA */
  73. SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA = 0x6, /**< 1-srcA, 1-srcA, 1-srcA, 1-srcA */
  74. SDL_BLENDFACTOR_DST_COLOR = 0x7, /**< dstR, dstG, dstB, dstA */
  75. SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR = 0x8, /**< 1-dstR, 1-dstG, 1-dstB, 1-dstA */
  76. SDL_BLENDFACTOR_DST_ALPHA = 0x9, /**< dstA, dstA, dstA, dstA */
  77. SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA = 0xA /**< 1-dstA, 1-dstA, 1-dstA, 1-dstA */
  78. } SDL_BlendFactor;
  79. /**
  80. * Compose a custom blend mode for renderers.
  81. *
  82. * The functions SDL_SetRenderDrawBlendMode and SDL_SetTextureBlendMode accept
  83. * the SDL_BlendMode returned by this function if the renderer supports it.
  84. *
  85. * A blend mode controls how the pixels from a drawing operation (source) get
  86. * combined with the pixels from the render target (destination). First, the
  87. * components of the source and destination pixels get multiplied with their
  88. * blend factors. Then, the blend operation takes the two products and
  89. * calculates the result that will get stored in the render target.
  90. *
  91. * Expressed in pseudocode, it would look like this:
  92. *
  93. * ```c
  94. * dstRGB = colorOperation(srcRGB * srcColorFactor, dstRGB * dstColorFactor);
  95. * dstA = alphaOperation(srcA * srcAlphaFactor, dstA * dstAlphaFactor);
  96. * ```
  97. *
  98. * Where the functions `colorOperation(src, dst)` and `alphaOperation(src,
  99. * dst)` can return one of the following:
  100. *
  101. * - `src + dst`
  102. * - `src - dst`
  103. * - `dst - src`
  104. * - `min(src, dst)`
  105. * - `max(src, dst)`
  106. *
  107. * The red, green, and blue components are always multiplied with the first,
  108. * second, and third components of the SDL_BlendFactor, respectively. The
  109. * fourth component is not used.
  110. *
  111. * The alpha component is always multiplied with the fourth component of the
  112. * SDL_BlendFactor. The other components are not used in the alpha
  113. * calculation.
  114. *
  115. * Support for these blend modes varies for each renderer. To check if a
  116. * specific SDL_BlendMode is supported, create a renderer and pass it to
  117. * either SDL_SetRenderDrawBlendMode or SDL_SetTextureBlendMode. They will
  118. * return with an error if the blend mode is not supported.
  119. *
  120. * This list describes the support of custom blend modes for each renderer in
  121. * SDL 2.0.6. All renderers support the four blend modes listed in the
  122. * SDL_BlendMode enumeration.
  123. *
  124. * - **direct3d**: Supports all operations with all factors. However, some
  125. * factors produce unexpected results with `SDL_BLENDOPERATION_MINIMUM` and
  126. * `SDL_BLENDOPERATION_MAXIMUM`.
  127. * - **direct3d11**: Same as Direct3D 9.
  128. * - **opengl**: Supports the `SDL_BLENDOPERATION_ADD` operation with all
  129. * factors. OpenGL versions 1.1, 1.2, and 1.3 do not work correctly with SDL
  130. * 2.0.6.
  131. * - **opengles**: Supports the `SDL_BLENDOPERATION_ADD` operation with all
  132. * factors. Color and alpha factors need to be the same. OpenGL ES 1
  133. * implementation specific: May also support `SDL_BLENDOPERATION_SUBTRACT`
  134. * and `SDL_BLENDOPERATION_REV_SUBTRACT`. May support color and alpha
  135. * operations being different from each other. May support color and alpha
  136. * factors being different from each other.
  137. * - **opengles2**: Supports the `SDL_BLENDOPERATION_ADD`,
  138. * `SDL_BLENDOPERATION_SUBTRACT`, `SDL_BLENDOPERATION_REV_SUBTRACT`
  139. * operations with all factors.
  140. * - **psp**: No custom blend mode support.
  141. * - **software**: No custom blend mode support.
  142. *
  143. * Some renderers do not provide an alpha component for the default render
  144. * target. The `SDL_BLENDFACTOR_DST_ALPHA` and
  145. * `SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA` factors do not have an effect in this
  146. * case.
  147. *
  148. * \param srcColorFactor the SDL_BlendFactor applied to the red, green, and
  149. * blue components of the source pixels
  150. * \param dstColorFactor the SDL_BlendFactor applied to the red, green, and
  151. * blue components of the destination pixels
  152. * \param colorOperation the SDL_BlendOperation used to combine the red,
  153. * green, and blue components of the source and
  154. * destination pixels
  155. * \param srcAlphaFactor the SDL_BlendFactor applied to the alpha component of
  156. * the source pixels
  157. * \param dstAlphaFactor the SDL_BlendFactor applied to the alpha component of
  158. * the destination pixels
  159. * \param alphaOperation the SDL_BlendOperation used to combine the alpha
  160. * component of the source and destination pixels
  161. * \returns an SDL_BlendMode that represents the chosen factors and
  162. * operations.
  163. *
  164. * \since This function is available since SDL 2.0.6.
  165. *
  166. * \sa SDL_SetRenderDrawBlendMode
  167. * \sa SDL_GetRenderDrawBlendMode
  168. * \sa SDL_SetTextureBlendMode
  169. * \sa SDL_GetTextureBlendMode
  170. */
  171. extern DECLSPEC SDL_BlendMode SDLCALL SDL_ComposeCustomBlendMode(SDL_BlendFactor srcColorFactor,
  172. SDL_BlendFactor dstColorFactor,
  173. SDL_BlendOperation colorOperation,
  174. SDL_BlendFactor srcAlphaFactor,
  175. SDL_BlendFactor dstAlphaFactor,
  176. SDL_BlendOperation alphaOperation);
  177. /* Ends C function definitions when using C++ */
  178. #ifdef __cplusplus
  179. }
  180. #endif
  181. #include "close_code.h"
  182. #endif /* SDL_blendmode_h_ */
  183. /* vi: set ts=4 sw=4 expandtab: */