summaryrefslogtreecommitdiffstats
path: root/src/opengl
diff options
context:
space:
mode:
authorJiang Jiang <jiang.jiang@nokia.com>2011-07-28 08:55:21 (GMT)
committerJiang Jiang <jiang.jiang@nokia.com>2011-07-29 12:02:39 (GMT)
commitb3187d850aa6e0a4818e2a982d13aab77ca20a82 (patch)
treecc3b069edd75a1076d2e930f466b30143e1b6463 /src/opengl
parent3a66c5da851223cb4017d69ef3cca7d3818431c7 (diff)
downloadQt-b3187d850aa6e0a4818e2a982d13aab77ca20a82.zip
Qt-b3187d850aa6e0a4818e2a982d13aab77ca20a82.tar.gz
Qt-b3187d850aa6e0a4818e2a982d13aab77ca20a82.tar.bz2
Fix gamma corrected source color in GL
GL_EXT_framebuffer_sRGB expects linear RGB as input color, thus we need to convert sRGB based input color into linear RGB first before using glBlendColor with it. Task-number: QTBUG-20574 Reviewed-by: Samuel Rødal
Diffstat (limited to 'src/opengl')
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp48
1 files changed, 30 insertions, 18 deletions
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
index a961366..dbbb07c 100644
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
@@ -1580,6 +1580,11 @@ static bool fontSmoothingApproximately(qreal target)
}
#endif
+static inline qreal qt_sRGB_to_linear_RGB(qreal f)
+{
+ return f > 0.04045 ? qPow((f + 0.055) / 1.055, 2.4) : f / 12.92;
+}
+
// #define QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO
void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyphType,
@@ -1739,12 +1744,34 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp
}
QBrush pensBrush = q->state()->pen.brush();
- setBrush(pensBrush);
- if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) {
+ bool srgbFrameBufferEnabled = false;
+ if (pensBrush.style() == Qt::SolidPattern &&
+ (ctx->d_ptr->extension_flags & QGLExtensions::SRGBFrameBuffer)) {
+#if defined(Q_WS_MAC)
+ if (glyphType == QFontEngineGlyphCache::Raster_RGBMask)
+#elif defined(Q_WS_WIN)
+ if (glyphType != QFontEngineGlyphCache::Raster_RGBMask || fontSmoothingApproximately(2.1))
+#else
+ if (false)
+#endif
+ {
+ QColor c = pensBrush.color();
+ qreal red = qt_sRGB_to_linear_RGB(c.redF());
+ qreal green = qt_sRGB_to_linear_RGB(c.greenF());
+ qreal blue = qt_sRGB_to_linear_RGB(c.blueF());
+ c = QColor::fromRgbF(red, green, blue, c.alphaF());
+ pensBrush.setColor(c);
+
+ glEnable(FRAMEBUFFER_SRGB_EXT);
+ srgbFrameBufferEnabled = true;
+ }
+ }
- // Subpixel antialiasing without gamma correction
+ setBrush(pensBrush);
+ if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) {
+ // Subpixel antialiasing with gamma correction
QPainter::CompositionMode compMode = q->state()->composition_mode;
Q_ASSERT(compMode == QPainter::CompositionMode_Source
|| compMode == QPainter::CompositionMode_SourceOver);
@@ -1851,21 +1878,6 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp
}
}
- bool srgbFrameBufferEnabled = false;
- if (ctx->d_ptr->extension_flags & QGLExtensions::SRGBFrameBuffer) {
-#if defined(Q_WS_MAC)
- if (glyphType == QFontEngineGlyphCache::Raster_RGBMask)
-#elif defined(Q_WS_WIN)
- if (glyphType != QFontEngineGlyphCache::Raster_RGBMask || fontSmoothingApproximately(2.1))
-#else
- if (false)
-#endif
- {
- glEnable(FRAMEBUFFER_SRGB_EXT);
- srgbFrameBufferEnabled = true;
- }
- }
-
#if defined(QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO)
glDrawElements(GL_TRIANGLE_STRIP, 6 * numGlyphs, GL_UNSIGNED_SHORT, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);