]> git.tdb.fi Git - libs/gl.git/blob - source/core/vertexsetup.h
Add support for integer vertex attributes
[libs/gl.git] / source / core / vertexsetup.h
1 #ifndef MSP_GL_VERTEXSETUP_H_
2 #define MSP_GL_VERTEXSETUP_H_
3
4 #include "datatype.h"
5 #include "vertexformat.h"
6
7 namespace Msp {
8 namespace GL {
9
10 class Buffer;
11 class VertexArray;
12
13 /**
14 Combines a VertexArray with an index buffer.  This wraps OpenGL's vertex array
15 objects.  Intended for internal use.
16 */
17 class VertexSetup
18 {
19 private:
20         enum ComponentMask
21         {
22                 VERTEX_ARRAY = 1,
23                 INSTANCE_ARRAY = 2,
24                 INDEX_BUFFER = 4
25         };
26
27         unsigned id;
28         mutable unsigned dirty;
29         const VertexArray *vertex_array;
30         VertexFormat vertex_format;
31         const VertexArray *inst_array;
32         VertexFormat inst_format;
33         const Buffer *index_buffer;
34         DataType index_type;
35
36 public:
37         VertexSetup();
38         ~VertexSetup();
39
40         void set_format(const VertexFormat &);
41         void set_format_instanced(const VertexFormat &, const VertexFormat &);
42
43         void set_vertex_array(const VertexArray &);
44         void set_instance_array(const VertexArray &);
45         void set_index_buffer(const Buffer &, DataType);
46         const VertexArray *get_vertex_array() const { return vertex_array; }
47         const VertexArray *get_instance_array() const { return inst_array; }
48         const Buffer *get_index_buffer() const { return index_buffer; }
49         DataType get_index_type() const { return index_type; }
50
51 private:
52         static bool verify_format(const VertexFormat &);
53         static void require_format(const VertexFormat &);
54         void update() const;
55         void update_vertex_array(const VertexArray &, unsigned, unsigned, bool) const;
56
57 public:
58         void refresh() const { if(dirty) update(); }
59
60         unsigned get_id() const { return id; }
61
62         void unload();
63
64         void set_debug_name(const std::string &);
65 };
66
67 } // namespace GL
68 } // namespace Msp
69
70 #endif