Skip to content

Commit

Permalink
Support sRGB color space in RenderTexture
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Sakarah committed Mar 10, 2021
1 parent 252d26a commit b7beca8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/SFML/Graphics/RenderTexture.cpp
Expand Up @@ -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))
{
Expand Down
3 changes: 2 additions & 1 deletion src/SFML/Graphics/RenderTextureImplFBO.cpp
Expand Up @@ -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<unsigned int>(color);
Expand All @@ -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)
Expand Down

0 comments on commit b7beca8

Please sign in to comment.