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.
This commit is contained in:
Fredrik Höglund 2012-09-17 23:35:52 +02:00
parent a5a2561f69
commit de4b7e8db1
2 changed files with 50 additions and 1 deletions

View file

@ -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];

View file

@ -30,6 +30,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QSet>
#include <QRect>
#include <QtGui/QRegion>
#include <QtGui/QVector2D>
#include <QtGui/QVector3D>
#include <QVector>
#include <QList>
@ -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;
};