summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-05-31 08:36:52 +0200
committerSamuli Piippo <samuli.piippo@digia.com>2011-06-09 13:06:02 +0300
commit252dab06707b60e4cfdeee6025180a0080f70c63 (patch)
tree22b6daee0adb7b0e6af006cf8d36fb6fe22445c2
parent569123b25689d3007b53e3031dac79758d05f12f (diff)
downloadqt4-tools-252dab06707b60e4cfdeee6025180a0080f70c63.tar.gz
Fix antialiasing with transformed text in OpenGL2 paint engine
Since the paint engine now transforms the prerendered glyphs instead of rendering transformed glyphs as paths, we need to turn on texture filtering to avoid antialiasing artifacts. In order to do this, we also need to pad the glyphs in the glyph cache, otherwise you will get artifacts when sampling the area around the glyph's bounding rect (where there might be other glyphs.) This done by adding a glyphPadding() function to the cache which returns the number of pixels to pad between each glyph. Updated: This also fixes a general issue where some combinations of font sizes and transformations will cause the engine to sample neighbouring glyphs, so this has been backported to Qt 4.6.x. Task-number: QTBUG-9706, QTBUG-11028 Reviewed-by: Tom Conflicts: src/gui/painting/qtextureglyphcache.cpp src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp (cherry picked from commit 21f5bf3a3030a393ba17ce7726b70fe853b5b608)
-rw-r--r--src/gui/painting/qtextureglyphcache.cpp7
-rw-r--r--src/gui/painting/qtextureglyphcache_p.h1
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp3
-rw-r--r--src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp5
-rw-r--r--src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h1
5 files changed, 13 insertions, 4 deletions
diff --git a/src/gui/painting/qtextureglyphcache.cpp b/src/gui/painting/qtextureglyphcache.cpp
index 011700a561..efdbb2f0f2 100644
--- a/src/gui/painting/qtextureglyphcache.cpp
+++ b/src/gui/painting/qtextureglyphcache.cpp
@@ -66,6 +66,7 @@ void QTextureGlyphCache::populate(const QTextItemInt &ti,
m_current_textitem = &ti;
const int margin = glyphMargin();
+ const int paddingDoubled = glyphPadding() * 2;
QHash<glyph_t, Coord> listItemCoordinates;
int rowHeight = 0;
@@ -114,7 +115,7 @@ void QTextureGlyphCache::populate(const QTextItemInt &ti,
if (listItemCoordinates.isEmpty())
return;
- rowHeight += margin * 2;
+ rowHeight += margin * 2 + paddingDoubled;
if (isNull())
createCache(QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH, rowHeight);
@@ -126,7 +127,7 @@ void QTextureGlyphCache::populate(const QTextItemInt &ti,
if (m_cx + c.w > m_w) {
// no room on the current line, start new glyph strip
m_cx = 0;
- m_cy = m_h;
+ m_cy = m_h + paddingDoubled;
}
if (m_cy + c.h > m_h) {
int new_height;
@@ -153,7 +154,7 @@ void QTextureGlyphCache::populate(const QTextItemInt &ti,
} else {
// for the Mono case, glyph_width is 8-bit aligned,
// and therefore so will m_cx
- m_cx += c.w;
+ m_cx += c.w + paddingDoubled;
}
++iter;
}
diff --git a/src/gui/painting/qtextureglyphcache_p.h b/src/gui/painting/qtextureglyphcache_p.h
index e1a20a8747..65e661ddb3 100644
--- a/src/gui/painting/qtextureglyphcache_p.h
+++ b/src/gui/painting/qtextureglyphcache_p.h
@@ -97,6 +97,7 @@ public:
virtual void createTextureData(int width, int height) = 0;
virtual void resizeTextureData(int width, int height) = 0;
virtual int glyphMargin() const { return 0; }
+ virtual int glyphPadding() const { return 0; }
virtual void fillTexture(const Coord &coord, glyph_t glyph) = 0;
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
index 2b27506b5a..b4ea386910 100644
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
@@ -1394,7 +1394,8 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(const QPointF &p, QFontEngineGly
glActiveTexture(GL_TEXTURE0 + QT_MASK_TEXTURE_UNIT);
glBindTexture(GL_TEXTURE_2D, cache->texture());
- updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, false);
+ QOpenGL2PaintEngineState *s = q->state();
+ updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, s->matrix.type() > QTransform::TxTranslate);
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::MaskTexture), QT_MASK_TEXTURE_UNIT);
glDrawArrays(GL_TRIANGLES, 0, 6 * glyphs.size());
diff --git a/src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp b/src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp
index 69398f9481..68d935e0f5 100644
--- a/src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp
+++ b/src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp
@@ -246,4 +246,9 @@ int QGLTextureGlyphCache::glyphMargin() const
#endif
}
+int QGLTextureGlyphCache::glyphPadding() const
+{
+ return 1;
+}
+
QT_END_NAMESPACE
diff --git a/src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h b/src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h
index 375b2044c3..27ecf6580f 100644
--- a/src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h
+++ b/src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h
@@ -73,6 +73,7 @@ public:
virtual void resizeTextureData(int width, int height);
virtual void fillTexture(const Coord &c, glyph_t glyph);
virtual int glyphMargin() const;
+ virtual int glyphPadding() const;
inline GLuint texture() const { return m_texture; }