summaryrefslogtreecommitdiffstats
path: root/src/opengl/gl2paintengineex
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
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')
-rw-r--r--src/opengl/gl2paintengineex/qgl2pexvertexarray_p.h14
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp23
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h1
3 files changed, 34 insertions, 4 deletions
diff --git a/src/opengl/gl2paintengineex/qgl2pexvertexarray_p.h b/src/opengl/gl2paintengineex/qgl2pexvertexarray_p.h
index ae73040..d1e7615 100644
--- a/src/opengl/gl2paintengineex/qgl2pexvertexarray_p.h
+++ b/src/opengl/gl2paintengineex/qgl2pexvertexarray_p.h
@@ -118,6 +118,20 @@ public:
<< QGLPoint(left, top);
}
+ inline void addQuad(const QRectF &rect)
+ {
+ qreal top = rect.top();
+ qreal left = rect.left();
+ qreal bottom = rect.bottom();
+ qreal right = rect.right();
+
+ vertexArray << QGLPoint(left, top)
+ << QGLPoint(right, top)
+ << QGLPoint(left, bottom)
+ << QGLPoint(right, bottom);
+
+ }
+
void addPath(const QVectorPath &path, GLfloat curveInverseScale, bool outline = true);
void clear();
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;
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h
index 70a1621..f757bc4 100644
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h
@@ -267,6 +267,7 @@ public:
QGL2PEXVertexArray vertexCoordinateArray;
QGL2PEXVertexArray textureCoordinateArray;
+ QVector<GLushort> elementIndices;
QDataBuffer<GLfloat> opacityArray;
GLfloat staticVertexCoordinateArray[8];
GLfloat staticTextureCoordinateArray[8];