diff options
author | Samuel Rødal <sroedal@trolltech.com> | 2009-07-28 12:46:21 (GMT) |
---|---|---|
committer | Samuel Rødal <sroedal@trolltech.com> | 2009-07-28 12:47:35 (GMT) |
commit | 928eb3dee17f43d54262d1f3dfc5212f183e6ce9 (patch) | |
tree | 43d4b5a7ede9dd9156047abea70f8d9defce0b59 /src/opengl/gl2paintengineex | |
parent | dbdc54791e585f3c6bf62c1a091ef844a66483ba (diff) | |
download | Qt-928eb3dee17f43d54262d1f3dfc5212f183e6ce9.zip Qt-928eb3dee17f43d54262d1f3dfc5212f183e6ce9.tar.gz Qt-928eb3dee17f43d54262d1f3dfc5212f183e6ce9.tar.bz2 |
Improve GL filter performance by caching custom shader programs.
This brings performance back up to where it was pre-merge.
Diffstat (limited to 'src/opengl/gl2paintengineex')
-rw-r--r-- | src/opengl/gl2paintengineex/qglengineshadermanager.cpp | 26 | ||||
-rw-r--r-- | src/opengl/gl2paintengineex/qglengineshadermanager_p.h | 3 |
2 files changed, 19 insertions, 10 deletions
diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp index dab1257..0692277 100644 --- a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp +++ b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp @@ -320,6 +320,19 @@ void QGLEngineShaderManager::setCustomStage(QGLCustomShaderStage* stage) shaderProgNeedsChanging = true; } +void QGLEngineShaderManager::shaderDestroyed(QObject *shader) +{ + // Remove any shader programs which has this as the srcPixel shader: + for (int i = 0; i < cachedPrograms.size(); ++i) { + if (cachedPrograms.at(i).srcPixelFragShader == shader) { + delete cachedPrograms.at(i).program; + cachedPrograms.removeAt(i--); + } + } + + shaderProgNeedsChanging = true; +} + void QGLEngineShaderManager::removeCustomStage(QGLCustomShaderStage* stage) { Q_UNUSED(stage); // Currently we only support one at a time... @@ -329,16 +342,6 @@ void QGLEngineShaderManager::removeCustomStage(QGLCustomShaderStage* stage) if (!compiledShader) return; - // Remove any shader programs which has this as the srcPixel shader: - for (int i = 0; i < cachedPrograms.size(); ++i) { - QGLEngineShaderProg &prog = cachedPrograms[i]; - if (prog.srcPixelFragShader == compiledShader) { - delete prog.program; - cachedPrograms.removeOne(prog); - break; - } - } - compiledShaders[CustomImageSrcFragmentShader] = 0; customSrcStage = 0; shaderProgNeedsChanging = true; @@ -618,6 +621,9 @@ void QGLEngineShaderManager::compileNamedShader(QGLEngineShaderManager::ShaderNa newShader = new QGLShader(type, ctx, this); newShader->compile(source); customShaderCache.insert(source, newShader); + + connect(newShader, SIGNAL(destroyed(QObject *)), + this, SLOT(shaderDestroyed(QObject *))); } } else { source = qglEngineShaderSourceCode[name]; diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager_p.h b/src/opengl/gl2paintengineex/qglengineshadermanager_p.h index 69574ba..8122a08 100644 --- a/src/opengl/gl2paintengineex/qglengineshadermanager_p.h +++ b/src/opengl/gl2paintengineex/qglengineshadermanager_p.h @@ -408,6 +408,9 @@ public: Q_ENUMS(ShaderName) #endif +private slots: + void shaderDestroyed(QObject *shader); + private: QGLContext* ctx; bool shaderProgNeedsChanging; |