]> git.tdb.fi Git - libs/gl.git/commitdiff
Let Batch decide whether appending is possible
authorMikko Rasa <tdb@tdb.fi>
Sat, 3 Nov 2012 13:53:40 +0000 (15:53 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 3 Nov 2012 13:53:40 +0000 (15:53 +0200)
source/batch.cpp
source/batch.h
source/mesh.cpp

index 3f7bffee901da3bfab572e197a44da13ff912741..8807b2c539c983e61de11628627d5b6392986b7c 100644 (file)
@@ -117,6 +117,16 @@ void Batch::append(const vector<unsigned> &ind)
        dirty = true;
 }
 
+bool Batch::can_append(PrimitiveType other_type)
+{
+       if(other_type!=prim_type)
+               return false;
+       else if(prim_type==LINE_STRIP || prim_type==LINE_LOOP || prim_type==TRIANGLE_FAN || prim_type==POLYGON)
+               return NV_primitive_restart;
+       else
+               return true;
+}
+
 void Batch::append(const Batch &other)
 {
        if(other.prim_type!=prim_type)
index 92a10e6b4923a4d82678794e3ce7653766b9ca7f..907a0b7f29c08c92540d53fef4afc27d8183836c 100644 (file)
@@ -51,6 +51,7 @@ public:
 
        Batch &append(unsigned);
        void append(const std::vector<unsigned> &);
+       bool can_append(PrimitiveType);
        void append(const Batch &);
 private:
        void append_index(unsigned);
index 508054a521346ac45e394848fb0c7ec11f0fe799..572ac6195502afc97259a45857d94998c666fa4d 100644 (file)
@@ -1,6 +1,5 @@
 #include "buffer.h"
 #include "mesh.h"
-#include "nv_primitive_restart.h"
 #include "renderer.h"
 
 using namespace std;
@@ -63,22 +62,13 @@ float *Mesh::modify_vertex(unsigned i)
 
 void Mesh::add_batch(const Batch &b)
 {
-       bool can_append = false;
-       if(!batches.empty())
-       {
-               PrimitiveType type = b.get_type();
-               can_append = (type==batches.back().get_type() &&
-                       type!=LINE_STRIP && type!=LINE_LOOP && type!=POLYGON &&
-                       (type!=TRIANGLE_FAN || NV_primitive_restart));
-       }
-
        if(defer_ibuf)
        {
                ibuf = new Buffer(ELEMENT_ARRAY_BUFFER);
                defer_ibuf = false;
        }
 
-       if(can_append)
+       if(!batches.empty() && batches.back().can_append(b.get_type()))
                batches.back().append(b);
        else
        {