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;
57 VertexArray(const VertexArray &);
58 VertexArray &operator=(const VertexArray &);
60 VertexArray(const VertexFormat &);
63 const VertexFormat &get_format() const { return format; }
64 const std::vector<float> &get_data() const { return data; }
65 void use_vertex_buffer();
66 void use_vertex_buffer(Buffer *);
67 void reserve(unsigned);
68 unsigned size() const { return data.size()/stride; }
70 void reset(const VertexFormat &);
74 float *operator[](unsigned i) { return &data[0]+i*stride; }
75 const float *operator[](unsigned i) const { return &data[0]+i*stride; }
78 static ArrayMask enabled_arrays;
81 void array_element(int);
82 void draw_arrays(PrimitiveType, int, unsigned);
83 void draw_elements(PrimitiveType, unsigned, DataType, const void *);
84 void draw_range_elements(PrimitiveType, unsigned, unsigned, unsigned, DataType, const void *);
86 inline void draw_elements(PrimitiveType mode, unsigned count, const unsigned *indices)
87 { draw_elements(mode, count, UNSIGNED_INT, indices); }
89 inline void draw_elements(PrimitiveType mode, unsigned count, const unsigned short *indices)
90 { draw_elements(mode, count, UNSIGNED_SHORT, indices); }
92 inline void draw_range_elements(PrimitiveType mode, unsigned low, unsigned high, unsigned count, const unsigned short *indices)
93 { draw_range_elements(mode, low, high, count, UNSIGNED_SHORT, indices); }
95 inline void draw_range_elements(PrimitiveType mode, unsigned low, unsigned high, unsigned count, const unsigned *indices)
96 { draw_range_elements(mode, low, high, count, UNSIGNED_INT, indices); }