From 993b50cf1cc653c440bff3cc6d30d45d9cac4bce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Mon, 18 Mar 2013 16:43:08 +0100 Subject: [PATCH] kwin: Add a new GLVertexBuffer::draw() method Expose bindArrays(), unbindArrays() and add a draw() method that takes an offset and a count. This makes it possible to upload geometry, call bindArrays(), and then call draw() multiple times to draw different subsets of the uploaded geometry. --- libkwineffects/kwinglutils.cpp | 21 +++++++++++++++++---- libkwineffects/kwinglutils.h | 15 +++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/libkwineffects/kwinglutils.cpp b/libkwineffects/kwinglutils.cpp index cb88aff081..3ce9998071 100644 --- a/libkwineffects/kwinglutils.cpp +++ b/libkwineffects/kwinglutils.cpp @@ -1600,18 +1600,31 @@ void GLVertexBuffer::render(GLenum primitiveMode) void GLVertexBuffer::render(const QRegion& region, GLenum primitiveMode, bool hardwareClipping) { d->bindArrays(); + draw(region, primitiveMode, 0, d->vertexCount, hardwareClipping); + d->unbindArrays(); +} +void GLVertexBuffer::bindArrays() +{ + d->bindArrays(); +} + +void GLVertexBuffer::unbindArrays() +{ + d->unbindArrays(); +} + +void GLVertexBuffer::draw(const QRegion ®ion, GLenum primitiveMode, int first, int count, bool hardwareClipping) +{ if (!hardwareClipping) { - glDrawArrays(primitiveMode, 0, d->vertexCount); + glDrawArrays(primitiveMode, first, count); } else { // Clip using scissoring foreach (const QRect &r, region.rects()) { glScissor(r.x(), displayHeight() - r.y() - r.height(), r.width(), r.height()); - glDrawArrays(primitiveMode, 0, d->vertexCount); + glDrawArrays(primitiveMode, first, count); } } - - d->unbindArrays(); } bool GLVertexBuffer::isSupported() diff --git a/libkwineffects/kwinglutils.h b/libkwineffects/kwinglutils.h index 70b250ac04..54c9ca316d 100644 --- a/libkwineffects/kwinglutils.h +++ b/libkwineffects/kwinglutils.h @@ -707,6 +707,21 @@ public: */ void unmap(); + /** + * Binds the vertex arrays to the context. + */ + void bindArrays(); + + /** + * Disables the vertex arrays. + */ + void unbindArrays(); + + /** + * Draws count vertices beginning with first. + */ + void draw(const QRegion ®ion, GLenum primitiveMode, int first, int count, bool hardwareClipping = false); + /** * Renders the vertex data in given @a primitiveMode. * Please refer to OpenGL documentation of glDrawArrays or glDrawElements for allowed