Skip to content

Commit

Permalink
Fix restoring state after creating new render target
Browse files Browse the repository at this point in the history
  • Loading branch information
lethal-guitar committed Jan 24, 2021
1 parent 61477f5 commit 4b55c38
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/renderer/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,18 +848,9 @@ struct Renderer::Impl {
}

if (state.mRenderTargetTexture != mLastCommittedState.mRenderTargetTexture) {
base::Extents framebufferSize;
if (state.mRenderTargetTexture != 0) {
const auto iData = mRenderTargetDict.find(state.mRenderTargetTexture);
assert(iData != mRenderTargetDict.end());

glBindFramebuffer(GL_FRAMEBUFFER, iData->second.mFbo);
framebufferSize = iData->second.mSize;
} else {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
framebufferSize = mWindowSize;
}
const auto framebufferSize = currentFramebufferSize();

commitRenderTarget(state);
glViewport(0, 0, framebufferSize.width, framebufferSize.height);
commitClipRect(state, framebufferSize);
commitVertexAttributeFormat();
Expand Down Expand Up @@ -903,6 +894,17 @@ struct Renderer::Impl {
}


void commitRenderTarget(const State& state) {
if (state.mRenderTargetTexture != 0) {
const auto iData = mRenderTargetDict.find(state.mRenderTargetTexture);
assert(iData != mRenderTargetDict.end());
glBindFramebuffer(GL_FRAMEBUFFER, iData->second.mFbo);
} else {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
}


void commitClipRect(
const State& state,
const base::Extents& framebufferSize
Expand Down Expand Up @@ -1031,8 +1033,8 @@ struct Renderer::Impl {
textureHandle,
0);

mStateChanged = true;
glBindTexture(GL_TEXTURE_2D, mLastUsedTexture);
commitRenderTarget(mLastCommittedState);

mRenderTargetDict.insert({textureHandle, {{width, height}, fboHandle}});

Expand Down

0 comments on commit 4b55c38

Please sign in to comment.