]> git.tdb.fi Git - libs/gl.git/blobdiff - source/vertexarray.cpp
Unbind things if they are deleted while current
[libs/gl.git] / source / vertexarray.cpp
index 72fd8a48ecddc802ec6a1bd0aa2cb985e3c9328a..042f58c758b41ac48af3fccd52dcb7ec5f75440b 100644 (file)
@@ -18,13 +18,10 @@ VertexArray::VertexArray(const VertexFormat &f)
 
 VertexArray::~VertexArray()
 {
+       /* Unbind accesses the current VertexArray, so a call from ~Bindable would
+       try to access destroyed data. */
        if(current()==this)
-       {
-               /* We must deactivate arrays here, or apply() would try to access deleted
-               data on the next invocation. */
-               set_current(0);
-               apply_arrays(0, &arrays, 0, 0);
-       }
+               unbind();
 }
 
 void VertexArray::reset(const VertexFormat &f)
@@ -103,12 +100,7 @@ unsigned VertexArray::get_data_size() const
        return data.size()*sizeof(float);
 }
 
-void VertexArray::upload_data() const
-{
-       get_buffer()->sub_data(get_offset(), get_data_size(), &data[0]);
-}
-
-void VertexArray::apply() const
+void VertexArray::bind() const
 {
        if(format.empty())
                throw invalid_operation("VertexArray::apply");
@@ -215,6 +207,13 @@ void VertexArray::apply_arrays(const vector<Array> *arrays, const vector<Array>
                glClientActiveTexture(GL_TEXTURE0);
 }
 
+void VertexArray::unbind()
+{
+       const VertexArray *old = current();
+       if(set_current(0))
+               apply_arrays(0, &old->arrays, 0, 0);
+}
+
 
 VertexArray::Array::Array():
        component(0),