Batch::Batch(PrimitiveType t):
prim_type(t),
- data_type(UNSIGNED_SHORT),
+ index_type(UNSIGNED_SHORT),
max_index(0),
restart(false)
{ }
{
}
-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<UInt16, UInt32>(data);
- else if(data_type==UNSIGNED_INT && t==UNSIGNED_SHORT)
+ else if(index_type==UNSIGNED_INT && t==UNSIGNED_SHORT)
shrink<UInt32, UInt16>(data);
- data_type = t;
+ index_type = t;
update_offset();
dirty = true;
}
else if(MSP_primitive_restart)
{
restart = true;
- if(data_type==UNSIGNED_INT)
+ if(index_type==UNSIGNED_INT)
::append<UInt32>(data, 0xFFFFFFFF);
else
::append<UInt16>(data, 0xFFFF);
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<UInt32>(data, i);
else
::append<UInt16>(data, 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)];
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
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);