]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/batch.cpp
Rewrite state management
[libs/gl.git] / source / core / batch.cpp
index f14cc307ff71b92deb212e9f759ac70f1c8d69f0..2bc44c9ddfe285c1dac5afa2fb2cd28ef63fba16 100644 (file)
@@ -55,6 +55,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)
 { }
@@ -76,6 +77,7 @@ void Batch::set_index_type(DataType t)
                shrink<UInt32, UInt16>(data);
 
        index_type = t;
+       gl_index_type = get_gl_type(t);
        update_offset();
        dirty = true;
 }
@@ -186,20 +188,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