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