#include <msp/gl/extensions/arb_draw_instanced.h>
#include <msp/gl/extensions/msp_primitive_restart.h>
#include "batch.h"
-#include "bindable.h"
#include "buffer.h"
#include "error.h"
#include "mesh.h"
Batch::Batch(PrimitiveType t):
prim_type(t),
index_type(UNSIGNED_SHORT),
+ gl_index_type(get_gl_type(index_type)),
max_index(0),
restart(false)
{ }
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)
shrink<UInt32, UInt16>(data);
index_type = t;
+ gl_index_type = get_gl_type(t);
update_offset();
dirty = true;
}
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