From a2a00bdc96a7d2aa4c95c5a125c0c438147d7495 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 25 Jan 2021 03:13:29 +0200 Subject: [PATCH] Rename batch's data_type to index_type --- source/batch.cpp | 28 ++++++++++++++-------------- source/batch.h | 9 ++++++--- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/source/batch.cpp b/source/batch.cpp index 1f787d29..64187eed 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,14 @@ 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(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); diff --git a/source/batch.h b/source/batch.h index d42a8629..6fb013af 100644 --- a/source/batch.h +++ b/source/batch.h @@ -33,7 +33,7 @@ public: private: PrimitiveType prim_type; - DataType data_type; + DataType index_type; std::vector data; unsigned min_index; unsigned max_index; @@ -46,8 +46,11 @@ public: ~Batch(); PrimitiveType get_type() const { return prim_type; } - void set_data_type(DataType); - DataType get_data_type() const { return data_type; } + void set_index_type(DataType); + DataType get_index_type() const { return index_type; } + + DEPRECATED void set_data_type(DataType t) { set_index_type(t); } + DEPRECATED DataType get_data_type() const { return index_type; } Batch &append(unsigned); Batch &append(const std::vector &); -- 2.45.2