]> git.tdb.fi Git - libs/gl.git/blob - source/builders/primitivebuilder.cpp
Export raw texture data to a separate file
[libs/gl.git] / source / builders / 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         for(VertexAttribute a: array.get_format())
63         {
64                 unsigned sem = get_attribute_semantic(a);
65                 if(sem<attr.size())
66                         vab.attrib(sem, attr[sem]);
67         }
68         vab.vertex(v);
69
70         if(in_batch)
71                 element_(array.size()-1);
72 }
73
74 } // namespace GL
75 } // namespace Msp