]> git.tdb.fi Git - libs/gl.git/blob - source/vertexsetup.h
Remove the deprecated ProgramBuilder class
[libs/gl.git] / source / 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                 UNUSED_ATTRIBS = 8,
25                 ATTRIB_SHIFT = 4
26         };
27
28         unsigned id;
29         mutable unsigned dirty;
30         const VertexArray *vertex_array;
31         VertexFormat vertex_format;
32         const VertexArray *inst_array;
33         VertexFormat inst_format;
34         const Buffer *index_buffer;
35
36 public:
37         VertexSetup();
38         ~VertexSetup();
39
40         void set_vertex_array(const VertexArray &);
41         void set_instance_array(const VertexArray *);
42         void set_index_buffer(const Buffer &);
43         void refresh();
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 unsigned get_attribs(const VertexFormat &);
50         static unsigned get_update_mask(unsigned, const VertexFormat &, const VertexArray &);
51         void update(unsigned) const;
52         void update_vertex_array(const VertexArray &, unsigned, unsigned, bool) const;
53
54 public:
55         void bind() const;
56         static void unbind();
57 };
58
59 } // namespace GL
60 } // namespace Msp
61
62 #endif