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)
float *VertexArray::append()
{
data.insert(data.end(), stride, 0.0f);
+ update_offset();
dirty = true;
return &*(data.end()-stride);
}
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");
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),