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_
20 Base class for classes that build vertices from a series of function calls.
21 The operating model closely follows that of OpenGL immediate mode: vertex
22 attributes can be specified at any time, and when a vertex() function is
23 called, a vertex is created with the active attribute values.
25 A derived class must overload the 4-argument vertex_() function to process the
26 data. Attributes can be read from protected member variables.
34 std::map<unsigned, Vector4> texc;
35 std::map<unsigned, Vector4> attr;
38 VertexBuilder(): nor(0, 0, 1) { }
40 virtual ~VertexBuilder() { }
45 void vertex(float x, float y)
46 { vertex(x, y, 0, 1); }
48 void vertex(float x, float y, float z)
49 { vertex(x, y, z, 1); }
51 void vertex(float x, float y, float z, float w)
52 { vertex(Vector4(x, y, z, w)); }
54 void vertex(const Vector4 &v)
55 { vertex_(mtx.top()*v); }
58 virtual void vertex_(const Vector4 &) = 0;
61 void normal(float x, float y, float z)
62 { normal(Vector3(x, y, z)); }
64 void normal(const Vector3 &n)
66 Vector4 tn = mtx.top()*Vector4(n.x, n.y, n.z, 0);
67 nor = Vector3(tn.x, tn.y, tn.z);
70 void texcoord(float s)
71 { texcoord(s, 0, 0, 1); }
73 void texcoord(float s, float t)
74 { texcoord(s, t, 0, 1); }
76 void texcoord(float s, float t, float r)
77 { texcoord(s, t, r, 1); }
79 void texcoord(float s, float t, float r, float q)
80 { texcoord(Vector4(s, t, r, q)); }
82 void texcoord(const Vector4 &t)
83 { multitexcoord(0, t); }
85 void multitexcoord(unsigned i, float s)
86 { multitexcoord(i, s, 0, 0, 1); }
88 void multitexcoord(unsigned i, float s, float t)
89 { multitexcoord(i, s, t, 0, 1); }
91 void multitexcoord(unsigned i, float s, float t, float r)
92 { multitexcoord(i, s, t, r, 1); }
94 void multitexcoord(unsigned i, float s, float t, float r, float q)
95 { multitexcoord(i, Vector4(s, t, r, q)); }
97 void multitexcoord(unsigned i, const Vector4 &t)
100 void color(unsigned char r, unsigned char g, unsigned char b)
101 { color(r, g, b, 255); }
103 void color(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
104 { color(r/255.f, g/255.f, b/255.f, a/255.f); }
106 void color(float r, float g, float b)
107 { color(r, g, b, 1); }
109 void color(float r, float g, float b, float a)
110 { color(Color(r, g, b, a)); }
112 void color(const Color &c)
115 void attrib(unsigned i, float x)
116 { attrib(i, x, 0, 0, 1); }
118 void attrib(unsigned i, float x, float y)
119 { attrib(i, x, y, 0, 1); }
121 void attrib(unsigned i, float x, float y, float z)
122 { attrib(i, x, y, z, 1); }
124 void attrib(unsigned i, float x, float y, float z, float w)
125 { attrib(i, Vector4(x, y, z, w)); }
127 void attrib(unsigned i, const Vector4 &a)