From ade4a3912a56ff3d67ece7180a48d758857b7bc8 Mon Sep 17 00:00:00 2001 From: Guillaume Bertholon Date: Wed, 10 Mar 2021 14:44:31 +0100 Subject: [PATCH] Support sRGB color space in RenderTexture When the sf::ContextSettings asks for an sRGB capable buffer, set the rendered image to sRGB mode and convert pixels when drawing. This is the choice of simplicity compared to actually support textures with more color depth. --- src/SFML/Graphics/RenderTexture.cpp | 3 +++ src/SFML/Graphics/RenderTextureImplFBO.cpp | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/SFML/Graphics/RenderTexture.cpp b/src/SFML/Graphics/RenderTexture.cpp index fc33c1d94..d66c31d27 100644 --- a/src/SFML/Graphics/RenderTexture.cpp +++ b/src/SFML/Graphics/RenderTexture.cpp @@ -58,6 +58,9 @@ bool RenderTexture::create(unsigned int width, unsigned int height, bool depthBu //////////////////////////////////////////////////////////// bool RenderTexture::create(unsigned int width, unsigned int height, const ContextSettings& settings) { + // Set texture to be in sRGB scale if requested + m_texture.setSrgb(settings.sRgbCapable); + // Create the texture if (!m_texture.create(width, height)) { diff --git a/src/SFML/Graphics/RenderTextureImplFBO.cpp b/src/SFML/Graphics/RenderTextureImplFBO.cpp index 432208fa9..bd83d6a52 100644 --- a/src/SFML/Graphics/RenderTextureImplFBO.cpp +++ b/src/SFML/Graphics/RenderTextureImplFBO.cpp @@ -296,6 +296,7 @@ bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsig #ifndef SFML_OPENGL_ES // Create the multisample color buffer + bool srgb = settings.sRgbCapable && GLEXT_texture_sRGB; GLuint color = 0; glCheck(GLEXT_glGenRenderbuffers(1, &color)); m_colorBuffer = static_cast(color); @@ -305,7 +306,7 @@ bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsig return false; } glCheck(GLEXT_glBindRenderbuffer(GLEXT_GL_RENDERBUFFER, m_colorBuffer)); - glCheck(GLEXT_glRenderbufferStorageMultisample(GLEXT_GL_RENDERBUFFER, settings.antialiasingLevel, GL_RGBA, width, height)); + glCheck(GLEXT_glRenderbufferStorageMultisample(GLEXT_GL_RENDERBUFFER, settings.antialiasingLevel, srgb ? GL_SRGB8_ALPHA8_EXT : GL_RGBA, width, height)); // Create the multisample depth/stencil buffer if requested if (settings.stencilBits)