}
VertexArray::~VertexArray()
-{ }
+{
+ 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);
+ }
+}
void VertexArray::reset(const VertexFormat &f)
{
const float *base = (vbuf ? 0 : &data[0]);
unsigned stride_bytes = stride*sizeof(float);
+ apply_arrays(&arrays, (old ? &old->arrays : 0), base, stride_bytes);
+
+ if(vbuf)
+ Buffer::unbind_from(ARRAY_BUFFER);
+}
+
+void VertexArray::apply_arrays(const vector<Array> *arrays, const vector<Array> *old_arrays, const float *base, unsigned stride_bytes)
+{
unsigned active_tex = 0;
- unsigned n_arrays = arrays.size();
- if(old)
- n_arrays = max<unsigned>(n_arrays, old->arrays.size());
+ unsigned n_arrays = arrays ? arrays->size() : 0;
+ if(old_arrays)
+ n_arrays = max<unsigned>(n_arrays, old_arrays->size());
for(unsigned i=0; i<n_arrays; ++i)
{
- const Array *arr = ((i<arrays.size() && arrays[i].component) ? &arrays[i] : 0);
- const Array *old_arr = ((old && i<old->arrays.size() && old->arrays[i].component) ? &old->arrays[i] : 0);
+ const Array *arr = ((arrays && i<arrays->size() && (*arrays)[i].component) ? &(*arrays)[i] : 0);
+ const Array *old_arr = ((old_arrays && i<old_arrays->size() && (*old_arrays)[i].component) ? &(*old_arrays)[i] : 0);
if(!arr && !old_arr)
continue;
if(active_tex)
glClientActiveTexture(GL_TEXTURE0);
-
- if(vbuf)
- Buffer::unbind_from(ARRAY_BUFFER);
}