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 void binormal(float x, float y, float z)
93 { binormal(Vector3(x, y, z)); }
95 void binormal(const Vector3 &b)
96 { attrib(get_attribute_semantic(BINORMAL3), mtx*Vector4(b.x, b.y, b.z, 0)); }
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)); }
143 void generic(unsigned i, float x)
144 { generic(i, x, 0, 0, 1); }
146 void generic(unsigned i, float x, float y)
147 { generic(i, x, y, 0, 1); }
149 void generic(unsigned i, float x, float y, float z)
150 { generic(i, x, y, z, 1); }
152 void generic(unsigned i, float x, float y, float z, float w)
153 { generic(i, Vector4(x, y, z, w)); }
155 void generic(unsigned i, const Vector4 &a)
156 { attrib(get_attribute_semantic(GENERIC4)+i, a); }