3 This file is part of libmspgl
4 Copyright © 2007-2010 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #ifndef MSP_GL_VERTEXARRAY_H_
9 #define MSP_GL_VERTEXARRAY_H_
13 #include <msp/core/refptr.h>
14 #include <msp/datafile/loader.h>
16 #include "primitivetype.h"
17 #include "vertexarraybuilder.h"
18 #include "vertexformat.h"
28 class Loader: public DataFile::Loader, public VertexArrayBuilder
31 Loader(VertexArray &);
39 B = (sizeof(unsigned)*CHAR_BIT),
48 bool is_set(unsigned) const;
52 std::vector<float> data;
58 static ArrayMask enabled_arrays;
60 VertexArray(const VertexArray &);
61 VertexArray &operator=(const VertexArray &);
63 VertexArray(const VertexFormat &);
66 const VertexFormat &get_format() const { return format; }
67 const std::vector<float> &get_data() const { return data; }
68 void use_vertex_buffer();
69 void use_vertex_buffer(Buffer *);
70 void reserve(unsigned);
71 unsigned size() const { return data.size()/stride; }
73 void reset(const VertexFormat &);
76 float *modify(unsigned);
77 float *operator[](unsigned i) { return modify(i); }
78 const float *operator[](unsigned i) const { return &data[0]+i*stride; }
84 void array_element(int);
85 void draw_arrays(PrimitiveType, int, unsigned);
86 void draw_elements(PrimitiveType, unsigned, DataType, const void *);
87 void draw_range_elements(PrimitiveType, unsigned, unsigned, unsigned, DataType, const void *);
89 inline void draw_elements(PrimitiveType mode, unsigned count, const unsigned *indices)
90 { draw_elements(mode, count, UNSIGNED_INT, indices); }
92 inline void draw_elements(PrimitiveType mode, unsigned count, const unsigned short *indices)
93 { draw_elements(mode, count, UNSIGNED_SHORT, indices); }
95 inline void draw_range_elements(PrimitiveType mode, unsigned low, unsigned high, unsigned count, const unsigned short *indices)
96 { draw_range_elements(mode, low, high, count, UNSIGNED_SHORT, indices); }
98 inline void draw_range_elements(PrimitiveType mode, unsigned low, unsigned high, unsigned count, const unsigned *indices)
99 { draw_range_elements(mode, low, high, count, UNSIGNED_INT, indices); }