summaryrefslogtreecommitdiffstats
path: root/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
diff options
context:
space:
mode:
authorSamuel Rødal <sroedal@trolltech.com>2009-06-30 07:45:14 (GMT)
committerSamuel Rødal <sroedal@trolltech.com>2009-06-30 12:20:11 (GMT)
commit351e890aa13faac69a0ceaa8cb02660b2275cf82 (patch)
treecaf61d0d83735128390759638b20011d3b150cf7 /src/opengl/gl2paintengineex/qglengineshadermanager.cpp
parent9dd82fcebc50ca802e9e24a50283152e1dc35508 (diff)
downloadQt-351e890aa13faac69a0ceaa8cb02660b2275cf82.zip
Qt-351e890aa13faac69a0ceaa8cb02660b2275cf82.tar.gz
Qt-351e890aa13faac69a0ceaa8cb02660b2275cf82.tar.bz2
Added custom shader hook to the GL 2 paint engine.
This will make it easier to implement pixmap filters, YUV->RGB conversions, etc in other parts of Qt.
Diffstat (limited to 'src/opengl/gl2paintengineex/qglengineshadermanager.cpp')
-rw-r--r--src/opengl/gl2paintengineex/qglengineshadermanager.cpp65
1 files changed, 57 insertions, 8 deletions
diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
index 4b73ca9..068f804 100644
--- a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
+++ b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
@@ -49,6 +49,30 @@
QT_BEGIN_NAMESPACE
+QGLCustomShader::QGLCustomShader(QGLShader *shader)
+ : m_shader(shader)
+{
+}
+
+QGLCustomShader::~QGLCustomShader()
+{
+ delete m_shader;
+}
+
+void QGLCustomShader::updateUniforms(QGLShaderProgram *)
+{
+}
+
+void QGLCustomShader::setShader(QGLShader *shader)
+{
+ m_shader = shader;
+}
+
+QGLShader *QGLCustomShader::shader() const
+{
+ return m_shader;
+}
+
const char* QGLEngineShaderManager::qglEngineShaderSourceCode[] = {
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
@@ -66,7 +90,8 @@ QGLEngineShaderManager::QGLEngineShaderManager(QGLContext* context)
compositionMode(QPainter::CompositionMode_SourceOver),
blitShaderProg(0),
simpleShaderProg(0),
- currentShaderProg(0)
+ currentShaderProg(0),
+ customShader(0)
{
memset(compiledShaders, 0, sizeof(compiledShaders));
@@ -107,6 +132,7 @@ QGLEngineShaderManager::QGLEngineShaderManager(QGLContext* context)
code[MainFragmentShader] = qglslMainFragmentShader;
code[ImageSrcFragmentShader] = qglslImageSrcFragmentShader;
+ code[CustomSrcFragmentShader] = qglslCustomSrcFragmentShader;
code[ImageSrcWithPatternFragmentShader] = qglslImageSrcWithPatternFragmentShader;
code[NonPremultipliedImageSrcFragmentShader] = qglslNonPremultipliedImageSrcFragmentShader;
code[SolidBrushSrcFragmentShader] = qglslSolidBrushSrcFragmentShader;
@@ -228,7 +254,7 @@ void QGLEngineShaderManager::setDirty()
void QGLEngineShaderManager::setSrcPixelType(Qt::BrushStyle style)
{
- if (srcPixelType == PixelSrcType(style))
+ if (customShader || srcPixelType == PixelSrcType(style))
return;
srcPixelType = style;
@@ -237,13 +263,20 @@ void QGLEngineShaderManager::setSrcPixelType(Qt::BrushStyle style)
void QGLEngineShaderManager::setSrcPixelType(PixelSrcType type)
{
- if (srcPixelType == type)
+ if (customShader || srcPixelType == type)
return;
srcPixelType = type;
shaderProgNeedsChanging = true; //###
}
+void QGLEngineShaderManager::setCustomShader(QGLCustomShader *shader)
+{
+ srcPixelType = CustomSrc;
+ shaderProgNeedsChanging = true;
+ customShader = shader;
+}
+
void QGLEngineShaderManager::setTextureCoordsEnabled(bool enabled)
{
if (useTextureCoords == enabled)
@@ -338,6 +371,10 @@ bool QGLEngineShaderManager::useCorrectShaderProg()
srcPixelFragShaderName = ImageSrcFragmentShader;
positionVertexShaderName = PositionOnlyVertexShader;
break;
+ case QGLEngineShaderManager::CustomSrc:
+ srcPixelFragShaderName = CustomSrcFragmentShader;
+ positionVertexShaderName = PositionOnlyVertexShader;
+ break;
case QGLEngineShaderManager::PatternSrc:
srcPixelFragShaderName = ImageSrcWithPatternFragmentShader;
positionVertexShaderName = PositionOnlyVertexShader;
@@ -381,7 +418,6 @@ bool QGLEngineShaderManager::useCorrectShaderProg()
requiredProgram.positionVertexShader = compiledShaders[positionVertexShaderName];
requiredProgram.srcPixelFragShader = compiledShaders[srcPixelFragShaderName];
-
const bool hasCompose = compositionMode > QPainter::CompositionMode_Plus;
const bool hasMask = maskType != QGLEngineShaderManager::NoMask;
@@ -483,6 +519,7 @@ bool QGLEngineShaderManager::useCorrectShaderProg()
currentShaderProg = &prog;
currentShaderProg->program->enable();
shaderProgNeedsChanging = false;
+
return true;
}
}
@@ -496,6 +533,9 @@ bool QGLEngineShaderManager::useCorrectShaderProg()
requiredProgram.program->addShader(requiredProgram.maskFragShader);
requiredProgram.program->addShader(requiredProgram.compositionFragShader);
+ if (customShader)
+ requiredProgram.program->addShader(customShader->shader());
+
// We have to bind the vertex attribute names before the program is linked:
requiredProgram.program->bindAttributeLocation("vertexCoordsArray", QT_VERTEX_COORDS_ATTR);
if (useTextureCoords)
@@ -520,11 +560,20 @@ bool QGLEngineShaderManager::useCorrectShaderProg()
qWarning() << error;
}
else {
- cachedPrograms.append(requiredProgram);
- // taking the address here is safe since
- // cachePrograms isn't resized anywhere else
- currentShaderProg = &cachedPrograms.last();
+ 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();
+ }
currentShaderProg->program->enable();
+
+ if (customShader)
+ customShader->updateUniforms(currentShaderProg->program);
}
shaderProgNeedsChanging = false;
return true;