]> git.tdb.fi Git - libs/gl.git/blob - source/core/batch.h
Disconnect the PrimitiveType enum from OpenGL constants
[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 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         GLenum gl_prim_type;
37         DataType index_type;
38         GLenum gl_index_type;
39         std::vector<UInt8> data;
40         unsigned max_index;
41         bool restart;
42
43         static unsigned restart_index;
44
45 public:
46         Batch(PrimitiveType t);
47         ~Batch();
48
49         PrimitiveType get_type() const { return prim_type; }
50         GLenum get_gl_primitive_type() const { return gl_prim_type; }
51         void set_index_type(DataType);
52         DataType get_index_type() const { return index_type; }
53         GLenum get_gl_index_type() const { return gl_index_type; }
54
55         DEPRECATED void set_data_type(DataType t) { set_index_type(t); }
56         DEPRECATED DataType get_data_type() const { return index_type; }
57
58         Batch &append(unsigned);
59         Batch &append(const std::vector<unsigned> &);
60         bool can_append(PrimitiveType);
61         Batch &append(const Batch &);
62 private:
63         void append_index(unsigned);
64         virtual unsigned get_data_size() const { return data.size(); }
65         virtual const void *get_data_pointer() const { return &data[0]; }
66         virtual unsigned get_alignment() const { return get_index_size(); }
67         unsigned get_index_size() const;
68 public:
69         unsigned size() const { return data.size()/get_index_size(); }
70
71         unsigned get_index(unsigned) const;
72 };
73
74 } // namespace GL
75 } // namespace Msp
76
77 #endif