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