]> git.tdb.fi Git - libs/gl.git/blob - source/batch.h
Make use of Bufferable in Batch
[libs/gl.git] / source / batch.h
1 #ifndef MSP_GL_BATCH_H_
2 #define MSP_GL_BATCH_H_
3
4 #include <vector>
5 #include <msp/datafile/objectloader.h>
6 #include "bufferable.h"
7 #include "datatype.h"
8 #include "primitivetype.h"
9
10 namespace Msp {
11 namespace GL {
12
13 class Buffer;
14
15 /**
16 Stores primitive type and element indices for a single GL draw call.  Data
17 type for indices is automatically chosen to accommodate the largest index in
18 the Batch.
19
20 This is a pretty low-level class and mainly intended to be used by the Mesh
21 class.
22 */
23 class Batch: public Bufferable
24 {
25 public:
26         class Loader: public DataFile::ObjectLoader<Batch>
27         {
28         public:
29                 Loader(Batch &);
30         private:
31                 void indices(const std::vector<unsigned> &);
32         };
33
34 private:
35         PrimitiveType prim_type;
36         DataType data_type;
37         std::vector<unsigned char> data;
38         unsigned min_index;
39         unsigned max_index;
40         bool restart;
41
42         static unsigned restart_index;
43
44 public:
45         Batch(PrimitiveType t);
46         ~Batch();
47
48         PrimitiveType get_type() const { return prim_type; }
49         void set_data_type(DataType);
50         DataType get_data_type() const { return data_type; }
51
52         Batch &append(unsigned);
53         void append(const std::vector<unsigned> &);
54         void append(const Batch &);
55 private:
56         virtual unsigned get_data_size() const { return data.size(); }
57         virtual void upload_data() const;
58         unsigned get_index_size() const;
59 public:
60         unsigned size() const { return data.size()/get_index_size(); }
61
62         unsigned get_index(unsigned) const;
63
64         void draw() const;
65 };
66
67 } // namespace GL
68 } // namespace Msp
69
70 #endif