3 This file is part of libmspgl
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #ifndef MSP_GL_VERTEXARRAY_H_
9 #define MSP_GL_VERTEXARRAY_H_
12 #include <msp/core/refptr.h>
13 #include <msp/datafile/loader.h>
14 #include "primitivetype.h"
16 #include "vertexarraybuilder.h"
17 #include "vertexformat.h"
27 class Loader: public DataFile::Loader, public VertexArrayBuilder
30 Loader(VertexArray &);
35 std::vector<float> data;
40 VertexArray(const VertexArray &);
41 VertexArray &operator=(const VertexArray &);
43 VertexArray(const VertexFormat &);
46 const VertexFormat &get_format() const { return format; }
47 const std::vector<float> &get_data() const { return data; }
48 void use_vertex_buffer();
49 void use_vertex_buffer(Buffer *);
50 void reserve(unsigned);
51 unsigned size() const { return data.size()/stride; }
53 void reset(const VertexFormat &);
57 float *operator[](unsigned i) { return &data[0]+i*stride; }
58 const float *operator[](unsigned i) const { return &data[0]+i*stride; }
60 void set_array(unsigned, bool, unsigned) const;
62 static unsigned enabled_arrays;
65 void array_element(int);
66 void draw_arrays(PrimitiveType, int, sizei);
67 void draw_elements(PrimitiveType, sizei, DataType, const void *);
68 void draw_range_elements(PrimitiveType, uint, uint, sizei, DataType, const void *);
70 inline void draw_elements(PrimitiveType mode, sizei count, const unsigned *indices)
71 { draw_elements(mode, count, UNSIGNED_INT, indices); }
73 inline void draw_elements(PrimitiveType mode, sizei count, const unsigned short *indices)
74 { draw_elements(mode, count, UNSIGNED_SHORT, indices); }
76 inline void draw_range_elements(PrimitiveType mode, uint low, uint high, sizei count, const unsigned short *indices)
77 { draw_range_elements(mode, low, high, count, UNSIGNED_SHORT, indices); }
79 inline void draw_range_elements(PrimitiveType mode, uint low, uint high, sizei count, const unsigned *indices)
80 { draw_range_elements(mode, low, high, count, UNSIGNED_INT, indices); }