[effects] Use shader traits API for CubeCap shader

This commit is contained in:
Martin Gräßlin 2015-11-30 11:39:04 +01:00
parent 712e46e468
commit 6bdef479a9
4 changed files with 27 additions and 23 deletions

View file

@ -104,7 +104,10 @@ CubeEffect::CubeEffect()
const QString fragmentshader = QStandardPaths::locate(QStandardPaths::GenericDataLocation, m_shadersDir + QStringLiteral("cube-reflection.glsl"));
m_reflectionShader = ShaderManager::instance()->loadFragmentShader(ShaderManager::GenericShader, fragmentshader);
const QString capshader = QStandardPaths::locate(QStandardPaths::GenericDataLocation, m_shadersDir + QStringLiteral("cube-cap.glsl"));
m_capShader = ShaderManager::instance()->loadFragmentShader(ShaderManager::GenericShader, capshader);
QFile ff(capshader);
if (ff.open(QIODevice::ReadOnly)) {
m_capShader = ShaderManager::instance()->generateCustomShader(ShaderTrait::MapTexture, QByteArray(), ff.readAll());
}
} else {
m_reflectionShader = NULL;
m_capShader = NULL;
@ -222,7 +225,7 @@ void CubeEffect::reconfigure(ReconfigureFlags)
// set the cap color on the shader
if (m_capShader && m_capShader->isValid()) {
ShaderBinder binder(m_capShader);
m_capShader->setUniform("u_capColor", capColor);
m_capShader->setUniform(GLShader::Color, capColor);
}
}
@ -292,7 +295,6 @@ void CubeEffect::slotWallPaperLoaded()
void CubeEffect::slotResetShaders()
{
ShaderManager::instance()->resetShader(m_capShader, ShaderManager::GenericShader);
ShaderManager::instance()->resetShader(m_reflectionShader, ShaderManager::GenericShader);
ShaderManager::instance()->resetShader(cylinderShader, ShaderManager::GenericShader);
ShaderManager::instance()->resetShader(sphereShader, ShaderManager::GenericShader);
@ -448,7 +450,7 @@ void CubeEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
}
reflectionPainting = true;
glEnable(GL_CULL_FACE);
paintCap(true, -point - zTranslate);
paintCap(true, -point - zTranslate, data.projectionMatrix());
// cube
glCullFace(GL_BACK);
@ -457,7 +459,7 @@ void CubeEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
glCullFace(GL_FRONT);
paintCube(mask, region, data);
paintCap(false, -point - zTranslate);
paintCap(false, -point - zTranslate, data.projectionMatrix());
glDisable(GL_CULL_FACE);
reflectionPainting = false;
// TODO: find a solution for GLES
@ -513,7 +515,7 @@ void CubeEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
}
glEnable(GL_CULL_FACE);
// caps
paintCap(false, -point - zTranslate);
paintCap(false, -point - zTranslate, data.projectionMatrix());
// cube
glCullFace(GL_FRONT);
@ -523,7 +525,7 @@ void CubeEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
paintCube(mask, region, data);
// cap
paintCap(true, -point - zTranslate);
paintCap(true, -point - zTranslate, data.projectionMatrix());
glDisable(GL_CULL_FACE);
glDisable(GL_BLEND);
@ -700,7 +702,7 @@ void CubeEffect::paintCube(int mask, QRegion region, ScreenPaintData& data)
painting_desktop = effects->currentDesktop();
}
void CubeEffect::paintCap(bool frontFirst, float zOffset)
void CubeEffect::paintCap(bool frontFirst, float zOffset, const QMatrix4x4 &projection)
{
if ((!paintCaps) || effects->numberOfDesktops() <= 2)
return;
@ -726,6 +728,7 @@ void CubeEffect::paintCap(bool frontFirst, float zOffset)
}
}
QMatrix4x4 capMvp;
QMatrix4x4 capMatrix;
capMatrix.translate(rect.width() / 2, 0.0, zOffset);
capMatrix.rotate((1 - frontDesktop) * 360.0f / effects->numberOfDesktops(), 0.0, 1.0, 0.0);
@ -747,11 +750,11 @@ void CubeEffect::paintCap(bool frontFirst, float zOffset)
m_capShader->setUniform("u_opacity", opacity);
m_capShader->setUniform("u_mirror", 1);
if (reflectionPainting) {
m_capShader->setUniform(GLShader::ScreenTransformation, m_reflectionMatrix * m_rotationMatrix);
capMvp = projection * m_reflectionMatrix * m_rotationMatrix;
} else {
m_capShader->setUniform(GLShader::ScreenTransformation, m_rotationMatrix);
capMvp = projection * m_rotationMatrix;
}
m_capShader->setUniform(GLShader::WindowTransformation, capMatrix);
m_capShader->setUniform(GLShader::ModelViewProjectionMatrix, capMvp * capMatrix);
m_capShader->setUniform("u_untextured", texturedCaps ? 0 : 1);
if (texturedCaps && effects->numberOfDesktops() > 3 && capTexture) {
capTexture->bind();
@ -767,7 +770,7 @@ void CubeEffect::paintCap(bool frontFirst, float zOffset)
}
capMatrix.translate(0.0, -rect.height(), 0.0);
if (capShader) {
m_capShader->setUniform("windowTransformation", capMatrix);
m_capShader->setUniform(GLShader::ModelViewProjectionMatrix, capMvp * capMatrix);
m_capShader->setUniform("u_mirror", 0);
}
glCullFace(secondCull);
@ -1421,6 +1424,7 @@ void CubeEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPa
}
bool capShader = false;
if (effects->compositingType() == OpenGL2Compositing && m_capShader && m_capShader->isValid()) {
// FIXME: needs projection being passed through to WindowPaintData
capShader = true;
ShaderManager::instance()->pushShader(m_capShader);
m_capShader->setUniform("u_mirror", 0);

View file

@ -160,7 +160,7 @@ private:
};
void toggle(CubeMode newMode = Cube);
void paintCube(int mask, QRegion region, ScreenPaintData& data);
void paintCap(bool frontFirst, float zOffset);
void paintCap(bool frontFirst, float zOffset, const QMatrix4x4 &projection);
void paintCubeCap();
void paintCylinderCap();
void paintSphereCap();

