X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fbatch.cpp;h=1260c6abe5e995203af5ff3a70d10ce9fc1d8d63;hp=228ff20bf7a0d395d6fbec42c3cf938d13dbd3fa;hb=f14435e58bfa0fa697a06ba9a454bb30cd37d9d8;hpb=083578c2ca0aabfa60e8872e23d53e9101795dff diff --git a/source/batch.cpp b/source/batch.cpp index 228ff20b..1260c6ab 100644 --- a/source/batch.cpp +++ b/source/batch.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007-2010 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include "batch.h" #include "bindable.h" #include "buffer.h" @@ -119,9 +112,42 @@ Batch &Batch::append(unsigned i) void Batch::append(const vector &ind) { - data.reserve(data.size()+ind.size()*get_index_size()); + if(ind.empty()) + return; + + if(data.empty()) + min_index = max_index = ind.front(); + for(vector::const_iterator i=ind.begin(); i!=ind.end(); ++i) - append(*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); + + 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; i