1 #ifndef MSP_GL_VERTEXBUILDER_H_
2 #define MSP_GL_VERTEXBUILDER_H_
8 #include "vertexformat.h"
14 Base class for classes that build vertices from a series of function calls.
15 The operating model closely follows that of OpenGL immediate mode: vertex
16 attributes can be specified at any time, and when a vertex() function is
17 called, a vertex is created with the active attribute values.
19 A derived class must overload the 4-argument vertex_() function to process the
20 data. Attributes can be read from protected member variables.
28 std::map<unsigned, Vector4> texc;
29 std::map<unsigned, Vector4> attr;
32 VertexBuilder(): nor(0, 0, 1) { }
34 virtual ~VertexBuilder() { }
39 void vertex(float x, float y)
40 { vertex(x, y, 0, 1); }
42 void vertex(float x, float y, float z)
43 { vertex(x, y, z, 1); }
45 void vertex(float x, float y, float z, float w)
46 { vertex(Vector4(x, y, z, w)); }
48 void vertex(const Vector4 &v)
49 { vertex_(mtx.top()*v); }
52 virtual void vertex_(const Vector4 &) = 0;
55 void normal(float x, float y, float z)
56 { normal(Vector3(x, y, z)); }
58 void normal(const Vector3 &n)
60 Vector4 tn = mtx.top()*Vector4(n.x, n.y, n.z, 0);
61 nor = Vector3(tn.x, tn.y, tn.z);
64 void tangent(float x, float y, float z)
65 { tangent(Vector3(x, y, z)); }
67 void tangent(const Vector3 &t)
69 Vector4 tt = mtx.top()*Vector4(t.x, t.y, t.z, 0);
70 attrib(get_component_type(TANGENT3), tt);
73 void binormal(float x, float y, float z)
74 { binormal(Vector3(x, y, z)); }
76 void binormal(const Vector3 &b)
78 Vector4 tb = mtx.top()*Vector4(b.x, b.y, b.z, 0);
79 attrib(get_component_type(BINORMAL3), tb);
82 void texcoord(float s)
83 { texcoord(s, 0, 0, 1); }
85 void texcoord(float s, float t)
86 { texcoord(s, t, 0, 1); }
88 void texcoord(float s, float t, float r)
89 { texcoord(s, t, r, 1); }
91 void texcoord(float s, float t, float r, float q)
92 { texcoord(Vector4(s, t, r, q)); }
94 void texcoord(const Vector4 &t)
95 { multitexcoord(0, t); }
97 void multitexcoord(unsigned i, float s)
98 { multitexcoord(i, s, 0, 0, 1); }
100 void multitexcoord(unsigned i, float s, float t)
101 { multitexcoord(i, s, t, 0, 1); }
103 void multitexcoord(unsigned i, float s, float t, float r)
104 { multitexcoord(i, s, t, r, 1); }
106 void multitexcoord(unsigned i, float s, float t, float r, float q)
107 { multitexcoord(i, Vector4(s, t, r, q)); }
109 void multitexcoord(unsigned i, const Vector4 &t)
112 void color(unsigned char r, unsigned char g, unsigned char b)
113 { color(r, g, b, 255); }
115 void color(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
116 { color(r/255.f, g/255.f, b/255.f, a/255.f); }
118 void color(float r, float g, float b)
119 { color(r, g, b, 1); }
121 void color(float r, float g, float b, float a)
122 { color(Color(r, g, b, a)); }
124 void color(const Color &c)
127 void attrib(unsigned i, float x)
128 { attrib(i, x, 0, 0, 1); }
130 void attrib(unsigned i, float x, float y)
131 { attrib(i, x, y, 0, 1); }
133 void attrib(unsigned i, float x, float y, float z)
134 { attrib(i, x, y, z, 1); }
136 void attrib(unsigned i, float x, float y, float z, float w)
137 { attrib(i, Vector4(x, y, z, w)); }
139 void attrib(unsigned i, const Vector4 &a)