X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fmesh.cpp;h=b3b719c516942c42e5012a8ad92ad21dec06958d;hp=d0e71489f1f48a22c6de0d1b686648c452024d98;hb=a9c375e17065bcc429b430bd8211a9ee845159a5;hpb=8e51e1e7089d79359ec584bb4292b6cb2ecfd495 diff --git a/source/mesh.cpp b/source/mesh.cpp index d0e71489..b3b719c5 100644 --- a/source/mesh.cpp +++ b/source/mesh.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include "buffer.h" @@ -29,7 +30,7 @@ void Mesh::init(ResourceManager *rm) vbuf = 0; ibuf = 0; vao_id = 0; - defer_buffers = true; + defer_buffers = ARB_vertex_buffer_object; dirty = true; disallow_rendering = false; winding = 0; @@ -127,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); + } } } @@ -157,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(); } @@ -173,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); } @@ -274,7 +294,7 @@ Mesh::AsyncLoader::AsyncLoader(Mesh &m, IO::Seekable &i): phase(0) { // Make sure the extension is initialized in the rendering thread. - (bool)NV_primitive_restart; + (void)(bool)NV_primitive_restart; mesh.disallow_rendering = true; if(mesh.defer_buffers)