X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fvertexarray.cpp;h=867aee7b189b71f348950741e4f2ccda6ae18921;hb=922fac753e31d97fc88daa166e93e4c5572bd2ba;hp=72fd8a48ecddc802ec6a1bd0aa2cb985e3c9328a;hpb=61ff840cd211f10d45dca8c4dad2cca5f68aaa42;p=libs%2Fgl.git diff --git a/source/vertexarray.cpp b/source/vertexarray.cpp index 72fd8a48..867aee7b 100644 --- a/source/vertexarray.cpp +++ b/source/vertexarray.cpp @@ -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) @@ -88,6 +85,7 @@ void VertexArray::reserve(unsigned n) float *VertexArray::append() { data.insert(data.end(), stride, 0.0f); + update_offset(); dirty = true; return &*(data.end()-stride); } @@ -103,12 +101,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 +208,13 @@ void VertexArray::apply_arrays(const vector *arrays, const vector 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),