]> git.tdb.fi Git - libs/gl.git/blob - source/batch.h
Move Batch members around
[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 "datatype.h"
7 #include "primitivetype.h"
8
9 namespace Msp {
10 namespace GL {
11
12 class Buffer;
13
14 /**
15 Stores primitive type and element indices for a single GL draw call.  Data
16 type for indices is automatically chosen to accommodate the largest index in
17 the Batch.
18
19 This is a pretty low-level class and mainly intended to be used by the Mesh
20 class.
21 */
22 class Batch
23 {
24 public:
25         class Loader: public DataFile::ObjectLoader<Batch>
26         {
27         public:
28                 Loader(Batch &);
29         private:
30                 void indices(const std::vector<unsigned> &);
31         };
32
33 private:
34         PrimitiveType prim_type;
35         DataType data_type;
36         std::vector<unsigned char> data;
37         unsigned min_index;
38         unsigned max_index;
39         bool restart;
40         Buffer *ibuf;
41         unsigned ibuf_offset;
42         Batch *next_in_ibuf;
43         Batch *prev_in_ibuf;
44         mutable bool dirty;
45
46         static unsigned restart_index;
47
48 public:
49         Batch(PrimitiveType t);
50         ~Batch();
51
52         PrimitiveType get_type() const { return prim_type; }
53         void set_data_type(DataType);
54         DataType get_data_type() const { return data_type; }
55         void use_index_buffer(Buffer *, Batch * = 0);
56 private:
57         void unlink_from_ibuf();
58         void update_ibuf_offsets();
59
60 public:
61         Batch &append(unsigned);
62         void append(const std::vector<unsigned> &);
63         void append(const Batch &);
64 private:
65         unsigned get_index_size() const;
66 public:
67         unsigned size() const { return data.size()/get_index_size(); }
68
69         unsigned get_index(unsigned) const;
70
71         void draw() const;
72 };
73
74 } // namespace GL
75 } // namespace Msp
76
77 #endif