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<float> data;
43 VertexArray(const VertexArray &);
44 VertexArray &operator=(const VertexArray &);
46 VertexArray(const VertexFormat &);
48 /// Resets the VertexArray to a different format. All data is cleared.
49 void reset(const VertexFormat &);
51 const VertexFormat &get_format() const { return format; }
53 /// Clears all vertices from the array.
56 /// Reserve space for vertices.
57 void reserve(unsigned);
59 /// Append a new vertex at the end of the array and return its location.
62 /// Returns the location of a vertex for modification.
63 float *modify(unsigned);
65 virtual unsigned get_data_size() const;
66 virtual const void *get_data_pointer() const { return &data[0]; }
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; }