]> git.tdb.fi Git - libs/gl.git/blobdiff - source/vertexsetup.cpp
Only update the changed parts of VertexSetup
[libs/gl.git] / source / vertexsetup.cpp
index f6a71f4996162b9addaa3b337c6a5ea35121e1be..275585beac07c39a2ef260229a0c22727081f3af 100644 (file)
@@ -10,7 +10,7 @@ namespace Msp {
 namespace GL {
 
 VertexSetup::VertexSetup():
-       dirty(false),
+       dirty(0),
        array(0),
        index_buffer(0)
 {
@@ -28,23 +28,32 @@ VertexSetup::~VertexSetup()
 void VertexSetup::set_vertex_array(const VertexArray &a)
 {
        array = &a;
-       update();
+       update(VERTEX_ARRAY);
 }
 
 void VertexSetup::set_index_buffer(const Buffer &ibuf)
 {
        index_buffer = &ibuf;
-       update();
+       update(INDEX_BUFFER);
 }
 
-void VertexSetup::update() const
+void VertexSetup::update(unsigned mask) const
 {
        if(current()!=this)
        {
-               dirty = true;
+               dirty |= mask;
                return;
        }
 
+       if(mask&VERTEX_ARRAY)
+               update_vertex_array();
+
+       if(mask&INDEX_BUFFER)
+               glBindBuffer(ELEMENT_ARRAY_BUFFER, index_buffer->get_id());
+}
+
+void VertexSetup::update_vertex_array() const
+{
        Bind bind_vbuf(array->get_buffer(), ARRAY_BUFFER);
 
        const VertexFormat &fmt = array->get_format();
@@ -63,8 +72,6 @@ void VertexSetup::update() const
                glEnableVertexAttribArray(t);
                ptr += sz;
        }
-
-       glBindBuffer(ELEMENT_ARRAY_BUFFER, index_buffer->get_id());
 }
 
 void VertexSetup::bind() const
@@ -74,8 +81,8 @@ void VertexSetup::bind() const
                glBindVertexArray(id);
                if(dirty)
                {
-                       update();
-                       dirty = false;
+                       update(dirty);
+                       dirty = 0;
                }
        }
 }