Skip to content

Commit

Permalink
Readded a blendmode. This blendmode is called premultiplied alpha and…
Browse files Browse the repository at this point in the history
… is somewhat useful. Currently only used/needed for team backgrounds (?).
  • Loading branch information
pvandommelen committed Nov 13, 2017
1 parent 3258fee commit 8522d34
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/effect/efimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class BlendColorImage : public WrapImage {
void Render(Context* pcontext)
{
WrapImage::Render(pcontext);
pcontext->SetBlendMode(BlendModeSourceAlpha);
pcontext->SetBlendMode(BlendModeSourceAlphaPreMultiplied);
pcontext->FillRect(GetBounds().GetRect(), GetColor()->GetValue());
}
};
Expand Down
8 changes: 8 additions & 0 deletions src/engine/RasterD3D9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,14 @@ class D3D9RasterizerImpl : public D3D9Rasterizer
D3DCall(CD3DDevice9::Get()->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA));
break;

case BlendModeSourceAlphaPreMultiplied:
CD3DDevice9::Get()->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
CD3DDevice9::Get()->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
D3DCall(CD3DDevice9::Get()->SetRenderState(D3DRS_ALPHABLENDENABLE, true));
D3DCall(CD3DDevice9::Get()->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE));
D3DCall(CD3DDevice9::Get()->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA));
break;

default:

ZError("Invalid BlendMode");
Expand Down
14 changes: 14 additions & 0 deletions src/engine/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,13 @@ class ContextImpl : public PrivateContext {
pDev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pDev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
break;
case BlendModeSourceAlphaPreMultiplied:
pDev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
pDev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
pDev->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
pDev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
pDev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
break;
default:
ZError("Invalid blend mode");
}
Expand Down Expand Up @@ -987,6 +994,13 @@ class ContextImpl : public PrivateContext {
pDev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pDev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
break;
case BlendModeSourceAlphaPreMultiplied:
pDev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
pDev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
pDev->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
pDev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
pDev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
break;
default:
ZError("Invalid blend mode");
}
Expand Down
3 changes: 2 additions & 1 deletion src/engine/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,8 @@ enum ShadeMode {
enum BlendMode {
BlendModeSource,
BlendModeAdd,
BlendModeSourceAlpha
BlendModeSourceAlpha,
BlendModeSourceAlphaPreMultiplied
};

enum WrapMode {
Expand Down

0 comments on commit 8522d34

Please sign in to comment.