Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #12287 from Tilka/blending
VideoCommon: copy software renderer logic for blend mode priorities
  • Loading branch information
Tilka committed Nov 12, 2023
2 parents f35ee22 + ac9079f commit e5d2deb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
4 changes: 2 additions & 2 deletions Source/Core/VideoCommon/BPMemory.cpp
Expand Up @@ -11,8 +11,8 @@ BPMemory bpmem;

bool BlendMode::UseLogicOp() const
{
// Logicop bit has lowest priority.
if (subtract || blendenable || !logicopenable)
// Blending overrides the logicop bit.
if (blendenable || !logicopenable)
return false;

// Fast path for Kirby's Return to Dreamland, they use it with dstAlpha.
Expand Down
66 changes: 32 additions & 34 deletions Source/Core/VideoCommon/RenderState.cpp
Expand Up @@ -120,47 +120,45 @@ void BlendingState::Generate(const BPMemory& bp)
const bool dstalpha = bp.dstalpha.enable && alphaupdate;
usedualsrc = true;

// The subtract bit has the highest priority
if (bp.blendmode.subtract)
if (bp.blendmode.blendenable)
{
blendenable = true;
subtractAlpha = subtract = true;
srcfactoralpha = srcfactor = SrcBlendFactor::One;
dstfactoralpha = dstfactor = DstBlendFactor::One;

if (dstalpha)
if (bp.blendmode.subtract)
{
subtractAlpha = false;
srcfactoralpha = SrcBlendFactor::One;
dstfactoralpha = DstBlendFactor::Zero;
}
}
blendenable = true;
subtractAlpha = subtract = true;
srcfactoralpha = srcfactor = SrcBlendFactor::One;
dstfactoralpha = dstfactor = DstBlendFactor::One;

// The blendenable bit has the middle priority
else if (bp.blendmode.blendenable)
{
blendenable = true;
srcfactor = bp.blendmode.srcfactor;
dstfactor = bp.blendmode.dstfactor;
if (!target_has_alpha)
{
// uses ONE instead of DSTALPHA
srcfactor = RemoveDstAlphaUsage(srcfactor);
dstfactor = RemoveDstAlphaUsage(dstfactor);
if (dstalpha)
{
subtractAlpha = false;
srcfactoralpha = SrcBlendFactor::One;
dstfactoralpha = DstBlendFactor::Zero;
}
}
// replaces SrcClr with SrcAlpha and DstClr with DstAlpha, it is important to
// use the dst function for the src factor and vice versa
srcfactoralpha = RemoveDstColorUsage(srcfactor);
dstfactoralpha = RemoveSrcColorUsage(dstfactor);

if (dstalpha)
else
{
srcfactoralpha = SrcBlendFactor::One;
dstfactoralpha = DstBlendFactor::Zero;
blendenable = true;
srcfactor = bp.blendmode.srcfactor;
dstfactor = bp.blendmode.dstfactor;
if (!target_has_alpha)
{
// uses ONE instead of DSTALPHA
srcfactor = RemoveDstAlphaUsage(srcfactor);
dstfactor = RemoveDstAlphaUsage(dstfactor);
}
// replaces SrcClr with SrcAlpha and DstClr with DstAlpha, it is important to
// use the dst function for the src factor and vice versa
srcfactoralpha = RemoveDstColorUsage(srcfactor);
dstfactoralpha = RemoveSrcColorUsage(dstfactor);

if (dstalpha)
{
srcfactoralpha = SrcBlendFactor::One;
dstfactoralpha = DstBlendFactor::Zero;
}
}
}

// The logicop bit has the lowest priority
else if (bp.blendmode.logicopenable)
{
if (bp.blendmode.logicmode == LogicOp::NoOp)
Expand Down

0 comments on commit e5d2deb

Please sign in to comment.