summaryrefslogtreecommitdiffstats
path: root/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-02-09 12:05:15 (GMT)
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-02-09 12:05:15 (GMT)
commitd92f8dd19a2f52771063faf0b926faa22149a206 (patch)
treeb5dd526c1b7ddec05dedbd8bf9e13613d329c25e /src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
parent1f931d2d879cf51d56268f592298f81218fb43fa (diff)
downloadQt-d92f8dd19a2f52771063faf0b926faa22149a206.zip
Qt-d92f8dd19a2f52771063faf0b926faa22149a206.tar.gz
Qt-d92f8dd19a2f52771063faf0b926faa22149a206.tar.bz2
Use glDrawElements and triangle strips to draw glyphs in GL engine
We keep around a engine-global index array which we only grow when we need to. This should hopefully speed up text drawing on some devices.
Diffstat (limited to 'src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp')
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
index 18d67e9..685f0c1 100644
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
@@ -1372,13 +1372,28 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp
int x = staticTextItem->glyphPositions[i].x.toInt() + c.baseLineX - margin;
int y = staticTextItem->glyphPositions[i].y.toInt() - c.baseLineY - margin;
- vertexCoordinates->addRect(QRectF(x, y, c.w, c.h));
- textureCoordinates->addRect(QRectF(c.x*dx, c.y*dy, c.w * dx, c.h * dy));
+ vertexCoordinates->addQuad(QRectF(x, y, c.w, c.h));
+ textureCoordinates->addQuad(QRectF(c.x*dx, c.y*dy, c.w * dx, c.h * dy));
}
staticTextItem->userDataNeedsUpdate = false;
}
+ if (elementIndices.size() < staticTextItem->numGlyphs*6) {
+ Q_ASSERT(elementIndices.size() % 6 == 0);
+ int j = elementIndices.size() / 6 * 4;
+ while (j < staticTextItem->numGlyphs*4) {
+ elementIndices.append(j + 0);
+ elementIndices.append(j + 0);
+ elementIndices.append(j + 1);
+ elementIndices.append(j + 2);
+ elementIndices.append(j + 3);
+ elementIndices.append(j + 3);
+
+ j += 4;
+ }
+ }
+
setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinates->data());
setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinates->data());
@@ -1454,7 +1469,7 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp
updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, false);
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::MaskTexture), QT_MASK_TEXTURE_UNIT);
- glDrawArrays(GL_TRIANGLES, 0, 6 * staticTextItem->numGlyphs);
+ glDrawElements(GL_TRIANGLE_STRIP, 6 * staticTextItem->numGlyphs, GL_UNSIGNED_SHORT, elementIndices.data());
shaderManager->setMaskType(QGLEngineShaderManager::SubPixelMaskPass2);
@@ -1485,7 +1500,7 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::MaskTexture), QT_MASK_TEXTURE_UNIT);
- glDrawArrays(GL_TRIANGLES, 0, 6 * staticTextItem->numGlyphs);
+ glDrawElements(GL_TRIANGLE_STRIP, 6 * staticTextItem->numGlyphs, GL_UNSIGNED_SHORT, elementIndices.data());
if (includeMatrixInCache)
s->matrix = old;