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>
37 inline VertexFormat operator,(VertexFormat a, VertexFormat b) { return VertexFormat((a<<4)|b); }
38 uint get_stride(VertexFormat);
40 class VertexArrayBuilder
43 std::vector<float> &data;
45 VertexArrayBuilder(VertexArray &, std::vector<float> &);
46 void vertex(float x, float y) { vertex(x, y, 0, 1); }
47 void vertex(float x, float y, float z) { vertex(x, y, z, 1); }
48 void vertex(float, float, float, float);
49 void normal(float x, float y, float z) { nx=x; ny=y; nz=z; }
50 void texcoord(float s) { texcoord(s, 0, 0, 1); }
51 void texcoord(float s, float t) { texcoord(s, t, 0, 1); }
52 void texcoord(float s, float t, float r) { texcoord(s, t, r, 1); }
53 void texcoord(float s, float t, float r, float q) { ts=s; tt=t; tr=r; tq=q; }
54 void color(ubyte r, ubyte g, ubyte b) { color(r, g, b, 255); }
55 void color(ubyte r, ubyte g, ubyte b, ubyte a) { color(r/255.f, g/255.f, b/255.f, a/255.f); }
56 void color(float r, float g, float b) { color(r, g, b, 1); }
57 void color(float r, float g, float b, float a) { cr=r; cg=g; cb=b; ca=a; }
58 ~VertexArrayBuilder();
64 float cr, cg, cb, ca; // Color
65 float ts, tt, tr, tq; // TexCoord
66 float nx, ny, nz; // Normal
72 VertexArray(VertexFormat);
75 VertexFormat get_format() const { return format; }
76 const std::vector<float> &get_data() const { return data; }
77 void use_vertex_buffer();
78 void use_vertex_buffer(VertexBuffer *);
80 RefPtr<VertexArrayBuilder> modify() { return new VertexArrayBuilder(*this, data); }
85 std::vector<float> data;
90 void set_array(unsigned, unsigned, unsigned) const;
92 static unsigned enabled_arrays;