]> git.tdb.fi Git - libs/gl.git/blob - source/vertexarray.h
Rework vertex array application
[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 "bindable.h"
9 #include "datatype.h"
10 #include "primitivetype.h"
11 #include "vertexarraybuilder.h"
12 #include "vertexformat.h"
13
14 namespace Msp {
15 namespace GL {
16
17 class Buffer;
18
19 class VertexArray: public Bindable<VertexArray>
20 {
21 public:
22         class Loader: public DataFile::Loader, public VertexArrayBuilder
23         {
24         public:
25                 Loader(VertexArray &);
26         };
27
28 private:
29         VertexFormat format;
30         std::vector<float> data;
31         unsigned stride;
32         std::vector<unsigned char> arrays;
33         RefPtr<Buffer> vbuf;
34         bool defer_vbuf;
35         mutable bool dirty;
36
37         VertexArray(const VertexArray &);
38         VertexArray &operator=(const VertexArray &);
39 public:
40         VertexArray(const VertexFormat &);
41         ~VertexArray();
42
43         void reset(const VertexFormat &);
44         const VertexFormat &get_format() const { return format; }
45 private:
46         static unsigned get_array_slot(unsigned char);
47
48 public:
49         void use_vertex_buffer();
50         void use_vertex_buffer(Buffer *);
51
52         void clear();
53         void reserve(unsigned);
54         float *append();
55         float *modify(unsigned);
56 private:
57         void set_dirty();
58
59 public:
60         unsigned size() const { return data.size()/stride; }
61         const std::vector<float> &get_data() const { return data; }
62         const float *operator[](unsigned i) const { return &data[0]+i*stride; }
63
64         void apply() const;
65 };
66
67 } // namespace GL
68 } // namespace Msp
69
70 #endif