Path: blob/master/thirdparty/sdl/include/SDL3/SDL_blendmode.h
9912 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/2021/**22* # CategoryBlendmode23*24* Blend modes decide how two colors will mix together. There are both25* standard modes for basic needs and a means to create custom modes,26* dictating what sort of math to do on what color components.27*/2829#ifndef SDL_blendmode_h_30#define SDL_blendmode_h_3132#include <SDL3/SDL_stdinc.h>3334#include <SDL3/SDL_begin_code.h>35/* Set up for C function definitions, even when using C++ */36#ifdef __cplusplus37extern "C" {38#endif3940/**41* A set of blend modes used in drawing operations.42*43* These predefined blend modes are supported everywhere.44*45* Additional values may be obtained from SDL_ComposeCustomBlendMode.46*47* \since This datatype is available since SDL 3.2.0.48*49* \sa SDL_ComposeCustomBlendMode50*/51typedef Uint32 SDL_BlendMode;5253#define SDL_BLENDMODE_NONE 0x00000000u /**< no blending: dstRGBA = srcRGBA */54#define SDL_BLENDMODE_BLEND 0x00000001u /**< alpha blending: dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA)), dstA = srcA + (dstA * (1-srcA)) */55#define SDL_BLENDMODE_BLEND_PREMULTIPLIED 0x00000010u /**< pre-multiplied alpha blending: dstRGBA = srcRGBA + (dstRGBA * (1-srcA)) */56#define SDL_BLENDMODE_ADD 0x00000002u /**< additive blending: dstRGB = (srcRGB * srcA) + dstRGB, dstA = dstA */57#define SDL_BLENDMODE_ADD_PREMULTIPLIED 0x00000020u /**< pre-multiplied additive blending: dstRGB = srcRGB + dstRGB, dstA = dstA */58#define SDL_BLENDMODE_MOD 0x00000004u /**< color modulate: dstRGB = srcRGB * dstRGB, dstA = dstA */59#define SDL_BLENDMODE_MUL 0x00000008u /**< color multiply: dstRGB = (srcRGB * dstRGB) + (dstRGB * (1-srcA)), dstA = dstA */60#define SDL_BLENDMODE_INVALID 0x7FFFFFFFu6162/**63* The blend operation used when combining source and destination pixel64* components.65*66* \since This enum is available since SDL 3.2.0.67*/68typedef enum SDL_BlendOperation69{70SDL_BLENDOPERATION_ADD = 0x1, /**< dst + src: supported by all renderers */71SDL_BLENDOPERATION_SUBTRACT = 0x2, /**< src - dst : supported by D3D, OpenGL, OpenGLES, and Vulkan */72SDL_BLENDOPERATION_REV_SUBTRACT = 0x3, /**< dst - src : supported by D3D, OpenGL, OpenGLES, and Vulkan */73SDL_BLENDOPERATION_MINIMUM = 0x4, /**< min(dst, src) : supported by D3D, OpenGL, OpenGLES, and Vulkan */74SDL_BLENDOPERATION_MAXIMUM = 0x5 /**< max(dst, src) : supported by D3D, OpenGL, OpenGLES, and Vulkan */75} SDL_BlendOperation;7677/**78* The normalized factor used to multiply pixel components.79*80* The blend factors are multiplied with the pixels from a drawing operation81* (src) and the pixels from the render target (dst) before the blend82* operation. The comma-separated factors listed above are always applied in83* the component order red, green, blue, and alpha.84*85* \since This enum is available since SDL 3.2.0.86*/87typedef enum SDL_BlendFactor88{89SDL_BLENDFACTOR_ZERO = 0x1, /**< 0, 0, 0, 0 */90SDL_BLENDFACTOR_ONE = 0x2, /**< 1, 1, 1, 1 */91SDL_BLENDFACTOR_SRC_COLOR = 0x3, /**< srcR, srcG, srcB, srcA */92SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR = 0x4, /**< 1-srcR, 1-srcG, 1-srcB, 1-srcA */93SDL_BLENDFACTOR_SRC_ALPHA = 0x5, /**< srcA, srcA, srcA, srcA */94SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA = 0x6, /**< 1-srcA, 1-srcA, 1-srcA, 1-srcA */95SDL_BLENDFACTOR_DST_COLOR = 0x7, /**< dstR, dstG, dstB, dstA */96SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR = 0x8, /**< 1-dstR, 1-dstG, 1-dstB, 1-dstA */97SDL_BLENDFACTOR_DST_ALPHA = 0x9, /**< dstA, dstA, dstA, dstA */98SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA = 0xA /**< 1-dstA, 1-dstA, 1-dstA, 1-dstA */99} SDL_BlendFactor;100101/**102* Compose a custom blend mode for renderers.103*104* The functions SDL_SetRenderDrawBlendMode and SDL_SetTextureBlendMode accept105* the SDL_BlendMode returned by this function if the renderer supports it.106*107* A blend mode controls how the pixels from a drawing operation (source) get108* combined with the pixels from the render target (destination). First, the109* components of the source and destination pixels get multiplied with their110* blend factors. Then, the blend operation takes the two products and111* calculates the result that will get stored in the render target.112*113* Expressed in pseudocode, it would look like this:114*115* ```c116* dstRGB = colorOperation(srcRGB * srcColorFactor, dstRGB * dstColorFactor);117* dstA = alphaOperation(srcA * srcAlphaFactor, dstA * dstAlphaFactor);118* ```119*120* Where the functions `colorOperation(src, dst)` and `alphaOperation(src,121* dst)` can return one of the following:122*123* - `src + dst`124* - `src - dst`125* - `dst - src`126* - `min(src, dst)`127* - `max(src, dst)`128*129* The red, green, and blue components are always multiplied with the first,130* second, and third components of the SDL_BlendFactor, respectively. The131* fourth component is not used.132*133* The alpha component is always multiplied with the fourth component of the134* SDL_BlendFactor. The other components are not used in the alpha135* calculation.136*137* Support for these blend modes varies for each renderer. To check if a138* specific SDL_BlendMode is supported, create a renderer and pass it to139* either SDL_SetRenderDrawBlendMode or SDL_SetTextureBlendMode. They will140* return with an error if the blend mode is not supported.141*142* This list describes the support of custom blend modes for each renderer.143* All renderers support the four blend modes listed in the SDL_BlendMode144* enumeration.145*146* - **direct3d**: Supports all operations with all factors. However, some147* factors produce unexpected results with `SDL_BLENDOPERATION_MINIMUM` and148* `SDL_BLENDOPERATION_MAXIMUM`.149* - **direct3d11**: Same as Direct3D 9.150* - **opengl**: Supports the `SDL_BLENDOPERATION_ADD` operation with all151* factors. OpenGL versions 1.1, 1.2, and 1.3 do not work correctly here.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 render159* target. The `SDL_BLENDFACTOR_DST_ALPHA` and160* `SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA` factors do not have an effect in this161* case.162*163* \param srcColorFactor the SDL_BlendFactor applied to the red, green, and164* blue components of the source pixels.165* \param dstColorFactor the SDL_BlendFactor applied to the red, green, and166* 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 and169* destination pixels.170* \param srcAlphaFactor the SDL_BlendFactor applied to the alpha component of171* the source pixels.172* \param dstAlphaFactor the SDL_BlendFactor applied to the alpha component of173* the destination pixels.174* \param alphaOperation the SDL_BlendOperation used to combine the alpha175* component of the source and destination pixels.176* \returns an SDL_BlendMode that represents the chosen factors and177* operations.178*179* \threadsafety It is safe to call this function from any thread.180*181* \since This function is available since SDL 3.2.0.182*183* \sa SDL_SetRenderDrawBlendMode184* \sa SDL_GetRenderDrawBlendMode185* \sa SDL_SetTextureBlendMode186* \sa SDL_GetTextureBlendMode187*/188extern SDL_DECLSPEC SDL_BlendMode SDLCALL SDL_ComposeCustomBlendMode(SDL_BlendFactor srcColorFactor,189SDL_BlendFactor dstColorFactor,190SDL_BlendOperation colorOperation,191SDL_BlendFactor srcAlphaFactor,192SDL_BlendFactor dstAlphaFactor,193SDL_BlendOperation alphaOperation);194195/* Ends C function definitions when using C++ */196#ifdef __cplusplus197}198#endif199#include <SDL3/SDL_close_code.h>200201#endif /* SDL_blendmode_h_ */202203204