1 #ifndef MSP_GL_VERTEXARRAY_H_
2 #define MSP_GL_VERTEXARRAY_H_
5 #include <msp/datafile/loader.h>
6 #include "bufferable.h"
7 #include "vertexarraybuilder.h"
8 #include "vertexformat.h"
16 The array's contents can be modified with the append and modify methods. To
17 obtain the location of an individual component within the vertex, use
20 A higher-level interface for filling in vertex data is available in the
21 VertexArrayBuilder class.
23 class VertexArray: public Bufferable
26 class Loader: public DataFile::Loader, public VertexArrayBuilder
29 Loader(VertexArray &);
34 std::vector<char> data;
37 VertexArray(const VertexArray &);
38 VertexArray &operator=(const VertexArray &);
42 /// Construct a VertexArray and set its format.
43 VertexArray(const VertexFormat &);
45 /// Sets the format of the VertexArray.
46 void set_format(const VertexFormat &);
48 const VertexFormat &get_format() const { return format; }
50 /// Clears all vertices from the array.
53 /// Reserve space for vertices.
54 void reserve(unsigned);
56 /// Append a new vertex at the end of the array and return its location.
59 /// Returns the location of a vertex for modification.
60 char *modify(unsigned);
62 virtual unsigned get_data_size() const;
63 virtual const void *get_data_pointer() const { return &data[0]; }
66 unsigned size() const { return data.size()/stride; }
67 const std::vector<char> &get_data() const { return data; }
68 const char *operator[](unsigned i) const { return &data[0]+i*stride; }