kwin: Simplify ShaderManager::resetShader()

This commit is contained in:
Fredrik Höglund 2011-02-10 21:36:24 +01:00
parent 5e97ccf7e0
commit 50e19e2cbc

View file

@ -1283,29 +1283,20 @@ void ShaderManager::initShaders()
void ShaderManager::resetShader(ShaderType type)
{
// resetShader is either called from init or from push, we know that a built-in shader is bound
const QMatrix4x4 identity;
QMatrix4x4 projection;
QMatrix4x4 modelView;
GLShader *shader = getBoundShader();
switch(type) {
case SimpleShader: {
QMatrix4x4 projection;
case SimpleShader:
projection.ortho(0, displayWidth(), displayHeight(), 0, 0, 65535);
shader->setUniform(GLShader::ProjectionMatrix, projection);
shader->setUniform(GLShader::Offset, QVector2D(0, 0));
shader->setUniform("debug", 0);
shader->setUniform("sample", 0);
// TODO: has to become textureSize
shader->setUniform(GLShader::TextureWidth, 1.0f);
shader->setUniform(GLShader::TextureHeight, 1.0f);
// TODO: has to become colorManiuplation
shader->setUniform(GLShader::Opacity, 1.0f);
shader->setUniform(GLShader::Brightness, 1.0f);
shader->setUniform(GLShader::Saturation, 1.0f);
shader->setUniform(GLShader::AlphaToOne, 0);
break;
}
case GenericShader: {
shader->setUniform("debug", 0);
shader->setUniform("sample", 0);
QMatrix4x4 projection;
// Set up the projection matrix
float fovy = 60.0f;
float aspect = 1.0f;
float zNear = 0.1f;
@ -1315,34 +1306,38 @@ void ShaderManager::resetShader(ShaderType type)
float xmin = ymin * aspect;
float xmax = ymax * aspect;
projection.frustum(xmin, xmax, ymin, ymax, zNear, zFar);
shader->setUniform(GLShader::ProjectionMatrix, projection);
QMatrix4x4 modelview;
// Set up the model-view matrix
float scaleFactor = 1.1 * tan(fovy * M_PI / 360.0f) / ymax;
modelview.translate(xmin * scaleFactor, ymax * scaleFactor, -1.1);
modelview.scale((xmax - xmin)*scaleFactor / displayWidth(), -(ymax - ymin)*scaleFactor / displayHeight(), 0.001);
shader->setUniform(GLShader::ModelViewMatrix, modelview);
const QMatrix4x4 identity;
modelView.translate(xmin * scaleFactor, ymax * scaleFactor, -1.1);
modelView.scale((xmax - xmin)*scaleFactor / displayWidth(), -(ymax - ymin)*scaleFactor / displayHeight(), 0.001);
break;
}
case ColorShader:
projection.ortho(0, displayWidth(), displayHeight(), 0, 0, 65535);
shader->setUniform("geometryColor", QVector4D(0, 0, 0, 1));
break;
}
//shader->setUniform("debug", 0);
shader->setUniform("sample", 0);
shader->setUniform(GLShader::ProjectionMatrix, projection);
shader->setUniform(GLShader::ModelViewMatrix, modelView);
shader->setUniform(GLShader::ScreenTransformation, identity);
shader->setUniform(GLShader::WindowTransformation, identity);
// TODO: has to become textureSize
shader->setUniform(GLShader::TextureWidth, 1.0f);
shader->setUniform(GLShader::TextureHeight, 1.0f);
// TODO: has to become colorManiuplation
shader->setUniform(GLShader::Offset, QVector2D(0, 0));
shader->setUniform(GLShader::Opacity, 1.0f);
shader->setUniform(GLShader::Brightness, 1.0f);
shader->setUniform(GLShader::Saturation, 1.0f);
shader->setUniform(GLShader::AlphaToOne, 0);
break;
}
case ColorShader: {
QMatrix4x4 projection;
projection.ortho(0, displayWidth(), displayHeight(), 0, 0, 65535);
shader->setUniform(GLShader::ProjectionMatrix, projection);
shader->setUniform(GLShader::Offset, QVector2D(0, 0));
shader->setUniform("geometryColor", QVector4D(0, 0, 0, 1));
break;
}
}
// TODO: has to become textureSize
shader->setUniform(GLShader::TextureWidth, 1.0f);
shader->setUniform(GLShader::TextureHeight, 1.0f);
}
/*** GLRenderTarget ***/