From 9514422eeecb468fbf0a60604f5699f9caba3f39 Mon Sep 17 00:00:00 2001 From: Wouter Huysentruit Date: Mon, 1 Jul 2013 14:27:37 +0200 Subject: Set projection matrix for systems with OpenGL 3.1 The projection matrix should also be set for systems running OpenGL 3.1 with GL_ARB_compatibility extension. Task-number: QTBUG-28284 Change-Id: I756155a6064dcbff29fd817e676d31f24f559e8c Reviewed-by: Sean Harmer --- src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/opengl') diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index 4e198cf550..824e7ecbad 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -545,8 +545,10 @@ void QGL2PaintEngineEx::beginNativePainting() d->funcs.glDisableVertexAttribArray(i); #ifndef QT_OPENGL_ES_2 + const QGLContext *ctx = d->ctx; const QGLFormat &fmt = d->device->format(); if (fmt.majorVersion() < 3 || (fmt.majorVersion() == 3 && fmt.minorVersion() < 1) + || (fmt.majorVersion() == 3 && fmt.minorVersion() == 1 && ctx->contextHandle()->hasExtension(QByteArrayLiteral("GL_ARB_compatibility"))) || fmt.profile() == QGLFormat::CompatibilityProfile) { // be nice to people who mix OpenGL 1.x code with QPainter commands -- cgit v1.2.3 From df1e835f3e3f3f5ca03e73cf328750d3139cf3b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 5 Jul 2013 15:40:19 +0200 Subject: Restore smooth-scaled drawing of 0.5x-2.0x scaled glyphs in the GL engine Commit b5922c89ba942 (Add support for retina glyph-based text drawing in the GL engine), and commit 155a20628b91 (Use QPaintEngineEx to decide if font is too big for using the glyph cache) together changed the behavior of drawing scaled cached glyphs in the GL engine, producing blocky text drawing when using the FreeType font engine. Whereas before we would cache all glyphs without any transform, and let the paint engine take care of the transform, commit b5922c added support for a scaled GL glyph cache, resulting in a 2x cache, drawn at 1x for example. The problem was that the FreeType engine claimed to support producing glyphs at 2x, but did that using the QFontEngine baseclass implementations, which use a simple fast-transform to scale up the glyphs. The result was a 2x cache with horrible looking glyphs. The first step in fixing this issue was to have the FreeType engine claim to only support translations. This would then make the paint engine choose path-based drawing for all scaled text, which is slow. To restore the optimization that we would draw 0.5x-2.0x scaled text using a smooth-scale in the GL engine (which was removed in 155a206), we then needed to extend shouldDrawCachedGlyphs() and add a special condition for this, coupled with a bit of logic in drawCachedGlyphs() that ensures we don't propagate the painter scale to the glyph cache if the engine is not able to produce scaled glyphs for it. This means we get the old behavior of the GL engine doing a smooth scale of the 1x glyph in the cache. Finally, since the raster engine also checks if the font engine supports the current transform, but for FreeType then ends up in a separate code path when actually drawing the glyphs (as the FreeType font engine supports internal glyph caching), we need to add a corresponding check for hasInternalCaching() in the shouldDrawCachedGlyphs() function, now that the FreeType engine only reports that it supports translations. Change-Id: Id03de896dec5f29535b281fb235332ef018045d8 Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../gl2paintengineex/qpaintengineex_opengl2.cpp | 48 ++++++++++++++++------ 1 file changed, 36 insertions(+), 12 deletions(-) (limited to 'src/opengl') diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index 824e7ecbad..80660041b7 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -627,8 +627,28 @@ bool QGL2PaintEngineEx::isNativePaintingActive() const { bool QGL2PaintEngineEx::shouldDrawCachedGlyphs(QFontEngine *fontEngine, const QTransform &t) const { - // Don't try to cache vastly transformed fonts - return t.type() < QTransform::TxProject && QPaintEngineEx::shouldDrawCachedGlyphs(fontEngine, t); + // The paint engine does not support projected cached glyph drawing + if (t.type() == QTransform::TxProject) + return false; + + // The font engine might not support filling the glyph cache + // with the given transform applied, in which case we need to + // fall back to the QPainterPath code-path. + if (!fontEngine->supportsTransformation(t)) { + // Except that drawing paths is slow, so for scales between + // 0.5 and 2.0 we leave the glyph cache untransformed and deal + // with the transform ourselves when painting, resulting in + // drawing 1x cached glyphs with a smooth-scale. + float det = t.determinant(); + if (det >= 0.25f && det <= 4.f) { + // Assuming the baseclass still agrees + return QPaintEngineEx::shouldDrawCachedGlyphs(fontEngine, t); + } + + return false; // Fall back to path-drawing + } + + return QPaintEngineEx::shouldDrawCachedGlyphs(fontEngine, t); } void QGL2PaintEngineExPrivate::transferMode(EngineMode newMode) @@ -1586,19 +1606,23 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp void *cacheKey = const_cast(QGLContextPrivate::contextGroup(ctx)->context()); bool recreateVertexArrays = false; - // We allow scaling, so that the glyph-cache will contain glyphs with the - // appropriate resolution in the case of displays with a device-pixel-ratio != 1. - QTransform transform = s->matrix.type() < QTransform::TxRotate ? - QTransform::fromScale(qAbs(s->matrix.m11()), qAbs(s->matrix.m22())) : - QTransform::fromScale( - QVector2D(s->matrix.m11(), s->matrix.m12()).length(), - QVector2D(s->matrix.m21(), s->matrix.m22()).length()); - + QTransform glyphCacheTransform; QFontEngine *fe = staticTextItem->fontEngine(); + if (fe->supportsTransformation(s->matrix)) { + // The font-engine supports rendering glyphs with the current transform, so we + // build a glyph-cache with the scale pre-applied, so that the cache contains + // glyphs with the appropriate resolution in the case of retina displays. + glyphCacheTransform = s->matrix.type() < QTransform::TxRotate ? + QTransform::fromScale(qAbs(s->matrix.m11()), qAbs(s->matrix.m22())) : + QTransform::fromScale( + QVector2D(s->matrix.m11(), s->matrix.m12()).length(), + QVector2D(s->matrix.m21(), s->matrix.m22()).length()); + } + QGLTextureGlyphCache *cache = - (QGLTextureGlyphCache *) fe->glyphCache(cacheKey, glyphType, transform); + (QGLTextureGlyphCache *) fe->glyphCache(cacheKey, glyphType, glyphCacheTransform); if (!cache || cache->cacheType() != glyphType || cache->contextGroup() == 0) { - cache = new QGLTextureGlyphCache(glyphType, transform); + cache = new QGLTextureGlyphCache(glyphType, glyphCacheTransform); fe->setGlyphCache(cacheKey, cache); recreateVertexArrays = true; } -- cgit v1.2.3