]> git.tdb.fi Git - libs/gl.git/blob - source/batch.h
Drop Id tags and copyright notices from files
[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         Batch &append(unsigned);
57         void append(const std::vector<unsigned> &);
58         void append(const Batch &);
59         unsigned size() const { return data.size()/get_index_size(); }
60         unsigned get_index(unsigned) const;
61         void draw() const;
62
63 private:
64         unsigned get_index_size() const;
65
66         template<typename T>
67         void append_index(T);
68
69         template<typename T, typename U>
70         void expand_data();
71
72         template<typename T, typename U>
73         void shrink_data();
74
75         template<typename T, typename U>
76         U convert(T) const;
77
78         void unlink_from_ibuf();
79         void update_ibuf_offsets();
80 };
81
82 } // namespace GL
83 } // namespace Msp
84
85 #endif