]> git.tdb.fi Git - libs/gl.git/blob - source/mesh.h
Add vertex array object support 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: public Bindable<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         unsigned vao_id;
41         bool defer_buffers;
42         mutable unsigned char dirty;
43         const WindingTest *winding;
44
45 public:
46         Mesh();
47         Mesh(const VertexFormat &f);
48         ~Mesh();
49
50         void clear();
51         void use_buffers(bool);
52 private:
53         void create_buffers();
54         void refresh() const;
55
56 public:
57         const VertexArray &get_vertices() const { return vertices; }
58         unsigned get_n_vertices() const;
59         float *modify_vertex(unsigned);
60
61         void add_batch(const Batch &b);
62         const std::list<Batch> &get_batches() { return batches; }
63
64         void set_winding(const WindingTest *);
65
66         void draw() const;
67         void draw(Renderer &) const;
68
69         void bind() const;
70
71         static void unbind();
72 };
73
74 } // namespace GL
75 } // namespace Msp
76
77 #endif