]> git.tdb.fi Git - libs/gl.git/blob - source/vertexarray.h
Remove alignment where it doesn't belong
[libs/gl.git] / source / vertexarray.h
1 #ifndef MSP_GL_VERTEXARRAY_H_
2 #define MSP_GL_VERTEXARRAY_H_
3
4 #include <climits>
5 #include <vector>
6 #include <msp/core/refptr.h>
7 #include <msp/datafile/loader.h>
8 #include "datatype.h"
9 #include "primitivetype.h"
10 #include "vertexarraybuilder.h"
11 #include "vertexformat.h"
12
13 namespace Msp {
14 namespace GL {
15
16 class Buffer;
17
18 class VertexArray
19 {
20 public:
21         class Loader: public DataFile::Loader, public VertexArrayBuilder
22         {
23         public:
24                 Loader(VertexArray &);
25         };
26
27 private:
28         struct ArrayMask
29         {
30                 enum
31                 {
32                         B = (sizeof(unsigned)*CHAR_BIT),
33                         N = (63+B)/B
34                 };
35
36                 unsigned mask[N];
37
38                 ArrayMask();
39
40                 void set(unsigned);
41                 bool is_set(unsigned) const;
42         };
43
44         VertexFormat format;
45         std::vector<float> data;
46         unsigned stride;
47         RefPtr<Buffer> vbuf;
48         bool defer_vbuf;
49         mutable bool dirty;
50
51         static ArrayMask enabled_arrays;
52
53         VertexArray(const VertexArray &);
54         VertexArray &operator=(const VertexArray &);
55 public:
56         VertexArray(const VertexFormat &);
57         ~VertexArray();
58
59         const VertexFormat &get_format() const { return format; }
60         const std::vector<float> &get_data() const { return data; }
61         void use_vertex_buffer();
62         void use_vertex_buffer(Buffer *);
63         void reserve(unsigned);
64         unsigned size() const { return data.size()/stride; }
65         void clear();
66         void reset(const VertexFormat &);
67         void apply() const;
68         float *append();
69         float *modify(unsigned);
70         const float *operator[](unsigned i) const { return &data[0]+i*stride; }
71
72 private:
73         void set_dirty();
74 };
75
76 void array_element(int);
77 void draw_arrays(PrimitiveType, int, unsigned);
78 void draw_elements(PrimitiveType, unsigned, DataType, const void *);
79 void draw_range_elements(PrimitiveType, unsigned, unsigned, unsigned, DataType, const void *);
80
81 inline void draw_elements(PrimitiveType mode, unsigned count, const unsigned *indices)
82 { draw_elements(mode, count, UNSIGNED_INT, indices); }
83
84 inline void draw_elements(PrimitiveType mode, unsigned count, const unsigned short *indices)
85 { draw_elements(mode, count, UNSIGNED_SHORT, indices); }
86
87 inline void draw_range_elements(PrimitiveType mode, unsigned low, unsigned high, unsigned count, const unsigned short *indices)
88 { draw_range_elements(mode, low, high, count, UNSIGNED_SHORT, indices); }
89
90 inline void draw_range_elements(PrimitiveType mode, unsigned low, unsigned high, unsigned count, const unsigned *indices)
91 { draw_range_elements(mode, low, high, count, UNSIGNED_INT, indices); }
92
93 } // namespace GL
94 } // namespace Msp
95
96 #endif