From e1e997eda4b6492e885aaf1e2edc654747a9c433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Sun, 24 Mar 2013 16:44:40 +0100 Subject: [PATCH] kwin/blur: Optimize vertex uploads Use the new GLVertexBuffer::map() interface. Reviewed-by: Philipp Knechtges --- effects/blur/blur.cpp | 43 +++++++++++++++++++++++++++++-------------- effects/blur/blur.h | 1 - 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/effects/blur/blur.cpp b/effects/blur/blur.cpp index 8aad86c2bd..9b4f066fea 100644 --- a/effects/blur/blur.cpp +++ b/effects/blur/blur.cpp @@ -229,21 +229,36 @@ QRegion BlurEffect::blurRegion(const EffectWindow *w) const void BlurEffect::drawRegion(const QRegion ®ion) { const int vertexCount = region.rectCount() * 6; - if (vertices.size() < vertexCount) - vertices.resize(vertexCount); - - int i = 0; - foreach (const QRect & r, region.rects()) { - vertices[i++] = QVector2D(r.x() + r.width(), r.y()); - vertices[i++] = QVector2D(r.x(), r.y()); - vertices[i++] = QVector2D(r.x(), r.y() + r.height()); - vertices[i++] = QVector2D(r.x(), r.y() + r.height()); - vertices[i++] = QVector2D(r.x() + r.width(), r.y() + r.height()); - vertices[i++] = QVector2D(r.x() + r.width(), r.y()); - } GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); - vbo->reset(); - vbo->setData(vertexCount, 2, (float*)vertices.constData(), (float*)vertices.constData()); + + QVector2D *map = (QVector2D *) vbo->map(vertexCount * sizeof(QVector2D)); + + foreach (const QRect &r, region.rects()) { + const QVector2D topLeft(r.x(), r.y()); + const QVector2D topRight(r.x() + r.width(), r.y()); + const QVector2D bottomLeft(r.x(), r.y() + r.height()); + const QVector2D bottomRight(r.x() + r.width(), r.y() + r.height()); + + // First triangle + *(map++) = topRight; + *(map++) = topLeft; + *(map++) = bottomLeft; + + // Second triangle + *(map++) = bottomLeft; + *(map++) = bottomRight; + *(map++) = topRight; + } + + vbo->unmap(); + + const GLVertexAttrib layout[] = { + { VA_Position, 2, GL_FLOAT, 0 }, + { VA_TexCoord, 2, GL_FLOAT, 0 } + }; + + vbo->setVertexCount(vertexCount); + vbo->setAttribLayout(layout, 2, sizeof(QVector2D)); vbo->render(GL_TRIANGLES); } diff --git a/effects/blur/blur.h b/effects/blur/blur.h index 3c18f204d2..396e3e6c11 100644 --- a/effects/blur/blur.h +++ b/effects/blur/blur.h @@ -75,7 +75,6 @@ private: private: BlurShader *shader; - QVector vertices; GLRenderTarget *target; GLTexture tex; long net_wm_blur_region;