From 75426b7cd200a502d3a0b821c49ef3f1ea3029d2 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Mon, 14 Sep 2009 11:19:41 +0200 Subject: Some small optimizations to gl2 engine. Use qpen_ and qbrush_ accessors for slightly better performance and avoid calling for the same value again and again. Secondly, the engine doesn't use its pen and brush states so there is no point in maintaining them, so don't reset old brush all the time. Reviewed-by: Samuel --- .../gl2paintengineex/qglengineshadermanager.cpp | 4 ++- .../gl2paintengineex/qpaintengineex_opengl2.cpp | 37 +++++----------------- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp index 2d1885c..2502069 100644 --- a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp +++ b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp @@ -216,6 +216,8 @@ void QGLEngineSharedShaders::shaderDestroyed(QObject *shader) QGLShader *QGLEngineSharedShaders::compileNamedShader(ShaderName name, QGLShader::ShaderType type) { Q_ASSERT(name != CustomImageSrcFragmentShader); + Q_ASSERT(name < InvalidShaderName); + if (compiledShaders[name]) return compiledShaders[name]; @@ -514,7 +516,7 @@ bool QGLEngineShaderManager::useCorrectShaderProg() else switch (srcPixelType) { default: case Qt::NoBrush: - qCritical("QGLEngineShaderManager::useCorrectShaderProg() - I'm scared, Qt::NoBrush style is set"); + qFatal("QGLEngineShaderManager::useCorrectShaderProg() - Qt::NoBrush style is set"); break; case QGLEngineShaderManager::ImageSrc: srcPixelFragShaderName = QGLEngineSharedShaders::ImageSrcFragmentShader; diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index adde89c..ea5bec8 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -1039,13 +1039,12 @@ void QGL2PaintEngineEx::fill(const QVectorPath &path, const QBrush &brush) { Q_D(QGL2PaintEngineEx); - if (brush.style() == Qt::NoBrush) + if (qbrush_style(brush) == Qt::NoBrush) return; if (!d->inRenderText) ensureActive(); d->setBrush(&brush); d->fill(path); - d->setBrush(&(state()->brush)); // reset back to the state's brush } void QGL2PaintEngineEx::stroke(const QVectorPath &path, const QPen &pen) @@ -1059,42 +1058,26 @@ void QGL2PaintEngineEx::stroke(const QVectorPath &path, const QPen &pen) ensureActive(); - if ( (pen.isCosmetic() && (pen.style() == Qt::SolidLine)) && (pen.widthF() < 2.5f) ) + qreal penWidth = qpen_widthf(pen); + if ( (pen.isCosmetic() && (penStyle == Qt::SolidLine)) && (penWidth < 2.5f) ) { // We only handle solid, cosmetic pens with a width of 1 pixel const QBrush& brush = pen.brush(); d->setBrush(&brush); - if (pen.widthF() < 0.01f) + if (penWidth < 0.01f) glLineWidth(1.0); else - glLineWidth(pen.widthF()); + glLineWidth(penWidth); d->drawOutline(path); - d->setBrush(&(state()->brush)); } else return QPaintEngineEx::stroke(path, pen); } -void QGL2PaintEngineEx::penChanged() -{ -// qDebug("QGL2PaintEngineEx::penChanged() not implemented!"); -} - - -void QGL2PaintEngineEx::brushChanged() -{ -// qDebug("QGL2PaintEngineEx::brushChanged()"); - Q_D(QGL2PaintEngineEx); - d->setBrush(&(state()->brush)); -} - -void QGL2PaintEngineEx::brushOriginChanged() -{ -// qDebug("QGL2PaintEngineEx::brushOriginChanged()"); - Q_D(QGL2PaintEngineEx); - d->brushUniformsDirty = true; -} +void QGL2PaintEngineEx::penChanged() { } +void QGL2PaintEngineEx::brushChanged() { } +void QGL2PaintEngineEx::brushOriginChanged() { } void QGL2PaintEngineEx::opacityChanged() { @@ -1302,8 +1285,6 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(const QPointF &p, const QTextIte glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, textureCoordinateArray.data()); glDrawArrays(GL_TRIANGLES, 0, 6 * glyphs.size()); - - setBrush(&(q->state()->brush)); //### } bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) @@ -1717,8 +1698,6 @@ void QGL2PaintEngineEx::setState(QPainterState *new_state) d->matrixDirty = true; d->compositionModeDirty = true; - d->brushTextureDirty = true; - d->brushUniformsDirty = true; d->simpleShaderDepthUniformDirty = true; d->depthUniformDirty = true; d->simpleShaderMatrixUniformDirty = true; -- cgit v0.12