]> git.tdb.fi Git - libs/gl.git/blob - source/batch.cpp
Add Mesh and Batch classes
[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 void 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
34 void Batch::append(const vector<uint> &ind)
35 {
36         indices.reserve(indices.size()+ind.size());
37         for(vector<uint>::const_iterator i=ind.begin(); i!=ind.end(); ++i)
38                 append(*i);
39 }
40
41 void Batch::draw() const
42 {
43         glDrawRangeElements(type, min_index, max_index, indices.size(), GL_UNSIGNED_INT, &indices[0]);
44 }
45
46
47 Batch::Loader::Loader(Batch &b):
48         batch(b)
49 {
50         add("indices", &Loader::indices);
51 }
52
53 void Batch::Loader::indices(const vector<uint> &ind)
54 {
55         batch.append(ind);
56 }
57
58 } // namespace GL
59 } // namespace Msp