]> git.tdb.fi Git - libs/gl.git/blob - source/mesh.cpp
Add Mesh and Batch classes
[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
19 void Mesh::draw() const
20 {
21         vertices.apply();
22         for(list<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
23                 i->draw();
24 }
25
26
27 Mesh::Loader::Loader(Mesh &m):
28         mesh(m)
29 {
30         add("vertices", &Loader::vertices);
31         add("batch",    &Loader::batch);
32 }
33
34 void Mesh::Loader::vertices(VertexFormat f)
35 {
36         mesh.vertices.reset(f);
37         load_sub(mesh.vertices);
38 }
39
40 void Mesh::Loader::batch(PrimitiveType p)
41 {
42         mesh.batches.push_back(Batch(p));
43         load_sub(mesh.batches.back());
44 }
45
46 } // namespace GL
47 } // namespace Msp