sdl3_sys/generated/blendmode.rs
1//! Blend modes decide how two colors will mix together. There are both
2//! standard modes for basic needs and a means to create custom modes,
3//! dictating what sort of math to do on what color components.
4
5use super::stdinc::*;
6
7/// A set of blend modes used in drawing operations.
8///
9/// These predefined blend modes are supported everywhere.
10///
11/// Additional values may be obtained from [`SDL_ComposeCustomBlendMode`].
12///
13/// ## Availability
14/// This datatype is available since SDL 3.2.0.
15///
16/// ## See also
17/// - [`SDL_ComposeCustomBlendMode`]
18///
19/// ## Known values (`sdl3-sys`)
20/// | Associated constant | Global constant | Description |
21/// | ------------------- | --------------- | ----------- |
22/// | [`NONE`](SDL_BlendMode::NONE) | [`SDL_BLENDMODE_NONE`] | no blending: dstRGBA = srcRGBA |
23/// | [`BLEND`](SDL_BlendMode::BLEND) | [`SDL_BLENDMODE_BLEND`] | alpha blending: dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA)), dstA = srcA + (dstA * (1-srcA)) |
24/// | [`BLEND_PREMULTIPLIED`](SDL_BlendMode::BLEND_PREMULTIPLIED) | [`SDL_BLENDMODE_BLEND_PREMULTIPLIED`] | pre-multiplied alpha blending: dstRGBA = srcRGBA + (dstRGBA * (1-srcA)) |
25/// | [`ADD`](SDL_BlendMode::ADD) | [`SDL_BLENDMODE_ADD`] | additive blending: dstRGB = (srcRGB * srcA) + dstRGB, dstA = dstA |
26/// | [`ADD_PREMULTIPLIED`](SDL_BlendMode::ADD_PREMULTIPLIED) | [`SDL_BLENDMODE_ADD_PREMULTIPLIED`] | pre-multiplied additive blending: dstRGB = srcRGB + dstRGB, dstA = dstA |
27/// | [`MOD`](SDL_BlendMode::MOD) | [`SDL_BLENDMODE_MOD`] | color modulate: dstRGB = srcRGB * dstRGB, dstA = dstA |
28/// | [`MUL`](SDL_BlendMode::MUL) | [`SDL_BLENDMODE_MUL`] | color multiply: dstRGB = (srcRGB * dstRGB) + (dstRGB * (1-srcA)), dstA = dstA |
29/// | [`INVALID`](SDL_BlendMode::INVALID) | [`SDL_BLENDMODE_INVALID`] | |
30#[repr(transparent)]
31#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
32pub struct SDL_BlendMode(pub Uint32);
33
34impl ::core::cmp::PartialEq<Uint32> for SDL_BlendMode {
35 #[inline(always)]
36 fn eq(&self, other: &Uint32) -> bool {
37 &self.0 == other
38 }
39}
40
41impl ::core::cmp::PartialEq<SDL_BlendMode> for Uint32 {
42 #[inline(always)]
43 fn eq(&self, other: &SDL_BlendMode) -> bool {
44 self == &other.0
45 }
46}
47
48impl From<SDL_BlendMode> for Uint32 {
49 #[inline(always)]
50 fn from(value: SDL_BlendMode) -> Self {
51 value.0
52 }
53}
54
55#[cfg(feature = "debug-impls")]
56impl ::core::fmt::Debug for SDL_BlendMode {
57 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
58 let mut first = true;
59 let all_bits = 0;
60 write!(f, "SDL_BlendMode(")?;
61 let all_bits = all_bits | Self::NONE.0;
62 if (Self::NONE != 0 || self.0 == 0) && *self & Self::NONE == Self::NONE {
63 if !first {
64 write!(f, " | ")?;
65 }
66 first = false;
67 write!(f, "NONE")?;
68 }
69 let all_bits = all_bits | Self::BLEND.0;
70 if (Self::BLEND != 0 || self.0 == 0) && *self & Self::BLEND == Self::BLEND {
71 if !first {
72 write!(f, " | ")?;
73 }
74 first = false;
75 write!(f, "BLEND")?;
76 }
77 let all_bits = all_bits | Self::BLEND_PREMULTIPLIED.0;
78 if (Self::BLEND_PREMULTIPLIED != 0 || self.0 == 0)
79 && *self & Self::BLEND_PREMULTIPLIED == Self::BLEND_PREMULTIPLIED
80 {
81 if !first {
82 write!(f, " | ")?;
83 }
84 first = false;
85 write!(f, "BLEND_PREMULTIPLIED")?;
86 }
87 let all_bits = all_bits | Self::ADD.0;
88 if (Self::ADD != 0 || self.0 == 0) && *self & Self::ADD == Self::ADD {
89 if !first {
90 write!(f, " | ")?;
91 }
92 first = false;
93 write!(f, "ADD")?;
94 }
95 let all_bits = all_bits | Self::ADD_PREMULTIPLIED.0;
96 if (Self::ADD_PREMULTIPLIED != 0 || self.0 == 0)
97 && *self & Self::ADD_PREMULTIPLIED == Self::ADD_PREMULTIPLIED
98 {
99 if !first {
100 write!(f, " | ")?;
101 }
102 first = false;
103 write!(f, "ADD_PREMULTIPLIED")?;
104 }
105 let all_bits = all_bits | Self::MOD.0;
106 if (Self::MOD != 0 || self.0 == 0) && *self & Self::MOD == Self::MOD {
107 if !first {
108 write!(f, " | ")?;
109 }
110 first = false;
111 write!(f, "MOD")?;
112 }
113 let all_bits = all_bits | Self::MUL.0;
114 if (Self::MUL != 0 || self.0 == 0) && *self & Self::MUL == Self::MUL {
115 if !first {
116 write!(f, " | ")?;
117 }
118 first = false;
119 write!(f, "MUL")?;
120 }
121 let all_bits = all_bits | Self::INVALID.0;
122 if (Self::INVALID != 0 || self.0 == 0) && *self & Self::INVALID == Self::INVALID {
123 if !first {
124 write!(f, " | ")?;
125 }
126 first = false;
127 write!(f, "INVALID")?;
128 }
129
130 if self.0 & !all_bits != 0 {
131 if !first {
132 write!(f, " | ")?;
133 }
134 write!(f, "{:#x}", self.0)?;
135 } else if first {
136 write!(f, "0")?;
137 }
138 write!(f, ")")
139 }
140}
141
142impl ::core::ops::BitAnd for SDL_BlendMode {
143 type Output = Self;
144
145 #[inline(always)]
146 fn bitand(self, rhs: Self) -> Self::Output {
147 Self(self.0 & rhs.0)
148 }
149}
150
151impl ::core::ops::BitAndAssign for SDL_BlendMode {
152 #[inline(always)]
153 fn bitand_assign(&mut self, rhs: Self) {
154 self.0 &= rhs.0;
155 }
156}
157
158impl ::core::ops::BitOr for SDL_BlendMode {
159 type Output = Self;
160
161 #[inline(always)]
162 fn bitor(self, rhs: Self) -> Self::Output {
163 Self(self.0 | rhs.0)
164 }
165}
166
167impl ::core::ops::BitOrAssign for SDL_BlendMode {
168 #[inline(always)]
169 fn bitor_assign(&mut self, rhs: Self) {
170 self.0 |= rhs.0;
171 }
172}
173
174impl ::core::ops::BitXor for SDL_BlendMode {
175 type Output = Self;
176
177 #[inline(always)]
178 fn bitxor(self, rhs: Self) -> Self::Output {
179 Self(self.0 ^ rhs.0)
180 }
181}
182
183impl ::core::ops::BitXorAssign for SDL_BlendMode {
184 #[inline(always)]
185 fn bitxor_assign(&mut self, rhs: Self) {
186 self.0 ^= rhs.0;
187 }
188}
189
190impl ::core::ops::Not for SDL_BlendMode {
191 type Output = Self;
192
193 #[inline(always)]
194 fn not(self) -> Self::Output {
195 Self(!self.0)
196 }
197}
198
199impl SDL_BlendMode {
200 /// no blending: dstRGBA = srcRGBA
201 pub const NONE: Self = Self((0x00000000 as Uint32));
202 /// alpha blending: dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA)), dstA = srcA + (dstA * (1-srcA))
203 pub const BLEND: Self = Self((0x00000001 as Uint32));
204 /// pre-multiplied alpha blending: dstRGBA = srcRGBA + (dstRGBA * (1-srcA))
205 pub const BLEND_PREMULTIPLIED: Self = Self((0x00000010 as Uint32));
206 /// additive blending: dstRGB = (srcRGB * srcA) + dstRGB, dstA = dstA
207 pub const ADD: Self = Self((0x00000002 as Uint32));
208 /// pre-multiplied additive blending: dstRGB = srcRGB + dstRGB, dstA = dstA
209 pub const ADD_PREMULTIPLIED: Self = Self((0x00000020 as Uint32));
210 /// color modulate: dstRGB = srcRGB * dstRGB, dstA = dstA
211 pub const MOD: Self = Self((0x00000004 as Uint32));
212 /// color multiply: dstRGB = (srcRGB * dstRGB) + (dstRGB * (1-srcA)), dstA = dstA
213 pub const MUL: Self = Self((0x00000008 as Uint32));
214 pub const INVALID: Self = Self((0x7fffffff as Uint32));
215}
216
217/// no blending: dstRGBA = srcRGBA
218pub const SDL_BLENDMODE_NONE: SDL_BlendMode = SDL_BlendMode::NONE;
219/// alpha blending: dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA)), dstA = srcA + (dstA * (1-srcA))
220pub const SDL_BLENDMODE_BLEND: SDL_BlendMode = SDL_BlendMode::BLEND;
221/// pre-multiplied alpha blending: dstRGBA = srcRGBA + (dstRGBA * (1-srcA))
222pub const SDL_BLENDMODE_BLEND_PREMULTIPLIED: SDL_BlendMode = SDL_BlendMode::BLEND_PREMULTIPLIED;
223/// additive blending: dstRGB = (srcRGB * srcA) + dstRGB, dstA = dstA
224pub const SDL_BLENDMODE_ADD: SDL_BlendMode = SDL_BlendMode::ADD;
225/// pre-multiplied additive blending: dstRGB = srcRGB + dstRGB, dstA = dstA
226pub const SDL_BLENDMODE_ADD_PREMULTIPLIED: SDL_BlendMode = SDL_BlendMode::ADD_PREMULTIPLIED;
227/// color modulate: dstRGB = srcRGB * dstRGB, dstA = dstA
228pub const SDL_BLENDMODE_MOD: SDL_BlendMode = SDL_BlendMode::MOD;
229/// color multiply: dstRGB = (srcRGB * dstRGB) + (dstRGB * (1-srcA)), dstA = dstA
230pub const SDL_BLENDMODE_MUL: SDL_BlendMode = SDL_BlendMode::MUL;
231pub const SDL_BLENDMODE_INVALID: SDL_BlendMode = SDL_BlendMode::INVALID;
232
233#[cfg(feature = "metadata")]
234impl sdl3_sys::metadata::GroupMetadata for SDL_BlendMode {
235 const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
236 &crate::metadata::blendmode::METADATA_SDL_BlendMode;
237}
238
239/// The blend operation used when combining source and destination pixel
240/// components.
241///
242/// ## Availability
243/// This enum is available since SDL 3.2.0.
244///
245/// ## Known values (`sdl3-sys`)
246/// | Associated constant | Global constant | Description |
247/// | ------------------- | --------------- | ----------- |
248/// | [`ADD`](SDL_BlendOperation::ADD) | [`SDL_BLENDOPERATION_ADD`] | dst + src: supported by all renderers |
249/// | [`SUBTRACT`](SDL_BlendOperation::SUBTRACT) | [`SDL_BLENDOPERATION_SUBTRACT`] | src - dst : supported by D3D, OpenGL, OpenGLES, and Vulkan |
250/// | [`REV_SUBTRACT`](SDL_BlendOperation::REV_SUBTRACT) | [`SDL_BLENDOPERATION_REV_SUBTRACT`] | dst - src : supported by D3D, OpenGL, OpenGLES, and Vulkan |
251/// | [`MINIMUM`](SDL_BlendOperation::MINIMUM) | [`SDL_BLENDOPERATION_MINIMUM`] | min(dst, src) : supported by D3D, OpenGL, OpenGLES, and Vulkan |
252/// | [`MAXIMUM`](SDL_BlendOperation::MAXIMUM) | [`SDL_BLENDOPERATION_MAXIMUM`] | max(dst, src) : supported by D3D, OpenGL, OpenGLES, and Vulkan |
253#[repr(transparent)]
254#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
255pub struct SDL_BlendOperation(pub ::core::ffi::c_int);
256
257impl ::core::cmp::PartialEq<::core::ffi::c_int> for SDL_BlendOperation {
258 #[inline(always)]
259 fn eq(&self, other: &::core::ffi::c_int) -> bool {
260 &self.0 == other
261 }
262}
263
264impl ::core::cmp::PartialEq<SDL_BlendOperation> for ::core::ffi::c_int {
265 #[inline(always)]
266 fn eq(&self, other: &SDL_BlendOperation) -> bool {
267 self == &other.0
268 }
269}
270
271impl From<SDL_BlendOperation> for ::core::ffi::c_int {
272 #[inline(always)]
273 fn from(value: SDL_BlendOperation) -> Self {
274 value.0
275 }
276}
277
278#[cfg(feature = "debug-impls")]
279impl ::core::fmt::Debug for SDL_BlendOperation {
280 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
281 #[allow(unreachable_patterns)]
282 f.write_str(match *self {
283 Self::ADD => "SDL_BLENDOPERATION_ADD",
284 Self::SUBTRACT => "SDL_BLENDOPERATION_SUBTRACT",
285 Self::REV_SUBTRACT => "SDL_BLENDOPERATION_REV_SUBTRACT",
286 Self::MINIMUM => "SDL_BLENDOPERATION_MINIMUM",
287 Self::MAXIMUM => "SDL_BLENDOPERATION_MAXIMUM",
288
289 _ => return write!(f, "SDL_BlendOperation({})", self.0),
290 })
291 }
292}
293
294impl SDL_BlendOperation {
295 /// dst + src: supported by all renderers
296 pub const ADD: Self = Self((0x1 as ::core::ffi::c_int));
297 /// src - dst : supported by D3D, OpenGL, OpenGLES, and Vulkan
298 pub const SUBTRACT: Self = Self((0x2 as ::core::ffi::c_int));
299 /// dst - src : supported by D3D, OpenGL, OpenGLES, and Vulkan
300 pub const REV_SUBTRACT: Self = Self((0x3 as ::core::ffi::c_int));
301 /// min(dst, src) : supported by D3D, OpenGL, OpenGLES, and Vulkan
302 pub const MINIMUM: Self = Self((0x4 as ::core::ffi::c_int));
303 /// max(dst, src) : supported by D3D, OpenGL, OpenGLES, and Vulkan
304 pub const MAXIMUM: Self = Self((0x5 as ::core::ffi::c_int));
305}
306
307/// dst + src: supported by all renderers
308pub const SDL_BLENDOPERATION_ADD: SDL_BlendOperation = SDL_BlendOperation::ADD;
309/// src - dst : supported by D3D, OpenGL, OpenGLES, and Vulkan
310pub const SDL_BLENDOPERATION_SUBTRACT: SDL_BlendOperation = SDL_BlendOperation::SUBTRACT;
311/// dst - src : supported by D3D, OpenGL, OpenGLES, and Vulkan
312pub const SDL_BLENDOPERATION_REV_SUBTRACT: SDL_BlendOperation = SDL_BlendOperation::REV_SUBTRACT;
313/// min(dst, src) : supported by D3D, OpenGL, OpenGLES, and Vulkan
314pub const SDL_BLENDOPERATION_MINIMUM: SDL_BlendOperation = SDL_BlendOperation::MINIMUM;
315/// max(dst, src) : supported by D3D, OpenGL, OpenGLES, and Vulkan
316pub const SDL_BLENDOPERATION_MAXIMUM: SDL_BlendOperation = SDL_BlendOperation::MAXIMUM;
317
318#[cfg(feature = "metadata")]
319impl sdl3_sys::metadata::GroupMetadata for SDL_BlendOperation {
320 const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
321 &crate::metadata::blendmode::METADATA_SDL_BlendOperation;
322}
323
324/// The normalized factor used to multiply pixel components.
325///
326/// The blend factors are multiplied with the pixels from a drawing operation
327/// (src) and the pixels from the render target (dst) before the blend
328/// operation. The comma-separated factors listed above are always applied in
329/// the component order red, green, blue, and alpha.
330///
331/// ## Availability
332/// This enum is available since SDL 3.2.0.
333///
334/// ## Known values (`sdl3-sys`)
335/// | Associated constant | Global constant | Description |
336/// | ------------------- | --------------- | ----------- |
337/// | [`ZERO`](SDL_BlendFactor::ZERO) | [`SDL_BLENDFACTOR_ZERO`] | 0, 0, 0, 0 |
338/// | [`ONE`](SDL_BlendFactor::ONE) | [`SDL_BLENDFACTOR_ONE`] | 1, 1, 1, 1 |
339/// | [`SRC_COLOR`](SDL_BlendFactor::SRC_COLOR) | [`SDL_BLENDFACTOR_SRC_COLOR`] | srcR, srcG, srcB, srcA |
340/// | [`ONE_MINUS_SRC_COLOR`](SDL_BlendFactor::ONE_MINUS_SRC_COLOR) | [`SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR`] | 1-srcR, 1-srcG, 1-srcB, 1-srcA |
341/// | [`SRC_ALPHA`](SDL_BlendFactor::SRC_ALPHA) | [`SDL_BLENDFACTOR_SRC_ALPHA`] | srcA, srcA, srcA, srcA |
342/// | [`ONE_MINUS_SRC_ALPHA`](SDL_BlendFactor::ONE_MINUS_SRC_ALPHA) | [`SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA`] | 1-srcA, 1-srcA, 1-srcA, 1-srcA |
343/// | [`DST_COLOR`](SDL_BlendFactor::DST_COLOR) | [`SDL_BLENDFACTOR_DST_COLOR`] | dstR, dstG, dstB, dstA |
344/// | [`ONE_MINUS_DST_COLOR`](SDL_BlendFactor::ONE_MINUS_DST_COLOR) | [`SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR`] | 1-dstR, 1-dstG, 1-dstB, 1-dstA |
345/// | [`DST_ALPHA`](SDL_BlendFactor::DST_ALPHA) | [`SDL_BLENDFACTOR_DST_ALPHA`] | dstA, dstA, dstA, dstA |
346/// | [`ONE_MINUS_DST_ALPHA`](SDL_BlendFactor::ONE_MINUS_DST_ALPHA) | [`SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA`] | 1-dstA, 1-dstA, 1-dstA, 1-dstA |
347#[repr(transparent)]
348#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
349pub struct SDL_BlendFactor(pub ::core::ffi::c_int);
350
351impl ::core::cmp::PartialEq<::core::ffi::c_int> for SDL_BlendFactor {
352 #[inline(always)]
353 fn eq(&self, other: &::core::ffi::c_int) -> bool {
354 &self.0 == other
355 }
356}
357
358impl ::core::cmp::PartialEq<SDL_BlendFactor> for ::core::ffi::c_int {
359 #[inline(always)]
360 fn eq(&self, other: &SDL_BlendFactor) -> bool {
361 self == &other.0
362 }
363}
364
365impl From<SDL_BlendFactor> for ::core::ffi::c_int {
366 #[inline(always)]
367 fn from(value: SDL_BlendFactor) -> Self {
368 value.0
369 }
370}
371
372#[cfg(feature = "debug-impls")]
373impl ::core::fmt::Debug for SDL_BlendFactor {
374 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
375 #[allow(unreachable_patterns)]
376 f.write_str(match *self {
377 Self::ZERO => "SDL_BLENDFACTOR_ZERO",
378 Self::ONE => "SDL_BLENDFACTOR_ONE",
379 Self::SRC_COLOR => "SDL_BLENDFACTOR_SRC_COLOR",
380 Self::ONE_MINUS_SRC_COLOR => "SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR",
381 Self::SRC_ALPHA => "SDL_BLENDFACTOR_SRC_ALPHA",
382 Self::ONE_MINUS_SRC_ALPHA => "SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA",
383 Self::DST_COLOR => "SDL_BLENDFACTOR_DST_COLOR",
384 Self::ONE_MINUS_DST_COLOR => "SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR",
385 Self::DST_ALPHA => "SDL_BLENDFACTOR_DST_ALPHA",
386 Self::ONE_MINUS_DST_ALPHA => "SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA",
387
388 _ => return write!(f, "SDL_BlendFactor({})", self.0),
389 })
390 }
391}
392
393impl SDL_BlendFactor {
394 /// 0, 0, 0, 0
395 pub const ZERO: Self = Self((0x1 as ::core::ffi::c_int));
396 /// 1, 1, 1, 1
397 pub const ONE: Self = Self((0x2 as ::core::ffi::c_int));
398 /// srcR, srcG, srcB, srcA
399 pub const SRC_COLOR: Self = Self((0x3 as ::core::ffi::c_int));
400 /// 1-srcR, 1-srcG, 1-srcB, 1-srcA
401 pub const ONE_MINUS_SRC_COLOR: Self = Self((0x4 as ::core::ffi::c_int));
402 /// srcA, srcA, srcA, srcA
403 pub const SRC_ALPHA: Self = Self((0x5 as ::core::ffi::c_int));
404 /// 1-srcA, 1-srcA, 1-srcA, 1-srcA
405 pub const ONE_MINUS_SRC_ALPHA: Self = Self((0x6 as ::core::ffi::c_int));
406 /// dstR, dstG, dstB, dstA
407 pub const DST_COLOR: Self = Self((0x7 as ::core::ffi::c_int));
408 /// 1-dstR, 1-dstG, 1-dstB, 1-dstA
409 pub const ONE_MINUS_DST_COLOR: Self = Self((0x8 as ::core::ffi::c_int));
410 /// dstA, dstA, dstA, dstA
411 pub const DST_ALPHA: Self = Self((0x9 as ::core::ffi::c_int));
412 /// 1-dstA, 1-dstA, 1-dstA, 1-dstA
413 pub const ONE_MINUS_DST_ALPHA: Self = Self((0xa as ::core::ffi::c_int));
414}
415
416/// 0, 0, 0, 0
417pub const SDL_BLENDFACTOR_ZERO: SDL_BlendFactor = SDL_BlendFactor::ZERO;
418/// 1, 1, 1, 1
419pub const SDL_BLENDFACTOR_ONE: SDL_BlendFactor = SDL_BlendFactor::ONE;
420/// srcR, srcG, srcB, srcA
421pub const SDL_BLENDFACTOR_SRC_COLOR: SDL_BlendFactor = SDL_BlendFactor::SRC_COLOR;
422/// 1-srcR, 1-srcG, 1-srcB, 1-srcA
423pub const SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR: SDL_BlendFactor =
424 SDL_BlendFactor::ONE_MINUS_SRC_COLOR;
425/// srcA, srcA, srcA, srcA
426pub const SDL_BLENDFACTOR_SRC_ALPHA: SDL_BlendFactor = SDL_BlendFactor::SRC_ALPHA;
427/// 1-srcA, 1-srcA, 1-srcA, 1-srcA
428pub const SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA: SDL_BlendFactor =
429 SDL_BlendFactor::ONE_MINUS_SRC_ALPHA;
430/// dstR, dstG, dstB, dstA
431pub const SDL_BLENDFACTOR_DST_COLOR: SDL_BlendFactor = SDL_BlendFactor::DST_COLOR;
432/// 1-dstR, 1-dstG, 1-dstB, 1-dstA
433pub const SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR: SDL_BlendFactor =
434 SDL_BlendFactor::ONE_MINUS_DST_COLOR;
435/// dstA, dstA, dstA, dstA
436pub const SDL_BLENDFACTOR_DST_ALPHA: SDL_BlendFactor = SDL_BlendFactor::DST_ALPHA;
437/// 1-dstA, 1-dstA, 1-dstA, 1-dstA
438pub const SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA: SDL_BlendFactor =
439 SDL_BlendFactor::ONE_MINUS_DST_ALPHA;
440
441#[cfg(feature = "metadata")]
442impl sdl3_sys::metadata::GroupMetadata for SDL_BlendFactor {
443 const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
444 &crate::metadata::blendmode::METADATA_SDL_BlendFactor;
445}
446
447unsafe extern "C" {
448 /// Compose a custom blend mode for renderers.
449 ///
450 /// The functions [`SDL_SetRenderDrawBlendMode`] and [`SDL_SetTextureBlendMode`] accept
451 /// the [`SDL_BlendMode`] returned by this function if the renderer supports it.
452 ///
453 /// A blend mode controls how the pixels from a drawing operation (source) get
454 /// combined with the pixels from the render target (destination). First, the
455 /// components of the source and destination pixels get multiplied with their
456 /// blend factors. Then, the blend operation takes the two products and
457 /// calculates the result that will get stored in the render target.
458 ///
459 /// Expressed in pseudocode, it would look like this:
460 ///
461 /// ```c
462 /// dstRGB = colorOperation(srcRGB * srcColorFactor, dstRGB * dstColorFactor);
463 /// dstA = alphaOperation(srcA * srcAlphaFactor, dstA * dstAlphaFactor);
464 /// ```
465 ///
466 /// Where the functions `colorOperation(src, dst)` and `alphaOperation(src,
467 /// dst)` can return one of the following:
468 ///
469 /// - `src + dst`
470 /// - `src - dst`
471 /// - `dst - src`
472 /// - `min(src, dst)`
473 /// - `max(src, dst)`
474 ///
475 /// The red, green, and blue components are always multiplied with the first,
476 /// second, and third components of the [`SDL_BlendFactor`], respectively. The
477 /// fourth component is not used.
478 ///
479 /// The alpha component is always multiplied with the fourth component of the
480 /// [`SDL_BlendFactor`]. The other components are not used in the alpha
481 /// calculation.
482 ///
483 /// Support for these blend modes varies for each renderer. To check if a
484 /// specific [`SDL_BlendMode`] is supported, create a renderer and pass it to
485 /// either [`SDL_SetRenderDrawBlendMode`] or [`SDL_SetTextureBlendMode`]. They will
486 /// return with an error if the blend mode is not supported.
487 ///
488 /// This list describes the support of custom blend modes for each renderer.
489 /// All renderers support the four blend modes listed in the [`SDL_BlendMode`]
490 /// enumeration.
491 ///
492 /// - **direct3d**: Supports all operations with all factors. However, some
493 /// factors produce unexpected results with [`SDL_BLENDOPERATION_MINIMUM`] and
494 /// [`SDL_BLENDOPERATION_MAXIMUM`].
495 /// - **direct3d11**: Same as Direct3D 9.
496 /// - **opengl**: Supports the [`SDL_BLENDOPERATION_ADD`] operation with all
497 /// factors. OpenGL versions 1.1, 1.2, and 1.3 do not work correctly here.
498 /// - **opengles2**: Supports the [`SDL_BLENDOPERATION_ADD`],
499 /// [`SDL_BLENDOPERATION_SUBTRACT`], [`SDL_BLENDOPERATION_REV_SUBTRACT`]
500 /// operations with all factors.
501 /// - **psp**: No custom blend mode support.
502 /// - **software**: No custom blend mode support.
503 ///
504 /// Some renderers do not provide an alpha component for the default render
505 /// target. The [`SDL_BLENDFACTOR_DST_ALPHA`] and
506 /// [`SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA`] factors do not have an effect in this
507 /// case.
508 ///
509 /// ## Parameters
510 /// - `srcColorFactor`: the [`SDL_BlendFactor`] applied to the red, green, and
511 /// blue components of the source pixels.
512 /// - `dstColorFactor`: the [`SDL_BlendFactor`] applied to the red, green, and
513 /// blue components of the destination pixels.
514 /// - `colorOperation`: the [`SDL_BlendOperation`] used to combine the red,
515 /// green, and blue components of the source and
516 /// destination pixels.
517 /// - `srcAlphaFactor`: the [`SDL_BlendFactor`] applied to the alpha component of
518 /// the source pixels.
519 /// - `dstAlphaFactor`: the [`SDL_BlendFactor`] applied to the alpha component of
520 /// the destination pixels.
521 /// - `alphaOperation`: the [`SDL_BlendOperation`] used to combine the alpha
522 /// component of the source and destination pixels.
523 ///
524 /// ## Return value
525 /// Returns an [`SDL_BlendMode`] that represents the chosen factors and
526 /// operations.
527 ///
528 /// ## Thread safety
529 /// It is safe to call this function from any thread.
530 ///
531 /// ## Availability
532 /// This function is available since SDL 3.2.0.
533 ///
534 /// ## See also
535 /// - [`SDL_SetRenderDrawBlendMode`]
536 /// - [`SDL_GetRenderDrawBlendMode`]
537 /// - [`SDL_SetTextureBlendMode`]
538 /// - [`SDL_GetTextureBlendMode`]
539 pub safe fn SDL_ComposeCustomBlendMode(
540 srcColorFactor: SDL_BlendFactor,
541 dstColorFactor: SDL_BlendFactor,
542 colorOperation: SDL_BlendOperation,
543 srcAlphaFactor: SDL_BlendFactor,
544 dstAlphaFactor: SDL_BlendFactor,
545 alphaOperation: SDL_BlendOperation,
546 ) -> SDL_BlendMode;
547}
548
549#[cfg(doc)]
550use crate::everything::*;