diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index a289fc4ce..6b2e16e2d 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -3821,18 +3821,6 @@ namespace bgfx { namespace gl m_needPresent |= true; m_currentFbo = m_msaaBackBufferFbo; - - if (m_srgbWriteControlSupport) - { - if (0 != (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER) ) - { - GL_CHECK(glEnable(GL_FRAMEBUFFER_SRGB) ); - } - else - { - GL_CHECK(glDisable(GL_FRAMEBUFFER_SRGB) ); - } - } } else { @@ -3853,6 +3841,26 @@ namespace bgfx { namespace gl } } + if (m_srgbWriteControlSupport) + { + if (0 == m_currentFbo) + { + if (0 != (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER) ) + { + GL_CHECK(glEnable(GL_FRAMEBUFFER_SRGB) ); + } + else + { + GL_CHECK(glDisable(GL_FRAMEBUFFER_SRGB) ); + } + } + else + { + // actual sRGB write/blending determined by FBO's color attachments format + GL_CHECK(glEnable(GL_FRAMEBUFFER_SRGB) ); + } + } + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_currentFbo) ); m_fbh = _fbh; @@ -8579,6 +8587,12 @@ namespace bgfx { namespace gl profiler.end(); } + + if (m_srgbWriteControlSupport) + { + // switch state back to default for cases when the on-screen draw is done externally + GL_CHECK(glDisable(GL_FRAMEBUFFER_SRGB) ); + } } BGFX_GL_PROFILER_END();