]> git.tdb.fi Git - libs/gl.git/blob - source/primitivebuilder.cpp
Add static Texture::unbind_from function
[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         vab(array),
16         in_batch(false)
17 { }
18
19 void PrimitiveBuilder::begin(PrimitiveType t)
20 {
21         if(in_batch)
22                 throw InvalidState("begin() already called");
23
24         type=t;
25         in_batch=true;
26
27         begin_();
28 }
29
30 void PrimitiveBuilder::end()
31 {
32         if(!in_batch)
33                 throw InvalidState("end() called without begin()");
34
35         in_batch=false;
36
37         end_();
38 }
39
40 void PrimitiveBuilder::element(unsigned i)
41 {
42         if(!in_batch)
43                 throw InvalidState("Element specification not between begin() and end()");
44         if(i>=array.size())
45                 throw InvalidParameterValue("Element index out of range");
46         element_(i);
47 }
48
49 PrimitiveType PrimitiveBuilder::get_type() const
50 {
51         if(!in_batch)
52                 throw InvalidState("Not between begin() and end()");
53         return type;
54 }
55
56 void PrimitiveBuilder::vertex_(float x, float y, float z, float w)
57 {
58         vab.texcoord(ts, tt, tr, tq);
59         vab.color(cr, cg, cb, ca);
60         vab.normal(nx, ny, nz);
61         for(std::map<unsigned, Attrib>::iterator i=av.begin(); i!=av.end(); ++i)
62                 vab.attrib(i->first, i->second.x, i->second.y, i->second.z, i->second.w);
63         vab.vertex(x, y, z, w);
64
65         if(in_batch)
66                 element_(array.size()-1);
67 }
68
69 } // namespace GL
70 } // namespace Msp