]> git.tdb.fi Git - libs/gl.git/blob - source/mesh.h
Present Mesh's index buffer as current while the Mesh is bound
[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         const Buffer *get_index_buffer() const { return ibuf; }
59         unsigned get_n_vertices() const;
60         float *modify_vertex(unsigned);
61
62         void add_batch(const Batch &b);
63         const std::list<Batch> &get_batches() { return batches; }
64
65         void set_winding(const WindingTest *);
66
67         void draw() const;
68         void draw(Renderer &) const;
69
70         void bind() const;
71
72         static void unbind();
73 };
74
75 } // namespace GL
76 } // namespace Msp
77
78 #endif