- glDrawRangeElements(type, min_index, max_index, indices.size(), GL_UNSIGNED_INT, &indices[0]);
+ BindRestore _bind_ibuf(get_buffer(), ELEMENT_ARRAY_BUFFER);
+ const void *data_ptr = setup_draw();
+
+ glDrawElements(prim_type, size(), index_type, data_ptr);
+}
+
+void Batch::draw_instanced(unsigned count) const
+{
+ static Require req(ARB_draw_instanced);
+
+ BindRestore _bind_ibuf(get_buffer(), ELEMENT_ARRAY_BUFFER);
+ const void *data_ptr = setup_draw();
+
+ glDrawElementsInstanced(prim_type, size(), index_type, data_ptr, count);
+}
+
+const void *Batch::setup_draw() const
+{
+ if(!get_buffer())
+ throw invalid_operation("Batch::setup_draw");
+
+ if(restart)
+ {
+ unsigned index = (index_type==UNSIGNED_INT ? 0xFFFFFFFF : 0xFFFF);
+
+ if(index!=restart_index)
+ set_restart_index(index);
+ }
+ else if(restart_index && restart_index<=max_index)
+ set_restart_index(0);
+
+ refresh();
+
+ return reinterpret_cast<const void *>(get_offset());
+}
+
+void Batch::set_restart_index(unsigned index)
+{
+ if(index>0)
+ {
+ if(!restart_index)
+ glEnable(GL_PRIMITIVE_RESTART);
+ glPrimitiveRestartIndex(index);
+ }
+ else
+ glDisable(GL_PRIMITIVE_RESTART);
+
+ restart_index = index;