From 82c1e1168d1bd5ebabcf1ca6e13bb5882dc24970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Wed, 12 Sep 2012 20:55:27 +0200 Subject: [PATCH] kwin: Store the usage hint in GLVertexBufferPrivate ..instead of computing it every time setData() is called. --- libkwineffects/kwinglutils.cpp | 41 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/libkwineffects/kwinglutils.cpp b/libkwineffects/kwinglutils.cpp index da0e7cc32d..90c79310c0 100644 --- a/libkwineffects/kwinglutils.cpp +++ b/libkwineffects/kwinglutils.cpp @@ -1132,8 +1132,7 @@ class GLVertexBufferPrivate { public: GLVertexBufferPrivate(GLVertexBuffer::UsageHint usageHint) - : hint(usageHint) - , numberVertices(0) + : numberVertices(0) , dimension(2) , useColor(false) , useTexCoords(true) @@ -1141,14 +1140,28 @@ public: if (GLVertexBufferPrivate::supported) { glGenBuffers(2, buffers); } + + switch(usageHint) { + case GLVertexBuffer::Dynamic: + usage = GL_DYNAMIC_DRAW; + break; + case GLVertexBuffer::Static: + usage = GL_STATIC_DRAW; + break; + default: + usage = GL_STREAM_DRAW; + break; + } } + ~GLVertexBufferPrivate() { if (GLVertexBufferPrivate::supported) { glDeleteBuffers(2, buffers); } } - GLVertexBuffer::UsageHint hint; + GLuint buffers[2]; + GLenum usage; int numberVertices; int dimension; static bool supported; @@ -1298,6 +1311,7 @@ void GLVertexBuffer::setData(int numberVertices, int dim, const float* vertices, d->numberVertices = numberVertices; d->dimension = dim; d->useTexCoords = (texcoords != NULL); + if (!GLVertexBufferPrivate::supported) { // legacy data d->legacyVertices.clear(); @@ -1314,28 +1328,13 @@ void GLVertexBuffer::setData(int numberVertices, int dim, const float* vertices, } return; } - GLenum hint; - switch(d->hint) { - case Dynamic: - hint = GL_DYNAMIC_DRAW; - break; - case Static: - hint = GL_STATIC_DRAW; - break; - case Stream: - hint = GL_STREAM_DRAW; - break; - default: - // just to make the compiler happy - hint = GL_STREAM_DRAW; - break; - } + glBindBuffer(GL_ARRAY_BUFFER, d->buffers[ 0 ]); - glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*numberVertices * d->dimension, vertices, hint); + glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*numberVertices * d->dimension, vertices, d->usage); if (d->useTexCoords) { glBindBuffer(GL_ARRAY_BUFFER, d->buffers[ 1 ]); - glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*numberVertices * 2, texcoords, hint); + glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*numberVertices * 2, texcoords, d->usage); } glBindBuffer(GL_ARRAY_BUFFER, 0);