18 Mesh::Mesh(const VertexFormat &f):
38 void Mesh::use_buffers(bool b)
40 defer_buffers = false;
45 vertices.use_vertex_buffer(0);
53 void Mesh::create_buffers()
55 defer_buffers = false;
58 vbuf = new Buffer(ARRAY_BUFFER);
59 vertices.use_vertex_buffer(vbuf);
62 ibuf = new Buffer(ELEMENT_ARRAY_BUFFER);
65 unsigned Mesh::get_n_vertices() const
67 return vertices.size();
70 float *Mesh::modify_vertex(unsigned i)
72 return vertices.modify(i);
75 void Mesh::add_batch(const Batch &b)
80 if(!batches.empty() && batches.back().can_append(b.get_type()))
81 batches.back().append(b);
84 Batch *prev = (batches.empty() ? 0 : &batches.back());
87 batches.back().use_buffer(ibuf, prev);
91 void Mesh::set_winding(const WindingTest *w)
96 void Mesh::draw() const
101 ibuf->bind_to(ELEMENT_ARRAY_BUFFER);
102 Bind bind_winding(winding);
104 for(list<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
108 Buffer::unbind_from(ELEMENT_ARRAY_BUFFER);
111 void Mesh::draw(Renderer &renderer) const
114 renderer.set_element_buffer(ibuf);
115 renderer.set_winding_test(winding);
117 for(list<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
122 Mesh::Loader::Loader(Mesh &m):
123 DataFile::ObjectLoader<Mesh>(m)
125 add("batch", &Loader::batch);
126 add("vertices", &Loader::vertices);
127 add("winding", &Loader::winding);
130 void Mesh::Loader::vertices(const vector<VertexComponent> &c)
133 throw invalid_argument("No vertex components");
136 for(vector<VertexComponent>::const_iterator i=c.begin(); i!=c.end(); ++i)
138 obj.vertices.reset(fmt);
139 load_sub(obj.vertices);
142 void Mesh::Loader::batch(PrimitiveType p)
149 void Mesh::Loader::winding(FaceWinding w)
152 obj.winding = &WindingTest::clockwise();
153 else if(w==COUNTERCLOCKWISE)
154 obj.winding = &WindingTest::counterclockwise();