kwin: Add GLSL 1.40 versions of the scene shaders
Adjust ShaderManager to load the 1.40 versions when GLSL 1.40 is supported.
This commit is contained in:
parent
79db2fc98a
commit
54b63a85a6
10 changed files with 137 additions and 17 deletions
|
@ -84,7 +84,10 @@ void LanczosFilter::init()
|
||||||
if (gl->isRadeon() && gl->chipClass() < R600)
|
if (gl->isRadeon() && gl->chipClass() < R600)
|
||||||
return;
|
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()) {
|
if (m_shader->isValid()) {
|
||||||
ShaderBinder binder(m_shader.data());
|
ShaderBinder binder(m_shader.data());
|
||||||
m_uTexUnit = m_shader->uniformLocation("texUnit");
|
m_uTexUnit = m_shader->uniformLocation("texUnit");
|
||||||
|
|
|
@ -791,12 +791,12 @@ void ShaderManager::popShader()
|
||||||
GLShader *ShaderManager::loadFragmentShader(ShaderType vertex, const QString &fragmentFile)
|
GLShader *ShaderManager::loadFragmentShader(ShaderType vertex, const QString &fragmentFile)
|
||||||
{
|
{
|
||||||
const char *vertexFile[] = {
|
const char *vertexFile[] = {
|
||||||
":/resources/shaders/1.10/scene-vertex.glsl",
|
"scene-vertex.glsl",
|
||||||
":/resources/shaders/1.10/scene-generic-vertex.glsl",
|
"scene-generic-vertex.glsl",
|
||||||
":/resources/shaders/1.10/scene-color-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()) {
|
if (shader->isValid()) {
|
||||||
pushShader(shader);
|
pushShader(shader);
|
||||||
|
@ -811,12 +811,12 @@ GLShader *ShaderManager::loadVertexShader(ShaderType fragment, const QString &ve
|
||||||
{
|
{
|
||||||
// The Simple and Generic shaders use same fragment shader
|
// The Simple and Generic shaders use same fragment shader
|
||||||
const char *fragmentFile[] = {
|
const char *fragmentFile[] = {
|
||||||
":/resources/shaders/1.10/scene-fragment.glsl",
|
"scene-fragment.glsl",
|
||||||
":/resources/shaders/1.10/scene-fragment.glsl",
|
"scene-fragment.glsl",
|
||||||
":/resources/shaders/1.10/scene-color-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()) {
|
if (shader->isValid()) {
|
||||||
pushShader(shader);
|
pushShader(shader);
|
||||||
|
@ -837,22 +837,29 @@ GLShader *ShaderManager::loadShaderFromCode(const QByteArray &vertexSource, cons
|
||||||
void ShaderManager::initShaders()
|
void ShaderManager::initShaders()
|
||||||
{
|
{
|
||||||
const char *vertexFile[] = {
|
const char *vertexFile[] = {
|
||||||
":/resources/shaders/1.10/scene-vertex.glsl",
|
"scene-vertex.glsl",
|
||||||
":/resources/shaders/1.10/scene-generic-vertex.glsl",
|
"scene-generic-vertex.glsl",
|
||||||
":/resources/shaders/1.10/scene-color-vertex.glsl",
|
"scene-color-vertex.glsl",
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *fragmentFile[] = {
|
const char *fragmentFile[] = {
|
||||||
":/resources/shaders/1.10/scene-fragment.glsl",
|
"scene-fragment.glsl",
|
||||||
":/resources/shaders/1.10/scene-fragment.glsl",
|
"scene-fragment.glsl",
|
||||||
":/resources/shaders/1.10/scene-color-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
|
// Be optimistic
|
||||||
m_valid = true;
|
m_valid = true;
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
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()) {
|
if (!m_shader[i]->isValid()) {
|
||||||
m_valid = false;
|
m_valid = false;
|
||||||
|
|
|
@ -396,6 +396,7 @@ private:
|
||||||
bool m_inited;
|
bool m_inited;
|
||||||
bool m_valid;
|
bool m_valid;
|
||||||
bool m_debug;
|
bool m_debug;
|
||||||
|
QByteArray m_shaderDir;
|
||||||
static ShaderManager *s_shaderManager;
|
static ShaderManager *s_shaderManager;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,5 +6,12 @@
|
||||||
<file>shaders/1.10/scene-color-vertex.glsl</file>
|
<file>shaders/1.10/scene-color-vertex.glsl</file>
|
||||||
<file>shaders/1.10/scene-color-fragment.glsl</file>
|
<file>shaders/1.10/scene-color-fragment.glsl</file>
|
||||||
<file>shaders/1.10/scene-generic-vertex.glsl</file>
|
<file>shaders/1.10/scene-generic-vertex.glsl</file>
|
||||||
</qresource>
|
|
||||||
|
<file>shaders/1.40/lanczos-fragment.glsl</file>
|
||||||
|
<file>shaders/1.40/scene-vertex.glsl</file>
|
||||||
|
<file>shaders/1.40/scene-fragment.glsl</file>
|
||||||
|
<file>shaders/1.40/scene-color-vertex.glsl</file>
|
||||||
|
<file>shaders/1.40/scene-color-fragment.glsl</file>
|
||||||
|
<file>shaders/1.40/scene-generic-vertex.glsl</file>
|
||||||
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
19
shaders/1.40/lanczos-fragment.glsl
Normal file
19
shaders/1.40/lanczos-fragment.glsl
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
|
10
shaders/1.40/scene-color-fragment.glsl
Normal file
10
shaders/1.40/scene-color-fragment.glsl
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#version 140
|
||||||
|
|
||||||
|
uniform vec4 geometryColor;
|
||||||
|
|
||||||
|
out vec4 fragColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
fragColor = geometryColor;
|
||||||
|
}
|
13
shaders/1.40/scene-color-vertex.glsl
Normal file
13
shaders/1.40/scene-color-vertex.glsl
Normal file
|
@ -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);
|
||||||
|
}
|
26
shaders/1.40/scene-fragment.glsl
Normal file
26
shaders/1.40/scene-fragment.glsl
Normal file
|
@ -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;
|
||||||
|
}
|
17
shaders/1.40/scene-generic-vertex.glsl
Normal file
17
shaders/1.40/scene-generic-vertex.glsl
Normal file
|
@ -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;
|
||||||
|
}
|
17
shaders/1.40/scene-vertex.glsl
Normal file
17
shaders/1.40/scene-vertex.glsl
Normal file
|
@ -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);
|
||||||
|
}
|
Loading…
Reference in a new issue