X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fbatch.cpp;h=af1d243e6cba1551e6be65255a55e69a4e7029cf;hp=89b8f48f4d44920d4b63a3829a44f81f9c2f44e8;hb=b0059bd068c99dadfc922584911fcb25a21b737b;hpb=3ba81ebaaec0c271d68cc12afbea86c394c3403d diff --git a/source/batch.cpp b/source/batch.cpp index 89b8f48f..af1d243e 100644 --- a/source/batch.cpp +++ b/source/batch.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -225,6 +226,27 @@ unsigned Batch::get_index(unsigned i) const } 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); +} + +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(), data_type, data_ptr, count); +} + +const void *Batch::setup_draw() const { if(restart) { @@ -242,23 +264,15 @@ void Batch::draw() const else if(restart_index && restart_index<=max_index) set_restart_index(0); - 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(get_offset()); + return reinterpret_cast(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)