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.
This commit is contained in:
Guillaume Bertholon 2021-03-10 14:44:31 +01:00 committed by Lukas Dürrenberger
parent 9e27096c37
commit ade4a3912a
2 changed files with 5 additions and 1 deletions

View File

@ -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) 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 // Create the texture
if (!m_texture.create(width, height)) if (!m_texture.create(width, height))
{ {

View File

@ -296,6 +296,7 @@ bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsig
#ifndef SFML_OPENGL_ES #ifndef SFML_OPENGL_ES
// Create the multisample color buffer // Create the multisample color buffer
bool srgb = settings.sRgbCapable && GLEXT_texture_sRGB;
GLuint color = 0; GLuint color = 0;
glCheck(GLEXT_glGenRenderbuffers(1, &color)); glCheck(GLEXT_glGenRenderbuffers(1, &color));
m_colorBuffer = static_cast<unsigned int>(color); m_colorBuffer = static_cast<unsigned int>(color);
@ -305,7 +306,7 @@ bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsig
return false; return false;
} }
glCheck(GLEXT_glBindRenderbuffer(GLEXT_GL_RENDERBUFFER, m_colorBuffer)); 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 // Create the multisample depth/stencil buffer if requested
if (settings.stencilBits) if (settings.stencilBits)