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 /// Deprecated alias for use_buffer
72 void use_vertex_buffer(Buffer *b) { use_buffer(b); }
74 /// Clears all vertices from the array.
77 /// Reserve space for vertices.
78 void reserve(unsigned);
80 /// Append a new vertex at the end of the array and return its location.
83 /// Returns the location of a vertex for modification.
84 float *modify(unsigned);
86 virtual unsigned get_data_size() const;
87 virtual const void *get_data_pointer() const { return &data[0]; }
90 unsigned size() const { return data.size()/stride; }
91 const std::vector<float> &get_data() const { return data; }
92 const float *operator[](unsigned i) const { return &data[0]+i*stride; }
94 /** Equivalent to apply(true). For compatibility with the Bindable
96 void bind() const { apply(); }
98 /** Applies component arrays to the GL. If legacy is true, they are applied
99 as is. If legacy is false, any legacy attributes are converted to generic
101 void apply(bool legacy = true) const;
104 static void apply_arrays(const std::vector<Array> *, const std::vector<Array> *, const float *, unsigned, bool);
106 static void unbind();