]> git.tdb.fi Git - libs/gl.git/blob - source/mesh.cpp
Add append() method and and operator[] to VertexArray
[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 Mesh::Mesh(VertexFormat f):
20         vertices(f)
21 { }
22
23 void Mesh::use_vertex_buffer(bool b)
24 {
25         if(b)
26                 vertices.use_vertex_buffer();
27         else
28                 vertices.use_vertex_buffer(0);
29 }
30
31 void Mesh::add_batch(const Batch &b)
32 {
33         batches.push_back(b);
34 }
35
36 void Mesh::draw() const
37 {
38         vertices.apply();
39         for(list<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
40                 i->draw();
41 }
42
43
44 Mesh::Loader::Loader(Mesh &m):
45         mesh(m)
46 {
47         add("vertices", &Loader::vertices);
48         add("batch",    &Loader::batch);
49 }
50
51 void Mesh::Loader::vertices(VertexFormat f)
52 {
53         mesh.vertices.reset(f);
54         load_sub(mesh.vertices);
55 }
56
57 void Mesh::Loader::batch(PrimitiveType p)
58 {
59         mesh.batches.push_back(Batch(p));
60         load_sub(mesh.batches.back());
61 }
62
63 } // namespace GL
64 } // namespace Msp