+void Batch::append(const vector<unsigned> &ind)
+{
+ 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)
+ {
+ 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)
+{
+ if(other.prim_type!=prim_type)
+ throw invalid_argument("Batch::append");
+ if(prim_type==LINE_STRIP || prim_type==LINE_LOOP)
+ throw incompatible_data("Batch::append");
+ else if(prim_type==POLYGON)
+ throw incompatible_data("Batch::append");
+ else if(prim_type==TRIANGLE_FAN)
+ static Require _req(NV_primitive_restart);
+
+ if(other.data.empty())
+ return;
+
+ if(NV_primitive_restart)
+ {
+ restart = true;
+ if(data_type==UNSIGNED_SHORT)
+ ::append<unsigned short>(data, 0xFFFF);
+ else if(data_type==UNSIGNED_INT)
+ ::append<unsigned>(data, 0xFFFFFFFF);
+ else
+ data.push_back(0xFF);
+ }
+ else if(prim_type==TRIANGLE_STRIP)
+ {
+ append(get_index(size()-1));
+ append(other.get_index(0));
+ if(size()&1)
+ append(other.get_index(0));
+ }
+ else if(prim_type==QUAD_STRIP)
+ {
+ append(get_index(size()-1));
+ append(get_index(size()-1));
+ append(other.get_index(0));
+ append(other.get_index(0));
+ }
+
+ unsigned count = other.size();
+ for(unsigned i=0; i<count; ++i)
+ append(other.get_index(i));
+}
+
+unsigned Batch::get_index_size() const