From 76ca3c65dbb96461e42300016a85a4e158f5596b Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 25 Jan 2021 01:46:34 +0200 Subject: [PATCH] Some tweaks to Mesh::add_batch 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 | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/source/mesh.cpp b/source/mesh.cpp index b5535039..8f791121 100644 --- a/source/mesh.cpp +++ b/source/mesh.cpp @@ -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::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::iterator i=batches.begin(); i!=batches.end(); ++i) { - prev = 0; - for(vector::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); } } -- 2.45.2