Skip to content

Commit a9c923c

Browse files
Add SDL_blendmode.inc
1 parent c94c267 commit a9c923c

File tree

1 file changed

+173
-0
lines changed

1 file changed

+173
-0
lines changed

units/SDL_blendmode.inc

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
{
2+
This file is part of:
3+
4+
SDL3 for Pascal
5+
(https://github.com/PascalGameDevelopment/SDL3-for-Pascal)
6+
SPDX-License-Identifier: Zlib
7+
}
8+
9+
{*
10+
* A set of blend modes used in drawing operations.
11+
*
12+
* These predefined blend modes are supported everywhere.
13+
*
14+
* Additional values may be obtained from SDL_ComposeCustomBlendMode.
15+
*
16+
* \since This datatype is available since SDL 3.1.3.
17+
*
18+
* \sa SDL_ComposeCustomBlendMode
19+
}
20+
type
21+
PPSDL_BlendMode = ^PSDL_BlendMode;
22+
PSDL_BlendMode = ^TSDL_BlendMode;
23+
TSDL_BlendMode = cuint32;
24+
25+
const
26+
SDL_BLENDMODE_NONE = TSDL_BlendMode($00000000); {*< no blending: dstRGBA = srcRGBA }
27+
SDL_BLENDMODE_BLEND = TSDL_BlendMode($00000001); {*< alpha blending: dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA)), dstA = srcA + (dstA * (1-srcA)) }
28+
SDL_BLENDMODE_BLEND_PREMULTIPLIED = TSDL_BlendMode($00000010); {*< pre-multiplied alpha blending: dstRGBA = srcRGBA + (dstRGBA * (1-srcA)) }
29+
SDL_BLENDMODE_ADD = TSDL_BlendMode($00000002); {*< additive blending: dstRGB = (srcRGB * srcA) + dstRGB, dstA = dstA }
30+
SDL_BLENDMODE_ADD_PREMULTIPLIED = TSDL_BlendMode($00000020); {*< pre-multiplied additive blending: dstRGB = srcRGB + dstRGB, dstA = dstA }
31+
SDL_BLENDMODE_MOD = TSDL_BlendMode($00000004); {*< color modulate: dstRGB = srcRGB * dstRGB, dstA = dstA }
32+
SDL_BLENDMODE_MUL = TSDL_BlendMode($00000008); {*< color multiply: dstRGB = (srcRGB * dstRGB) + (dstRGB * (1-srcA)), dstA = dstA }
33+
SDL_BLENDMODE_INVALID = TSDL_BlendMode($7FFFFFFF);
34+
35+
{*
36+
* The blend operation used when combining source and destination pixel
37+
* components.
38+
*
39+
* \since This enum is available since SDL 3.1.3.
40+
}
41+
type
42+
PPSDL_BlendOperation = ^PSDL_BlendOperation;
43+
PSDL_BlendOperation = ^TSDL_BlendOperation;
44+
TSDL_BlendOperation = Integer;
45+
const
46+
SDL_BLENDOPERATION_ADD = TSDL_BlendOperation($1); {*< dst + src: supported by all renderers }
47+
SDL_BLENDOPERATION_SUBTRACT = TSDL_BlendOperation($2); {*< src - dst: supported by D3D, OpenGL, OpenGLES, and Vulkan }
48+
SDL_BLENDOPERATION_REV_SUBTRACT = TSDL_BlendOperation($3); {*< dst - src: supported by D3D, OpenGL, OpenGLES, and Vulkan }
49+
SDL_BLENDOPERATION_MINIMUM = TSDL_BlendOperation($4); {*< min(dst, src): supported by D3D, OpenGL, OpenGLES, and Vulkan }
50+
SDL_BLENDOPERATION_MAXIMUM = TSDL_BlendOperation($5); {*< max(dst, src): supported by D3D, OpenGL, OpenGLES, and Vulkan }
51+
52+
{*
53+
* The normalized factor used to multiply pixel components.
54+
*
55+
* The blend factors are multiplied with the pixels from a drawing operation
56+
* (src) and the pixels from the render target (dst) before the blend
57+
* operation. The comma-separated factors listed above are always applied in
58+
* the component order red, green, blue, and alpha.
59+
*
60+
* \since This enum is available since SDL 3.1.3.
61+
}
62+
type
63+
PPSDL_BlendFactor = ^PSDL_BlendFactor;
64+
PSDL_BlendFactor = ^TSDL_BlendFactor;
65+
TSDL_BlendFactor = Integer;
66+
const
67+
SDL_BLENDFACTOR_ZERO = TSDL_BlendFactor($1); {*< 0, 0, 0, 0 }
68+
SDL_BLENDFACTOR_ONE = TSDL_BlendFactor($2); {*< 1, 1, 1, 1 }
69+
SDL_BLENDFACTOR_SRC_COLOR = TSDL_BlendFactor($3); {*< srcR, srcG, srcB, srcA }
70+
SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR = TSDL_BlendFactor($4); {*< 1-srcR, 1-srcG, 1-srcB, 1-srcA }
71+
SDL_BLENDFACTOR_SRC_ALPHA = TSDL_BlendFactor($5); {*< srcA, srcA, srcA, srcA }
72+
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA = TSDL_BlendFactor($6); {*< 1-srcA, 1-srcA, 1-srcA, 1-srcA }
73+
SDL_BLENDFACTOR_DST_COLOR = TSDL_BlendFactor($7); {*< dstR, dstG, dstB, dstA }
74+
SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR = TSDL_BlendFactor($8); {*< 1-dstR, 1-dstG, 1-dstB, 1-dstA }
75+
SDL_BLENDFACTOR_DST_ALPHA = TSDL_BlendFactor($9); {*< dstA, dstA, dstA, dstA }
76+
SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA = TSDL_BlendFactor($A); {*< 1-dstA, 1-dstA, 1-dstA, 1-dstA }
77+
78+
{*
79+
* Compose a custom blend mode for renderers.
80+
*
81+
* The functions SDL_SetRenderDrawBlendMode and SDL_SetTextureBlendMode accept
82+
* the SDL_BlendMode returned by this function if the renderer supports it.
83+
*
84+
* A blend mode controls how the pixels from a drawing operation (source) get
85+
* combined with the pixels from the render target (destination). First, the
86+
* components of the source and destination pixels get multiplied with their
87+
* blend factors. Then, the blend operation takes the two products and
88+
* calculates the result that will get stored in the render target.
89+
*
90+
* Expressed in pseudocode, it would look like this:
91+
*
92+
* ```c
93+
* dstRGB = colorOperation(srcRGB * srcColorFactor, dstRGB * dstColorFactor);
94+
* dstA = alphaOperation(srcA * srcAlphaFactor, dstA * dstAlphaFactor);
95+
* ```
96+
*
97+
* Where the functions `colorOperation(src, dst)` and `alphaOperation(src,
98+
* dst)` can return one of the following:
99+
*
100+
* - `src + dst`
101+
* - `src - dst`
102+
* - `dst - src`
103+
* - `min(src, dst)`
104+
* - `max(src, dst)`
105+
*
106+
* The red, green, and blue components are always multiplied with the first,
107+
* second, and third components of the SDL_BlendFactor, respectively. The
108+
* fourth component is not used.
109+
*
110+
* The alpha component is always multiplied with the fourth component of the
111+
* SDL_BlendFactor. The other components are not used in the alpha
112+
* calculation.
113+
*
114+
* Support for these blend modes varies for each renderer. To check if a
115+
* specific SDL_BlendMode is supported, create a renderer and pass it to
116+
* either SDL_SetRenderDrawBlendMode or SDL_SetTextureBlendMode. They will
117+
* return with an error if the blend mode is not supported.
118+
*
119+
* This list describes the support of custom blend modes for each renderer.
120+
* All renderers support the four blend modes listed in the SDL_BlendMode
121+
* enumeration.
122+
*
123+
* - **direct3d**: Supports all operations with all factors. However, some
124+
* factors produce unexpected results with `SDL_BLENDOPERATION_MINIMUM` and
125+
* `SDL_BLENDOPERATION_MAXIMUM`.
126+
* - **direct3d11**: Same as Direct3D 9.
127+
* - **opengl**: Supports the `SDL_BLENDOPERATION_ADD` operation with all
128+
* factors. OpenGL versions 1.1, 1.2, and 1.3 do not work correctly here.
129+
* - **opengles2**: Supports the `SDL_BLENDOPERATION_ADD`,
130+
* `SDL_BLENDOPERATION_SUBTRACT`, `SDL_BLENDOPERATION_REV_SUBTRACT`
131+
* operations with all factors.
132+
* - **psp**: No custom blend mode support.
133+
* - **software**: No custom blend mode support.
134+
*
135+
* Some renderers do not provide an alpha component for the default render
136+
* target. The `SDL_BLENDFACTOR_DST_ALPHA` and
137+
* `SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA` factors do not have an effect in this
138+
* case.
139+
*
140+
* \param srcColorFactor the SDL_BlendFactor applied to the red, green, and
141+
* blue components of the source pixels.
142+
* \param dstColorFactor the SDL_BlendFactor applied to the red, green, and
143+
* blue components of the destination pixels.
144+
* \param colorOperation the SDL_BlendOperation used to combine the red,
145+
* green, and blue components of the source and
146+
* destination pixels.
147+
* \param srcAlphaFactor the SDL_BlendFactor applied to the alpha component of
148+
* the source pixels.
149+
* \param dstAlphaFactor the SDL_BlendFactor applied to the alpha component of
150+
* the destination pixels.
151+
* \param alphaOperation the SDL_BlendOperation used to combine the alpha
152+
* component of the source and destination pixels.
153+
* \returns an SDL_BlendMode that represents the chosen factors and
154+
* operations.
155+
*
156+
* \threadsafety It is safe to call this function from any thread.
157+
*
158+
* \since This function is available since SDL 3.1.3.
159+
*
160+
* \sa SDL_SetRenderDrawBlendMode
161+
* \sa SDL_GetRenderDrawBlendMode
162+
* \sa SDL_SetTextureBlendMode
163+
* \sa SDL_GetTextureBlendMode
164+
}
165+
function SDL_ComposeCustomBlendMode(
166+
srcColorFactor: TSDL_BlendFactor;
167+
dstColorFactor: TSDL_BlendFactor;
168+
colorOperation: TSDL_BlendOperation;
169+
srcAlphaFactor: TSDL_BlendFactor;
170+
dstAlphaFactor: TSDL_BlendFactor;
171+
alphaOperation: TSDL_BlendOperation): TSDL_BlendMode; cdecl;
172+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ComposeCustomBlendMode' {$ENDIF} {$ENDIF};
173+

0 commit comments

Comments
 (0)