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