From: Mikko Rasa Date: Thu, 30 Aug 2012 19:54:34 +0000 (+0300) Subject: Only call update_offset() once per append operation X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=d58a3bd12fb8c6331bb9208aa68f8c082be48863;p=libs%2Fgl.git Only call update_offset() once per append operation --- diff --git a/source/batch.cpp b/source/batch.cpp index d4b6497f..d6924a80 100644 --- a/source/batch.cpp +++ b/source/batch.cpp @@ -96,25 +96,7 @@ void Batch::set_data_type(DataType t) Batch &Batch::append(unsigned i) { - if(data.empty()) - min_index = max_index = i; - else - { - min_index = min(min_index, i); - max_index = max(max_index, i); - } - - if((data_type==UNSIGNED_BYTE || data_type==UNSIGNED_SHORT) && max_index>0xFFFE) - set_data_type(UNSIGNED_INT); - else if(data_type==UNSIGNED_BYTE && max_index>0xFE) - set_data_type(UNSIGNED_SHORT); - - if(data_type==UNSIGNED_SHORT) - ::append(data, i); - else if(data_type==UNSIGNED_INT) - ::append(data, i); - else - data.push_back(i); + append_index(i); update_offset(); dirty = true; @@ -127,39 +109,11 @@ void Batch::append(const vector &ind) if(ind.empty()) return; - if(data.empty()) - min_index = max_index = ind.front(); - + data.reserve(data.size()+ind.size()*get_index_size()); for(vector::const_iterator i=ind.begin(); i!=ind.end(); ++i) - { - min_index = min(min_index, *i); - max_index = max(max_index, *i); - } - - if((data_type==UNSIGNED_BYTE || data_type==UNSIGNED_SHORT) && max_index>0xFFFE) - set_data_type(UNSIGNED_INT); - else if(data_type==UNSIGNED_BYTE && max_index>0xFE) - set_data_type(UNSIGNED_SHORT); + append_index(*i); - unsigned base = data.size(); - data.resize(data.size()+ind.size()*get_index_size()); - if(data_type==UNSIGNED_SHORT) - { - unsigned short *ptr = reinterpret_cast(&data[base]); - for(unsigned i=0; i(&data[base]); - for(unsigned i=0; i0xFFFE) + set_data_type(UNSIGNED_INT); + else if(data_type==UNSIGNED_BYTE && max_index>0xFE) + set_data_type(UNSIGNED_SHORT); + + if(data_type==UNSIGNED_SHORT) + ::append(data, i); + else if(data_type==UNSIGNED_INT) + ::append(data, i); + else + data.push_back(i); } void Batch::upload_data() const diff --git a/source/batch.h b/source/batch.h index 3c54089a..92a10e6b 100644 --- a/source/batch.h +++ b/source/batch.h @@ -53,6 +53,7 @@ public: void append(const std::vector &); void append(const Batch &); private: + void append_index(unsigned); virtual unsigned get_data_size() const { return data.size(); } virtual void upload_data() const; unsigned get_index_size() const;