X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fvertexarray.cpp;h=527052e9c0a36322c64aa6022da5e650a64e7e21;hb=a64e2e362cd7bce6f103f8878d69fcca4261bac9;hp=6c0e5f1aea363c8de02eeaea1c714f7ac1196645;hpb=ab59f5a9e66b3fc7872ad96ec7949940189f0819;p=libs%2Fgl.git diff --git a/source/vertexarray.cpp b/source/vertexarray.cpp index 6c0e5f1a..527052e9 100644 --- a/source/vertexarray.cpp +++ b/source/vertexarray.cpp @@ -18,7 +18,15 @@ VertexArray::VertexArray(const VertexFormat &f): } 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) { @@ -125,7 +133,11 @@ void VertexArray::apply() const throw invalid_operation("VertexArray::apply"); const VertexArray *old = current(); - if(!set_current(this)) + /* If the array has been modified, apply it even if it was the last one to + be applied. This is necessary to get the data updated to vertex buffer, and + to resync things after a format change. Radeon drivers also have some + problems with modifying vertex arrays without re-setting the pointers. */ + if(!set_current(this) && !dirty) return; if(vbuf) @@ -140,14 +152,22 @@ void VertexArray::apply() const 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 *arrays, const vector *old_arrays, const float *base, unsigned stride_bytes) +{ unsigned active_tex = 0; - unsigned n_arrays = arrays.size(); - if(old) - n_arrays = max(n_arrays, old->arrays.size()); + unsigned n_arrays = arrays ? arrays->size() : 0; + if(old_arrays) + n_arrays = max(n_arrays, old_arrays->size()); for(unsigned i=0; iarrays.size() && old->arrays[i].component) ? &old->arrays[i] : 0); + const Array *arr = ((arrays && isize() && (*arrays)[i].component) ? &(*arrays)[i] : 0); + const Array *old_arr = ((old_arrays && isize() && (*old_arrays)[i].component) ? &(*old_arrays)[i] : 0); if(!arr && !old_arr) continue; @@ -217,9 +237,6 @@ void VertexArray::apply() const if(active_tex) glClientActiveTexture(GL_TEXTURE0); - - if(vbuf) - Buffer::unbind_from(ARRAY_BUFFER); }