X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fbatch.cpp;h=f14cc307ff71b92deb212e9f759ac70f1c8d69f0;hp=f2614c416e1413c065bcfe972402eb9cf2f554ef;hb=bec07999d95b76f4b47cffcc564d0cd0afc0435e;hpb=c897f76c44c2baaa90c0f85e0bcbee152a99272a diff --git a/source/batch.cpp b/source/batch.cpp index f2614c41..f14cc307 100644 --- a/source/batch.cpp +++ b/source/batch.cpp @@ -54,7 +54,7 @@ unsigned Batch::restart_index = 0; Batch::Batch(PrimitiveType t): prim_type(t), - data_type(UNSIGNED_SHORT), + index_type(UNSIGNED_SHORT), max_index(0), restart(false) { } @@ -63,19 +63,19 @@ Batch::~Batch() { } -void Batch::set_data_type(DataType t) +void Batch::set_index_type(DataType t) { if(t!=UNSIGNED_SHORT && t!=UNSIGNED_INT) throw invalid_argument("Batch::set_data_type"); if(t==UNSIGNED_SHORT && max_index>0xFFFE) throw invalid_operation("Batch::set_data_type"); - if(data_type==UNSIGNED_SHORT && t==UNSIGNED_INT) + if(index_type==UNSIGNED_SHORT && t==UNSIGNED_INT) expand(data); - else if(data_type==UNSIGNED_INT && t==UNSIGNED_SHORT) + else if(index_type==UNSIGNED_INT && t==UNSIGNED_SHORT) shrink(data); - data_type = t; + index_type = t; update_offset(); dirty = true; } @@ -132,7 +132,7 @@ Batch &Batch::append(const Batch &other) else if(MSP_primitive_restart) { restart = true; - if(data_type==UNSIGNED_INT) + if(index_type==UNSIGNED_INT) ::append(data, 0xFFFFFFFF); else ::append(data, 0xFFFF); @@ -162,10 +162,10 @@ void Batch::append_index(unsigned i) else max_index = max(max_index, i); - if(data_type==UNSIGNED_SHORT && max_index>0xFFFE) - set_data_type(UNSIGNED_INT); + if(index_type==UNSIGNED_SHORT && max_index>0xFFFE) + set_index_type(UNSIGNED_INT); - if(data_type==UNSIGNED_INT) + if(index_type==UNSIGNED_INT) ::append(data, i); else ::append(data, i); @@ -173,12 +173,12 @@ void Batch::append_index(unsigned i) unsigned Batch::get_index_size() const { - return (data_type==UNSIGNED_INT ? sizeof(UInt32) : sizeof(UInt16)); + return (index_type==UNSIGNED_INT ? sizeof(UInt32) : sizeof(UInt16)); } unsigned Batch::get_index(unsigned i) const { - if(data_type==UNSIGNED_INT) + if(index_type==UNSIGNED_INT) return *(UInt32 *)&data[i*sizeof(UInt32)]; else return *(UInt16 *)&data[i*sizeof(UInt16)]; @@ -189,7 +189,7 @@ void Batch::draw() const BindRestore _bind_ibuf(get_buffer(), ELEMENT_ARRAY_BUFFER); const void *data_ptr = setup_draw(); - glDrawElements(prim_type, size(), data_type, data_ptr); + glDrawElements(prim_type, size(), index_type, data_ptr); } void Batch::draw_instanced(unsigned count) const @@ -199,14 +199,17 @@ void Batch::draw_instanced(unsigned count) const BindRestore _bind_ibuf(get_buffer(), ELEMENT_ARRAY_BUFFER); const void *data_ptr = setup_draw(); - glDrawElementsInstanced(prim_type, size(), data_type, data_ptr, count); + 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 = (data_type==UNSIGNED_INT ? 0xFFFFFFFF : 0xFFFF); + unsigned index = (index_type==UNSIGNED_INT ? 0xFFFFFFFF : 0xFFFF); if(index!=restart_index) set_restart_index(index); @@ -214,15 +217,9 @@ const void *Batch::setup_draw() const else if(restart_index && restart_index<=max_index) set_restart_index(0); - if(get_buffer()) - { - if(dirty) - update_buffer(); + refresh(); - return reinterpret_cast(get_offset()); - } - else - return &data[0]; + return reinterpret_cast(get_offset()); } void Batch::set_restart_index(unsigned index)