]> git.tdb.fi Git - libs/gl.git/blob - source/batch.cpp
Windows compatibility:
[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 "version_1_2.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         require_version(1, 2);
23 }
24
25 Batch &Batch::append(uint i)
26 {
27         if(indices.empty())
28                 min_index=max_index=i;
29         else
30         {
31                 min_index=min(min_index, i);
32                 max_index=max(max_index, i);
33         }
34         indices.push_back(i);
35
36         return *this;
37 }
38
39 void Batch::append(const vector<uint> &ind)
40 {
41         indices.reserve(indices.size()+ind.size());
42         for(vector<uint>::const_iterator i=ind.begin(); i!=ind.end(); ++i)
43                 append(*i);
44 }
45
46 void Batch::draw() const
47 {
48         glDrawRangeElements(type, min_index, max_index, indices.size(), GL_UNSIGNED_INT, &indices[0]);
49 }
50
51
52 Batch::Loader::Loader(Batch &b):
53         batch(b)
54 {
55         add("indices", &Loader::indices);
56 }
57
58 void Batch::Loader::indices(const vector<uint> &ind)
59 {
60         batch.append(ind);
61 }
62
63 } // namespace GL
64 } // namespace Msp