]> git.tdb.fi Git - libs/gl.git/blobdiff - source/vertexarray.cpp
Require mspgbase now that Image was moved there
[libs/gl.git] / source / vertexarray.cpp
index c0ca8dca80f22b96f1efdfe8f9de6ccd9dc04ffd..81a2acd5182a413777c39f0ebe944fe617b79b22 100644 (file)
@@ -33,18 +33,22 @@ VertexArray::~VertexArray()
 
 void VertexArray::use_vertex_buffer()
 {
-       if(vbuf) return;
+       if(vbuf && own_vbuf)
+               return;
 
        vbuf=new VertexBuffer();
        own_vbuf=true;
+
        update_data();
 }
 
 void VertexArray::use_vertex_buffer(VertexBuffer *b)
 {
-       if(vbuf) return;
-
+       if(own_vbuf)
+               delete vbuf;
        vbuf=b;
+       own_vbuf=false;
+
        update_data();
 }
 
@@ -114,7 +118,8 @@ void VertexArray::apply() const
        set_array(GL_TEXTURE_COORD_ARRAY, found&4, 4);
        set_array(GL_COLOR_ARRAY, found&8, 8);
 
-       VertexBuffer::unbind();
+       if(vbuf)
+               VertexBuffer::unbind();
 }
 
 /**
@@ -123,7 +128,10 @@ Updates the VertexArray data to the VertexBuffer tied to the array, if any.
 void VertexArray::update_data()
 {
        if(vbuf)
+       {
                vbuf->data(data.size()*sizeof(float), &data[0]);
+               VertexBuffer::unbind();
+       }
 }
 
 void VertexArray::set_array(unsigned array, unsigned bit, unsigned mask) const