]> git.tdb.fi Git - libs/gl.git/blob - source/core/vertexarray.h
Rearrange soucre files into subdirectories
[libs/gl.git] / source / core / 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 "bufferable.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 /**
20 Stores vertex data.
21
22 The array's contents can be modified with the append and modify methods.  To
23 obtain the location of an individual component within the vertex, use
24 VertexFormat::offset.
25
26 A higher-level interface for filling in vertex data is available in the
27 VertexArrayBuilder class.
28 */
29 class VertexArray: public Bufferable
30 {
31 public:
32         class Loader: public DataFile::Loader, public VertexArrayBuilder
33         {
34         public:
35                 Loader(VertexArray &);
36         };
37
38 private:
39         VertexFormat format;
40         std::vector<float> data;
41         unsigned stride;
42
43         VertexArray(const VertexArray &);
44         VertexArray &operator=(const VertexArray &);
45 public:
46         VertexArray(const VertexFormat &);
47
48         /// Resets the VertexArray to a different format.  All data is cleared.
49         void reset(const VertexFormat &);
50
51         const VertexFormat &get_format() const { return format; }
52
53         /// Clears all vertices from the array.
54         void clear();
55
56         /// Reserve space for vertices.
57         void reserve(unsigned);
58
59         /// Append a new vertex at the end of the array and return its location.
60         float *append();
61
62         /// Returns the location of a vertex for modification.
63         float *modify(unsigned);
64 private:
65         virtual unsigned get_data_size() const;
66         virtual const void *get_data_pointer() const { return &data[0]; }
67
68 public:
69         unsigned size() const { return data.size()/stride; }
70         const std::vector<float> &get_data() const { return data; }
71         const float *operator[](unsigned i) const { return &data[0]+i*stride; }
72 };
73
74 } // namespace GL
75 } // namespace Msp
76
77 #endif