From b0582571d660fd8d2640543d03c691bc65bc749e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Mon, 25 Mar 2013 23:54:24 +0100 Subject: [PATCH] kwin/blur: Save the uniform locations Store the uniform locations in the GLSLBlurShader object instead of looking them up each time the uniforms are set. --- effects/blur/blurshader.cpp | 32 ++++++++++++++++++-------------- effects/blur/blurshader.h | 3 +++ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/effects/blur/blurshader.cpp b/effects/blur/blurshader.cpp index 27900f677c..20829ffc15 100644 --- a/effects/blur/blurshader.cpp +++ b/effects/blur/blurshader.cpp @@ -178,23 +178,24 @@ void GLSLBlurShader::setPixelDistance(float val) pixelSize.setX(val); else pixelSize.setY(val); - shader->setUniform("pixelSize", pixelSize); + + shader->setUniform(pixelSizeLocation, pixelSize); } void GLSLBlurShader::setTextureMatrix(const QMatrix4x4 &matrix) { - if (!isValid()) { + if (!isValid()) return; - } - shader->setUniform("u_textureMatrix", matrix); + + shader->setUniform(textureMatrixLocation, matrix); } void GLSLBlurShader::setModelViewProjectionMatrix(const QMatrix4x4 &matrix) { - if (!isValid()) { + if (!isValid()) return; - } - shader->setUniform("u_modelViewProjectionMatrix", matrix); + + shader->setUniform(mvpMatrixLocation, matrix); } void GLSLBlurShader::bind() @@ -269,8 +270,8 @@ void GLSLBlurShader::init() if (glsl_140) stream << "#version 140\n\n"; - stream << "uniform mat4 u_modelViewProjectionMatrix;\n"; - stream << "uniform mat4 u_textureMatrix;\n"; + stream << "uniform mat4 modelViewProjectionMatrix;\n"; + stream << "uniform mat4 textureMatrix;\n"; stream << "uniform vec2 pixelSize;\n\n"; stream << attribute << " vec4 vertex;\n"; stream << attribute << " vec4 texCoord;\n\n"; @@ -278,7 +279,7 @@ void GLSLBlurShader::init() stream << "\n"; stream << "void main(void)\n"; stream << "{\n"; - stream << " vec4 center = vec4(u_textureMatrix * texCoord).stst;\n"; + stream << " vec4 center = vec4(textureMatrix * texCoord).stst;\n"; stream << " vec4 ps = pixelSize.stst;\n\n"; for (int i = 0; i < offsets.size(); i++) { stream << " samplePos[" << i << "] = center + ps * vec4(" @@ -286,7 +287,7 @@ void GLSLBlurShader::init() << offsets[i].z() << ", " << offsets[i].w() << ");\n"; } stream << "\n"; - stream << " gl_Position = u_modelViewProjectionMatrix * vertex;\n"; + stream << " gl_Position = modelViewProjectionMatrix * vertex;\n"; stream << "}\n"; stream.flush(); @@ -319,12 +320,15 @@ void GLSLBlurShader::init() shader = ShaderManager::instance()->loadShaderFromCode(vertexSource, fragmentSource); if (shader->isValid()) { + pixelSizeLocation = shader->uniformLocation("pixelSize"); + textureMatrixLocation = shader->uniformLocation("textureMatrix"); + mvpMatrixLocation = shader->uniformLocation("modelViewProjectionMatrix"); + QMatrix4x4 modelViewProjection; modelViewProjection.ortho(0, displayWidth(), displayHeight(), 0, 0, 65535); ShaderManager::instance()->pushShader(shader); - shader->setUniform("texUnit", 0); - shader->setUniform("u_textureMatrix", QMatrix4x4()); - shader->setUniform("u_modelViewProjectionMatrix", modelViewProjection); + shader->setUniform(textureMatrixLocation, QMatrix4x4()); + shader->setUniform(mvpMatrixLocation, modelViewProjection); ShaderManager::instance()->popShader(); } diff --git a/effects/blur/blurshader.h b/effects/blur/blurshader.h index 5d65b4d3ef..54bde620b3 100644 --- a/effects/blur/blurshader.h +++ b/effects/blur/blurshader.h @@ -111,6 +111,9 @@ protected: private: GLShader *shader; + int mvpMatrixLocation; + int textureMatrixLocation; + int pixelSizeLocation; };