From 728e3ed6f646b6c61262d6b0637fc2a10df3e551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Wed, 10 Mar 2010 18:31:59 +0000 Subject: [PATCH] Use the texture matrix to do the screen to texture coordinate transformations. svn path=/trunk/KDE/kdebase/workspace/; revision=1101728 --- effects/blur/blur.cpp | 36 +++++++++++++++++------------------- effects/blur/blur.h | 1 - effects/blur/blurshader.cpp | 7 ++++--- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/effects/blur/blur.cpp b/effects/blur/blur.cpp index d7d1c5049f..68c5791868 100644 --- a/effects/blur/blur.cpp +++ b/effects/blur/blur.cpp @@ -219,46 +219,44 @@ void BlurEffect::drawWindow(EffectWindow *w, int mask, QRegion region, WindowPai glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); } - const float tw = tex->width(); - const float th = tex->height(); int vertexCount = shape.rectCount() * 4; - - if (vertices.size() < vertexCount) { + if (vertices.size() < vertexCount) vertices.resize(vertexCount); - texCoords.resize(vertexCount); - } + + // Set the up the texture matrix to transform from screen coordinates + // to texture coordinates. + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + glLoadIdentity(); + glScalef(1.0 / tex->width(), -1.0 / tex->height(), 1); + glTranslatef(offset.x(), -tex->height() + offset.y(), 0); int i = 0; foreach (const QRect &r, shape.rects()) { - vertices[i + 0] = QVector2D(r.x(), r.y()); - vertices[i + 1] = QVector2D(r.x() + r.width(), r.y()); - vertices[i + 2] = QVector2D(r.x() + r.width(), r.y() + r.height()); - vertices[i + 3] = QVector2D(r.x(), r.y() + r.height()); - - const QRect sr = r.translated(offset); - texCoords[i + 0] = QVector2D(sr.x() / tw, 1 - sr.y() / th); - texCoords[i + 1] = QVector2D((sr.x() + sr.width()) / tw, 1 - sr.y() / th); - texCoords[i + 2] = QVector2D((sr.x() + sr.width()) / tw, 1 - (sr.y() + sr.height()) / th); - texCoords[i + 3] = QVector2D(sr.x() / tw, 1 - (sr.y() + sr.height()) / th); - i += 4; + vertices[i++] = QVector2D(r.x(), r.y()); + vertices[i++] = QVector2D(r.x() + r.width(), r.y()); + vertices[i++] = QVector2D(r.x() + r.width(), r.y() + r.height()); + vertices[i++] = QVector2D(r.x(), r.y() + r.height()); } if (vertexCount > 1000) { glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, 0, (float*)texCoords.constData()); + glTexCoordPointer(2, GL_FLOAT, 0, (float*)vertices.constData()); glVertexPointer(2, GL_FLOAT, 0, (float*)vertices.constData()); glDrawArrays(GL_QUADS, 0, vertexCount); glPopClientAttrib(); } else { glBegin(GL_QUADS); for (int i = 0; i < vertexCount; i++) { - glTexCoord2fv((const float*)&texCoords[i]); + glTexCoord2fv((const float*)&vertices[i]); glVertex2fv((const float*)&vertices[i]); } glEnd(); } + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); if (opacity < 1.0) glPopAttrib(); diff --git a/effects/blur/blur.h b/effects/blur/blur.h index 0caf608c57..dfcb03bae2 100644 --- a/effects/blur/blur.h +++ b/effects/blur/blur.h @@ -53,7 +53,6 @@ private: private: BlurShader *shader; QVector vertices; - QVector texCoords; GLRenderTarget *target; GLTexture *tex; long net_wm_blur_region; diff --git a/effects/blur/blurshader.cpp b/effects/blur/blurshader.cpp index 6c91253a0a..2220697a8a 100644 --- a/effects/blur/blurshader.cpp +++ b/effects/blur/blurshader.cpp @@ -230,13 +230,14 @@ void GLSLBlurShader::init() stream << "\n"; stream << "void main(void)\n"; stream << "{\n"; + stream << " gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;\n"; for (int i = 0; i < center; i++) - stream << " samplePos" << i << " = gl_MultiTexCoord0.st + pixelSize * vec2(" + stream << " samplePos" << i << " = gl_TexCoord[0].st + pixelSize * vec2(" << -(1.5 + (center - i - 1) * 2.0) << ");\n"; - stream << " samplePos" << center << " = gl_MultiTexCoord0.st;\n"; + stream << " samplePos" << center << " = gl_TexCoord[0].st;\n"; for (int i = center + 1; i < size; i++) - stream << " samplePos" << i << " = gl_MultiTexCoord0.st + pixelSize * vec2(" + stream << " samplePos" << i << " = gl_TexCoord[0].st + pixelSize * vec2(" << 1.5 + (i - center - 1) * 2.0 << ");\n"; stream << "\n"; stream << " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n";