1 #ifndef MSP_GL_VERTEXBUILDER_H_
2 #define MSP_GL_VERTEXBUILDER_H_
13 Base class for classes that build vertices from a series of function calls.
14 The operating model closely follows that of OpenGL immediate mode: vertex
15 attributes can be specified at any time, and when a vertex() function is
16 called, a vertex is created with the active attribute values.
18 A derived class must overload the 4-argument vertex_() function to process the
19 data. Attributes can be read from protected member variables.
27 std::map<unsigned, Vector4> texc;
28 std::map<unsigned, Vector4> attr;
31 VertexBuilder(): nor(0, 0, 1) { }
33 virtual ~VertexBuilder() { }
38 void vertex(float x, float y)
39 { vertex(x, y, 0, 1); }
41 void vertex(float x, float y, float z)
42 { vertex(x, y, z, 1); }
44 void vertex(float x, float y, float z, float w)
45 { vertex(Vector4(x, y, z, w)); }
47 void vertex(const Vector4 &v)
48 { vertex_(mtx.top()*v); }
51 virtual void vertex_(const Vector4 &) = 0;
54 void normal(float x, float y, float z)
55 { normal(Vector3(x, y, z)); }
57 void normal(const Vector3 &n)
59 Vector4 tn = mtx.top()*Vector4(n.x, n.y, n.z, 0);
60 nor = Vector3(tn.x, tn.y, tn.z);
63 void texcoord(float s)
64 { texcoord(s, 0, 0, 1); }
66 void texcoord(float s, float t)
67 { texcoord(s, t, 0, 1); }
69 void texcoord(float s, float t, float r)
70 { texcoord(s, t, r, 1); }
72 void texcoord(float s, float t, float r, float q)
73 { texcoord(Vector4(s, t, r, q)); }
75 void texcoord(const Vector4 &t)
76 { multitexcoord(0, t); }
78 void multitexcoord(unsigned i, float s)
79 { multitexcoord(i, s, 0, 0, 1); }
81 void multitexcoord(unsigned i, float s, float t)
82 { multitexcoord(i, s, t, 0, 1); }
84 void multitexcoord(unsigned i, float s, float t, float r)
85 { multitexcoord(i, s, t, r, 1); }
87 void multitexcoord(unsigned i, float s, float t, float r, float q)
88 { multitexcoord(i, Vector4(s, t, r, q)); }
90 void multitexcoord(unsigned i, const Vector4 &t)
93 void color(unsigned char r, unsigned char g, unsigned char b)
94 { color(r, g, b, 255); }
96 void color(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
97 { color(r/255.f, g/255.f, b/255.f, a/255.f); }
99 void color(float r, float g, float b)
100 { color(r, g, b, 1); }
102 void color(float r, float g, float b, float a)
103 { color(Color(r, g, b, a)); }
105 void color(const Color &c)
108 void attrib(unsigned i, float x)
109 { attrib(i, x, 0, 0, 1); }
111 void attrib(unsigned i, float x, float y)
112 { attrib(i, x, y, 0, 1); }
114 void attrib(unsigned i, float x, float y, float z)
115 { attrib(i, x, y, z, 1); }
117 void attrib(unsigned i, float x, float y, float z, float w)
118 { attrib(i, Vector4(x, y, z, w)); }
120 void attrib(unsigned i, const Vector4 &a)