X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fmesh.cpp;h=b3b719c516942c42e5012a8ad92ad21dec06958d;hp=8c1e79c49b3efaffbfcdbf0216a7105a15bd5fe9;hb=4e4a3514961d130045619ea74d0bbab71580838c;hpb=51c775a5df70fe5a538c3e4bcccd3ab857ba5b59 diff --git a/source/mesh.cpp b/source/mesh.cpp index 8c1e79c4..b3b719c5 100644 --- a/source/mesh.cpp +++ b/source/mesh.cpp @@ -128,10 +128,29 @@ void Mesh::add_batch(const Batch &b) batches.back().append(b); else { + bool reallocate = (batches.size()==batches.capacity()); + if(reallocate && ibuf) + { + for(vector::iterator i=batches.end(); i!=batches.begin(); ) + (--i)->use_buffer(0); + } + Batch *prev = (batches.empty() ? 0 : &batches.back()); batches.push_back(b); if(ibuf) - batches.back().use_buffer(ibuf, prev); + { + if(reallocate) + { + prev = 0; + for(vector::iterator i=batches.begin(); i!=batches.end(); ++i) + { + i->use_buffer(ibuf, prev); + prev = &*i; + } + } + else + batches.back().use_buffer(ibuf, prev); + } } } @@ -158,7 +177,7 @@ void Mesh::draw() const BindRestore bind_ibuf(ibuf, ELEMENT_ARRAY_BUFFER); Bind bind_winding(winding); - for(list::const_iterator i=batches.begin(); i!=batches.end(); ++i) + for(vector::const_iterator i=batches.begin(); i!=batches.end(); ++i) i->draw(); } @@ -174,7 +193,7 @@ void Mesh::draw(Renderer &renderer) const renderer.set_mesh(this); renderer.set_winding_test(winding); - for(list::const_iterator i=batches.begin(); i!=batches.end(); ++i) + for(vector::const_iterator i=batches.begin(); i!=batches.end(); ++i) renderer.draw(*i); }