From 7dd7f76e870d45abfd8b828745b00d0f3d810f9f Mon Sep 17 00:00:00 2001 From: Deve Date: Fri, 11 Dec 2015 18:53:48 +0100 Subject: [PATCH] Check if we really need to re-create the device by checking if framebuffer is sRGB or not. --- src/graphics/central_settings.cpp | 12 ++++++++++++ src/graphics/central_settings.hpp | 2 ++ src/graphics/irr_driver.cpp | 12 +++++++----- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/graphics/central_settings.cpp b/src/graphics/central_settings.cpp index 719e7f4f9..7c946f5e8 100644 --- a/src/graphics/central_settings.cpp +++ b/src/graphics/central_settings.cpp @@ -46,6 +46,7 @@ void CentralVideoSettings::init() hasTextureCompression = false; hasUBO = false; hasGS = false; + hasSRGBCapableVisual = false; m_GI_has_artifact = false; m_need_rh_workaround = false; @@ -179,6 +180,12 @@ void CentralVideoSettings::init() // Bindless textures are all treated RGB even sRGB one m_need_srgb_workaround = true; } + + // Check if visual is sRGB-capable + GLint param; + glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_BACK_LEFT, + GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING, ¶m); + hasSRGBCapableVisual = (param == GL_SRGB); } } @@ -207,6 +214,11 @@ bool CentralVideoSettings::needsRGBBindlessWorkaround() const return m_need_srgb_workaround; } +bool CentralVideoSettings::needsSRGBCapableVisualWorkaround() const +{ + return !hasSRGBCapableVisual && GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_FRAMEBUFFER_SRGB_CAPABLE); +} + bool CentralVideoSettings::isARBGeometryShader4Usable() const { return hasGS; diff --git a/src/graphics/central_settings.hpp b/src/graphics/central_settings.hpp index dbde9c656..295c8689a 100644 --- a/src/graphics/central_settings.hpp +++ b/src/graphics/central_settings.hpp @@ -40,6 +40,7 @@ private: bool hasSSBO; bool hasImageLoadStore; bool hasMultiDrawIndirect; + bool hasSRGBCapableVisual; bool m_need_rh_workaround; bool m_need_srgb_workaround; @@ -52,6 +53,7 @@ public: // Needs special handle ? bool needRHWorkaround() const; bool needsRGBBindlessWorkaround() const; + bool needsSRGBCapableVisualWorkaround() const; // Extension is available and safe to use bool isARBUniformBufferObjectUsable() const; diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 0377b3c9c..6b1a73dd9 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -511,14 +511,16 @@ void IrrDriver::initDevice() } CVS->init(); - + // This is the ugly hack for intel driver on linux, which doesn't // use sRGB-capable visual, even if we request it. This causes - // the screen to be darker than expected. Setting WithAlphaChannel - // to true forces using the proper format on mesa side. - if (!ProfileWorld::isNoGraphics() && GraphicsRestrictions::isDisabled( - GraphicsRestrictions::GR_FRAMEBUFFER_SRGB_CAPABLE)) + // the screen to be darker than expected. It affects mesa 10.6 and newer. + // Though we are able to force to use the proper format on mesa side by + // setting WithAlphaChannel parameter. + if (!ProfileWorld::isNoGraphics() && CVS->needsSRGBCapableVisualWorkaround()) { + Log::warn("irr_driver", "Created visual is not sRGB-capable. " + "Re-creating device to workaround the issue."); m_device->closeDevice(); m_device->drop();