diff --git a/GPU/Directx9/StateMappingDX9.cpp b/GPU/Directx9/StateMappingDX9.cpp index 7efbbc3856..955e488ccc 100644 --- a/GPU/Directx9/StateMappingDX9.cpp +++ b/GPU/Directx9/StateMappingDX9.cpp @@ -150,11 +150,7 @@ bool TransformDrawEngineDX9::ApplyShaderBlending() { return false; } - framebufferManager_->BindFramebufferColor(1, nullptr, false); - // If we are rendering at a higher resolution, linear is probably best for the dest color. - pD3Ddevice->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); - pD3Ddevice->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); - fboTexBound_ = true; + fboTexNeedBind_ = true; shaderManager_->DirtyUniform(DIRTY_SHADERBLEND); return true; @@ -810,4 +806,21 @@ void TransformDrawEngineDX9::ApplyDrawState(int prim) { } } +void TransformDrawEngineDX9::ApplyDrawStateLate() { + // At this point, we know if the vertices are full alpha or not. + // TODO: Set the nearest/linear here (since we correctly know if alpha/color tests are needed)? + if (!gstate.isModeClear()) { + // TODO: Test texture? + + if (fboTexNeedBind_) { + framebufferManager_->BindFramebufferColor(1, nullptr, false); + // If we are rendering at a higher resolution, linear is probably best for the dest color. + pD3Ddevice->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); + pD3Ddevice->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); + fboTexBound_ = true; + fboTexNeedBind_ = false; + } + } +} + } diff --git a/GPU/Directx9/TransformPipelineDX9.cpp b/GPU/Directx9/TransformPipelineDX9.cpp index 2856af7297..4e9aa4c3b1 100644 --- a/GPU/Directx9/TransformPipelineDX9.cpp +++ b/GPU/Directx9/TransformPipelineDX9.cpp @@ -90,6 +90,7 @@ TransformDrawEngineDX9::TransformDrawEngineDX9() decodeCounter_(0), dcid_(0), uvScale(0), + fboTexNeedBind_(false), fboTexBound_(false) { memset(&decOptions_, 0, sizeof(decOptions_)); @@ -777,6 +778,8 @@ rotateVBO: gstate_c.vertexFullAlpha = gstate_c.vertexFullAlpha && ((hasColor && (gstate.materialupdate & 1)) || gstate.getMaterialAmbientA() == 255) && (!gstate.isLightingEnabled() || gstate.getAmbientA() == 255); } + ApplyDrawStateLate(); + vshader = shaderManager_->ApplyShader(prim, lastVType_); IDirect3DVertexDeclaration9 *pHardwareVertexDecl = SetupDecFmtForDraw(vshader, dec_->GetDecVtxFmt(), dec_->VertexType()); if (pHardwareVertexDecl) { @@ -808,6 +811,9 @@ rotateVBO: gstate_c.vertexFullAlpha = gstate_c.vertexFullAlpha && ((hasColor && (gstate.materialupdate & 1)) || gstate.getMaterialAmbientA() == 255) && (!gstate.isLightingEnabled() || gstate.getAmbientA() == 255); } + ApplyDrawStateLate(); + vshader = shaderManager_->ApplyShader(prim, lastVType_); + gpuStats.numUncachedVertsDrawn += indexGen.VertexCount(); prim = indexGen.Prim(); // Undo the strip optimization, not supported by the SW code yet. diff --git a/GPU/Directx9/TransformPipelineDX9.h b/GPU/Directx9/TransformPipelineDX9.h index c698cccfe7..cec618529e 100644 --- a/GPU/Directx9/TransformPipelineDX9.h +++ b/GPU/Directx9/TransformPipelineDX9.h @@ -247,6 +247,7 @@ private: UVScale *uvScale; + bool fboTexNeedBind_; bool fboTexBound_; }; diff --git a/GPU/GLES/StateMapping.cpp b/GPU/GLES/StateMapping.cpp index 1d728c7a1c..2a0bd9f6b3 100644 --- a/GPU/GLES/StateMapping.cpp +++ b/GPU/GLES/StateMapping.cpp @@ -190,13 +190,7 @@ bool TransformDrawEngine::ApplyShaderBlending() { return false; } - framebufferManager_->BindFramebufferColor(GL_TEXTURE1, gstate.getFrameBufRawAddress(), nullptr); - glActiveTexture(GL_TEXTURE1); - // If we are rendering at a higher resolution, linear is probably best for the dest color. - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glActiveTexture(GL_TEXTURE0); - fboTexBound_ = true; + fboTexNeedBind_ = true; shaderManager_->DirtyUniform(DIRTY_SHADERBLEND); return true; @@ -906,5 +900,16 @@ void TransformDrawEngine::ApplyDrawStateLate() { if (gstate.isAlphaTestEnabled() || gstate.isColorTestEnabled()) { fragmentTestCache_->BindTestTexture(GL_TEXTURE2); } + + if (fboTexNeedBind_) { + framebufferManager_->BindFramebufferColor(GL_TEXTURE1, gstate.getFrameBufRawAddress(), nullptr); + glActiveTexture(GL_TEXTURE1); + // If we are rendering at a higher resolution, linear is probably best for the dest color. + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glActiveTexture(GL_TEXTURE0); + fboTexBound_ = true; + fboTexNeedBind_ = false; + } } } diff --git a/GPU/GLES/TransformPipeline.cpp b/GPU/GLES/TransformPipeline.cpp index bf313174e5..608fd06b23 100644 --- a/GPU/GLES/TransformPipeline.cpp +++ b/GPU/GLES/TransformPipeline.cpp @@ -126,6 +126,7 @@ TransformDrawEngine::TransformDrawEngine() decodeCounter_(0), dcid_(0), uvScale(0), + fboTexNeedBind_(false), fboTexBound_(false) { decimationCounter_ = VERTEXCACHE_DECIMATION_INTERVAL; memset(&decOptions_, 0, sizeof(decOptions_)); diff --git a/GPU/GLES/TransformPipeline.h b/GPU/GLES/TransformPipeline.h index b93a6c992a..a6fa13534f 100644 --- a/GPU/GLES/TransformPipeline.h +++ b/GPU/GLES/TransformPipeline.h @@ -250,5 +250,6 @@ private: UVScale *uvScale; + bool fboTexNeedBind_; bool fboTexBound_; };