3 This file is part of libmspgl
4 Copyright © 2007, 2009-2010 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #ifndef MSP_GL_VERTEXBUILDER_H_
9 #define MSP_GL_VERTEXBUILDER_H_
19 Base class for classes that build vertices from a series of function calls.
20 The operating model closely follows that of OpenGL immediate mode: vertex
21 attributes can be specified at any time, and when a vertex() function is
22 called, a vertex is created with the active attribute values.
24 A derived class must overload the 4-argument vertex_() function to process the
25 data. Attributes can be read from protected member variables.
30 VertexBuilder(): nor(0, 0, 1) { }
32 virtual ~VertexBuilder() { }
34 void vertex(float x, float y)
35 { vertex(x, y, 0, 1); }
37 void vertex(float x, float y, float z)
38 { vertex(x, y, z, 1); }
40 void vertex(float x, float y, float z, float w)
41 { vertex_(x, y, z, w); }
43 void vertex(const Vector4 &v)
44 { vertex(v.x, v.y, v.z, v.w); }
47 virtual void vertex_(float x, float y, float z, float w) =0;
50 void normal(float x, float y, float z)
51 { normal(Vector3(x, y, z)); }
53 void normal(const Vector3 &n)
56 void texcoord(float s)
57 { texcoord(s, 0, 0, 1); }
59 void texcoord(float s, float t)
60 { texcoord(s, t, 0, 1); }
62 void texcoord(float s, float t, float r)
63 { texcoord(s, t, r, 1); }
65 void texcoord(float s, float t, float r, float q)
66 { texcoord(Vector4(s, t, r, q)); }
68 void texcoord(const Vector4 &t)
69 { multitexcoord(0, t); }
71 void multitexcoord(unsigned i, float s)
72 { multitexcoord(i, s, 0, 0, 1); }
74 void multitexcoord(unsigned i, float s, float t)
75 { multitexcoord(i, s, t, 0, 1); }
77 void multitexcoord(unsigned i, float s, float t, float r)
78 { multitexcoord(i, s, t, r, 1); }
80 void multitexcoord(unsigned i, float s, float t, float r, float q)
81 { multitexcoord(i, Vector4(s, t, r, q)); }
83 void multitexcoord(unsigned i, const Vector4 &t)
86 void color(unsigned char r, unsigned char g, unsigned char b)
87 { color(r, g, b, 255); }
89 void color(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
90 { color(r/255.f, g/255.f, b/255.f, a/255.f); }
92 void color(float r, float g, float b)
93 { color(r, g, b, 1); }
95 void color(float r, float g, float b, float a)
96 { color(Color(r, g, b, a)); }
98 void color(const Color &c)
101 void attrib(unsigned i, float x)
102 { attrib(i, x, 0, 0, 1); }
104 void attrib(unsigned i, float x, float y)
105 { attrib(i, x, y, 0, 1); }
107 void attrib(unsigned i, float x, float y, float z)
108 { attrib(i, x, y, z, 1); }
110 void attrib(unsigned i, float x, float y, float z, float w)
111 { attrib(i, Vector4(x, y, z, w)); }
113 void attrib(unsigned i, const Vector4 &a)
119 std::map<unsigned, Vector4> texc;
120 std::map<unsigned, Vector4> attr;