+ if(data_type==UNSIGNED_SHORT)
+ return sizeof(unsigned short);
+ else if(data_type==UNSIGNED_INT)
+ return sizeof(unsigned);
+ return sizeof(unsigned char);
+}
+
+unsigned Batch::get_index(unsigned i) const
+{
+ if(data_type==UNSIGNED_SHORT)
+ return *(unsigned short *)&data[i*sizeof(unsigned short)];
+ else if(data_type==UNSIGNED_INT)
+ return *(unsigned *)&data[i*sizeof(unsigned )];
+ else
+ return data[i];
+}
+
+void Batch::draw() const
+{
+ if(restart)
+ {
+ unsigned index;
+ if(data_type==UNSIGNED_SHORT)
+ index = 0xFFFF;
+ else if(data_type==UNSIGNED_INT)
+ index = 0xFFFFFFFF;
+ else
+ index = 0xFF;
+
+ if(index!=restart_index)
+ {
+ if(!restart_index)
+ glEnableClientState(GL_PRIMITIVE_RESTART_NV);
+ glPrimitiveRestartIndexNV(index);
+ restart_index = index;
+ }
+ }
+ else if(restart_index && restart_index<=max_index)
+ {
+ glDisableClientState(GL_PRIMITIVE_RESTART_NV);
+ restart_index = 0;
+ }
+
+ if(Buffer *ibuf = get_buffer())
+ {
+ bool have_vao = Mesh::current();
+ const Buffer *old_ibuf = 0;
+ if(!have_vao)
+ {
+ old_ibuf = Buffer::current(ELEMENT_ARRAY_BUFFER);
+ ibuf->bind_to(ELEMENT_ARRAY_BUFFER);
+ }
+
+ if(dirty)
+ update_buffer();
+
+ glDrawRangeElements(prim_type, min_index, max_index, size(), data_type, reinterpret_cast<void *>(get_offset()));
+ if(!have_vao)
+ {
+ if(old_ibuf)
+ old_ibuf->bind_to(ELEMENT_ARRAY_BUFFER);
+ else
+ Buffer::unbind_from(ELEMENT_ARRAY_BUFFER);
+ }
+ }
+ else
+ glDrawRangeElements(prim_type, min_index, max_index, size(), data_type, &data[0]);