From dc6c88d147df19f811fa44f557130e25dd3a7478 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 21 Sep 2014 12:47:39 -0700 Subject: [PATCH] d3d9: Mask out alpha using KEEP stencil op. --- GPU/Directx9/StateMappingDX9.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/GPU/Directx9/StateMappingDX9.cpp b/GPU/Directx9/StateMappingDX9.cpp index e311d36fa..8c6dd6e96 100644 --- a/GPU/Directx9/StateMappingDX9.cpp +++ b/GPU/Directx9/StateMappingDX9.cpp @@ -483,10 +483,13 @@ void TransformDrawEngineDX9::ApplyDrawState(int prim) { dxstate.depthTest.enable(); dxstate.depthFunc.set(D3DCMP_ALWAYS); dxstate.depthWrite.set(gstate.isClearModeDepthMask()); + if (gstate.isClearModeDepthMask()) { + framebufferManager_->SetDepthUpdated(); + } // Color Test - bool colorMask = (gstate.clearmode >> 8) & 1; - bool alphaMask = (gstate.clearmode >> 9) & 1; + bool colorMask = gstate.isClearModeColorMask(); + bool alphaMask = gstate.isClearModeAlphaMask(); dxstate.colorMask.set(colorMask, colorMask, colorMask, alphaMask); // Stencil Test @@ -509,6 +512,9 @@ void TransformDrawEngineDX9::ApplyDrawState(int prim) { dxstate.depthTest.enable(); dxstate.depthFunc.set(ztests[gstate.getDepthTestFunction()]); dxstate.depthWrite.set(gstate.isDepthWriteEnabled()); + if (gstate.isDepthWriteEnabled()) { + framebufferManager_->SetDepthUpdated(); + } } else { dxstate.depthTest.disable(); } @@ -534,6 +540,16 @@ void TransformDrawEngineDX9::ApplyDrawState(int prim) { } #endif + // Let's not write to alpha if stencil isn't enabled. + if (!gstate.isStencilTestEnabled()) { + amask = false; + } else { + // If the stencil type is set to KEEP, we shouldn't write to the stencil/alpha channel. + if (ReplaceAlphaWithStencilType() == STENCIL_VALUE_KEEP) { + amask = false; + } + } + dxstate.colorMask.set(rmask, gmask, bmask, amask); // Stencil Test