]> git.tdb.fi Git - libs/gl.git/blob - source/mesh.h
Generalize VertexBuffer into Buffer with support for other types as well
[libs/gl.git] / source / mesh.h
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 #ifndef MSP_GL_MESH_H_
9 #define MSP_GL_MESH_H_
10
11 #include <msp/datafile/loader.h>
12 #include "batch.h"
13 #include "vertexarray.h"
14
15 namespace Msp {
16 namespace GL {
17
18 class Buffer;
19
20 class Mesh
21 {
22         friend class MeshBuilder;
23
24 public:
25         class Loader: public DataFile::Loader
26         {
27         public:
28                 Loader(Mesh &);
29         private:
30                 Mesh &mesh;
31
32                 void vertices(VertexFormat);
33                 void batch(PrimitiveType);
34         };
35
36 private:
37         VertexArray vertices;
38         std::list<Batch> batches;
39         Buffer *ibuf;
40
41 public:
42         Mesh();
43         Mesh(const VertexFormat &f);
44
45         void use_vertex_buffer(bool);
46         const VertexArray &get_vertices() const { return vertices; }
47         float *get_vertex(unsigned);
48         void add_batch(const Batch &b);
49         const std::list<Batch> &get_batches() { return batches; }
50         void clear();
51         void draw() const;
52 private:
53         void update_index_buffer();
54 };
55
56 } // namespace GL
57 } // namespace Msp
58
59 #endif