From fe23c1619897eb357e2f064a1cafe4f5f8926ef9 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Thu, 24 Dec 2020 20:31:33 -0400 Subject: [PATCH] Disable gamma correction on Windows + Intel HD 2/3000 / Intel HD Graphics It's completely broken there. Closes #1592 --- src/modules/graphics/opengl/Canvas.cpp | 9 --------- src/modules/graphics/opengl/Graphics.cpp | 4 ++-- src/modules/graphics/opengl/OpenGL.cpp | 16 ++++++++++++++-- src/modules/graphics/opengl/OpenGL.h | 7 +++++++ 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/modules/graphics/opengl/Canvas.cpp b/src/modules/graphics/opengl/Canvas.cpp index 9bd14ab51..9a38c0305 100644 --- a/src/modules/graphics/opengl/Canvas.cpp +++ b/src/modules/graphics/opengl/Canvas.cpp @@ -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)) @@ -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; } diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 6b5e229be..d826479ee 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -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()); diff --git a/src/modules/graphics/opengl/OpenGL.cpp b/src/modules/graphics/opengl/OpenGL.cpp index 44d7f8767..a5757798f 100644 --- a/src/modules/graphics/opengl/OpenGL.cpp +++ b/src/modules/graphics/opengl/OpenGL.cpp @@ -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 @@ -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]); } @@ -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) diff --git a/src/modules/graphics/opengl/OpenGL.h b/src/modules/graphics/opengl/OpenGL.h index a1a6cb61a..a2467ad25 100644 --- a/src/modules/graphics/opengl/OpenGL.h +++ b/src/modules/graphics/opengl/OpenGL.h @@ -177,6 +177,13 @@ public: **/ 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: