]> git.tdb.fi Git - libs/gl.git/blob - source/mesh.cpp
Make Material::apply const
[libs/gl.git] / source / mesh.cpp
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "mesh.h"
9
10 using namespace std;
11
12 namespace Msp {
13 namespace GL {
14
15 Mesh::Mesh():
16         vertices(NODATA)
17 {
18         vertices.use_vertex_buffer();
19 }
20
21 Mesh::Mesh(VertexFormat f):
22         vertices(f)
23 {
24         vertices.use_vertex_buffer();
25 }
26
27 void Mesh::add_batch(const Batch &b)
28 {
29         batches.push_back(b);
30 }
31
32 void Mesh::draw() const
33 {
34         vertices.apply();
35         for(list<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
36                 i->draw();
37 }
38
39
40 Mesh::Loader::Loader(Mesh &m):
41         mesh(m)
42 {
43         add("vertices", &Loader::vertices);
44         add("batch",    &Loader::batch);
45 }
46
47 void Mesh::Loader::vertices(VertexFormat f)
48 {
49         mesh.vertices.reset(f);
50         load_sub(mesh.vertices);
51 }
52
53 void Mesh::Loader::batch(PrimitiveType p)
54 {
55         mesh.batches.push_back(Batch(p));
56         load_sub(mesh.batches.back());
57 }
58
59 } // namespace GL
60 } // namespace Msp