]> git.tdb.fi Git - libs/gl.git/blob - source/primitivebuilder.cpp
Make the use of DevIL optional
[libs/gl.git] / source / primitivebuilder.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 "primitivebuilder.h"
9
10 namespace Msp {
11 namespace GL {
12
13 PrimitiveBuilder::PrimitiveBuilder(VertexArray &a):
14         array(a),
15         in_batch(false)
16 { }
17
18 void PrimitiveBuilder::begin(PrimitiveType t)
19 {
20         if(in_batch)
21                 throw InvalidState("begin() already called");
22
23         type=t;
24         in_batch=true;
25         builder=array.modify();
26
27         begin_();
28 }
29
30 void PrimitiveBuilder::end()
31 {
32         if(in_batch)
33                 throw InvalidState("end() called without begin()");
34
35         builder=0;
36         in_batch=false;
37
38         end_();
39 }
40
41 PrimitiveType PrimitiveBuilder::get_type() const
42 {
43         if(!in_batch)
44                 throw InvalidState("Not between begin() and end()");
45         return type;
46 }
47
48 void PrimitiveBuilder::vertex_(float x, float y, float z, float w)
49 {
50         if(!in_batch)
51                 throw InvalidState("Vertex specification not between begin() and end()");
52
53         builder->texcoord(ts, tt, tr,tq);
54         builder->color(cr, cg, cb, ca);
55         builder->normal(nx, ny, nz);
56         builder->vertex(x, y, z, w);
57 }
58
59 } // namespace GL
60 } // namespace Msp