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