3 This file is part of libmspgl
4 Copyright © 2007-2010 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
23 Mesh::Mesh(const VertexFormat &f):
40 void Mesh::use_buffers(bool b)
44 vertices.use_vertex_buffer();
46 ibuf = new Buffer(ELEMENT_ARRAY_BUFFER);
51 vertices.use_vertex_buffer(0);
58 unsigned Mesh::get_n_vertices() const
60 return vertices.size();
63 float *Mesh::modify_vertex(unsigned i)
65 return vertices.modify(i);
68 void Mesh::add_batch(const Batch &b)
70 bool can_append = false;
73 PrimitiveType type = b.get_type();
74 can_append = (type==batches.back().get_type() &&
75 type!=LINE_STRIP && type!=LINE_LOOP && type!=POLYGON &&
76 (type!=TRIANGLE_FAN || is_supported("GL_NV_primitive_restart")));
81 ibuf = new Buffer(ELEMENT_ARRAY_BUFFER);
86 batches.back().append(b);
89 Batch *prev = (batches.empty() ? 0 : &batches.back());
92 batches.back().use_index_buffer(ibuf, prev);
96 void Mesh::draw() const
101 ibuf->bind_to(ELEMENT_ARRAY_BUFFER);
103 for(list<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
107 Buffer::unbind_from(ELEMENT_ARRAY_BUFFER);
111 Mesh::Loader::Loader(Mesh &m):
112 DataFile::ObjectLoader<Mesh>(m)
114 add("vertices", &Loader::vertices);
115 add("batch", &Loader::batch);
118 void Mesh::Loader::vertices(VertexFormat f)
120 obj.vertices.reset(f);
121 load_sub(obj.vertices);
124 void Mesh::Loader::batch(PrimitiveType p)