summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--src/opengl/gl2paintengineex/qglengineshadermanager.cpp42
-rw-r--r--src/opengl/gl2paintengineex/qglengineshadermanager_p.h5
2 files changed, 32 insertions, 15 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])
diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager_p.h b/src/opengl/gl2paintengineex/qglengineshadermanager_p.h
index 891776f..c749f52 100644
--- a/src/opengl/gl2paintengineex/qglengineshadermanager_p.h
+++ b/src/opengl/gl2paintengineex/qglengineshadermanager_p.h
@@ -253,6 +253,7 @@ struct QGLEngineShaderProg
QGLShader* srcPixelFragShader;
QGLShader* maskFragShader; // Can be null for no mask
QGLShader* compositionFragShader; // Can be null for GL-handled mode
+ QGLShader* customShader;
QGLShaderProgram* program;
QVector<uint> uniformLocations;
@@ -387,6 +388,9 @@ public:
Q_ENUMS(ShaderName)
#endif
+private slots:
+ void shaderDestroyed(QObject *shader);
+
private:
QGLContext* ctx;
bool shaderProgNeedsChanging;
@@ -403,7 +407,6 @@ private:
QGLShaderProgram* simpleShaderProg;
QGLEngineShaderProg* currentShaderProg;
- QGLEngineShaderProg customShaderProg;
QGLCustomShader* customShader;
// TODO: Possibly convert to a LUT