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.
32 PushMatrix(VertexBuilder &b): bld(b), mtx(bld.mtx) { }
33 ~PushMatrix() { bld.mtx = mtx; }
38 std::vector<Vector4> attr;
41 VertexBuilder() { normal(0, 0, 1); }
43 virtual ~VertexBuilder() { }
45 void set_matrix(const Matrix &m)
48 void transform(const Matrix &m)
51 const Matrix &get_matrix() const
54 void vertex(float x, float y)
55 { vertex(x, y, 0, 1); }
57 void vertex(float x, float y, float z)
58 { vertex(x, y, z, 1); }
60 void vertex(float x, float y, float z, float w)
61 { vertex(Vector4(x, y, z, w)); }
63 void vertex(const Vector3 &v)
64 { vertex(Vector4(v.x, v.y, v.z, 1)); }
66 void vertex(const Vector4 &v)
70 virtual void vertex_(const Vector4 &) = 0;
73 void attrib(unsigned i, const Vector4 &v)
80 void normal(float x, float y, float z)
81 { normal(Vector3(x, y, z)); }
83 void normal(const Vector3 &n)
84 { attrib(get_attribute_semantic(NORMAL3), mtx*Vector4(n.x, n.y, n.z, 0)); }
86 void tangent(float x, float y, float z)
87 { tangent(Vector3(x, y, z)); }
89 void tangent(const Vector3 &t)
90 { attrib(get_attribute_semantic(TANGENT3), mtx*Vector4(t.x, t.y, t.z, 0)); }
92 DEPRECATED void binormal(float, float, float)
95 DEPRECATED void binormal(const Vector3 &)
98 void texcoord(float s)
99 { texcoord(s, 0, 0, 1); }
101 void texcoord(float s, float t)
102 { texcoord(s, t, 0, 1); }
104 void texcoord(float s, float t, float r)
105 { texcoord(s, t, r, 1); }
107 void texcoord(float s, float t, float r, float q)
108 { texcoord(Vector4(s, t, r, q)); }
110 void texcoord(const Vector4 &t)
111 { multitexcoord(0, t); }
113 void multitexcoord(unsigned i, float s)
114 { multitexcoord(i, s, 0, 0, 1); }
116 void multitexcoord(unsigned i, float s, float t)
117 { multitexcoord(i, s, t, 0, 1); }
119 void multitexcoord(unsigned i, float s, float t, float r)
120 { multitexcoord(i, s, t, r, 1); }
122 void multitexcoord(unsigned i, float s, float t, float r, float q)
123 { multitexcoord(i, Vector4(s, t, r, q)); }
125 void multitexcoord(unsigned i, const Vector4 &t)
126 { attrib(get_attribute_semantic(TEXCOORD4)+i, t); }
128 void color(unsigned char r, unsigned char g, unsigned char b)
129 { color(r, g, b, 255); }
131 void color(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
132 { color(r/255.f, g/255.f, b/255.f, a/255.f); }
134 void color(float r, float g, float b)
135 { color(r, g, b, 1); }
137 void color(float r, float g, float b, float a)
138 { color(Color(r, g, b, a)); }
140 void color(const Color &c)
141 { attrib(get_attribute_semantic(COLOR4_FLOAT), Vector4(c.r, c.g, c.b, c.a)); }
144 { group(g0, 0, 0, 0); }
146 void group(int g0, int g1)
147 { group(g0, g1, 0, 0); }
149 void group(int g0, int g1, int g2)
150 { group(g0, g1, g2, 0); }
152 void group(int g0, int g1, int g2, int g3)
153 { attrib(get_attribute_semantic(GROUP4), Vector4(g0, g1, g2, g3)); }
155 void weight(float w0)
156 { weight(w0, 0, 0, 0); }
158 void weight(float w0, float w1)
159 { weight(w0, w1, 0, 0); }
161 void weight(float w0, float w1, float w2)
162 { weight(w0, w1, w2, 0); }
164 void weight(float w0, float w1, float w2, float w3)
165 { attrib(get_attribute_semantic(WEIGHT4), Vector4(w0, w1, w2, w3)); }
167 void generic(unsigned i, float x)
168 { generic(i, x, 0, 0, 1); }
170 void generic(unsigned i, float x, float y)
171 { generic(i, x, y, 0, 1); }
173 void generic(unsigned i, float x, float y, float z)
174 { generic(i, x, y, z, 1); }
176 void generic(unsigned i, float x, float y, float z, float w)
177 { generic(i, Vector4(x, y, z, w)); }
179 void generic(unsigned i, const Vector4 &a)
180 { attrib(get_attribute_semantic(GENERIC4)+i, a); }