1 #ifndef MSP_GL_VERTEXARRAY_H_
2 #define MSP_GL_VERTEXARRAY_H_
6 #include <msp/core/refptr.h>
7 #include <msp/datafile/loader.h>
8 #include "bufferable.h"
10 #include "primitivetype.h"
11 #include "vertexarraybuilder.h"
12 #include "vertexformat.h"
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
26 A higher-level interface for filling in vertex data is available in the
27 VertexArrayBuilder class.
29 class VertexArray: public Bufferable
32 class Loader: public DataFile::Loader, public VertexArrayBuilder
35 Loader(VertexArray &);
40 std::vector<char> data;
43 VertexArray(const VertexArray &);
44 VertexArray &operator=(const VertexArray &);
48 /// Construct a VertexArray and set its format.
49 VertexArray(const VertexFormat &);
51 /// Sets the format of the VertexArray.
52 void set_format(const VertexFormat &);
54 const VertexFormat &get_format() const { return format; }
56 /// Clears all vertices from the array.
59 /// Reserve space for vertices.
60 void reserve(unsigned);
62 /// Append a new vertex at the end of the array and return its location.
65 /// Returns the location of a vertex for modification.
66 char *modify(unsigned);
68 virtual unsigned get_data_size() const;
69 virtual const void *get_data_pointer() const { return &data[0]; }
72 unsigned size() const { return data.size()/stride; }
73 const std::vector<char> &get_data() const { return data; }
74 const char *operator[](unsigned i) const { return &data[0]+i*stride; }