]> git.tdb.fi Git - libs/gl.git/blob - source/immediate.cpp
Move VertexFormat and VertexArrayBuilder to their own files
[libs/gl.git] / source / immediate.cpp
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 #include "immediate.h"
9
10 namespace Msp {
11 namespace GL {
12
13 Immediate::Immediate(VertexFormat f):
14         array(f),
15         in_batch(false),
16         n_vertices(0)
17 { }
18
19 void Immediate::begin(PrimitiveType t)
20 {
21         type=t;
22         in_batch=true;
23         n_vertices=0;
24         builder=array.modify();
25 }
26
27 void Immediate::end()
28 {
29         builder=0;
30
31         array.apply();
32         glDrawArrays(type, 0, n_vertices);
33
34         array.clear();
35         in_batch=false;
36 }
37
38 void Immediate::vertex_(float x, float y, float z, float w)
39 {
40         if(!in_batch)
41                 throw InvalidState("Vertex specification not between begin and end");
42
43         builder->texcoord(ts, tt, tr,tq);
44         builder->color(cr, cg, cb, ca);
45         builder->normal(nx, ny, nz);
46         builder->vertex(x, y, z, w);
47
48         ++n_vertices;
49 }
50
51 } // namespace GL
52 } // namespace Msp