summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@digia.com>2014-12-09 16:50:05 +0100
committerTor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>2014-12-10 21:49:55 +0100
commite9222e199d587f48bd1d0e597aa295ebbe0531e3 (patch)
treee418e7085915584a9c81d2c3f8f7bd3ecc66f320 /src
parente79cdd0e6df7dec2edaea13b6cff45965c3e7456 (diff)
GL2PaintEngine: Prevent fillInPendingGlyphs from breaking gradients
The glyph cache internally uses the image texture unit when blitting, but doesn't always activate the unit before binding its texture, resulting in sometimes binding the glyph cache texture to the wrong unit. The image texture unit is also the same as the brush texture unit, so any time we fill in pending glyphs we need to re-bind the brush texture, otherwise drawing text with eg. gradients will fail after the new glyphs have been filled. The new hasPendingGlyphs() member function of the glyph cache is an optimization so that we don't need to activate and rebind unless there are glyphs that need to be filled. Change-Id: Iac74130145d2d6d7bf95206b5e8a2fc760743cb5 Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/gui/opengl/qopenglpaintengine.cpp20
-rw-r--r--src/gui/painting/qtextureglyphcache.cpp2
-rw-r--r--src/gui/painting/qtextureglyphcache_p.h1
3 files changed, 21 insertions, 2 deletions
diff --git a/src/gui/opengl/qopenglpaintengine.cpp b/src/gui/opengl/qopenglpaintengine.cpp
index 834aed9142..ff1a26c914 100644
--- a/src/gui/opengl/qopenglpaintengine.cpp
+++ b/src/gui/opengl/qopenglpaintengine.cpp
@@ -1639,7 +1639,25 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngine::GlyphFormat gly
cache->populate(fe, staticTextItem->numGlyphs,
staticTextItem->glyphs, staticTextItem->glyphPositions);
}
- cache->fillInPendingGlyphs();
+
+ if (cache->hasPendingGlyphs()) {
+ // Filling in the glyphs binds and sets parameters, so we need to
+ // ensure that the glyph cache doesn't mess with whatever unit
+ // is currently active. Note that the glyph cache internally
+ // uses the image texture unit for blitting to the cache, while
+ // we switch between image and mask units when drawing.
+ static const GLenum glypchCacheTextureUnit = QT_IMAGE_TEXTURE_UNIT;
+ funcs.glActiveTexture(GL_TEXTURE0 + glypchCacheTextureUnit);
+
+ cache->fillInPendingGlyphs();
+
+ // We assume the cache can be trusted on which texture was bound
+ lastTextureUsed = cache->texture();
+
+ // But since the brush and image texture units are possibly shared
+ // we may have to re-bind brush textures after filling in the cache.
+ brushTextureDirty = (QT_BRUSH_TEXTURE_UNIT == glypchCacheTextureUnit);
+ }
}
if (cache->width() == 0 || cache->height() == 0)
diff --git a/src/gui/painting/qtextureglyphcache.cpp b/src/gui/painting/qtextureglyphcache.cpp
index e12d61bbf4..be46a0fba3 100644
--- a/src/gui/painting/qtextureglyphcache.cpp
+++ b/src/gui/painting/qtextureglyphcache.cpp
@@ -222,7 +222,7 @@ bool QTextureGlyphCache::populate(QFontEngine *fontEngine, int numGlyphs, const
void QTextureGlyphCache::fillInPendingGlyphs()
{
- if (m_pendingGlyphs.isEmpty())
+ if (!hasPendingGlyphs())
return;
int requiredHeight = m_h;
diff --git a/src/gui/painting/qtextureglyphcache_p.h b/src/gui/painting/qtextureglyphcache_p.h
index 50c2c9dcc6..2d2fcdfc93 100644
--- a/src/gui/painting/qtextureglyphcache_p.h
+++ b/src/gui/painting/qtextureglyphcache_p.h
@@ -104,6 +104,7 @@ public:
bool populate(QFontEngine *fontEngine, int numGlyphs, const glyph_t *glyphs,
const QFixedPoint *positions);
+ bool hasPendingGlyphs() const { return !m_pendingGlyphs.isEmpty(); };
void fillInPendingGlyphs();
virtual void createTextureData(int width, int height) = 0;