mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-06-03 18:37:40 +00:00
direct3d: Implement missing blend operations.
This is only for Direct3D 9; Direct3D 11 already had this implemented. Fixes #5375.
This commit is contained in:
parent
a630b02938
commit
7bc498d325
2 changed files with 39 additions and 15 deletions
|
@ -347,7 +347,8 @@ D3D_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
|
|||
}
|
||||
}
|
||||
|
||||
static D3DBLEND GetBlendFunc(SDL_BlendFactor factor)
|
||||
static D3DBLEND
|
||||
GetBlendFunc(SDL_BlendFactor factor)
|
||||
{
|
||||
switch (factor) {
|
||||
case SDL_BLENDFACTOR_ZERO:
|
||||
|
@ -370,9 +371,28 @@ static D3DBLEND GetBlendFunc(SDL_BlendFactor factor)
|
|||
return D3DBLEND_DESTALPHA;
|
||||
case SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA:
|
||||
return D3DBLEND_INVDESTALPHA;
|
||||
default:
|
||||
return (D3DBLEND)0;
|
||||
default: break;
|
||||
}
|
||||
return (D3DBLEND) 0;
|
||||
}
|
||||
|
||||
static D3DBLENDOP
|
||||
GetBlendEquation(SDL_BlendOperation operation)
|
||||
{
|
||||
switch (operation) {
|
||||
case SDL_BLENDOPERATION_ADD:
|
||||
return D3DBLENDOP_ADD;
|
||||
case SDL_BLENDOPERATION_SUBTRACT:
|
||||
return D3DBLENDOP_SUBTRACT;
|
||||
case SDL_BLENDOPERATION_REV_SUBTRACT:
|
||||
return D3DBLENDOP_REVSUBTRACT;
|
||||
case SDL_BLENDOPERATION_MINIMUM:
|
||||
return D3DBLENDOP_MIN;
|
||||
case SDL_BLENDOPERATION_MAXIMUM:
|
||||
return D3DBLENDOP_MAX;
|
||||
default: break;
|
||||
}
|
||||
return (D3DBLENDOP) 0;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
|
@ -387,14 +407,16 @@ D3D_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
|
|||
SDL_BlendOperation alphaOperation = SDL_GetBlendModeAlphaOperation(blendMode);
|
||||
|
||||
if (!GetBlendFunc(srcColorFactor) || !GetBlendFunc(srcAlphaFactor) ||
|
||||
!GetBlendFunc(dstColorFactor) || !GetBlendFunc(dstAlphaFactor)) {
|
||||
!GetBlendEquation(colorOperation) ||
|
||||
!GetBlendFunc(dstColorFactor) || !GetBlendFunc(dstAlphaFactor) ||
|
||||
!GetBlendEquation(alphaOperation)) {
|
||||
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;
|
||||
|
||||
if (!data->enableSeparateAlphaBlend) {
|
||||
if ((srcColorFactor != srcAlphaFactor) || (dstColorFactor != dstAlphaFactor) || (colorOperation != alphaOperation)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
}
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
@ -1040,11 +1062,15 @@ SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
|
|||
GetBlendFunc(SDL_GetBlendModeSrcColorFactor(blend)));
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
|
||||
GetBlendFunc(SDL_GetBlendModeDstColorFactor(blend)));
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_BLENDOP,
|
||||
GetBlendEquation(SDL_GetBlendModeColorOperation(blend)));
|
||||
if (data->enableSeparateAlphaBlend) {
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLENDALPHA,
|
||||
GetBlendFunc(SDL_GetBlendModeSrcAlphaFactor(blend)));
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLENDALPHA,
|
||||
GetBlendFunc(SDL_GetBlendModeDstAlphaFactor(blend)));
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_BLENDOPALPHA,
|
||||
GetBlendEquation(SDL_GetBlendModeAlphaOperation(blend)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue