]> git.tdb.fi Git - libs/gl.git/commitdiff
Fallback to glDrawElements if EXT_draw_range_elements is unavailable
authorMikko Rasa <tdb@tdb.fi>
Fri, 17 Oct 2014 11:18:27 +0000 (14:18 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 17 Oct 2014 11:18:27 +0000 (14:18 +0300)
source/batch.cpp

index e097fd6365d52b65db4a8d37110ef0f3010a7ccf..3cb0a6ce8dacd443210e47f57b45291611235420 100644 (file)
@@ -59,9 +59,6 @@ Batch::Batch(PrimitiveType t):
        max_index(0),
        restart(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()
@@ -242,16 +239,22 @@ void Batch::draw() const
        }
 
        Buffer *ibuf = get_buffer();
+       const void *data_ptr;
        BindRestore _bind_ibuf(ibuf, ELEMENT_ARRAY_BUFFER);
        if(ibuf)
        {
                if(dirty)
                        update_buffer();
 
-               glDrawRangeElements(prim_type, min_index, max_index, size(), data_type, reinterpret_cast<void *>(get_offset()));
+               data_ptr = reinterpret_cast<const void *>(get_offset());
        }
        else
-               glDrawRangeElements(prim_type, min_index, max_index, size(), data_type, &data[0]);
+               data_ptr = &data[0];
+
+       if(EXT_draw_range_elements)
+               glDrawRangeElements(prim_type, min_index, max_index, size(), data_type, data_ptr);
+       else
+               glDrawElements(prim_type, size(), data_type, data_ptr);
 }