kwin: Simplify makeDecorationArrays()

This also fixes coordinate inversion for rectangular textures.
icc-effect-5.14.5
Fredrik Höglund 2012-09-11 18:04:30 +02:00
parent d4aacd678e
commit 6891c900b3
1 changed files with 27 additions and 49 deletions

View File

@ -1261,63 +1261,41 @@ void SceneOpenGL::Window::paintShadow(const QRegion &region, const WindowPaintDa
#endif #endif
} }
void SceneOpenGL::Window::makeDecorationArrays(const WindowQuadList& quads, const QRect &rect, GLTexture *tex) const void SceneOpenGL::Window::makeDecorationArrays(const WindowQuadList &quads, const QRect &rect, GLTexture *texture) const
{ {
QVector<float> vertices; QVector<float> vertices;
QVector<float> texcoords; QVector<float> texcoords;
vertices.reserve(quads.count() * 6 * 2); vertices.reserve(quads.count() * 6 * 2);
texcoords.reserve(quads.count() * 6 * 2); texcoords.reserve(quads.count() * 6 * 2);
float width = rect.width();
float height = rect.height();
#ifndef KWIN_HAVE_OPENGLES
if (tex->target() == GL_TEXTURE_RECTANGLE_ARB) {
width = 1.0;
height = 1.0;
}
#endif
foreach (const WindowQuad & quad, quads) {
vertices << quad[ 1 ].x();
vertices << quad[ 1 ].y();
vertices << quad[ 0 ].x();
vertices << quad[ 0 ].y();
vertices << quad[ 3 ].x();
vertices << quad[ 3 ].y();
vertices << quad[ 3 ].x();
vertices << quad[ 3 ].y();
vertices << quad[ 2 ].x();
vertices << quad[ 2 ].y();
vertices << quad[ 1 ].x();
vertices << quad[ 1 ].y();
if (tex->isYInverted()) { // Since we know that the texture matrix just scales and translates
texcoords << (float)(quad.originalRight() - rect.x()) / width; // we can use this information to optimize the transformation
texcoords << (float)(quad.originalTop() - rect.y()) / height; QMatrix4x4 matrix = texture->matrix(UnnormalizedCoordinates);
texcoords << (float)(quad.originalLeft() - rect.x()) / width; matrix.translate(-rect.x(), -rect.y());
texcoords << (float)(quad.originalTop() - rect.y()) / height;
texcoords << (float)(quad.originalLeft() - rect.x()) / width; float uCoeff = matrix(0, 0);
texcoords << (float)(quad.originalBottom() - rect.y()) / height; float vCoeff = matrix(1, 1);
texcoords << (float)(quad.originalLeft() - rect.x()) / width;
texcoords << (float)(quad.originalBottom() - rect.y()) / height; float uOffset = matrix(0, 3);
texcoords << (float)(quad.originalRight() - rect.x()) / width; float vOffset = matrix(1, 3);
texcoords << (float)(quad.originalBottom() - rect.y()) / height;
texcoords << (float)(quad.originalRight() - rect.x()) / width; // Note: The positions in a WindowQuad are stored in clockwise order
texcoords << (float)(quad.originalTop() - rect.y()) / height; const int index[] = { 1, 0, 3, 3, 2, 1 };
} else {
texcoords << (float)(quad.originalRight() - rect.x()) / width; foreach (const WindowQuad &quad, quads) {
texcoords << 1.0f - (float)(quad.originalTop() - rect.y()) / height; for (int i = 0; i < 6; i++) {
texcoords << (float)(quad.originalLeft() - rect.x()) / width; const WindowVertex &v = quad[index[i]];
texcoords << 1.0f - (float)(quad.originalTop() - rect.y()) / height;
texcoords << (float)(quad.originalLeft() - rect.x()) / width; vertices << v.x();
texcoords << 1.0f - (float)(quad.originalBottom() - rect.y()) / height; vertices << v.y();
texcoords << (float)(quad.originalLeft() - rect.x()) / width;
texcoords << 1.0f - (float)(quad.originalBottom() - rect.y()) / height; texcoords << v.originalX() * uCoeff + uOffset;
texcoords << (float)(quad.originalRight() - rect.x()) / width; texcoords << v.originalY() * vCoeff + vOffset;
texcoords << 1.0f - (float)(quad.originalBottom() - rect.y()) / height;
texcoords << (float)(quad.originalRight() - rect.x()) / width;
texcoords << 1.0f - (float)(quad.originalTop() - rect.y()) / height;
} }
} }
GLVertexBuffer::streamingBuffer()->setData(quads.count() * 6, 2, vertices.data(), texcoords.data());
GLVertexBuffer::streamingBuffer()->setData(quads.count() * 6, 2, vertices.constData(), texcoords.constData());
} }
void SceneOpenGL::Window::renderQuads(int, const QRegion& region, const WindowQuadList& quads, void SceneOpenGL::Window::renderQuads(int, const QRegion& region, const WindowQuadList& quads,