mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-30 16:37:39 +00:00
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD); This fixes bug 2828 - Subtractive Blending blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_SUBTRACT, SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_SUBTRACT); This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD);
This commit is contained in:
parent
f8e1874d01
commit
c59d9923b3
16 changed files with 718 additions and 778 deletions
|
@ -125,6 +125,7 @@ static void PrintShaderData(LPDWORD shader_data, DWORD shader_size)
|
|||
static SDL_Renderer *D3D_CreateRenderer(SDL_Window * window, Uint32 flags);
|
||||
static void D3D_WindowEvent(SDL_Renderer * renderer,
|
||||
const SDL_WindowEvent *event);
|
||||
static SDL_bool D3D_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode);
|
||||
static int D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
|
||||
static int D3D_RecreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
|
||||
static int D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
|
@ -542,6 +543,7 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
}
|
||||
|
||||
renderer->WindowEvent = D3D_WindowEvent;
|
||||
renderer->SupportsBlendMode = D3D_SupportsBlendMode;
|
||||
renderer->CreateTexture = D3D_CreateTexture;
|
||||
renderer->UpdateTexture = D3D_UpdateTexture;
|
||||
renderer->UpdateTextureYUV = D3D_UpdateTextureYUV;
|
||||
|
@ -802,6 +804,58 @@ D3D_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
|
|||
}
|
||||
}
|
||||
|
||||
static D3DBLEND GetBlendFunc(SDL_BlendFactor factor)
|
||||
{
|
||||
switch (factor) {
|
||||
case SDL_BLENDFACTOR_ZERO:
|
||||
return D3DBLEND_ZERO;
|
||||
case SDL_BLENDFACTOR_ONE:
|
||||
return D3DBLEND_ONE;
|
||||
case SDL_BLENDFACTOR_SRC_COLOR:
|
||||
return D3DBLEND_SRCCOLOR;
|
||||
case SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR:
|
||||
return D3DBLEND_INVSRCCOLOR;
|
||||
case SDL_BLENDFACTOR_SRC_ALPHA:
|
||||
return D3DBLEND_SRCALPHA;
|
||||
case SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA:
|
||||
return D3DBLEND_INVSRCALPHA;
|
||||
case SDL_BLENDFACTOR_DST_COLOR:
|
||||
return D3DBLEND_DESTCOLOR;
|
||||
case SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR:
|
||||
return D3DBLEND_INVDESTCOLOR;
|
||||
case SDL_BLENDFACTOR_DST_ALPHA:
|
||||
return D3DBLEND_DESTALPHA;
|
||||
case SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA:
|
||||
return D3DBLEND_INVDESTALPHA;
|
||||
default:
|
||||
return (D3DBLEND)0;
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
D3D_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
|
||||
{
|
||||
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
|
||||
SDL_BlendFactor srcColorFactor = SDL_GetBlendModeSrcColorFactor(blendMode);
|
||||
SDL_BlendFactor srcAlphaFactor = SDL_GetBlendModeSrcAlphaFactor(blendMode);
|
||||
SDL_BlendOperation colorOperation = SDL_GetBlendModeColorOperation(blendMode);
|
||||
SDL_BlendFactor dstColorFactor = SDL_GetBlendModeDstColorFactor(blendMode);
|
||||
SDL_BlendFactor dstAlphaFactor = SDL_GetBlendModeDstAlphaFactor(blendMode);
|
||||
SDL_BlendOperation alphaOperation = SDL_GetBlendModeAlphaOperation(blendMode);
|
||||
|
||||
if (!GetBlendFunc(srcColorFactor) || !GetBlendFunc(srcAlphaFactor) ||
|
||||
!GetBlendFunc(dstColorFactor) || !GetBlendFunc(dstAlphaFactor)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
if ((srcColorFactor != srcAlphaFactor || dstColorFactor != dstAlphaFactor) && !data->enableSeparateAlphaBlend) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
if (colorOperation != SDL_BLENDOPERATION_ADD || alphaOperation != SDL_BLENDOPERATION_ADD) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
static D3DTEXTUREFILTERTYPE
|
||||
GetScaleQuality(void)
|
||||
{
|
||||
|
@ -1353,55 +1407,22 @@ D3D_RenderClear(SDL_Renderer * renderer)
|
|||
}
|
||||
|
||||
static void
|
||||
D3D_SetBlendMode(D3D_RenderData * data, int blendMode)
|
||||
D3D_SetBlendMode(D3D_RenderData * data, SDL_BlendMode blendMode)
|
||||
{
|
||||
switch (blendMode) {
|
||||
case SDL_BLENDMODE_NONE:
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
|
||||
FALSE);
|
||||
break;
|
||||
case SDL_BLENDMODE_BLEND:
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
|
||||
TRUE);
|
||||
if (blendMode == SDL_BLENDMODE_NONE) {
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE, FALSE);
|
||||
} else {
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE, TRUE);
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
|
||||
D3DBLEND_SRCALPHA);
|
||||
GetBlendFunc(SDL_GetBlendModeSrcColorFactor(blendMode)));
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
|
||||
D3DBLEND_INVSRCALPHA);
|
||||
GetBlendFunc(SDL_GetBlendModeDstColorFactor(blendMode)));
|
||||
if (data->enableSeparateAlphaBlend) {
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLENDALPHA,
|
||||
D3DBLEND_ONE);
|
||||
GetBlendFunc(SDL_GetBlendModeSrcAlphaFactor(blendMode)));
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLENDALPHA,
|
||||
D3DBLEND_INVSRCALPHA);
|
||||
GetBlendFunc(SDL_GetBlendModeDstAlphaFactor(blendMode)));
|
||||
}
|
||||
break;
|
||||
case SDL_BLENDMODE_ADD:
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
|
||||
TRUE);
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
|
||||
D3DBLEND_SRCALPHA);
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
|
||||
D3DBLEND_ONE);
|
||||
if (data->enableSeparateAlphaBlend) {
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLENDALPHA,
|
||||
D3DBLEND_ZERO);
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLENDALPHA,
|
||||
D3DBLEND_ONE);
|
||||
}
|
||||
break;
|
||||
case SDL_BLENDMODE_MOD:
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
|
||||
TRUE);
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
|
||||
D3DBLEND_ZERO);
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
|
||||
D3DBLEND_SRCCOLOR);
|
||||
if (data->enableSeparateAlphaBlend) {
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLENDALPHA,
|
||||
D3DBLEND_ZERO);
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLENDALPHA,
|
||||
D3DBLEND_ONE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue