Better support custom shaders.

This commit is contained in:
Martin Gräßlin 2011-01-06 19:55:26 +01:00
parent 6cd6883d8c
commit f78d838fc7
2 changed files with 26 additions and 18 deletions

View file

@ -592,21 +592,23 @@ void GLTexture::render( QRegion region, const QRect& rect )
}; };
m_vbo->setData( 4, 2, verts, texcoords ); m_vbo->setData( 4, 2, verts, texcoords );
} }
QMatrix4x4 translation;
translation.translate(rect.x(), rect.y());
if (ShaderManager::instance()->isShaderBound()) { if (ShaderManager::instance()->isShaderBound()) {
GLShader *shader = ShaderManager::instance()->getBoundShader(); GLShader *shader = ShaderManager::instance()->getBoundShader();
shader->setUniform("offset", QVector2D(rect.x(), rect.y())); shader->setUniform("offset", QVector2D(rect.x(), rect.y()));
shader->setUniform("windowTransformation", translation);
shader->setUniform("textureWidth", 1.0f); shader->setUniform("textureWidth", 1.0f);
shader->setUniform("textureHeight", 1.0f); shader->setUniform("textureHeight", 1.0f);
} else { } else {
#ifndef KWIN_HAVE_OPENGLES pushMatrix(translation);
glTranslatef( rect.x(), rect.y(), 0.0f );
#endif
} }
m_vbo->render( region, GL_TRIANGLE_STRIP ); m_vbo->render( region, GL_TRIANGLE_STRIP );
if (!ShaderManager::instance()->isShaderBound()) { if (ShaderManager::instance()->isShaderBound()) {
#ifndef KWIN_HAVE_OPENGLES GLShader *shader = ShaderManager::instance()->getBoundShader();
glTranslatef( -rect.x(), -rect.y(), 0.0f ); shader->setUniform("windowTransformation", QMatrix4x4());
#endif } else {
popMatrix();
} }
} }

View file

@ -574,7 +574,7 @@ void SceneOpenGL::Window::performPaint( int mask, QRegion region, WindowPaintDat
windowTransformation.rotate(data.rotation->angle, xAxis, yAxis, zAxis); windowTransformation.rotate(data.rotation->angle, xAxis, yAxis, zAxis);
windowTransformation.translate(-data.rotation->xRotationPoint, -data.rotation->yRotationPoint, -data.rotation->zRotationPoint); windowTransformation.translate(-data.rotation->xRotationPoint, -data.rotation->yRotationPoint, -data.rotation->zRotationPoint);
} }
if (sceneShader) { if (data.shader) {
data.shader->setUniform("windowTransformation", windowTransformation); data.shader->setUniform("windowTransformation", windowTransformation);
} }
} }
@ -1202,12 +1202,12 @@ void SceneOpenGL::EffectFrame::render( QRegion region, double opacity, double fr
{ {
shader = ShaderManager::instance()->pushShader(ShaderManager::SimpleShader); shader = ShaderManager::instance()->pushShader(ShaderManager::SimpleShader);
sceneShader = true; sceneShader = true;
} } else if (shader) {
ShaderManager::instance()->pushShader(shader);
}
if( shader ) if( shader )
{ {
if (shader != ShaderManager::instance()->getBoundShader()) {
ShaderManager::instance()->pushShader(shader);
}
if( sceneShader ) if( sceneShader )
shader->setUniform("offset", QVector2D(0, 0)); shader->setUniform("offset", QVector2D(0, 0));
shader->setUniform("saturation", 1.0f); shader->setUniform("saturation", 1.0f);
@ -1353,16 +1353,22 @@ void SceneOpenGL::EffectFrame::render( QRegion region, double opacity, double fr
if (sceneShader) { if (sceneShader) {
shader->setUniform("offset", QVector2D(pt.x(), pt.y())); shader->setUniform("offset", QVector2D(pt.x(), pt.y()));
} else { } else {
#ifndef KWIN_HAVE_OPENGLES QMatrix4x4 translation;
glTranslatef( pt.x(), pt.y(), 0.0f ); translation.translate(pt.x(), pt.y());
#endif if (shader) {
shader->setUniform("windowTransformation", translation);
} else {
pushMatrix(translation);
}
} }
m_unstyledVBO->render( region, GL_TRIANGLES ); m_unstyledVBO->render( region, GL_TRIANGLES );
#ifndef KWIN_HAVE_OPENGLES
if (!sceneShader) { if (!sceneShader) {
glTranslatef( -pt.x(), -pt.y(), 0.0f ); if (shader) {
shader->setUniform("windowTranslation", QMatrix4x4());
} else {
popMatrix();
}
} }
#endif
m_unstyledTexture->unbind(); m_unstyledTexture->unbind();
} }
else if( m_effectFrame->style() == EffectFrameStyled ) else if( m_effectFrame->style() == EffectFrameStyled )