From: Mikko Rasa Date: Tue, 11 Jan 2011 19:55:33 +0000 (+0000) Subject: Avoid unnecessary work in Batch's vector append X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=c48cb5362edb16c33ed5f6862a908bb9a754c85a;p=libs%2Fgl.git Avoid unnecessary work in Batch's vector append Make Immediate use Batch for drawing --- diff --git a/source/batch.cpp b/source/batch.cpp index 228ff20b..102b6487 100644 --- a/source/batch.cpp +++ b/source/batch.cpp @@ -119,9 +119,42 @@ Batch &Batch::append(unsigned i) void Batch::append(const vector &ind) { - data.reserve(data.size()+ind.size()*get_index_size()); + if(ind.empty()) + return; + + if(data.empty()) + min_index = max_index = ind.front(); + for(vector::const_iterator i=ind.begin(); i!=ind.end(); ++i) - append(*i); + { + min_index = min(min_index, *i); + max_index = max(max_index, *i); + } + + if((data_type==UNSIGNED_BYTE || data_type==UNSIGNED_SHORT) && max_index>0xFFFE) + set_data_type(UNSIGNED_INT); + else if(data_type==UNSIGNED_BYTE && max_index>0xFE) + set_data_type(UNSIGNED_SHORT); + + unsigned base = data.size(); + data.resize(data.size()+ind.size()*get_index_size()); + if(data_type==UNSIGNED_SHORT) + { + unsigned short *ptr = reinterpret_cast(&data[base]); + for(unsigned i=0; i(&data[base]); + for(unsigned i=0; i U convert(T) const; -private: + void unlink_from_ibuf(); void update_ibuf_offsets(); }; diff --git a/source/immediate.cpp b/source/immediate.cpp index 3d808d32..15d3a634 100644 --- a/source/immediate.cpp +++ b/source/immediate.cpp @@ -5,6 +5,7 @@ Copyright © 2007 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ +#include "batch.h" #include "immediate.h" namespace Msp { @@ -23,15 +24,19 @@ void Immediate::reset() throw InvalidState("Can't reset Immediate between begin() and end()"); array.clear(); +} + +void Immediate::begin_() +{ indices.clear(); } void Immediate::end_() { + Batch batch(type); + batch.append(indices); array.apply(); - draw_elements(type, indices.size(), &indices[0]); - - indices.clear(); + batch.draw(); } void Immediate::element_(unsigned i) diff --git a/source/immediate.h b/source/immediate.h index 89380c41..6822aba2 100644 --- a/source/immediate.h +++ b/source/immediate.h @@ -30,7 +30,7 @@ public: Immediate(VertexFormat); void reset(); private: - virtual void begin_() { } + virtual void begin_(); virtual void end_(); virtual void element_(unsigned); };