summaryrefslogtreecommitdiffstats
path: root/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
diff options
context:
space:
mode:
authorSamuel Rødal <sroedal@trolltech.com>2009-07-01 13:17:15 (GMT)
committerSamuel Rødal <sroedal@trolltech.com>2009-07-01 13:19:25 (GMT)
commitf86a6467c0dbfd54603b588e6c001265b0d527e3 (patch)
tree37d9617f4381d3151f878d78344f63766fc2cf43 /src/opengl/gl2paintengineex/qglengineshadermanager.cpp
parentc92b73a19b34ec97262c0959653ac1faf6621de6 (diff)
downloadQt-f86a6467c0dbfd54603b588e6c001265b0d527e3.zip
Qt-f86a6467c0dbfd54603b588e6c001265b0d527e3.tar.gz
Qt-f86a6467c0dbfd54603b588e6c001265b0d527e3.tar.bz2
Added caching of custom shader programs as well in GL 2 shader manager.
Ensures that the programs are evicted from the cache when the shaders are destroyed.
Diffstat (limited to 'src/opengl/gl2paintengineex/qglengineshadermanager.cpp')
-rw-r--r--src/opengl/gl2paintengineex/qglengineshadermanager.cpp42
1 files changed, 28 insertions, 14 deletions
diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
index 068f804..10654ae 100644
--- a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
+++ b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
@@ -506,6 +506,7 @@ bool QGLEngineShaderManager::useCorrectShaderProg()
else
requiredProgram.compositionFragShader = 0;
+ requiredProgram.customShader = customShader ? customShader->shader() : 0;
// At this point, requiredProgram is fully populated so try to find the program in the cache
for (int i = 0; i < cachedPrograms.size(); ++i) {
@@ -514,12 +515,16 @@ bool QGLEngineShaderManager::useCorrectShaderProg()
&& (prog.positionVertexShader == requiredProgram.positionVertexShader)
&& (prog.mainFragShader == requiredProgram.mainFragShader)
&& (prog.srcPixelFragShader == requiredProgram.srcPixelFragShader)
- && (prog.compositionFragShader == requiredProgram.compositionFragShader) )
+ && (prog.compositionFragShader == requiredProgram.compositionFragShader)
+ && (prog.customShader == requiredProgram.customShader) )
{
currentShaderProg = &prog;
currentShaderProg->program->enable();
shaderProgNeedsChanging = false;
+ if (customShader)
+ customShader->updateUniforms(currentShaderProg->program);
+
return true;
}
}
@@ -533,8 +538,8 @@ bool QGLEngineShaderManager::useCorrectShaderProg()
requiredProgram.program->addShader(requiredProgram.maskFragShader);
requiredProgram.program->addShader(requiredProgram.compositionFragShader);
- if (customShader)
- requiredProgram.program->addShader(customShader->shader());
+ if (requiredProgram.customShader)
+ requiredProgram.program->addShader(requiredProgram.customShader);
// We have to bind the vertex attribute names before the program is linked:
requiredProgram.program->bindAttributeLocation("vertexCoordsArray", QT_VERTEX_COORDS_ATTR);
@@ -560,25 +565,34 @@ bool QGLEngineShaderManager::useCorrectShaderProg()
qWarning() << error;
}
else {
- if (customShader) {
- // don't cache custom shaders
- customShaderProg = requiredProgram;
- currentShaderProg = &customShaderProg;
- } else {
- cachedPrograms.append(requiredProgram);
- // taking the address here is safe since
- // cachePrograms isn't resized anywhere else
- currentShaderProg = &cachedPrograms.last();
- }
+ cachedPrograms.append(requiredProgram);
+ // taking the address here is safe since
+ // cachePrograms isn't resized anywhere else
+ currentShaderProg = &cachedPrograms.last();
currentShaderProg->program->enable();
- if (customShader)
+ if (customShader) {
customShader->updateUniforms(currentShaderProg->program);
+ connect(customShader->shader(), SIGNAL(destroyed(QObject *)),
+ this, SLOT(shaderDestroyed(QObject *)));
+ }
}
shaderProgNeedsChanging = false;
return true;
}
+void QGLEngineShaderManager::shaderDestroyed(QObject *shader)
+{
+ for (int i = 0; i < cachedPrograms.size(); ++i) {
+ if (cachedPrograms.at(i).customShader == shader) {
+ delete cachedPrograms.at(i).program;
+ cachedPrograms.removeAt(i--);
+ }
+ }
+
+ shaderProgNeedsChanging = true;
+}
+
void QGLEngineShaderManager::compileNamedShader(QGLEngineShaderManager::ShaderName name, QGLShader::ShaderType type)
{
if (compiledShaders[name])