]> git.tdb.fi Git - libs/gl.git/blobdiff - source/batch.cpp
Complete rewrite of extension handling
[libs/gl.git] / source / batch.cpp
index 102b6487281244457950b6e0625b262e2ac3408e..afb9787b4d7f8bd7f34c0491120f668efc3c163b 100644 (file)
@@ -1,14 +1,8 @@
-/* $Id$
-
-This file is part of libmspgl
-Copyright © 2007-2010  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include "batch.h"
 #include "bindable.h"
 #include "buffer.h"
-#include "extension.h"
+#include "error.h"
+#include "ext_draw_range_elements.h"
 #include "nv_primitive_restart.h"
 #include "vertexarray.h"
 
@@ -30,7 +24,11 @@ Batch::Batch(PrimitiveType t):
        next_in_ibuf(0),
        prev_in_ibuf(0),
        dirty(false)
-{ }
+{
+       /* XXX Should probably provide a fallback to glDrawElements since this class
+       is pretty much required to render anything. */
+       static Require _req(EXT_draw_range_elements);
+}
 
 Batch::~Batch()
 {
@@ -40,11 +38,11 @@ Batch::~Batch()
 void Batch::set_data_type(DataType t)
 {
        if(t!=UNSIGNED_BYTE && t!=UNSIGNED_SHORT && t!=UNSIGNED_INT)
-               throw InvalidParameterValue("Batch data type must be an unsigned integer");
+               throw invalid_argument("Batch::set_data_type");
        if(t==UNSIGNED_BYTE && max_index>0xFE)
-               throw InvalidState("UNSIGNED_BYTE can't hold all indices in Batch");
+               throw invalid_operation("Batch::set_data_type");
        else if(t==UNSIGNED_SHORT && max_index>0xFFFE)
-               throw InvalidState("UNSIGNED_SHORT can't hold all indices in Batch");
+               throw invalid_operation("Batch::set_data_type");
 
        if(data_type==UNSIGNED_BYTE && t==UNSIGNED_SHORT)
                expand_data<unsigned char, unsigned short>();
@@ -67,7 +65,7 @@ void Batch::set_data_type(DataType t)
 void Batch::use_index_buffer(Buffer *buf, Batch *prev)
 {
        if(buf && prev && prev->ibuf!=buf)
-               throw InvalidParameterValue("Previous batch is not in the same buffer");
+               throw invalid_argument("Batch::use_index_buffer");
 
        if(!buf)
        {
@@ -160,18 +158,18 @@ void Batch::append(const vector<unsigned> &ind)
 void Batch::append(const Batch &other)
 {
        if(other.prim_type!=prim_type)
-               throw InvalidParameterValue("Can't concatenate batches with different primitive types");
+               throw invalid_argument("Batch::append");
        if(prim_type==LINE_STRIP || prim_type==LINE_LOOP)
-               throw InvalidState("Can't concatenate line strips or loops");
+               throw incompatible_data("Batch::append");
        else if(prim_type==POLYGON)
-               throw InvalidState("Can't concatenate polygons");
+               throw incompatible_data("Batch::append");
        else if(prim_type==TRIANGLE_FAN)
-               static RequireExtension _ext("GL_NV_primitive_restart");
+               static Require _req(NV_primitive_restart);
 
        if(other.data.empty())
                return;
 
-       if(is_supported("GL_NV_primitive_restart"))
+       if(NV_primitive_restart)
        {
                restart = true;
                if(data_type==UNSIGNED_SHORT)
@@ -250,7 +248,7 @@ void Batch::draw() const
                BufferAlias<ELEMENT_ARRAY_BUFFER> alias(*ibuf);
                Bind bind_ibuf(alias, true);
 
-               glDrawRangeElements(prim_type, min_index, max_index, size(), data_type, (void *)ibuf_offset);
+               glDrawRangeElements(prim_type, min_index, max_index, size(), data_type, reinterpret_cast<void *>(ibuf_offset));
        }
        else
                glDrawRangeElements(prim_type, min_index, max_index, size(), data_type, &data[0]);