1 #ifndef MSP_GL_VERTEXARRAY_H_
2 #define MSP_GL_VERTEXARRAY_H_
5 #include <msp/core/refptr.h>
30 inline VertexFormat operator,(VertexFormat a, VertexFormat b) { return VertexFormat((a<<4)|b); }
31 uint get_stride(VertexFormat);
33 class VertexArrayBuilder
36 std::vector<float> &data;
38 VertexArrayBuilder(VertexArray &, std::vector<float> &);
39 void vertex(float x, float y) { vertex(x, y, 0, 1); }
40 void vertex(float x, float y, float z) { vertex(x, y, z, 1); }
41 void vertex(float, float, float, float);
42 void normal(float x, float y, float z) { nx=x; ny=y; nz=z; }
43 void texcoord(float s) { texcoord(s, 0, 0, 1); }
44 void texcoord(float s, float t) { texcoord(s, t, 0, 1); }
45 void texcoord(float s, float t, float r) { texcoord(s, t, r, 1); }
46 void texcoord(float s, float t, float r, float q) { ts=s; tt=t; tr=r; tq=q; }
47 void color(ubyte r, ubyte g, ubyte b) { color(r, g, b, 255); }
48 void color(ubyte r, ubyte g, ubyte b, ubyte a) { color(r/255.f, g/255.f, b/255.f, a/255.f); }
49 void color(float r, float g, float b) { color(r, g, b, 1); }
50 void color(float r, float g, float b, float a) { cr=r; cg=g; cb=b; ca=a; }
51 ~VertexArrayBuilder();
57 float cr, cg, cb, ca; // Color
58 float ts, tt, tr, tq; // TexCoord
59 float nx, ny, nz; // Normal
65 VertexArray(VertexFormat);
68 VertexFormat get_format() const { return format; }
69 const std::vector<float> &get_data() const { return data; }
70 void use_vertex_buffer();
71 void use_vertex_buffer(VertexBuffer *);
73 RefPtr<VertexArrayBuilder> modify() { return new VertexArrayBuilder(*this, data); }
78 std::vector<float> data;
83 void set_array(unsigned, unsigned, unsigned) const;
85 static unsigned enabled_arrays;