From 9c1833920c83eaa867eba9ce9ce0d6570306832b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Tue, 18 Sep 2012 22:24:58 +0200 Subject: [PATCH] kwin: Use the new map() interface in renderQuads() Write the vertex data directly into the buffer object, instead of allocating two temporary arrays, coyping the data into them, and then copying the data from the arrays into the buffer object. This also makes renderQuads() handle coordinates for rectangular textures correctly. --- scene_opengl.cpp | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/scene_opengl.cpp b/scene_opengl.cpp index 077d361f94..f143985d2d 100644 --- a/scene_opengl.cpp +++ b/scene_opengl.cpp @@ -1312,25 +1312,24 @@ void SceneOpenGL::Window::renderQuads(int, const QRegion& region, const WindowQu { if (quads.isEmpty()) return; + + const QMatrix4x4 matrix = tex->matrix(normalized ? NormalizedCoordinates : UnnormalizedCoordinates); + + const GLVertexAttrib attribs[] = { + { VA_Position, 2, GL_FLOAT, offsetof(GLVertex2D, position) }, + { VA_TexCoord, 2, GL_FLOAT, offsetof(GLVertex2D, texcoord) }, + }; + // Render geometry - float* vertices; - float* texcoords; - QSizeF size(tex->size()); - if (normalized) { - size.setWidth(1.0); - size.setHeight(1.0); - } -#ifndef KWIN_HAVE_OPENGLES - if (tex->target() == GL_TEXTURE_RECTANGLE_ARB) { - size.setWidth(1.0); - size.setHeight(1.0); - } -#endif - quads.makeArrays(&vertices, &texcoords, size, tex->isYInverted()); - GLVertexBuffer::streamingBuffer()->setData(quads.count() * 6, 2, vertices, texcoords); - GLVertexBuffer::streamingBuffer()->render(region, GL_TRIANGLES, hardwareClipping); - delete[] vertices; - delete[] texcoords; + GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); + vbo->setAttribLayout(attribs, 2, sizeof(GLVertex2D)); + vbo->setVertexCount(quads.count() * 6); + + GLVertex2D *map = (GLVertex2D *) vbo->map(quads.count() * 6 * sizeof(GLVertex2D)); + quads.makeInterleavedArrays(map, matrix); + vbo->unmap(); + + vbo->render(region, GL_TRIANGLES, hardwareClipping); } GLTexture *SceneOpenGL::Window::textureForType(SceneOpenGL::Window::TextureType type)