}
void Batch::draw() const
+{
+ BindRestore _bind_ibuf(get_buffer(), ELEMENT_ARRAY_BUFFER);
+ const void *data_ptr = setup_draw();
+
+ if(EXT_draw_range_elements)
+ glDrawRangeElements(prim_type, min_index, max_index, size(), data_type, data_ptr);
+ else
+ glDrawElements(prim_type, size(), data_type, data_ptr);
+}
+
+const void *Batch::setup_draw() const
{
if(restart)
{
else if(restart_index && restart_index<=max_index)
set_restart_index(0);
- const Buffer *ibuf = get_buffer();
- const void *data_ptr;
- BindRestore _bind_ibuf(ibuf, ELEMENT_ARRAY_BUFFER);
- if(ibuf)
+ if(get_buffer())
{
if(dirty)
update_buffer();
- data_ptr = reinterpret_cast<const void *>(get_offset());
+ return reinterpret_cast<const void *>(get_offset());
}
else
- data_ptr = &data[0];
-
- if(EXT_draw_range_elements)
- glDrawRangeElements(prim_type, min_index, max_index, size(), data_type, data_ptr);
- else
- glDrawElements(prim_type, size(), data_type, data_ptr);
+ return &data[0];
}
void Batch::set_restart_index(unsigned index)
{
apply_state();
- bool legacy_bindings = (!state->shprog || state->shprog->uses_legacy_variables());
- if(state->mesh && legacy_bindings)
- {
- if(const Buffer *ibuf = state->mesh->get_index_buffer())
- ibuf->bind_to(ELEMENT_ARRAY_BUFFER);
- else
- Buffer::unbind_from(ELEMENT_ARRAY_BUFFER);
- }
-
batch.draw();
}
{
Mesh::unbind();
state->mesh->get_vertices().apply();
+ if(const Buffer *ibuf = state->mesh->get_index_buffer())
+ ibuf->bind_to(ELEMENT_ARRAY_BUFFER);
+ else
+ Buffer::unbind_from(ELEMENT_ARRAY_BUFFER);
}
else
state->mesh->bind();