aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick
diff options
context:
space:
mode:
authorSérgio Martins <sergio.martins@kdab.com>2016-08-12 18:49:14 +0100
committerSérgio Martins <sergio.martins@kdab.com>2016-08-24 09:38:08 +0000
commitd9c19faccda88dac54c6737f71b8e54ef2aec9cf (patch)
tree2a437d19e531be57b8bd0c34f43a3cc7435f13de /src/quick
parent01a9c006b0cb3f9ec7c140d25e6bfa3ca6250a4c (diff)
macOS: Check if sRGB is supported before activating the shader
Doing it in QSG24BitTextMaskShader::initialize() assumed that the FBO didn't change afterwards, but FBO can change (due to ShaderEffectSource or item.grabToImage()), resulting in qt_sRGB_to_linear_RGB() getting called for the case of the FBO not supporting sRGB. The work done in 1e18a4f985f6ec is still a good idea (enabling sRGB for all FBOs), and needed for exact rendering but this patch fixes an orthogonal issue. Change-Id: I98b12347e9ef60f46d8bcb20ac5d0d2d7b0c6f57 Task-Id: QTBUG-52906 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'src/quick')
-rw-r--r--src/quick/scenegraph/qsgdefaultglyphnode_p.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
index 5f4e54b218..3eba29ba41 100644
--- a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
+++ b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
@@ -35,6 +35,7 @@
#include <private/qsgmaterialshader_p.h>
#include <qopenglshaderprogram.h>
+#include <qopenglframebufferobject.h>
#include <QtGui/private/qguiapplication_p.h>
#include <qpa/qplatformintegration.h>
@@ -203,6 +204,7 @@ public:
void activate();
void deactivate();
+ bool useSRGB() const;
uint m_useSRGB : 1;
};
@@ -222,11 +224,26 @@ void QSG24BitTextMaskShader::initialize()
}
}
+bool QSG24BitTextMaskShader::useSRGB() const
+{
+#ifdef Q_OS_MACOS
+ if (!m_useSRGB)
+ return false;
+
+ // m_useSRGB is true, but if some QOGLFBO was bound check it's texture format:
+ QOpenGLContext *ctx = QOpenGLContext::currentContext();
+ QOpenGLFramebufferObject *qfbo = QOpenGLContextPrivate::get(ctx)->qgl_current_fbo;
+ return !qfbo || qfbo->format().internalTextureFormat() == GL_SRGB8_ALPHA8_EXT;
+#else
+ return m_useSRGB;
+#endif
+}
+
void QSG24BitTextMaskShader::activate()
{
QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
funcs->glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_SRC_COLOR);
- if (m_useSRGB)
+ if (useSRGB())
funcs->glEnable(GL_FRAMEBUFFER_SRGB);
}
@@ -234,7 +251,7 @@ void QSG24BitTextMaskShader::deactivate()
{
QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
funcs->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- if (m_useSRGB)
+ if (useSRGB())
funcs->glDisable(GL_FRAMEBUFFER_SRGB);
}
@@ -259,7 +276,7 @@ void QSG24BitTextMaskShader::updateState(const RenderState &state, QSGMaterial *
if (oldMaterial == 0 || material->color() != oldMaterial->color() || state.isOpacityDirty()) {
QVector4D color = material->color();
- if (m_useSRGB)
+ if (useSRGB())
color = qt_sRGB_to_linear_RGB(color);
QOpenGLContext::currentContext()->functions()->glBlendColor(color.x(), color.y(), color.z(), color.w());
color = qsg_premultiply(color, state.opacity());