1 #ifndef MSP_GL_VERTEXARRAY_H_
2 #define MSP_GL_VERTEXARRAY_H_
5 #include <msp/datafile/loader.h>
6 #include "bufferable.h"
7 #include "vertexarraybuilder.h"
8 #include "vertexformat.h"
14 Stores vertex data. Each vertex has one or more attributes defined by a
17 The array's contents can be modified with the append and modify methods. To
18 obtain the location of an individual component within the vertex, use
21 VertexArrayBuilder provides a convenient way of filling in vertex data.
23 Applications normally don't need to deal with VertexArrays directly. They're
24 managed by the Mesh and InstanceArray classes.
26 class VertexArray: public Bufferable
29 class Loader: public DataFile::Loader, public VertexArrayBuilder
32 Loader(VertexArray &);
37 std::vector<char> data;
40 VertexArray(const VertexArray &);
41 VertexArray &operator=(const VertexArray &);
43 VertexArray() = default;
45 /** Constructs a VertexArray and sets its format. */
46 VertexArray(const VertexFormat &);
48 /** Sets the format of the VertexArray. The format cannot be changed once
50 void set_format(const VertexFormat &);
52 const VertexFormat &get_format() const { return format; }
54 /** Clears all vertices from the array. Vertex format is retained. */
57 /** Reserve space for vertices. If n is smaller than the current size,
59 void reserve(std::size_t n);
61 /** Append a new vertex at the end of the array and return a pointer to it.
62 The array is marked as dirty. */
65 /** Returns a pointer to a vertex for modification. The array is marked as
67 char *modify(std::size_t);
69 virtual std::size_t get_data_size() const;
70 virtual const void *get_data_pointer() const { return &data[0]; }
73 std::size_t size() const { return data.size()/stride; }
74 const std::vector<char> &get_data() const { return data; }
75 const char *operator[](std::size_t i) const { return &data[0]+i*stride; }