3 This file is part of libmspgl
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
21 Mesh::Mesh(const VertexFormat &f):
26 void Mesh::use_vertex_buffer(bool b)
30 vertices.use_vertex_buffer();
32 ibuf = new Buffer(ELEMENT_ARRAY_BUFFER);
33 update_index_buffer();
37 vertices.use_vertex_buffer(0);
43 float *Mesh::get_vertex(unsigned i)
48 void Mesh::add_batch(const Batch &b)
51 update_index_buffer();
60 void Mesh::draw() const
67 for(list<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
69 i->draw_with_buffer(offset);
76 for(list<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
81 void Mesh::update_index_buffer()
87 for(list<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
90 ibuf->data(total*sizeof(unsigned), 0);
92 for(list<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
94 ibuf->sub_data(offset*sizeof(unsigned), i->size()*sizeof(unsigned), &i->get_indices()[0]);
101 Mesh::Loader::Loader(Mesh &m):
102 DataFile::ObjectLoader<Mesh>(m)
104 add("vertices", &Loader::vertices);
105 add("batch", &Loader::batch);
108 void Mesh::Loader::vertices(VertexFormat f)
110 obj.vertices.reset(f);
111 load_sub(obj.vertices);
114 void Mesh::Loader::batch(PrimitiveType p)
116 obj.batches.push_back(Batch(p));
117 load_sub(obj.batches.back());