1 #ifndef MSP_GL_VERTEXARRAY_H_
2 #define MSP_GL_VERTEXARRAY_H_
6 #include <msp/core/refptr.h>
7 #include <msp/datafile/loader.h>
9 #include "bufferable.h"
11 #include "primitivetype.h"
12 #include "vertexarraybuilder.h"
13 #include "vertexformat.h"
23 The array's contents can be modified with the append and modify methods. To
24 obtain the location of an individual component within the vertex, use
27 A higher-level interface for filling in vertex data is available in the
28 VertexArrayBuilder class.
30 class VertexArray: public Bindable<VertexArray>, public Bufferable
33 class Loader: public DataFile::Loader, public VertexArrayBuilder
36 Loader(VertexArray &);
42 unsigned char component;
49 std::vector<float> data;
51 std::vector<Array> arrays;
53 VertexArray(const VertexArray &);
54 VertexArray &operator=(const VertexArray &);
56 VertexArray(const VertexFormat &);
59 /// Resets the VertexArray to a different format. All data is cleared.
60 void reset(const VertexFormat &);
62 const VertexFormat &get_format() const { return format; }
64 static unsigned get_array_slot(unsigned char);
67 /// Clears all vertices from the array.
70 /// Reserve space for vertices.
71 void reserve(unsigned);
73 /// Append a new vertex at the end of the array and return its location.
76 /// Returns the location of a vertex for modification.
77 float *modify(unsigned);
79 virtual unsigned get_data_size() const;
80 virtual const void *get_data_pointer() const { return &data[0]; }
83 unsigned size() const { return data.size()/stride; }
84 const std::vector<float> &get_data() const { return data; }
85 const float *operator[](unsigned i) const { return &data[0]+i*stride; }
87 /// Equivalent to apply(). For compatibility with the Bindable interface.
88 void bind() const { apply(); }
90 /// Applies component arrays to the GL.
94 static void apply_arrays(const std::vector<Array> *, const std::vector<Array> *, const float *, unsigned);