diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-02-01 15:10:58 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-02-01 15:10:58 (GMT) |
commit | f3cf5dd98e321980984288a1768f3375a8349800 (patch) | |
tree | ae845bbe0f29d74367329a9dba5805140a461cdf /src/opengl | |
parent | d60916a4a9281ed1ce2fa5f360d512094b2548a6 (diff) | |
download | Qt-f3cf5dd98e321980984288a1768f3375a8349800.zip Qt-f3cf5dd98e321980984288a1768f3375a8349800.tar.gz Qt-f3cf5dd98e321980984288a1768f3375a8349800.tar.bz2 |
Fix transformed painting of QStaticText in GL2 paint engine
The GL2 paint engine was rewritten to use GL to transform glyphs when
copying them from the glyph cache instead of keeping a separate cache
for different transformations. Since the glyph positions in QStaticText
already include the transformation, we need to run the gl calls with
an identity matrix, otherwise the position of the glyphs will be
transformed twice. The output from drawText() and drawStaticText()
will for the same reason look different for the two different engines.
The option here is to detect the problem when drawing to the opengl2
engine, and then recalculating the glyph positions for the QStaticText.
This will of course create a big overhead when regularly switching
between different paint devices, but it might make sense to optimize
for one QStaticText per paint device. For the time being I haven't
done that, though, since that change would require a bigger hack, so
it warrants deeper consideration.
Diffstat (limited to 'src/opengl')
-rw-r--r-- | src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 27 | ||||
-rw-r--r-- | src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h | 3 |
2 files changed, 22 insertions, 8 deletions
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index 17b3317..544d327 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -1204,9 +1204,8 @@ void QGL2PaintEngineEx::drawStaticTextItem(QStaticTextItem *textItem) ? QFontEngineGlyphCache::Type(textItem->fontEngine->glyphFormat) : d->glyphCacheType; - // ### What about transformations and huge fonts? These are not passed through cache - // in drawTextItem(). - d->drawCachedGlyphs(glyphType, textItem); + // ### What about huge fonts? These are not passed through cache in drawTextItem(). + d->drawCachedGlyphs(glyphType, textItem, true); } void QGL2PaintEngineEx::drawTexture(const QRectF &dest, GLuint textureId, const QSize &size, const QRectF &src) @@ -1276,7 +1275,7 @@ void QGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &textItem staticTextItem.numGlyphs = glyphs.size(); staticTextItem.glyphPositions = positions.data(); - d->drawCachedGlyphs(glyphType, &staticTextItem); + d->drawCachedGlyphs(glyphType, &staticTextItem, false); } return; } @@ -1307,14 +1306,22 @@ namespace { }; } -void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyphType, QStaticTextItem *staticTextItem) +void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyphType, + QStaticTextItem *staticTextItem, + bool includeMatrixInCache) { Q_Q(QGL2PaintEngineEx); + QOpenGL2PaintEngineState *s = q->state(); + QGLTextureGlyphCache *cache = - (QGLTextureGlyphCache *) staticTextItem->fontEngine->glyphCache(ctx, glyphType, QTransform()); + (QGLTextureGlyphCache *) staticTextItem->fontEngine->glyphCache(ctx, glyphType, + includeMatrixInCache + ? s->matrix + : QTransform()); if (!cache || cache->cacheType() != glyphType) { - cache = new QGLTextureGlyphCache(ctx, glyphType, QTransform()); + cache = new QGLTextureGlyphCache(ctx, glyphType, + includeMatrixInCache ? s->matrix : QTransform()); staticTextItem->fontEngine->setGlyphCache(ctx, cache); } @@ -1405,6 +1412,9 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp QBrush pensBrush = q->state()->pen.brush(); setBrush(pensBrush); + QTransform old = s->matrix; + if (includeMatrixInCache) + s->matrix = QTransform(); if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) { // Subpixel antialiasing without gamma correction @@ -1492,6 +1502,9 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp // Reset bindings glBindBuffer(GL_ARRAY_BUFFER, 0); + + if (includeMatrixInCache) + s->matrix = old; } void QGL2PaintEngineEx::drawPixmaps(const QDrawPixmaps::Data *drawingData, int dataCount, const QPixmap &pixmap, QDrawPixmaps::DrawingHints hints) diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h index a7a40a8..4ef1bb9 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h @@ -195,7 +195,8 @@ public: void stroke(const QVectorPath &path, const QPen &pen); void drawTexture(const QGLRect& dest, const QGLRect& src, const QSize &textureSize, bool opaque, bool pattern = false); void drawPixmaps(const QDrawPixmaps::Data *drawingData, int dataCount, const QPixmap &pixmap, QDrawPixmaps::DrawingHints hints); - void drawCachedGlyphs(QFontEngineGlyphCache::Type glyphType, QStaticTextItem *staticTextItem); + void drawCachedGlyphs(QFontEngineGlyphCache::Type glyphType, QStaticTextItem *staticTextItem, + bool includeMatrixInCache); // Calls glVertexAttributePointer if the pointer has changed inline void setVertexAttributePointer(unsigned int arrayIndex, const GLfloat *pointer); |