aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph
diff options
context:
space:
mode:
authorSérgio Martins <sergio.martins@kdab.com>2016-06-28 11:34:59 +0100
committerSérgio Martins <sergio.martins@kdab.com>2016-07-11 12:09:26 +0000
commit1e18a4f985f6ec4a0191a2e0cc087b13d29b1719 (patch)
treeded02165d73eef8dd7c4852a36bf1e4ef11d7a51 /src/quick/scenegraph
parentf640a9b7bbefd069f9ee3bf9435e48ccc1f19d1a (diff)
macOS: Use sRGB when doing native font rendering into FBO
Otherwise text appears too dark. A similar bug was fixed in the past for QQuickWidget (which also uses FBO). Now this fixes it for ShaderEffectSource and QQuickItem::grabImage() too. Change-Id: Ia0e176372b9ba8282972f8d60f87f02747291ffe Task-Id: QTBUG-52906 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/quick/scenegraph')
-rw-r--r--src/quick/scenegraph/qsgdefaultlayer.cpp31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/quick/scenegraph/qsgdefaultlayer.cpp b/src/quick/scenegraph/qsgdefaultlayer.cpp
index fa69f911dd..99735564ef 100644
--- a/src/quick/scenegraph/qsgdefaultlayer.cpp
+++ b/src/quick/scenegraph/qsgdefaultlayer.cpp
@@ -42,6 +42,29 @@ DEFINE_BOOL_CONFIG_OPTION(qmlFboOverlay, QML_FBO_OVERLAY)
#endif
DEFINE_BOOL_CONFIG_OPTION(qmlFboFlushBeforeDetach, QML_FBO_FLUSH_BEFORE_DETACH)
+
+
+static QOpenGLFramebufferObject *createFramebuffer(const QSize &size,
+ QOpenGLFramebufferObjectFormat format)
+{
+#ifdef Q_OS_MACOS
+ QOpenGLContext *context = QOpenGLContext::currentContext();
+ if (context->hasExtension("GL_ARB_framebuffer_sRGB")
+ && context->hasExtension("GL_EXT_texture_sRGB")
+ && context->hasExtension("GL_EXT_texture_sRGB_decode"))
+ format.setInternalTextureFormat(GL_SRGB8_ALPHA8_EXT);
+#endif
+ QOpenGLFramebufferObject *fbo = new QOpenGLFramebufferObject(size, format);
+#ifdef Q_OS_MACOS
+ if (format.internalTextureFormat() == GL_SRGB8_ALPHA8_EXT) {
+ QOpenGLFunctions *funcs = context->functions();
+ funcs->glBindTexture(GL_TEXTURE_2D, fbo->texture());
+ funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT);
+ }
+#endif
+ return fbo;
+}
+
namespace
{
class BindableFbo : public QSGBindable
@@ -324,7 +347,7 @@ void QSGDefaultLayer::grab()
format.setInternalTextureFormat(m_format);
format.setSamples(m_context->openglContext()->format().samples());
- m_secondaryFbo = new QOpenGLFramebufferObject(m_size, format);
+ m_secondaryFbo = createFramebuffer(m_size, format);
m_depthStencilBuffer = m_context->depthStencilBufferForFbo(m_secondaryFbo);
} else {
QOpenGLFramebufferObjectFormat format;
@@ -333,14 +356,14 @@ void QSGDefaultLayer::grab()
if (m_recursive) {
deleteFboLater = true;
delete m_secondaryFbo;
- m_secondaryFbo = new QOpenGLFramebufferObject(m_size, format);
+ m_secondaryFbo = createFramebuffer(m_size, format);
funcs->glBindTexture(GL_TEXTURE_2D, m_secondaryFbo->texture());
updateBindOptions(true);
m_depthStencilBuffer = m_context->depthStencilBufferForFbo(m_secondaryFbo);
} else {
delete m_fbo;
delete m_secondaryFbo;
- m_fbo = new QOpenGLFramebufferObject(m_size, format);
+ m_fbo = createFramebuffer(m_size, format);
m_secondaryFbo = 0;
funcs->glBindTexture(GL_TEXTURE_2D, m_fbo->texture());
updateBindOptions(true);
@@ -354,7 +377,7 @@ void QSGDefaultLayer::grab()
Q_ASSERT(m_fbo);
Q_ASSERT(!m_multisampling);
- m_secondaryFbo = new QOpenGLFramebufferObject(m_size, m_fbo->format());
+ m_secondaryFbo = createFramebuffer(m_size, m_fbo->format());
funcs->glBindTexture(GL_TEXTURE_2D, m_secondaryFbo->texture());
updateBindOptions(true);
}