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"
21 Stores vertex data. Both legacy and generic attributes are supported. Mixing
22 the two is possible but discouraged, as driver-specific issues may arise.
24 The array's contents can be modified with the append and modify methods. To
25 obtain the location of an individual component within the vertex, use
28 A higher-level interface for filling in vertex data is available in the
29 VertexArrayBuilder class.
31 class VertexArray: public Bindable<VertexArray>, public Bufferable
34 class Loader: public DataFile::Loader, public VertexArrayBuilder
37 Loader(VertexArray &);
43 unsigned char component;
50 std::vector<float> data;
52 std::vector<Array> arrays;
55 static bool legacy_used;
57 VertexArray(const VertexArray &);
58 VertexArray &operator=(const VertexArray &);
60 VertexArray(const VertexFormat &);
63 /// Resets the VertexArray to a different format. All data is cleared.
64 void reset(const VertexFormat &);
66 const VertexFormat &get_format() const { return format; }
68 static unsigned get_array_slot(unsigned char);
71 /// Clears all vertices from the array.
74 /// Reserve space for vertices.
75 void reserve(unsigned);
77 /// Append a new vertex at the end of the array and return its location.
80 /// Returns the location of a vertex for modification.
81 float *modify(unsigned);
83 virtual unsigned get_data_size() const;
84 virtual const void *get_data_pointer() const { return &data[0]; }
87 unsigned size() const { return data.size()/stride; }
88 const std::vector<float> &get_data() const { return data; }
89 const float *operator[](unsigned i) const { return &data[0]+i*stride; }
91 /** Equivalent to apply(true). For compatibility with the Bindable
93 void bind() const { apply(); }
95 /** Applies component arrays to the GL. If legacy is true, they are applied
96 as is. If legacy is false, any legacy attributes are converted to generic
98 void apply(bool legacy = true) const;
101 static void apply_arrays(const std::vector<Array> *, const std::vector<Array> *, const float *, unsigned, bool);
103 static void unbind();