diff --git a/lanczosfilter.cpp b/lanczosfilter.cpp index 928e4050e0..d052f3efdd 100644 --- a/lanczosfilter.cpp +++ b/lanczosfilter.cpp @@ -84,7 +84,10 @@ void LanczosFilter::init() if (gl->isRadeon() && gl->chipClass() < R600) return; } - m_shader.reset(ShaderManager::instance()->loadFragmentShader(ShaderManager::SimpleShader, ":/resources/shaders/1.10/lanczos-fragment.glsl")); + m_shader.reset(ShaderManager::instance()->loadFragmentShader(ShaderManager::SimpleShader, + gl->glslVersion() >= kVersionNumber(1, 40) ? + ":/resources/shaders/1.40/lanczos-fragment.glsl" : + ":/resources/shaders/1.10/lanczos-fragment.glsl")); if (m_shader->isValid()) { ShaderBinder binder(m_shader.data()); m_uTexUnit = m_shader->uniformLocation("texUnit"); diff --git a/libkwineffects/kwinglutils.cpp b/libkwineffects/kwinglutils.cpp index a962cfaef4..4b07379883 100644 --- a/libkwineffects/kwinglutils.cpp +++ b/libkwineffects/kwinglutils.cpp @@ -791,12 +791,12 @@ void ShaderManager::popShader() GLShader *ShaderManager::loadFragmentShader(ShaderType vertex, const QString &fragmentFile) { const char *vertexFile[] = { - ":/resources/shaders/1.10/scene-vertex.glsl", - ":/resources/shaders/1.10/scene-generic-vertex.glsl", - ":/resources/shaders/1.10/scene-color-vertex.glsl" + "scene-vertex.glsl", + "scene-generic-vertex.glsl", + "scene-color-vertex.glsl" }; - GLShader *shader = new GLShader(vertexFile[vertex], fragmentFile); + GLShader *shader = new GLShader(m_shaderDir + vertexFile[vertex], fragmentFile); if (shader->isValid()) { pushShader(shader); @@ -811,12 +811,12 @@ GLShader *ShaderManager::loadVertexShader(ShaderType fragment, const QString &ve { // The Simple and Generic shaders use same fragment shader const char *fragmentFile[] = { - ":/resources/shaders/1.10/scene-fragment.glsl", - ":/resources/shaders/1.10/scene-fragment.glsl", - ":/resources/shaders/1.10/scene-color-fragment.glsl" + "scene-fragment.glsl", + "scene-fragment.glsl", + "scene-color-fragment.glsl" }; - GLShader *shader = new GLShader(vertexFile, fragmentFile[fragment]); + GLShader *shader = new GLShader(vertexFile, m_shaderDir + fragmentFile[fragment]); if (shader->isValid()) { pushShader(shader); @@ -837,22 +837,29 @@ GLShader *ShaderManager::loadShaderFromCode(const QByteArray &vertexSource, cons void ShaderManager::initShaders() { const char *vertexFile[] = { - ":/resources/shaders/1.10/scene-vertex.glsl", - ":/resources/shaders/1.10/scene-generic-vertex.glsl", - ":/resources/shaders/1.10/scene-color-vertex.glsl", + "scene-vertex.glsl", + "scene-generic-vertex.glsl", + "scene-color-vertex.glsl", }; const char *fragmentFile[] = { - ":/resources/shaders/1.10/scene-fragment.glsl", - ":/resources/shaders/1.10/scene-fragment.glsl", - ":/resources/shaders/1.10/scene-color-fragment.glsl", + "scene-fragment.glsl", + "scene-fragment.glsl", + "scene-color-fragment.glsl", }; +#ifndef KWIN_HAVE_OPENGLES + if (GLPlatform::instance()->glslVersion() >= kVersionNumber(1, 40)) + m_shaderDir = ":/resources/shaders/1.40/"; + else +#endif + m_shaderDir = ":/resources/shaders/1.10/"; + // Be optimistic m_valid = true; for (int i = 0; i < 3; i++) { - m_shader[i] = new GLShader(vertexFile[i], fragmentFile[i]); + m_shader[i] = new GLShader(m_shaderDir + vertexFile[i], m_shaderDir + fragmentFile[i]); if (!m_shader[i]->isValid()) { m_valid = false; diff --git a/libkwineffects/kwinglutils.h b/libkwineffects/kwinglutils.h index 0d520ba4e2..11e7959152 100644 --- a/libkwineffects/kwinglutils.h +++ b/libkwineffects/kwinglutils.h @@ -396,6 +396,7 @@ private: bool m_inited; bool m_valid; bool m_debug; + QByteArray m_shaderDir; static ShaderManager *s_shaderManager; }; diff --git a/resources.qrc b/resources.qrc index 3257d85b9e..58e6f333ae 100644 --- a/resources.qrc +++ b/resources.qrc @@ -6,5 +6,12 @@ shaders/1.10/scene-color-vertex.glsl shaders/1.10/scene-color-fragment.glsl shaders/1.10/scene-generic-vertex.glsl - + + shaders/1.40/lanczos-fragment.glsl + shaders/1.40/scene-vertex.glsl + shaders/1.40/scene-fragment.glsl + shaders/1.40/scene-color-vertex.glsl + shaders/1.40/scene-color-fragment.glsl + shaders/1.40/scene-generic-vertex.glsl + diff --git a/shaders/1.40/lanczos-fragment.glsl b/shaders/1.40/lanczos-fragment.glsl new file mode 100644 index 0000000000..0852ea1028 --- /dev/null +++ b/shaders/1.40/lanczos-fragment.glsl @@ -0,0 +1,19 @@ +#version 140 + +uniform sampler2D texUnit; +uniform vec2 offsets[16]; +uniform vec4 kernel[16]; + +in vec2 varyingTexCoords; +out vec4 fragColor; + +void main(void) +{ + vec4 sum = texture(texUnit, varyingTexCoords.st) * kernel[0]; + for (int i = 1; i < 16; i++) { + sum += texture(texUnit, varyingTexCoords.st - offsets[i]) * kernel[i]; + sum += texture(texUnit, varyingTexCoords.st + offsets[i]) * kernel[i]; + } + fragColor = sum; +} + diff --git a/shaders/1.40/scene-color-fragment.glsl b/shaders/1.40/scene-color-fragment.glsl new file mode 100644 index 0000000000..1272a35b2d --- /dev/null +++ b/shaders/1.40/scene-color-fragment.glsl @@ -0,0 +1,10 @@ +#version 140 + +uniform vec4 geometryColor; + +out vec4 fragColor; + +void main() +{ + fragColor = geometryColor; +} diff --git a/shaders/1.40/scene-color-vertex.glsl b/shaders/1.40/scene-color-vertex.glsl new file mode 100644 index 0000000000..dfe4b86c62 --- /dev/null +++ b/shaders/1.40/scene-color-vertex.glsl @@ -0,0 +1,13 @@ +#version 140 + +uniform mat4 projection; + +// offset of the window/texture to be rendered +uniform vec2 offset; + +in vec4 vertex; + +void main() +{ + gl_Position = projection * vec4(vertex.xy + offset, vertex.zw); +} diff --git a/shaders/1.40/scene-fragment.glsl b/shaders/1.40/scene-fragment.glsl new file mode 100644 index 0000000000..bfe0c7cbcc --- /dev/null +++ b/shaders/1.40/scene-fragment.glsl @@ -0,0 +1,26 @@ +#version 140 + +uniform sampler2D sampler; +uniform vec4 modulation; +uniform float saturation; + +in vec2 varyingTexCoords; + +out vec4 fragColor; + +void main() +{ + vec4 tex = texture(sampler, varyingTexCoords); + + if (saturation != 1.0) { + tex.rgb = mix(vec3(dot(vec3(0.30, 0.59, 0.11), tex.rgb)), tex.rgb, saturation); + } + + tex *= modulation; + +#ifdef KWIN_SHADER_DEBUG + tex.g = min(tex.g + 0.5, 1.0); +#endif + + fragColor = tex; +} diff --git a/shaders/1.40/scene-generic-vertex.glsl b/shaders/1.40/scene-generic-vertex.glsl new file mode 100644 index 0000000000..1cfcaa31bf --- /dev/null +++ b/shaders/1.40/scene-generic-vertex.glsl @@ -0,0 +1,17 @@ +#version 140 + +uniform mat4 projection; +uniform mat4 modelview; +uniform mat4 screenTransformation; +uniform mat4 windowTransformation; + +in vec4 vertex; +in vec2 texCoord; + +out vec2 varyingTexCoords; + +void main() +{ + varyingTexCoords = texCoord; + gl_Position = projection * (modelview * screenTransformation * windowTransformation) * vertex; +} diff --git a/shaders/1.40/scene-vertex.glsl b/shaders/1.40/scene-vertex.glsl new file mode 100644 index 0000000000..f7506112da --- /dev/null +++ b/shaders/1.40/scene-vertex.glsl @@ -0,0 +1,17 @@ +#version 140 + +uniform mat4 projection; + +// offset of the window/texture to be rendered +uniform vec2 offset; + +in vec4 vertex; +in vec2 texCoord; + +out vec2 varyingTexCoords; + +void main() +{ + varyingTexCoords = texCoord; + gl_Position = projection * vec4(vertex.xy + offset, vertex.zw); +}