]> git.tdb.fi Git - libs/gl.git/commitdiff
Store mesh batches in vector instead of list
authorMikko Rasa <tdb@tdb.fi>
Sun, 22 Apr 2018 08:54:16 +0000 (11:54 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 22 Apr 2018 08:57:08 +0000 (11:57 +0300)
source/mesh.cpp
source/mesh.h

index 8c1e79c49b3efaffbfcdbf0216a7105a15bd5fe9..b3b719c516942c42e5012a8ad92ad21dec06958d 100644 (file)
@@ -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<Batch>::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<Batch>::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<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
+       for(vector<Batch>::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<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
+       for(vector<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
                renderer.draw(*i);
 }
 
index e9feb675a0635ee67127b5b4cd0f426617be7855..70370633fd0425cf88222ceab22b40d012604a35 100644 (file)
@@ -52,7 +52,7 @@ private:
        };
 
        VertexArray vertices;
-       std::list<Batch> batches;
+       std::vector<Batch> batches;
        Buffer *vbuf;
        Buffer *ibuf;
        unsigned vao_id;
@@ -82,7 +82,7 @@ public:
        float *modify_vertex(unsigned);
 
        void add_batch(const Batch &b);
-       const std::list<Batch> &get_batches() { return batches; }
+       const std::vector<Batch> &get_batches() const { return batches; }
 
        void set_winding(const WindingTest *);