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