From: Mikko Rasa Date: Sat, 3 Nov 2012 13:53:40 +0000 (+0200) Subject: Let Batch decide whether appending is possible X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=d7e7f87d173156aa12694ce54d688c40a2eabe2e;p=libs%2Fgl.git Let Batch decide whether appending is possible --- diff --git a/source/batch.cpp b/source/batch.cpp index 3f7bffee..8807b2c5 100644 --- a/source/batch.cpp +++ b/source/batch.cpp @@ -117,6 +117,16 @@ void Batch::append(const vector &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) diff --git a/source/batch.h b/source/batch.h index 92a10e6b..907a0b7f 100644 --- a/source/batch.h +++ b/source/batch.h @@ -51,6 +51,7 @@ public: Batch &append(unsigned); void append(const std::vector &); + bool can_append(PrimitiveType); void append(const Batch &); private: void append_index(unsigned); diff --git a/source/mesh.cpp b/source/mesh.cpp index 508054a5..572ac619 100644 --- a/source/mesh.cpp +++ b/source/mesh.cpp @@ -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 {