summaryrefslogtreecommitdiffstats
path: root/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-02-02 13:23:22 (GMT)
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-02-02 13:23:22 (GMT)
commitc265f7ac9a7a2344cc441a474c76e2ecf36bafbf (patch)
treee5c7029b337d100e95146cfbee5c1fdf87bfbc6e /src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
parent8e4978fefaa52056dd0c58162d2eeeebdb739d36 (diff)
downloadQt-c265f7ac9a7a2344cc441a474c76e2ecf36bafbf.zip
Qt-c265f7ac9a7a2344cc441a474c76e2ecf36bafbf.tar.gz
Qt-c265f7ac9a7a2344cc441a474c76e2ecf36bafbf.tar.bz2
Add experimental support for using drawElements to draw cached text
According to some design documents, drawElements() is likely to be quicker on some devices, as the driver then does not have to create the index array. To test the impact of this, we cache use drawElements and cache the index array in QStaticText
Diffstat (limited to 'src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp')
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp37
1 files changed, 34 insertions, 3 deletions
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
index eff02b2..878faf4 100644
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
@@ -1276,6 +1276,8 @@ void QGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &textItem
QPaintEngineEx::drawTextItem(p, ti);
}
+#define QSTATICTEXT_USE_INDEXARRAY
+
namespace {
class QOpenGLStaticTextUserData: public QStaticTextUserData
@@ -1296,6 +1298,10 @@ namespace {
QGLContext *ctx;
GLuint vertexCoordVBOId;
GLuint textureCoordVBOId;
+
+#if defined(QSTATICTEXT_USE_INDEXARRAY)
+ QVector<GLubyte> indices;
+#endif
};
}
@@ -1332,12 +1338,21 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp
GLfloat dx = 1.0 / cache->width();
GLfloat dy = 1.0 / cache->height();
+#if defined(QSTATICTEXT_USE_INDEXARRAY)
+ QVector<GLubyte> indices;
+#endif
+
if (staticTextItem->userData == 0
|| staticTextItem->userData->type != QStaticTextUserData::OpenGLUserData
|| staticTextItem->userDataNeedsUpdate) {
vertexCoordinateArray.clear();
textureCoordinateArray.clear();
+#if defined(QSTATICTEXT_USE_INDEXARRAY)
+ indices.clear();
+ int j=0;
+#endif
+
for (int i=0; i<staticTextItem->numGlyphs; ++i) {
const QTextureGlyphCache::Coord &c = cache->coords.value(staticTextItem->glyphs[i]);
int x = staticTextItem->glyphPositions[i].x.toInt() + c.baseLineX - margin;
@@ -1345,8 +1360,12 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp
vertexCoordinateArray.addRect(QRectF(x, y, c.w, c.h));
textureCoordinateArray.addRect(QRectF(c.x*dx, c.y*dy, c.w * dx, c.h * dy));
- }
+#if defined(QSTATICTEXT_USE_INDEXARRAY)
+ for (int k=0; k<6; ++k)
+ indices.append(j++);
+#endif
+ }
if (staticTextItem->useBackendOptimizations) {
QOpenGLStaticTextUserData *userData =
@@ -1370,16 +1389,19 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp
glBufferData(GL_ARRAY_BUFFER, textureCoordinateArraySize,
textureCoordinateArray.data(), GL_STATIC_DRAW);
+#if defined(QSTATICTEXT_USE_INDEXARRAY)
+ userData->indices = indices;
+#endif
+
// If a new user data has been created, make sure we delete the old
staticTextItem->setUserData(userData);
- staticTextItem->userDataNeedsUpdate = false;
+ staticTextItem->userDataNeedsUpdate = false;
} else {
setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinateArray.data());
setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinateArray.data());
}
}
-
if (staticTextItem->useBackendOptimizations) {
Q_ASSERT(staticTextItem->userData != 0);
Q_ASSERT(staticTextItem->userData->type == QStaticTextUserData::OpenGLUserData);
@@ -1391,6 +1413,10 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp
glBindBuffer(GL_ARRAY_BUFFER, userData->textureCoordVBOId);
glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, 0);
+
+#if defined(QSTATICTEXT_USE_INDEXARRAY)
+ indices = userData->indices;
+#endif
}
if (addOffset) {
@@ -1491,7 +1517,12 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp
updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, false);
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::MaskTexture), QT_MASK_TEXTURE_UNIT);
+
+#if defined(QSTATICTEXT_USE_INDEXARRAY)
+ glDrawElements(GL_TRIANGLES, 6 * staticTextItem->numGlyphs, GL_UNSIGNED_BYTE, indices.constData());
+#else
glDrawArrays(GL_TRIANGLES, 0, 6 * staticTextItem->numGlyphs);
+#endif
// Reset bindings
glBindBuffer(GL_ARRAY_BUFFER, 0);