From d7e7f87d173156aa12694ce54d688c40a2eabe2e Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 3 Nov 2012 15:53:40 +0200 Subject: [PATCH] Let Batch decide whether appending is possible --- source/batch.cpp | 10 ++++++++++ source/batch.h | 1 + source/mesh.cpp | 12 +----------- 3 files changed, 12 insertions(+), 11 deletions(-) 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 { -- 2.43.0