]> git.tdb.fi Git - libs/gl.git/blob - source/mesh.h
Move vertex buffer management from VertexArray to Mesh
[libs/gl.git] / source / mesh.h
1 #ifndef MSP_GL_MESH_H_
2 #define MSP_GL_MESH_H_
3
4 #include <msp/datafile/objectloader.h>
5 #include "batch.h"
6 #include "vertexarray.h"
7 #include "windingtest.h"
8
9 namespace Msp {
10 namespace GL {
11
12 class Buffer;
13 class Renderer;
14
15 /**
16 Raw mesh data, consisting of a VertexArray and one or more Batches.  Though a
17 Mesh can draw itself, it's usually used as part of Renderables rather than on
18 its own.
19 */
20 class Mesh
21 {
22         friend class MeshBuilder;
23
24 public:
25         class Loader: public DataFile::ObjectLoader<Mesh>
26         {
27         public:
28                 Loader(Mesh &);
29         private:
30                 void vertices(const std::vector<VertexComponent> &);
31                 void batch(PrimitiveType);
32                 void winding(FaceWinding);
33         };
34
35 private:
36         VertexArray vertices;
37         std::list<Batch> batches;
38         Buffer *vbuf;
39         Buffer *ibuf;
40         bool defer_buffers;
41         const WindingTest *winding;
42
43 public:
44         Mesh();
45         Mesh(const VertexFormat &f);
46         ~Mesh();
47
48         void clear();
49         void use_buffers(bool);
50 private:
51         void create_buffers();
52
53 public:
54         const VertexArray &get_vertices() const { return vertices; }
55         unsigned get_n_vertices() const;
56         float *modify_vertex(unsigned);
57
58         void add_batch(const Batch &b);
59         const std::list<Batch> &get_batches() { return batches; }
60
61         void set_winding(const WindingTest *);
62
63         void draw() const;
64         void draw(Renderer &) const;
65 };
66
67 } // namespace GL
68 } // namespace Msp
69
70 #endif