Skip to content

Commit

Permalink
Disable gamma correction on Windows + Intel HD 2/3000 / Intel HD Grap…
Browse files Browse the repository at this point in the history
…hics

It's completely broken there. Closes #1592
  • Loading branch information
slime73 committed Dec 25, 2020
1 parent 90bd8f1 commit fe23c16
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
9 changes: 0 additions & 9 deletions src/modules/graphics/opengl/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ static GLenum createFBO(GLuint &framebuffer, TextureType texType, PixelFormat fo
glGenFramebuffers(1, &framebuffer);
gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, framebuffer);

// Might work around an Intel driver bug: https://github.com/love2d/love/issues/1592
bool current_srgb = gl.isStateEnabled(OpenGL::ENABLE_FRAMEBUFFER_SRGB);
if (current_srgb && isPixelFormatDepthStencil(format))
gl.setEnableState(OpenGL::ENABLE_FRAMEBUFFER_SRGB, false);

if (texture != 0)
{
if (isPixelFormatDepthStencil(format) && (GLAD_ES_VERSION_3_0 || !GLAD_ES_VERSION_2_0))
Expand Down Expand Up @@ -110,10 +105,6 @@ static GLenum createFBO(GLuint &framebuffer, TextureType texType, PixelFormat fo

gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, current_fbo);

// Restore sRGB state if we turned it off above.
if (current_srgb && isPixelFormatDepthStencil(format))
gl.setEnableState(OpenGL::ENABLE_FRAMEBUFFER_SRGB, current_srgb);

return status;
}

Expand Down
4 changes: 2 additions & 2 deletions src/modules/graphics/opengl/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ bool Graphics::setMode(int width, int height, int pixelwidth, int pixelheight, b
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);

// Set whether drawing converts input from linear -> sRGB colorspace.
if (GLAD_VERSION_3_0 || GLAD_ARB_framebuffer_sRGB || GLAD_EXT_framebuffer_sRGB
|| GLAD_ES_VERSION_3_0 || GLAD_EXT_sRGB)
if (!gl.bugs.brokenSRGB && (GLAD_VERSION_3_0 || GLAD_ARB_framebuffer_sRGB
|| GLAD_EXT_framebuffer_sRGB || GLAD_ES_VERSION_3_0 || GLAD_EXT_sRGB))
{
if (GLAD_VERSION_1_0 || GLAD_EXT_sRGB_write_control)
gl.setEnableState(OpenGL::ENABLE_FRAMEBUFFER_SRGB, isGammaCorrect());
Expand Down
16 changes: 14 additions & 2 deletions src/modules/graphics/opengl/OpenGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ bool OpenGL::initContext()
if (strstr(device, "HD Graphics 4000") || strstr(device, "HD Graphics 2500"))
bugs.clientWaitSyncStalls = true;
}

if (getVendor() == VENDOR_INTEL)
{
const char *device = (const char *) glGetString(GL_RENDERER);
if (strstr(device, "HD Graphics 3000") || strstr(device, "HD Graphics 2000")
|| !strcmp(device, "Intel(R) HD Graphics") || !strcmp(device, "Intel(R) HD Graphics Family"))
{
bugs.brokenSRGB = true;
}
}
#endif

#ifdef LOVE_WINDOWS
Expand Down Expand Up @@ -215,8 +225,8 @@ void OpenGL::setupContext()
setEnableState(ENABLE_SCISSOR_TEST, state.enableState[ENABLE_SCISSOR_TEST]);
setEnableState(ENABLE_FACE_CULL, state.enableState[ENABLE_FACE_CULL]);

if (GLAD_VERSION_3_0 || GLAD_ARB_framebuffer_sRGB || GLAD_EXT_framebuffer_sRGB
|| GLAD_EXT_sRGB_write_control)
if (!bugs.brokenSRGB && (GLAD_VERSION_3_0 || GLAD_ARB_framebuffer_sRGB
|| GLAD_EXT_framebuffer_sRGB || GLAD_EXT_sRGB_write_control))
{
setEnableState(ENABLE_FRAMEBUFFER_SRGB, state.enableState[ENABLE_FRAMEBUFFER_SRGB]);
}
Expand Down Expand Up @@ -1717,6 +1727,8 @@ bool OpenGL::isPixelFormatSupported(PixelFormat pixelformat, bool rendertarget,
else
return true;
case PIXELFORMAT_sRGBA8:
if (gl.bugs.brokenSRGB)
return false;
if (rendertarget)
{
if (GLAD_VERSION_1_0)
Expand Down
7 changes: 7 additions & 0 deletions src/modules/graphics/opengl/OpenGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ class OpenGL
**/
bool brokenR8PixelFormat;

/**
* Intel HD Graphics drivers on Windows prior to the HD 2500/4000 have
* completely broken sRGB support.
* https://github.com/love2d/love/issues/1592
**/
bool brokenSRGB;

/**
* Other bugs which have workarounds that don't use conditional code at
* the moment:
Expand Down

0 comments on commit fe23c16

Please sign in to comment.