X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fvertexarray.cpp;h=5065f305c3575920411b6d8ebfc707f61b6aabb3;hb=619aae12e01f25e79626a94c973927e5599e99a5;hp=79eecf58a2970ea53e850477e81ed11f6a96ce22;hpb=08d72eb25d3f99f347e6c801755871b7a5f29f5d;p=libs%2Fgl.git diff --git a/source/vertexarray.cpp b/source/vertexarray.cpp index 79eecf58..5065f305 100644 --- a/source/vertexarray.cpp +++ b/source/vertexarray.cpp @@ -1,5 +1,5 @@ -#include "arb_multitexture.h" -#include "arb_vertex_shader.h" +#include +#include #include "buffer.h" #include "error.h" #include "gl.h" @@ -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); }