Simple vertex shaders use projection matrix and offset

This commit is contained in:
Martin Gräßlin 2010-12-12 13:40:39 +01:00
parent 5f9b75b0c0
commit cab9154723
5 changed files with 26 additions and 26 deletions

View file

@ -545,10 +545,7 @@ void GLTexture::render( QRegion region, const QRect& rect, bool useShader )
m_vbo->setData( 4, 2, verts, texcoords ); m_vbo->setData( 4, 2, verts, texcoords );
} }
if (useShader) { if (useShader) {
GLint currentProgram; ShaderManager::instance()->getBoundShader()->setUniform("offset", QVector2D(rect.x(), rect.y()));
glGetIntegerv( GL_CURRENT_PROGRAM, &currentProgram );
GLint location = glGetUniformLocation(currentProgram, "geometry");
glUniform4f(location, rect.x(), rect.y(), 0.0f, 0.0f);
} else { } else {
#ifndef KWIN_HAVE_OPENGLES #ifndef KWIN_HAVE_OPENGLES
glTranslatef( rect.x(), rect.y(), 0.0f ); glTranslatef( rect.x(), rect.y(), 0.0f );
@ -1260,10 +1257,11 @@ void ShaderManager::resetShader(ShaderType type)
// resetShader is either called from init or from push, we know that a built-in shader is bound // resetShader is either called from init or from push, we know that a built-in shader is bound
GLShader *shader = getBoundShader(); GLShader *shader = getBoundShader();
switch (type) { switch (type) {
case SimpleShader: case SimpleShader: {
shader->setUniform("displaySize", QVector2D(displayWidth(), displayHeight())); QMatrix4x4 projection;
// TODO: has to become offset projection.ortho(0, displayWidth(), displayHeight(), 0, 0, 65535);
shader->setUniform("geometry", QVector4D(0, 0, 0, 0)); shader->setUniform("projection", projection);
shader->setUniform("offset", QVector2D(0, 0));
shader->setUniform("debug", 0); shader->setUniform("debug", 0);
shader->setUniform("sample", 0); shader->setUniform("sample", 0);
// TODO: has to become textureSize // TODO: has to become textureSize
@ -1274,6 +1272,7 @@ void ShaderManager::resetShader(ShaderType type)
shader->setUniform("brightness", 1.0f); shader->setUniform("brightness", 1.0f);
shader->setUniform("saturation", 1.0f); shader->setUniform("saturation", 1.0f);
break; break;
}
case GenericShader: { case GenericShader: {
shader->setUniform("debug", 0); shader->setUniform("debug", 0);
shader->setUniform("sample", 0); shader->setUniform("sample", 0);
@ -1305,13 +1304,15 @@ void ShaderManager::resetShader(ShaderType type)
shader->setUniform("saturation", 1.0f); shader->setUniform("saturation", 1.0f);
break; break;
} }
case ColorShader: case ColorShader: {
shader->setUniform("displaySize", QVector2D(displayWidth(), displayHeight())); QMatrix4x4 projection;
// TODO: has to become offset projection.ortho(0, displayWidth(), displayHeight(), 0, 0, 65535);
shader->setUniform("geometry", QVector4D(0, 0, 0, 0)); shader->setUniform("projection", projection);
shader->setUniform("offset", QVector2D(0, 0));
shader->setUniform("geometryColor", QVector4D(0, 0, 0, 1)); shader->setUniform("geometryColor", QVector4D(0, 0, 0, 1));
break; break;
} }
}
} }
/*** GLRenderTarget ***/ /*** GLRenderTarget ***/

View file

@ -1,11 +1,10 @@
// size of the complete display in pixels, x==width, y==height uniform mat4 projection;
uniform vec2 displaySize; // offset of the window/texture to be rendered
// geometry of the window/texture to be rendered: x, y, width, height in display geometry uniform vec2 offset;
uniform vec4 geometry;
// passed in vertex - only x and y are used // passed in vertex - only x and y are used
attribute vec4 vertex; attribute vec4 vertex;
void main() { void main() {
gl_Position.xy = 2.0*vec2(geometry.x + vertex.x, displaySize.y - vertex.y - geometry.y)/displaySize - vertex.ww; gl_Position = vec4(vertex.xy + offset, vertex.zw) * projection;
} }

