]> git.tdb.fi Git - libs/gl.git/blob - source/vertexbuilder.h
Move VertexFormat and VertexArrayBuilder to their own files
[libs/gl.git] / source / vertexbuilder.h
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_GL_VERTEXBUILDER_H_
9 #define MSP_GL_VERTEXBUILDER_H_
10
11 #include "types.h"
12
13 namespace Msp {
14 namespace GL {
15
16 /**
17 Base class for classes that build vertices from a series of function calls.
18 The operating model closely follows that of OpenGL immediate mode: vertex
19 attributes can be specified at any time, and when a vertex() function is
20 called, a vertex is created with the active attribute values.
21
22 A derived class must overload the 4-argument vertex_() function to process the
23 data.  Attributes can be read from protected member variables.
24 */
25 class VertexBuilder
26 {
27 public:
28         VertexBuilder();
29         virtual ~VertexBuilder() { }
30
31         void vertex(float x, float y)                     { vertex(x, y, 0, 1); }
32         void vertex(float x, float y, float z)            { vertex(x, y, z, 1); }
33         void vertex(float x, float y, float z, float w)   { vertex_(x, y, z, w); }
34         void normal(float x, float y, float z)            { nx=x; ny=y; nz=z; }
35         void texcoord(float s)                            { texcoord(s, 0, 0, 1); }
36         void texcoord(float s, float t)                   { texcoord(s, t, 0, 1); }
37         void texcoord(float s, float t, float r)          { texcoord(s, t, r, 1); }
38         void texcoord(float s, float t, float r, float q) { ts=s; tt=t; tr=r; tq=q; }
39         void color(ubyte r, ubyte g, ubyte b)             { color(r, g, b, 255); }
40         void color(ubyte r, ubyte g, ubyte b, ubyte a)    { color(r/255.f, g/255.f, b/255.f, a/255.f); }
41         void color(float r, float g, float b)             { color(r, g, b, 1); }
42         void color(float r, float g, float b, float a)    { cr=r; cg=g; cb=b; ca=a; }
43 protected:
44         float cr, cg, cb, ca;  // Color
45         float ts, tt, tr, tq;  // TexCoord
46         float nx, ny, nz;     // Normal
47
48         virtual void vertex_(float, float, float, float) =0;
49 };
50
51 } // namespace GL
52 } // namespace Msp
53
54 #endif