]> git.tdb.fi Git - libs/gl.git/blob - source/mesh.h
Add a rendering supervisor class
[libs/gl.git] / source / mesh.h
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007-2011  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/objectloader.h>
12 #include "batch.h"
13 #include "vertexarray.h"
14
15 namespace Msp {
16 namespace GL {
17
18 class Buffer;
19 class Renderer;
20
21 class Mesh
22 {
23         friend class MeshBuilder;
24
25 public:
26         class Loader: public DataFile::ObjectLoader<Mesh>
27         {
28         public:
29                 Loader(Mesh &);
30         private:
31                 void vertices(VertexFormat);
32                 void batch(PrimitiveType);
33         };
34
35 private:
36         VertexArray vertices;
37         std::list<Batch> batches;
38         Buffer *ibuf;
39         bool defer_ibuf;
40
41 public:
42         Mesh();
43         Mesh(const VertexFormat &f);
44         ~Mesh();
45
46         void clear();
47         void use_buffers(bool);
48
49         const VertexArray &get_vertices() const { return vertices; }
50         unsigned get_n_vertices() const;
51         float *modify_vertex(unsigned);
52
53         void add_batch(const Batch &b);
54         const std::list<Batch> &get_batches() { return batches; }
55
56         void draw() const;
57         void draw(Renderer &) const;
58 };
59
60 } // namespace GL
61 } // namespace Msp
62
63 #endif