summaryrefslogtreecommitdiffstats
path: root/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/opengl/gl2paintengineex/qglengineshadermanager.cpp')
-rw-r--r--src/opengl/gl2paintengineex/qglengineshadermanager.cpp59
1 files changed, 51 insertions, 8 deletions
diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
index b71c4c1..4b73ca9 100644
--- a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
+++ b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
+** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtOpenGL module of the Qt Toolkit.
**
@@ -34,7 +34,7 @@
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
+** contact the sales department at http://www.qtsoftware.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -191,7 +191,29 @@ QGLEngineShaderManager::~QGLEngineShaderManager()
}
+uint QGLEngineShaderManager::getUniformIdentifier(const char *uniformName)
+{
+ uniformIdentifiers << uniformName;
+ return uniformIdentifiers.size() - 1;
+}
+
+uint QGLEngineShaderManager::getUniformLocation(uint id)
+{
+ QVector<uint> &uniformLocations = currentShaderProg->uniformLocations;
+ uint oldSize = uniformLocations.size();
+ if (oldSize <= id) {
+ uint newSize = id + 1;
+ uniformLocations.resize(newSize);
+
+ for (uint i = oldSize; i < newSize; ++i)
+ uniformLocations[i] = GLuint(-1);
+ }
+ if (uniformLocations.at(id) == GLuint(-1))
+ uniformLocations[id] = currentShaderProg->program->uniformLocation(uniformIdentifiers.at(id));
+
+ return uniformLocations.at(id);
+}
void QGLEngineShaderManager::optimiseForBrushTransform(const QTransform &transform)
@@ -206,43 +228,61 @@ void QGLEngineShaderManager::setDirty()
void QGLEngineShaderManager::setSrcPixelType(Qt::BrushStyle style)
{
+ if (srcPixelType == PixelSrcType(style))
+ return;
+
srcPixelType = style;
shaderProgNeedsChanging = true; //###
}
void QGLEngineShaderManager::setSrcPixelType(PixelSrcType type)
{
+ if (srcPixelType == type)
+ return;
+
srcPixelType = type;
shaderProgNeedsChanging = true; //###
}
void QGLEngineShaderManager::setTextureCoordsEnabled(bool enabled)
{
+ if (useTextureCoords == enabled)
+ return;
+
useTextureCoords = enabled;
shaderProgNeedsChanging = true; //###
}
void QGLEngineShaderManager::setUseGlobalOpacity(bool useOpacity)
{
+ if (useGlobalOpacity == useOpacity)
+ return;
+
useGlobalOpacity = useOpacity;
shaderProgNeedsChanging = true; //###
}
void QGLEngineShaderManager::setMaskType(MaskType type)
{
+ if (maskType == type)
+ return;
+
maskType = type;
shaderProgNeedsChanging = true; //###
}
void QGLEngineShaderManager::setCompositionMode(QPainter::CompositionMode mode)
{
+ if (compositionMode == mode)
+ return;
+
compositionMode = mode;
shaderProgNeedsChanging = true; //###
}
QGLShaderProgram* QGLEngineShaderManager::currentProgram()
{
- return currentShaderProg;
+ return currentShaderProg->program;
}
QGLShaderProgram* QGLEngineShaderManager::simpleProgram()
@@ -432,15 +472,16 @@ bool QGLEngineShaderManager::useCorrectShaderProg()
// At this point, requiredProgram is fully populated so try to find the program in the cache
- foreach (const QGLEngineShaderProg &prog, cachedPrograms) {
+ for (int i = 0; i < cachedPrograms.size(); ++i) {
+ QGLEngineShaderProg &prog = cachedPrograms[i];
if ( (prog.mainVertexShader == requiredProgram.mainVertexShader)
&& (prog.positionVertexShader == requiredProgram.positionVertexShader)
&& (prog.mainFragShader == requiredProgram.mainFragShader)
&& (prog.srcPixelFragShader == requiredProgram.srcPixelFragShader)
&& (prog.compositionFragShader == requiredProgram.compositionFragShader) )
{
- currentShaderProg = prog.program;
- currentShaderProg->enable();
+ currentShaderProg = &prog;
+ currentShaderProg->program->enable();
shaderProgNeedsChanging = false;
return true;
}
@@ -480,8 +521,10 @@ bool QGLEngineShaderManager::useCorrectShaderProg()
}
else {
cachedPrograms.append(requiredProgram);
- currentShaderProg = requiredProgram.program;
- currentShaderProg->enable();
+ // taking the address here is safe since
+ // cachePrograms isn't resized anywhere else
+ currentShaderProg = &cachedPrograms.last();
+ currentShaderProg->program->enable();
}
shaderProgNeedsChanging = false;
return true;