]> git.tdb.fi Git - libs/gl.git/blob - source/core/batch.h
Move all OpenGL-specific code to a separate directory
[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 "batch_backend.h"
7 #include "bufferable.h"
8 #include "datatype.h"
9 #include "primitivetype.h"
10
11 namespace Msp {
12 namespace GL {
13
14 class Buffer;
15
16 /**
17 Stores primitive type and element indices for a single GL draw call.  Data
18 type for indices is automatically chosen to accommodate the largest index in
19 the Batch.
20
21 This is a pretty low-level class and mainly intended to be used by the Mesh
22 class.
23 */
24 class Batch: public BatchBackend, public Bufferable
25 {
26 public:
27         class Loader: public DataFile::ObjectLoader<Batch>
28         {
29         public:
30                 Loader(Batch &);
31         private:
32                 void indices(const std::vector<unsigned> &);
33         };
34
35 private:
36         PrimitiveType prim_type;
37         DataType index_type;
38         std::vector<std::uint8_t> data;
39         unsigned max_index;
40
41 public:
42         Batch(PrimitiveType t);
43         ~Batch();
44
45         PrimitiveType get_type() const { return prim_type; }
46         void set_index_type(DataType);
47         DataType get_index_type() const { return index_type; }
48
49         Batch &append(unsigned);
50         Batch &append(const std::vector<unsigned> &);
51         bool can_append(PrimitiveType);
52         Batch &append(const Batch &);
53 private:
54         void append_index(unsigned);
55         virtual unsigned get_data_size() const { return data.size(); }
56         virtual const void *get_data_pointer() const { return &data[0]; }
57         virtual unsigned get_alignment() const { return get_index_size(); }
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
65 } // namespace GL
66 } // namespace Msp
67
68 #endif