X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fbatch.cpp;h=ebd7b049125137d2fb89f9d40255d44a139f5b8c;hb=6955c16bb123f3b795186c99442dc4d92be0ebc9;hp=f14cc307ff71b92deb212e9f759ac70f1c8d69f0;hpb=7aaec9a70b8d7733429bec043f8e33e02956f266;p=libs%2Fgl.git diff --git a/source/core/batch.cpp b/source/core/batch.cpp index f14cc307..ebd7b049 100644 --- a/source/core/batch.cpp +++ b/source/core/batch.cpp @@ -1,7 +1,6 @@ #include #include #include "batch.h" -#include "bindable.h" #include "buffer.h" #include "error.h" #include "mesh.h" @@ -55,6 +54,7 @@ unsigned Batch::restart_index = 0; Batch::Batch(PrimitiveType t): prim_type(t), index_type(UNSIGNED_SHORT), + gl_index_type(get_gl_type(index_type)), max_index(0), restart(false) { } @@ -65,6 +65,8 @@ Batch::~Batch() void Batch::set_index_type(DataType t) { + if(t==index_type) + return; if(t!=UNSIGNED_SHORT && t!=UNSIGNED_INT) throw invalid_argument("Batch::set_data_type"); if(t==UNSIGNED_SHORT && max_index>0xFFFE) @@ -76,6 +78,7 @@ void Batch::set_index_type(DataType t) shrink(data); index_type = t; + gl_index_type = get_gl_type(t); update_offset(); dirty = true; } @@ -186,20 +189,16 @@ 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(); - - glDrawElements(prim_type, size(), index_type, data_ptr); + glDrawElements(prim_type, size(), gl_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); + glDrawElementsInstanced(prim_type, size(), gl_index_type, data_ptr, count); } const void *Batch::setup_draw() const