]> git.tdb.fi Git - libs/gl.git/blob - source/primitivebuilder.cpp
Drop Id tags and copyright notices from files
[libs/gl.git] / source / primitivebuilder.cpp
1 #include "primitivebuilder.h"
2
3 namespace Msp {
4 namespace GL {
5
6 PrimitiveBuilder::PrimitiveBuilder(VertexArray &a):
7         array(a),
8         vab(array),
9         in_batch(false),
10         offs(0)
11 { }
12
13 void PrimitiveBuilder::begin(PrimitiveType t)
14 {
15         if(in_batch)
16                 throw InvalidState("begin() already called");
17
18         type = t;
19         in_batch = true;
20
21         begin_();
22 }
23
24 void PrimitiveBuilder::end()
25 {
26         if(!in_batch)
27                 throw InvalidState("end() called without begin()");
28
29         in_batch = false;
30
31         end_();
32 }
33
34 void PrimitiveBuilder::offset(unsigned o)
35 {
36         if(o>array.size())
37                 throw InvalidParameterValue("Element offset out of range");
38         offs = o;
39 }
40
41 void PrimitiveBuilder::element(unsigned i)
42 {
43         if(!in_batch)
44                 throw InvalidState("Element specification not between begin() and end()");
45         if(offs+i>=array.size())
46                 throw InvalidParameterValue("Element index out of range");
47         element_(offs+i);
48 }
49
50 PrimitiveType PrimitiveBuilder::get_type() const
51 {
52         if(!in_batch)
53                 throw InvalidState("Not between begin() and end()");
54         return type;
55 }
56
57 void PrimitiveBuilder::vertex_(const Vector4 &v)
58 {
59         vab.color(col);
60         vab.normal(nor);
61         for(std::map<unsigned, Vector4>::iterator i=texc.begin(); i!=texc.end(); ++i)
62                 vab.multitexcoord(i->first, i->second);
63         for(std::map<unsigned, Vector4>::iterator i=attr.begin(); i!=attr.end(); ++i)
64                 vab.attrib(i->first, i->second);
65         vab.vertex(v);
66
67         if(in_batch)
68                 element_(array.size()-1);
69 }
70
71 } // namespace GL
72 } // namespace Msp