Browse Source

[GL] Fix sRGB framebuffer write (#3032)

Christophe Dehais 2 years ago
parent
commit
cd3a1ea7f8
1 changed files with 26 additions and 12 deletions
  1. 26 12
      src/renderer_gl.cpp

+ 26 - 12
src/renderer_gl.cpp

@@ -3821,18 +3821,6 @@ namespace bgfx { namespace gl
 				m_needPresent |= true;
 				m_needPresent |= true;
 
 
 				m_currentFbo = m_msaaBackBufferFbo;
 				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
 			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) );
 			GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_currentFbo) );
 
 
 			m_fbh       = _fbh;
 			m_fbh       = _fbh;
@@ -8579,6 +8587,12 @@ namespace bgfx { namespace gl
 
 
 				profiler.end();
 				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();
 		BGFX_GL_PROFILER_END();