]> git.tdb.fi Git - libs/gl.git/blob - source/batch.cpp
Style update: add spaces around assignment operators
[libs/gl.git] / source / batch.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 "batch.h"
9 #include "extension.h"
10 #include "vertexarray.h"
11
12 using namespace std;
13
14 namespace Msp {
15 namespace GL {
16
17 Batch::Batch(PrimitiveType t):
18         type(t),
19         min_index(0),
20         max_index(0)
21 { }
22
23 Batch &Batch::append(unsigned i)
24 {
25         if(indices.empty())
26                 min_index = max_index = i;
27         else
28         {
29                 min_index = min(min_index, i);
30                 max_index = max(max_index, i);
31         }
32         indices.push_back(i);
33
34         return *this;
35 }
36
37 void Batch::append(const vector<unsigned> &ind)
38 {
39         indices.reserve(indices.size()+ind.size());
40         for(vector<unsigned>::const_iterator i=ind.begin(); i!=ind.end(); ++i)
41                 append(*i);
42 }
43
44 void Batch::draw() const
45 {
46         draw_range_elements(type, min_index, max_index, indices.size(), &indices[0]);
47 }
48
49 void Batch::draw_with_buffer(unsigned offset) const
50 {
51         draw_range_elements(type, min_index, max_index, indices.size(), (unsigned *)0+offset);
52 }
53
54
55 Batch::Loader::Loader(Batch &b):
56         DataFile::ObjectLoader<Batch>(b)
57 {
58         add("indices", &Loader::indices);
59 }
60
61 void Batch::Loader::indices(const vector<unsigned> &ind)
62 {
63         obj.append(ind);
64 }
65
66 } // namespace GL
67 } // namespace Msp