]> git.tdb.fi Git - libs/gl.git/blob - source/core/batch.h
e03435550aa48857632aff62d4624eb69f871866
[libs/gl.git] / source / core / 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         friend class Commands;
26
27 public:
28         class Loader: public DataFile::ObjectLoader<Batch>
29         {
30         public:
31                 Loader(Batch &);
32         private:
33                 void indices(const std::vector<unsigned> &);
34         };
35
36 private:
37         PrimitiveType prim_type;
38         unsigned gl_prim_type;
39         DataType index_type;
40         unsigned gl_index_type;
41         std::vector<std::uint8_t> data;
42         unsigned max_index;
43
44 public:
45         Batch(PrimitiveType t);
46         ~Batch();
47
48         PrimitiveType get_type() const { return prim_type; }
49         void set_index_type(DataType);
50         DataType get_index_type() const { return index_type; }
51
52         Batch &append(unsigned);
53         Batch &append(const std::vector<unsigned> &);
54         bool can_append(PrimitiveType);
55         Batch &append(const Batch &);
56 private:
57         void append_index(unsigned);
58         virtual unsigned get_data_size() const { return data.size(); }
59         virtual const void *get_data_pointer() const { return &data[0]; }
60         virtual unsigned get_alignment() const { return get_index_size(); }
61         unsigned get_index_size() const;
62 public:
63         unsigned size() const { return data.size()/get_index_size(); }
64
65         unsigned get_index(unsigned) const;
66 };
67
68 } // namespace GL
69 } // namespace Msp
70
71 #endif