From de4b7e8db1f2ac4db4378a36641df4eaed1c7233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Mon, 17 Sep 2012 23:35:52 +0200 Subject: [PATCH] kwin: Add WindowQuadList::makeInterleavedArrays() Unlike makeArrays() this function writes into a pre-allocated array, and takes a matrix that's used to transform the texture coordinates. This allows this function to handle coordinates for rectangular textures correctly. --- libkwineffects/kwineffects.cpp | 32 ++++++++++++++++++++++++++++++++ libkwineffects/kwineffects.h | 19 ++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/libkwineffects/kwineffects.cpp b/libkwineffects/kwineffects.cpp index f4f519ad67..61e128aab1 100644 --- a/libkwineffects/kwineffects.cpp +++ b/libkwineffects/kwineffects.cpp @@ -1046,6 +1046,38 @@ WindowQuadList WindowQuadList::makeRegularGrid(int xSubdivisions, int ySubdivisi return ret; } +void WindowQuadList::makeInterleavedArrays(GLVertex2D *vertices, const QMatrix4x4 &textureMatrix) const +{ + // Since we know that the texture matrix just scales and translates + // we can use this information to optimize the transformation + const QVector2D coeff(textureMatrix(0, 0), textureMatrix(1, 1)); + const QVector2D offset(textureMatrix(0, 3), textureMatrix(1, 3)); + + GLVertex2D *vertex = vertices; + + for (int i = 0; i < count(); i++) { + const WindowQuad &quad = at(i); + GLVertex2D v[4]; // Four unique vertices / quad + + for (int j = 0; j < 4; j++) { + const WindowVertex &wv = quad[j]; + + v[j].position = QVector2D(wv.x(), wv.y()); + v[j].texcoord = QVector2D(wv.u(), wv.v()) * coeff + offset; + } + + // First triangle + *(vertex++) = v[1]; // Top-right + *(vertex++) = v[0]; // Top-left + *(vertex++) = v[3]; // Bottom-left + + // Second triangle + *(vertex++) = v[3]; // Bottom-left + *(vertex++) = v[2]; // Bottom-right + *(vertex++) = v[1]; // Top-right + } +} + void WindowQuadList::makeArrays(float **vertices, float **texcoords, const QSizeF &size, bool yInverted) const { *vertices = new float[count() * 6 * 2]; diff --git a/libkwineffects/kwineffects.h b/libkwineffects/kwineffects.h index 7d0522f170..f0bc22a4b9 100644 --- a/libkwineffects/kwineffects.h +++ b/libkwineffects/kwineffects.h @@ -30,6 +30,8 @@ along with this program. If not, see . #include #include #include +#include +#include #include #include @@ -49,7 +51,7 @@ class KActionCollection; class QFont; class QGraphicsScale; class QKeyEvent; -class QVector2D; +class QMatrix4x4; namespace KWin { @@ -1664,6 +1666,20 @@ public: explicit GlobalShortcutsEditor(QWidget *parent); }; + +struct GLVertex2D +{ + QVector2D position; + QVector2D texcoord; +}; + +struct GLVertex3D +{ + QVector3D position; + QVector2D texcoord; +}; + + /** * @short Vertex class * @@ -1741,6 +1757,7 @@ public: WindowQuadList select(WindowQuadType type) const; WindowQuadList filterOut(WindowQuadType type) const; bool smoothNeeded() const; + void makeInterleavedArrays(GLVertex2D *vertices, const QMatrix4x4 &matrix) const; void makeArrays(float** vertices, float** texcoords, const QSizeF &size, bool yInverted) const; bool isTransformed() const; };