View file

@ -1,7 +1,6 @@
// size of the complete display in pixels, x==width, y==height uniform mat4 projection;
uniform vec2 displaySize; // offset of the window/texture to be rendered
// geometry of the window/texture to be rendered: x, y, width, height in display geometry uniform vec2 offset;
uniform vec4 geometry;
// passed in vertex - only x and y are used // passed in vertex - only x and y are used
attribute vec4 vertex; attribute vec4 vertex;
@ -13,5 +12,5 @@ varying vec2 varyingTexCoords;
void main() { void main() {
varyingTexCoords = texCoord; varyingTexCoords = texCoord;
gl_Position.xy = 2.0*vec2(geometry.x + vertex.x, displaySize.y - vertex.y - geometry.y)/displaySize - vertex.ww; gl_Position = vec4(vertex.xy + offset, vertex.zw) * projection;
} }

View file

@ -457,7 +457,7 @@ void SceneOpenGL::Window::performPaint( int mask, QRegion region, WindowPaintDat
data.shader = ShaderManager::instance()->pushShader(ShaderManager::GenericShader); data.shader = ShaderManager::instance()->pushShader(ShaderManager::GenericShader);
} else { } else {
data.shader = ShaderManager::instance()->pushShader(ShaderManager::SimpleShader); data.shader = ShaderManager::instance()->pushShader(ShaderManager::SimpleShader);
data.shader->setUniform("geometry", QVector4D(x, y, toplevel->width(), toplevel->height())); data.shader->setUniform("offset", QVector2D(x, y));
} }
sceneShader = true; sceneShader = true;
} }
@ -1141,7 +1141,7 @@ void SceneOpenGL::EffectFrame::render( QRegion region, double opacity, double fr
ShaderManager::instance()->pushShader(shader); ShaderManager::instance()->pushShader(shader);
} }
if( sceneShader ) if( sceneShader )
shader->setUniform("geometry", QVector4D(0, 0, 0, 0)); shader->setUniform("offset", QVector2D(0, 0));
shader->setUniform("saturation", 1.0f); shader->setUniform("saturation", 1.0f);
shader->setUniform("brightness", 1.0f); shader->setUniform("brightness", 1.0f);
@ -1282,7 +1282,7 @@ void SceneOpenGL::EffectFrame::render( QRegion region, double opacity, double fr
m_unstyledTexture->bind(); m_unstyledTexture->bind();
const QPoint pt = m_effectFrame->geometry().topLeft(); const QPoint pt = m_effectFrame->geometry().topLeft();
if (sceneShader) { if (sceneShader) {
shader->setUniform("geometry", QVector4D(pt.x(), pt.y(), 0.0f, 0.0f)); shader->setUniform("geometry", QVector2D(pt.x(), pt.y()));
} else { } else {
#ifndef KWIN_HAVE_OPENGLES #ifndef KWIN_HAVE_OPENGLES
glTranslatef( pt.x(), pt.y(), 0.0f ); glTranslatef( pt.x(), pt.y(), 0.0f );

View file

@ -280,7 +280,8 @@ void SceneOpenGL::paintBackground(QRegion region)
vbo->setUseColor(true); vbo->setUseColor(true);
vbo->setUseShader(true); vbo->setUseShader(true);
vbo->setData(verts.count() / 2, 2, verts.data(), NULL); vbo->setData(verts.count() / 2, 2, verts.data(), NULL);
ShaderManager::instance()->pushShader(ShaderManager::ColorShader); GLShader *shader = ShaderManager::instance()->pushShader(ShaderManager::ColorShader);
shader->setUniform("offset", QVector2D(0, 0));
vbo->render(GL_TRIANGLES); vbo->render(GL_TRIANGLES);
ShaderManager::instance()->popShader(); ShaderManager::instance()->popShader();
} }