]> git.tdb.fi Git - libs/gl.git/blob - source/vertexsetup.h
Use direct state access for updating VertexSetup
[libs/gl.git] / source / vertexsetup.h
1 #ifndef MSP_GL_VERTEXSETUP_H_
2 #define MSP_GL_VERTEXSETUP_H_
3
4 #include "bindable.h"
5
6 namespace Msp {
7 namespace GL {
8
9 class VertexArray;
10
11 /**
12 Combines a VertexArray with an index buffer.  This wraps OpenGL's vertex array
13 objects.  Intended for internal use.
14 */
15 class VertexSetup: public Bindable<VertexSetup>
16 {
17 private:
18         enum ComponentMask
19         {
20                 VERTEX_ARRAY = 1,
21                 INDEX_BUFFER = 2
22         };
23
24         unsigned id;
25         mutable unsigned dirty;
26         const VertexArray *array;
27         const Buffer *index_buffer;
28
29 public:
30         VertexSetup();
31         ~VertexSetup();
32
33         void set_vertex_array(const VertexArray &);
34         void set_instance_array(const VertexArray &);
35         void set_index_buffer(const Buffer &);
36         const Buffer *get_index_buffer() const { return index_buffer; }
37
38 private:
39         void update(unsigned) const;
40         void update_vertex_array(bool) const;
41
42 public:
43         void bind() const;
44         static void unbind();
45 };
46
47 } // namespace GL
48 } // namespace Msp
49
50 #endif