]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/batch.cpp
Disconnect the PrimitiveType enum from OpenGL constants
[libs/gl.git] / source / core / batch.cpp
index 51746b37178a6345ca3e3ff1982a6bcdf7333e88..2be5cc3a69ffacd2472f2575da0b480db37b3989 100644 (file)
@@ -1,4 +1,3 @@
-#include <msp/gl/extensions/arb_draw_instanced.h>
 #include <msp/gl/extensions/msp_primitive_restart.h>
 #include "batch.h"
 #include "buffer.h"
@@ -53,6 +52,7 @@ unsigned Batch::restart_index = 0;
 
 Batch::Batch(PrimitiveType t):
        prim_type(t),
+       gl_prim_type(GL::get_gl_primitive_type(prim_type)),
        index_type(UNSIGNED_SHORT),
        gl_index_type(get_gl_type(index_type)),
        max_index(0),
@@ -65,6 +65,8 @@ Batch::~Batch()
 
 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)
@@ -185,54 +187,6 @@ unsigned Batch::get_index(unsigned i) const
                return *(UInt16 *)&data[i*sizeof(UInt16)];
 }
 
-void Batch::draw() const
-{
-       const void *data_ptr = setup_draw();
-       glDrawElements(prim_type, size(), gl_index_type, data_ptr);
-}
-
-void Batch::draw_instanced(unsigned count) const
-{
-       static Require req(ARB_draw_instanced);
-
-       const void *data_ptr = setup_draw();
-       glDrawElementsInstanced(prim_type, size(), gl_index_type, data_ptr, count);
-}
-
-const void *Batch::setup_draw() const
-{
-       if(!get_buffer())
-               throw invalid_operation("Batch::setup_draw");
-
-       if(restart)
-       {
-               unsigned index = (index_type==UNSIGNED_INT ? 0xFFFFFFFF : 0xFFFF);
-
-               if(index!=restart_index)
-                       set_restart_index(index);
-       }
-       else if(restart_index && restart_index<=max_index)
-               set_restart_index(0);
-
-       refresh();
-
-       return reinterpret_cast<const void *>(get_offset());
-}
-
-void Batch::set_restart_index(unsigned index)
-{
-       if(index>0)
-       {
-               if(!restart_index)
-                       glEnable(GL_PRIMITIVE_RESTART);
-               glPrimitiveRestartIndex(index);
-       }
-       else
-               glDisable(GL_PRIMITIVE_RESTART);
-
-       restart_index = index;
-}
-
 
 Batch::Loader::Loader(Batch &b):
        DataFile::ObjectLoader<Batch>(b)