]> git.tdb.fi Git - libs/gl.git/commitdiff
Some tweaks to Mesh::add_batch
authorMikko Rasa <tdb@tdb.fi>
Sun, 24 Jan 2021 23:46:34 +0000 (01:46 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 25 Jan 2021 00:12:20 +0000 (02:12 +0200)
Index buffer can be assumed to exist.  Add a fast path for first batch,
which will also be useful in the next stage of buffer refactoring.

source/mesh.cpp

index b5535039b44109a2f31ca8cd9c57105001966b64..8f7911219ec68afa3cb9048d35960bef3462437c 100644 (file)
@@ -79,33 +79,35 @@ void Mesh::add_batch(const Batch &b)
 {
        create_buffers();
 
-       if(!batches.empty() && batches.back().can_append(b.get_type()))
+       if(batches.empty())
+       {
+               batches.push_back(b);
+               batches.back().use_buffer(ibuf);
+       }
+       else if(batches.back().can_append(b.get_type()))
                batches.back().append(b);
        else
        {
                bool reallocate = (batches.size()==batches.capacity());
-               if(reallocate && ibuf)
+               if(reallocate)
                {
                        for(vector<Batch>::iterator i=batches.end(); i!=batches.begin(); )
                                (--i)->use_buffer(0);
                }
 
-               Batch *prev = (batches.empty() ? 0 : &batches.back());
+               Batch *prev = &batches.back();
                batches.push_back(b);
-               if(ibuf)
+               if(reallocate)
                {
-                       if(reallocate)
+                       prev = 0;
+                       for(vector<Batch>::iterator i=batches.begin(); i!=batches.end(); ++i)
                        {
-                               prev = 0;
-                               for(vector<Batch>::iterator i=batches.begin(); i!=batches.end(); ++i)
-                               {
-                                       i->use_buffer(ibuf, prev);
-                                       prev = &*i;
-                               }
+                               i->use_buffer(ibuf, prev);
+                               prev = &*i;
                        }
-                       else
-                               batches.back().use_buffer(ibuf, prev);
                }
+               else
+                       batches.back().use_buffer(ibuf, prev);
        }
 }