diff options
author | Samuel Rødal <sroedal@trolltech.com> | 2009-07-02 11:16:25 (GMT) |
---|---|---|
committer | Samuel Rødal <sroedal@trolltech.com> | 2009-07-02 11:16:25 (GMT) |
commit | 0431548ddffc56f74cc60e7d341ade3920adefb1 (patch) | |
tree | 2de2714f065e4c6833a8b0349d5fa33af30a7e6a /src/opengl | |
parent | 6dc1536c1d3964a16484b2a55aa161b49e639901 (diff) | |
download | Qt-0431548ddffc56f74cc60e7d341ade3920adefb1.zip Qt-0431548ddffc56f74cc60e7d341ade3920adefb1.tar.gz Qt-0431548ddffc56f74cc60e7d341ade3920adefb1.tar.bz2 |
Further optimized the GL blur filter by caching the QGLShader.
Diffstat (limited to 'src/opengl')
-rw-r--r-- | src/opengl/gl2paintengineex/qglengineshadermanager.cpp | 1 | ||||
-rw-r--r-- | src/opengl/qglpixmapfilter.cpp | 12 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp index 10654ae..9f62b59 100644 --- a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp +++ b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp @@ -56,7 +56,6 @@ QGLCustomShader::QGLCustomShader(QGLShader *shader) QGLCustomShader::~QGLCustomShader() { - delete m_shader; } void QGLCustomShader::updateUniforms(QGLShaderProgram *) diff --git a/src/opengl/qglpixmapfilter.cpp b/src/opengl/qglpixmapfilter.cpp index 662e818..06542a1 100644 --- a/src/opengl/qglpixmapfilter.cpp +++ b/src/opengl/qglpixmapfilter.cpp @@ -57,6 +57,7 @@ QT_BEGIN_NAMESPACE +static QCache<QByteArray, QGLShader> shaderCache; void QGLPixmapFilterBase::bindTexture(const QPixmap &src) const { @@ -321,9 +322,13 @@ bool QGLPixmapBlurFilter::processGL(QPainter *painter, const QPointF &pos, const QGLCustomShader *customShader = const_cast<QGLPixmapBlurFilter *>(this); if (!shader()) { - QGLShader *blurShader = new QGLShader(QGLShader::FragmentShader); - blurShader->compile(generateBlurShader(radius(), quality() == Qt::SmoothTransformation)); - + const QByteArray blurSource = generateBlurShader(radius(), quality() == Qt::SmoothTransformation); + QGLShader *blurShader = shaderCache.object(blurSource); + if (!blurShader) { + blurShader = new QGLShader(QGLShader::FragmentShader); + blurShader->compile(blurSource); + shaderCache.insert(blurSource, blurShader); + } customShader->setShader(blurShader); } @@ -404,6 +409,7 @@ QByteArray QGLPixmapBlurFilter::generateBlurShader(int radius, bool gaussianBlur Q_ASSERT(radius >= 1); QByteArray source; + source.reserve(1000); source.append("uniform highp vec2 invTextureSize;\n"); |