X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fvertexarray.cpp;fp=source%2Fvertexarray.cpp;h=042f58c758b41ac48af3fccd52dcb7ec5f75440b;hp=3848109973c9dca9c8c49c830ebfa10e0285c6e9;hb=0ef8e620a008e92069b0dd9ae4e972bc69430fc7;hpb=41264797bc55f27411555b3c217a80c791154afc diff --git a/source/vertexarray.cpp b/source/vertexarray.cpp index 38481099..042f58c7 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) @@ -103,7 +100,7 @@ unsigned VertexArray::get_data_size() const return data.size()*sizeof(float); } -void VertexArray::apply() const +void VertexArray::bind() const { if(format.empty()) throw invalid_operation("VertexArray::apply"); @@ -210,6 +207,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),