Skip to content

Commit

Permalink
Correct state leakage on shader blend/self render.
Browse files Browse the repository at this point in the history
This makes #2917 look right on desktop with blit and logic ops disabled.
  • Loading branch information
unknownbrackets committed Nov 15, 2015
1 parent 54535ec commit 010a7ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
21 changes: 19 additions & 2 deletions GPU/GLES/Framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1368,8 +1368,16 @@ void FramebufferManager::BlitFramebuffer(VirtualFramebuffer *dst, int dstX, int
// Make sure our 2D drawing program is ready. Compiles only if not already compiled.
CompileDraw2DProgram();

glViewport(0, 0, dst->renderWidth, dst->renderHeight);
DisableState();
glstate.viewport.force(0, 0, dst->renderWidth, dst->renderHeight);
glstate.blend.force(false);
glstate.cullFace.force(false);
glstate.depthTest.force(false);
glstate.stencilTest.force(false);
#if !defined(USING_GLES2)
glstate.colorLogicOp.force(false);
#endif
glstate.colorMask.force(true, true, true, true);
glstate.stencilMask.force(0xFF);

// The first four coordinates are relative to the 6th and 7th arguments of DrawActiveTexture.
// Should maybe revamp that interface.
Expand All @@ -1379,6 +1387,15 @@ void FramebufferManager::BlitFramebuffer(VirtualFramebuffer *dst, int dstX, int
glBindTexture(GL_TEXTURE_2D, 0);
textureCache_->ForgetLastTexture();
glstate.viewport.restore();
glstate.blend.restore();
glstate.cullFace.restore();
glstate.depthTest.restore();
glstate.stencilTest.restore();
#if !defined(USING_GLES2)
glstate.colorLogicOp.restore();
#endif
glstate.colorMask.restore();
glstate.stencilMask.restore();
}

glstate.scissorTest.restore();
Expand Down
6 changes: 4 additions & 2 deletions GPU/GLES/StateMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,6 @@ void TransformDrawEngine::ApplyDrawStateLate() {
fragmentTestCache_->BindTestTexture(GL_TEXTURE2);
}

textureCache_->ApplyTexture();

if (fboTexNeedBind_) {
// Note that this is positions, not UVs, that we need the copy from.
framebufferManager_->BindFramebufferColor(GL_TEXTURE1, gstate.getFrameBufRawAddress(), nullptr, BINDFBCOLOR_MAY_COPY);
Expand All @@ -399,5 +397,9 @@ void TransformDrawEngine::ApplyDrawStateLate() {
fboTexBound_ = true;
fboTexNeedBind_ = false;
}

// Apply the texture after the FBO tex, since it might unbind the texture.
// TODO: Could use a separate texture unit to be safer?
textureCache_->ApplyTexture();
}
}

0 comments on commit 010a7ac

Please sign in to comment.