]> git.tdb.fi Git - libs/gl.git/blob - source/mesh.h
Add WindingTest and support for it in Mesh and Renderer
[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 #include "windingtest.h"
15
16 namespace Msp {
17 namespace GL {
18
19 class Buffer;
20 class Renderer;
21
22 class Mesh
23 {
24         friend class MeshBuilder;
25
26 public:
27         class Loader: public DataFile::ObjectLoader<Mesh>
28         {
29         public:
30                 Loader(Mesh &);
31         private:
32                 void vertices(VertexFormat);
33                 void batch(PrimitiveType);
34                 void winding(FaceWinding);
35         };
36
37 private:
38         VertexArray vertices;
39         std::list<Batch> batches;
40         Buffer *ibuf;
41         bool defer_ibuf;
42         const WindingTest *winding;
43
44 public:
45         Mesh();
46         Mesh(const VertexFormat &f);
47         ~Mesh();
48
49         void clear();
50         void use_buffers(bool);
51
52         const VertexArray &get_vertices() const { return vertices; }
53         unsigned get_n_vertices() const;
54         float *modify_vertex(unsigned);
55
56         void add_batch(const Batch &b);
57         const std::list<Batch> &get_batches() { return batches; }
58
59         void set_winding(const WindingTest *);
60
61         void draw() const;
62         void draw(Renderer &) const;
63 };
64
65 } // namespace GL
66 } // namespace Msp
67
68 #endif