void Batch::append(const vector<unsigned> &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<unsigned>::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<unsigned short *>(&data[base]);
+ for(unsigned i=0; i<ind.size(); ++i)
+ ptr[i] = ind[i];
+ }
+ else if(data_type==UNSIGNED_INT)
+ {
+ unsigned *ptr = reinterpret_cast<unsigned *>(&data[base]);
+ for(unsigned i=0; i<ind.size(); ++i)
+ ptr[i] = ind[i];
+ }
+ else
+ {
+ for(unsigned i=0; i<ind.size(); ++i)
+ data[base+i] = ind[i];
+ }
}
void Batch::append(const Batch &other)
unsigned size() const { return data.size()/get_index_size(); }
unsigned get_index(unsigned) const;
void draw() const;
+
private:
unsigned get_index_size() const;
template<typename T, typename U>
U convert(T) const;
-private:
+
void unlink_from_ibuf();
void update_ibuf_offsets();
};
Distributed under the LGPL
*/
+#include "batch.h"
#include "immediate.h"
namespace Msp {
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)