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() { }
36 void set_matrix(const Matrix &m)
39 void transform(const Matrix &m)
42 const Matrix &get_matrix() const
49 void vertex(float x, float y)
50 { vertex(x, y, 0, 1); }
52 void vertex(float x, float y, float z)
53 { vertex(x, y, z, 1); }
55 void vertex(float x, float y, float z, float w)
56 { vertex(Vector4(x, y, z, w)); }
58 void vertex(const Vector3 &v)
59 { vertex(Vector4(v.x, v.y, v.z, 1)); }
61 void vertex(const Vector4 &v)
62 { vertex_(mtx.top()*v); }
65 virtual void vertex_(const Vector4 &) = 0;
68 void normal(float x, float y, float z)
69 { normal(Vector3(x, y, z)); }
71 void normal(const Vector3 &n)
73 Vector4 tn = mtx.top()*Vector4(n.x, n.y, n.z, 0);
74 nor = Vector3(tn.x, tn.y, tn.z);
77 void tangent(float x, float y, float z)
78 { tangent(Vector3(x, y, z)); }
80 void tangent(const Vector3 &t)
82 Vector4 tt = mtx.top()*Vector4(t.x, t.y, t.z, 0);
83 attrib(get_component_type(TANGENT3), tt);
86 void binormal(float x, float y, float z)
87 { binormal(Vector3(x, y, z)); }
89 void binormal(const Vector3 &b)
91 Vector4 tb = mtx.top()*Vector4(b.x, b.y, b.z, 0);
92 attrib(get_component_type(BINORMAL3), tb);
95 void texcoord(float s)
96 { texcoord(s, 0, 0, 1); }
98 void texcoord(float s, float t)
99 { texcoord(s, t, 0, 1); }
101 void texcoord(float s, float t, float r)
102 { texcoord(s, t, r, 1); }
104 void texcoord(float s, float t, float r, float q)
105 { texcoord(Vector4(s, t, r, q)); }
107 void texcoord(const Vector4 &t)
108 { multitexcoord(0, t); }
110 void multitexcoord(unsigned i, float s)
111 { multitexcoord(i, s, 0, 0, 1); }
113 void multitexcoord(unsigned i, float s, float t)
114 { multitexcoord(i, s, t, 0, 1); }
116 void multitexcoord(unsigned i, float s, float t, float r)
117 { multitexcoord(i, s, t, r, 1); }
119 void multitexcoord(unsigned i, float s, float t, float r, float q)
120 { multitexcoord(i, Vector4(s, t, r, q)); }
122 void multitexcoord(unsigned i, const Vector4 &t)
125 void color(unsigned char r, unsigned char g, unsigned char b)
126 { color(r, g, b, 255); }
128 void color(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
129 { color(r/255.f, g/255.f, b/255.f, a/255.f); }
131 void color(float r, float g, float b)
132 { color(r, g, b, 1); }
134 void color(float r, float g, float b, float a)
135 { color(Color(r, g, b, a)); }
137 void color(const Color &c)
140 void attrib(unsigned i, float x)
141 { attrib(i, x, 0, 0, 1); }
143 void attrib(unsigned i, float x, float y)
144 { attrib(i, x, y, 0, 1); }
146 void attrib(unsigned i, float x, float y, float z)
147 { attrib(i, x, y, z, 1); }
149 void attrib(unsigned i, float x, float y, float z, float w)
150 { attrib(i, Vector4(x, y, z, w)); }
152 void attrib(unsigned i, const Vector4 &a)