View file

@ -1,10 +1,10 @@
uniform sampler2D sampler;
uniform vec4 u_capColor;
uniform vec4 geometryColor;
uniform float u_opacity;
uniform int u_mirror;
uniform int u_untextured;
varying vec2 varyingTexCoords;
varying vec2 texcoord0;
vec2 mirrorTex(vec2 coords) {
vec2 mirrored = coords;
@ -15,12 +15,12 @@ vec2 mirrorTex(vec2 coords) {
}
void main() {
vec4 color = u_capColor;
vec2 texCoord = mirrorTex(varyingTexCoords);
vec4 color = geometryColor;
vec2 texCoord = mirrorTex(texcoord0);
vec4 tex = texture2D(sampler, texCoord);
if (texCoord.s < 0.0 || texCoord.s > 1.0 ||
texCoord.t < 0.0 || texCoord.t > 1.0 || u_untextured != 0) {
tex = u_capColor;
tex = geometryColor;
}
color.rgb = tex.rgb*tex.a + color.rgb*(1.0-tex.a);
color.a = u_opacity;

View file

@ -1,11 +1,11 @@
#version 140
uniform sampler2D sampler;
uniform vec4 u_capColor;
uniform vec4 geometryColor;
uniform float u_opacity;
uniform int u_mirror;
uniform int u_untextured;
in vec2 varyingTexCoords;
in vec2 texcoord0;
out vec4 fragColor;
@ -18,12 +18,12 @@ vec2 mirrorTex(vec2 coords) {
}
void main() {
vec4 color = u_capColor;
vec2 texCoord = mirrorTex(varyingTexCoords);
vec4 color = geometryColor;
vec2 texCoord = mirrorTex(texcoord0);
vec4 tex = texture(sampler, texCoord);
if (texCoord.s < 0.0 || texCoord.s > 1.0 ||
texCoord.t < 0.0 || texCoord.t > 1.0 || u_untextured != 0) {
tex = u_capColor;
tex = geometryColor;
}
color.rgb = tex.rgb*tex.a + color.rgb*(1.0-tex.a);
color.a = u_opacity;