summaryrefslogtreecommitdiffstats
path: root/src/opengl/gl2paintengineex
diff options
context:
space:
mode:
Diffstat (limited to 'src/opengl/gl2paintengineex')
-rw-r--r--src/opengl/gl2paintengineex/qglengineshadermanager.cpp29
-rw-r--r--src/opengl/gl2paintengineex/qglengineshadermanager_p.h3
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp11
3 files changed, 38 insertions, 5 deletions
diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
index d28d5f3..da33eb3 100644
--- a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
+++ b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
@@ -505,7 +505,27 @@ QGLShaderProgram* QGLEngineShaderManager::currentProgram()
if (currentShaderProg)
return currentShaderProg->program;
else
- return simpleProgram();
+ return sharedShaders->simpleProgram();
+}
+
+void QGLEngineShaderManager::useSimpleProgram()
+{
+ sharedShaders->simpleProgram()->bind();
+ QGLContextPrivate* ctx_d = ctx->d_func();
+ ctx_d->setVertexAttribArrayEnabled(QT_VERTEX_COORDS_ATTR, true);
+ ctx_d->setVertexAttribArrayEnabled(QT_TEXTURE_COORDS_ATTR, false);
+ ctx_d->setVertexAttribArrayEnabled(QT_OPACITY_ATTR, false);
+ shaderProgNeedsChanging = true;
+}
+
+void QGLEngineShaderManager::useBlitProgram()
+{
+ sharedShaders->blitProgram()->bind();
+ QGLContextPrivate* ctx_d = ctx->d_func();
+ ctx_d->setVertexAttribArrayEnabled(QT_VERTEX_COORDS_ATTR, true);
+ ctx_d->setVertexAttribArrayEnabled(QT_TEXTURE_COORDS_ATTR, true);
+ ctx_d->setVertexAttribArrayEnabled(QT_OPACITY_ATTR, false);
+ shaderProgNeedsChanging = true;
}
QGLShaderProgram* QGLEngineShaderManager::simpleProgram()
@@ -716,6 +736,13 @@ bool QGLEngineShaderManager::useCorrectShaderProg()
customSrcStage->setUniforms(currentShaderProg->program);
}
+ // Make sure all the vertex attribute arrays the program uses are enabled (and the ones it
+ // doesn't use are disabled)
+ QGLContextPrivate* ctx_d = ctx->d_func();
+ ctx_d->setVertexAttribArrayEnabled(QT_VERTEX_COORDS_ATTR, true);
+ ctx_d->setVertexAttribArrayEnabled(QT_TEXTURE_COORDS_ATTR, currentShaderProg->useTextureCoords);
+ ctx_d->setVertexAttribArrayEnabled(QT_OPACITY_ATTR, currentShaderProg->useOpacityAttribute);
+
shaderProgNeedsChanging = false;
return true;
}
diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager_p.h b/src/opengl/gl2paintengineex/qglengineshadermanager_p.h
index 1ec4cdc..a132e1b 100644
--- a/src/opengl/gl2paintengineex/qglengineshadermanager_p.h
+++ b/src/opengl/gl2paintengineex/qglengineshadermanager_p.h
@@ -468,6 +468,9 @@ public:
void setDirty(); // someone has manually changed the current shader program
bool useCorrectShaderProg(); // returns true if the shader program needed to be changed
+ void useSimpleProgram();
+ void useBlitProgram();
+
QGLShaderProgram* currentProgram(); // Returns pointer to the shader the manager has chosen
QGLShaderProgram* simpleProgram(); // Used to draw into e.g. stencil buffers
QGLShaderProgram* blitProgram(); // Used to blit a texture into the framebuffer
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
index d3a9547..0574c52 100644
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
@@ -248,9 +248,8 @@ void QGLTextureGlyphCache::resizeTextureData(int width, int height)
glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, vertexCoordinateArray);
glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, textureCoordinateArray);
- pex->shaderManager->blitProgram()->bind();
+ pex->shaderManager->useBlitProgram();
pex->shaderManager->blitProgram()->setUniformValue("imageTexture", QT_IMAGE_TEXTURE_UNIT);
- pex->shaderManager->setDirty();
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
@@ -413,8 +412,7 @@ void QGL2PaintEngineExPrivate::setBrush(const QBrush& brush)
void QGL2PaintEngineExPrivate::useSimpleShader()
{
- shaderManager->simpleProgram()->bind();
- shaderManager->setDirty();
+ shaderManager->useSimpleProgram();
if (matrixDirty)
updateMatrix();
@@ -745,6 +743,10 @@ void QGL2PaintEngineEx::beginNativePainting()
QGLContext *ctx = d->ctx;
glUseProgram(0);
+ // Disable all the vertex attribute arrays:
+ for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i)
+ glDisableVertexAttribArray(i);
+
#ifndef QT_OPENGL_ES_2
// be nice to people who mix OpenGL 1.x code with QPainter commands
// by setting modelview and projection matrices to mirror the GL 1
@@ -1935,6 +1937,7 @@ void QGL2PaintEngineEx::ensureActive()
glViewport(0, 0, d->width, d->height);
d->needsSync = false;
d->shaderManager->setDirty();
+ d->ctx->d_func()->syncGlState();
setState(state());
}
}