summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-02-08 13:18:18 (GMT)
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-02-08 13:18:18 (GMT)
commit1f931d2d879cf51d56268f592298f81218fb43fa (patch)
treee41acb9e481150d38d79b4a6f0fdf6231bce12a6
parentaa674169ca31b6e296021b3b8f5a448aeecf0973 (diff)
downloadQt-1f931d2d879cf51d56268f592298f81218fb43fa.zip
Qt-1f931d2d879cf51d56268f592298f81218fb43fa.tar.gz
Qt-1f931d2d879cf51d56268f592298f81218fb43fa.tar.bz2
Remove VBO caching and glDrawElements path in QStaticText
glDrawElements needs to be handled properly, using triangle strips rather than triangle lists, so the code has been removed for now. The VBO caching did not gain us any particular performance. We rather cache the client-side buffers for the same speed-up but with less clean-up complexity.
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp167
1 files changed, 43 insertions, 124 deletions
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
index c66472c..18d67e9 100644
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
@@ -1279,50 +1279,25 @@ void QGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &textItem
QPaintEngineEx::drawTextItem(p, ti);
}
-#define QSTATICTEXT_USE_INDEXARRAY
+namespace {
-class QOpenGLStaticTextUserData: public QObject, public QStaticTextUserData
-{
- Q_OBJECT
-public:
- QOpenGLStaticTextUserData(QGLContext *glContext)
- : QStaticTextUserData(OpenGLUserData),
- vertexCoordVBOId(0), textureCoordVBOId(0), ctx(glContext)
- {
- connect(QGLSignalProxy::instance(),
- SIGNAL(aboutToDestroyContext(const QGLContext*)),
- SLOT(cleanupGLContextRefs(const QGLContext*)));
- }
-
- ~QOpenGLStaticTextUserData()
+ class QOpenGLStaticTextUserData: public QStaticTextUserData
{
- if (ctx != 0)
- cleanupGLContextRefs(ctx);
- }
-
- QGLContext *ctx;
- GLuint vertexCoordVBOId;
- GLuint textureCoordVBOId;
-
-#if defined(QSTATICTEXT_USE_INDEXARRAY)
- QVector<GLuint> indices;
-#endif
+ public:
+ QOpenGLStaticTextUserData()
+ : QStaticTextUserData(OpenGLUserData)
+ {
+ }
-public Q_SLOTS:
- void cleanupGLContextRefs(const QGLContext *context)
- {
- if (context == ctx) {
- if (vertexCoordVBOId != 0)
- glDeleteBuffers(1, &vertexCoordVBOId);
+ ~QOpenGLStaticTextUserData()
+ {
+ }
- if (textureCoordVBOId != 0)
- glDeleteBuffers(1, &textureCoordVBOId);
+ QGL2PEXVertexArray vertexCoordinateArray;
+ QGL2PEXVertexArray textureCoordinateArray;
+ };
- vertexCoordVBOId = 0;
- textureCoordVBOId = 0;
- }
- }
-};
+}
void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyphType,
QStaticTextItem *staticTextItem,
@@ -1357,10 +1332,6 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp
GLfloat dx = 1.0 / cache->width();
GLfloat dy = 1.0 / cache->height();
-#if defined(QSTATICTEXT_USE_INDEXARRAY)
- QVector<GLuint> indices;
-#endif
-
bool recreateVertexArrays = false;
if (staticTextItem->userDataNeedsUpdate)
recreateVertexArrays = true;
@@ -1368,93 +1339,49 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp
recreateVertexArrays = true;
else if (staticTextItem->userData->type != QStaticTextUserData::OpenGLUserData)
recreateVertexArrays = true;
- else if (static_cast<QOpenGLStaticTextUserData *>(staticTextItem->userData)->ctx != ctx)
- recreateVertexArrays = true;
-
- if (recreateVertexArrays) {
- vertexCoordinateArray.clear();
- textureCoordinateArray.clear();
-
-#if defined(QSTATICTEXT_USE_INDEXARRAY)
- QStaticTextUserData *uData = staticTextItem->userData;
- QOpenGLStaticTextUserData *openGlUserData = uData != 0
- && uData->type == QStaticTextUserData::OpenGLUserData
- ? static_cast<QOpenGLStaticTextUserData *>(uData)
- : 0;
- bool updateIndices = openGlUserData == 0
- || openGlUserData->indices.size() < staticTextItem->numGlyphs;
- 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;
- int y = staticTextItem->glyphPositions[i].y.toInt() - c.baseLineY - margin;
-
- 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)
- if (updateIndices) {
- for (int k=0; k<6; ++k)
- indices.append(j++);
- }
-#endif
- }
- if (staticTextItem->useBackendOptimizations) {
- QOpenGLStaticTextUserData *userData =
- staticTextItem->userData != 0 && staticTextItem->userData->type == QStaticTextUserData::OpenGLUserData
- ? static_cast<QOpenGLStaticTextUserData *>(staticTextItem->userData)
- : new QOpenGLStaticTextUserData(ctx);
+ // Use global arrays by default
+ QGL2PEXVertexArray *vertexCoordinates = &vertexCoordinateArray;
+ QGL2PEXVertexArray *textureCoordinates = &textureCoordinateArray;
- int vertexCoordinateArraySize = vertexCoordinateArray.vertexCount() * sizeof(QGLPoint);
- if (userData->vertexCoordVBOId == 0)
- glGenBuffers(1, &userData->vertexCoordVBOId);
-
- int textureCoordinateArraySize = textureCoordinateArray.vertexCount() * sizeof(QGLPoint);
- if (userData->textureCoordVBOId == 0)
- glGenBuffers(1, &userData->textureCoordVBOId);
-
- glBindBuffer(GL_ARRAY_BUFFER, userData->vertexCoordVBOId);
- glBufferData(GL_ARRAY_BUFFER, vertexCoordinateArraySize,
- vertexCoordinateArray.data(), GL_STATIC_DRAW);
+ if (staticTextItem->useBackendOptimizations) {
+ QOpenGLStaticTextUserData *userData = 0;
- glBindBuffer(GL_ARRAY_BUFFER, userData->textureCoordVBOId);
- glBufferData(GL_ARRAY_BUFFER, textureCoordinateArraySize,
- textureCoordinateArray.data(), GL_STATIC_DRAW);
+ if (staticTextItem->userData == 0
+ || staticTextItem->userData->type != QStaticTextUserData::OpenGLUserData) {
-#if defined(QSTATICTEXT_USE_INDEXARRAY)
- if (updateIndices)
- userData->indices = indices;
-#endif
-
- // If a new user data has been created, make sure we delete the old
+ userData = new QOpenGLStaticTextUserData();
staticTextItem->setUserData(userData);
- staticTextItem->userDataNeedsUpdate = false;
} else {
- setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinateArray.data());
- setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinateArray.data());
+ userData = static_cast<QOpenGLStaticTextUserData*>(staticTextItem->userData);
}
+
+ // Use cache if backend optimizations is turned on
+ vertexCoordinates = &userData->vertexCoordinateArray;
+ textureCoordinates = &userData->textureCoordinateArray;
}
- if (staticTextItem->useBackendOptimizations) {
- Q_ASSERT(staticTextItem->userData != 0);
- Q_ASSERT(staticTextItem->userData->type == QStaticTextUserData::OpenGLUserData);
- QOpenGLStaticTextUserData *userData = static_cast<QOpenGLStaticTextUserData *>(staticTextItem->userData);
- glBindBuffer(GL_ARRAY_BUFFER, userData->vertexCoordVBOId);
- glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, 0);
+ if (recreateVertexArrays) {
+ vertexCoordinates->clear();
+ textureCoordinates->clear();
- glBindBuffer(GL_ARRAY_BUFFER, userData->textureCoordVBOId);
- glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, 0);
+ 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;
+ int y = staticTextItem->glyphPositions[i].y.toInt() - c.baseLineY - margin;
-#if defined(QSTATICTEXT_USE_INDEXARRAY)
- indices = userData->indices;
-#endif
+ vertexCoordinates->addRect(QRectF(x, y, c.w, c.h));
+ textureCoordinates->addRect(QRectF(c.x*dx, c.y*dy, c.w * dx, c.h * dy));
+ }
+
+ staticTextItem->userDataNeedsUpdate = false;
}
+ setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinates->data());
+ setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinates->data());
+
if (addOffset) {
addOffset = false;
matrixDirty = true;
@@ -1473,6 +1400,7 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp
QTransform old = s->matrix;
if (includeMatrixInCache)
s->matrix = QTransform();
+
if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) {
// Subpixel antialiasing without gamma correction
@@ -1557,14 +1485,7 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp
shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::MaskTexture), QT_MASK_TEXTURE_UNIT);
-#if defined(QSTATICTEXT_USE_INDEXARRAY)
- glDrawElements(GL_TRIANGLES, 6 * staticTextItem->numGlyphs, GL_UNSIGNED_INT, indices.constData());
-#else
glDrawArrays(GL_TRIANGLES, 0, 6 * staticTextItem->numGlyphs);
-#endif
-
- // Reset bindings
- glBindBuffer(GL_ARRAY_BUFFER, 0);
if (includeMatrixInCache)
s->matrix = old;
@@ -2191,5 +2112,3 @@ QOpenGL2PaintEngineState::~QOpenGL2PaintEngineState()
}
QT_END_NAMESPACE
-
-#include "qpaintengineex_opengl2.moc"