mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-22 12:48:28 +00:00
Fixed bug 4903 - Lack of color multiply with alpha (SDL_BLENDMODE_MOD + SDL_BLENDMODE_BLEND) blending mode for all renderers
Konrad This kind of blending is rather quite useful and in my opinion should be available for all renderers. I do need it myself, but since I didn't want to use a custom blending mode which is supported only by certain renderers (e.g. not in software which is quite important for me) I did write implementation of SDL_BLENDMODE_MUL for all renderers altogether. SDL_BLENDMODE_MUL implements following equation: dstRGB = (srcRGB * dstRGB) + (dstRGB * (1-srcA)) dstA = (srcA * dstA) + (dstA * (1-srcA)) Background: https://i.imgur.com/UsYhydP.png Blended texture: https://i.imgur.com/0juXQcV.png Result for SDL_BLENDMODE_MOD: https://i.imgur.com/wgNSgUl.png Result for SDL_BLENDMODE_MUL: https://i.imgur.com/Veokzim.png I think I did cover all possibilities within included patch, but I didn't write any tests for SDL_BLENDMODE_MUL, so it would be lovely if someone could do it.
This commit is contained in:
parent
669729a8a0
commit
981e0d367c
19 changed files with 819 additions and 159 deletions
|
@ -75,6 +75,10 @@
|
|||
SDL_COMPOSE_BLENDMODE(SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_SRC_COLOR, SDL_BLENDOPERATION_ADD, \
|
||||
SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD)
|
||||
|
||||
#define SDL_BLENDMODE_MUL_FULL \
|
||||
SDL_COMPOSE_BLENDMODE(SDL_BLENDFACTOR_DST_COLOR, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD, \
|
||||
SDL_BLENDFACTOR_DST_ALPHA, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD)
|
||||
|
||||
#if !SDL_RENDER_DISABLED
|
||||
static const SDL_RenderDriver *render_drivers[] = {
|
||||
#if SDL_VIDEO_RENDER_D3D
|
||||
|
@ -970,6 +974,7 @@ IsSupportedBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
|
|||
case SDL_BLENDMODE_BLEND:
|
||||
case SDL_BLENDMODE_ADD:
|
||||
case SDL_BLENDMODE_MOD:
|
||||
case SDL_BLENDMODE_MUL:
|
||||
return SDL_TRUE;
|
||||
|
||||
default:
|
||||
|
@ -3288,6 +3293,9 @@ SDL_GetShortBlendMode(SDL_BlendMode blendMode)
|
|||
if (blendMode == SDL_BLENDMODE_MOD_FULL) {
|
||||
return SDL_BLENDMODE_MOD;
|
||||
}
|
||||
if (blendMode == SDL_BLENDMODE_MUL_FULL) {
|
||||
return SDL_BLENDMODE_MUL;
|
||||
}
|
||||
return blendMode;
|
||||
}
|
||||
|
||||
|
@ -3306,6 +3314,9 @@ SDL_GetLongBlendMode(SDL_BlendMode blendMode)
|
|||
if (blendMode == SDL_BLENDMODE_MOD) {
|
||||
return SDL_BLENDMODE_MOD_FULL;
|
||||
}
|
||||
if (blendMode == SDL_BLENDMODE_MUL) {
|
||||
return SDL_BLENDMODE_MUL_FULL;
|
||||
}
|
||||
return blendMode;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue