]> git.tdb.fi Git - libs/gl.git/blobdiff - source/batch.cpp
Drop Id tags and copyright notices from files
[libs/gl.git] / source / batch.cpp
index 228ff20bf7a0d395d6fbec42c3cf938d13dbd3fa..1260c6abe5e995203af5ff3a70d10ce9fc1d8d63 100644 (file)
@@ -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<unsigned> &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<unsigned>::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<unsigned short *>(&data[base]);
+               for(unsigned i=0; i<ind.size(); ++i)
+                       ptr[i] = ind[i];
+       }
+       else if(data_type==UNSIGNED_INT)
+       {
+               unsigned *ptr = reinterpret_cast<unsigned *>(&data[base]);
+               for(unsigned i=0; i<ind.size(); ++i)
+                       ptr[i] = ind[i];
+       }
+       else
+       {
+               for(unsigned i=0; i<ind.size(); ++i)
+                       data[base+i] = ind[i];
+       }
 }
 
 void Batch::append(const Batch &other)