Add a define KWIN_SHADER_DEBUG to all shaders

If the environment variable KWIN_GL_DEBUG is set to 1
the define KWIN_SHADER_DEBUG is added to the glsl
source code allowing to add some custom ifdefed
visual debug handling.

As an example it's added to scene-fragment.glsl to
paint everything in a greenish way.
This commit is contained in:
Martin Gräßlin 2011-07-23 18:57:50 +02:00
parent 6d96696898
commit 2fc1ed25a5
3 changed files with 20 additions and 5 deletions

View file

@ -295,6 +295,9 @@ bool GLShader::compile(GLuint program, GLenum shaderType, const QByteArray &sour
#ifdef KWIN_HAVE_OPENGLES
ba.append("#ifdef GL_ES\nprecision highp float;\n#endif\n");
#endif
if (ShaderManager::instance()->isShaderDebug()) {
ba.append("#define KWIN_SHADER_DEBUG 1\n");
}
ba.append(source);
const char* src = ba.constData();
@ -615,6 +618,7 @@ ShaderManager::ShaderManager()
, m_inited(false)
, m_valid(false)
{
m_debug = qstrcmp(qgetenv("KWIN_GL_DEBUG"), "1") == 0;
initShaders();
m_inited = true;
}
@ -648,6 +652,11 @@ bool ShaderManager::isValid() const
return m_valid;
}
bool ShaderManager::isShaderDebug() const
{
return m_debug;
}
GLShader *ShaderManager::pushShader(ShaderType type, bool reset)
{
if (m_inited && !m_valid) {
@ -840,7 +849,6 @@ void ShaderManager::resetShader(ShaderType type)
break;
}
//shader->setUniform("debug", 0);
shader->setUniform("sampler", 0);
shader->setUniform(GLShader::ProjectionMatrix, projection);

View file

@ -289,6 +289,13 @@ public:
* @return @c true if the built-in shaders are valid, @c false otherwise
**/
bool isValid() const;
/**
* Is @c true if the environment variable KWIN_GL_DEBUG is set to 1.
* In that case shaders are compiled with KWIN_SHADER_DEBUG defined.
* @returns @c true if shaders are compiled with debug information
* @since 4.8
**/
bool isShaderDebug() const;
/**
* Binds the shader of specified @p type.
@ -363,6 +370,7 @@ private:
GLShader *m_colorShader;
bool m_inited;
bool m_valid;
bool m_debug;
static ShaderManager *s_shaderManager;
};

View file

@ -1,7 +1,6 @@
uniform sampler2D sampler;
uniform vec4 modulation;
uniform float saturation;
uniform int debug;
uniform int u_forceAlpha;
varying vec2 varyingTexCoords;
@ -23,9 +22,9 @@ void main() {
tex *= modulation;
/*if (debug != 0) {
tex.g += 0.5;
}*/
#ifdef KWIN_SHADER_DEBUG
tex.g = min(tex.g + 0.5, 1.0);
#endif
gl_FragColor = tex;
}