]> git.tdb.fi Git - libs/gl.git/blob - source/core/vertexsetup.h
Check the flat qualifier from the correct member
[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 vertex and instance attributes and an index buffer for a complete
16 description of vertex input state.
17
18 Applications normally don't need to deal with VertexSetups directly.  They're
19 managed by the Mesh and InstanceArray classes.
20 */
21 class VertexSetup: public VertexSetupBackend
22 {
23         friend VertexSetupBackend;
24
25 private:
26         enum ComponentMask
27         {
28                 VERTEX_ARRAY = 1,
29                 INSTANCE_ARRAY = 2,
30                 INDEX_BUFFER = 4
31         };
32
33         mutable unsigned dirty = 0;
34         const VertexArray *vertex_array = 0;
35         VertexFormat vertex_format;
36         const VertexArray *inst_array = 0;
37         VertexFormat inst_format;
38         const Buffer *index_buffer = 0;
39         DataType index_type = UNSIGNED_SHORT;
40
41 public:
42         /** Sets format for vertex data.  Instance attributes won't be used.  The
43         format cannot be changed once set. */
44         void set_format(const VertexFormat &);
45
46         /** Sets formats for both vertex and instance data.  The formats cannot be
47         changed once set. */
48         void set_format_instanced(const VertexFormat &, const VertexFormat &);
49
50         /** Sets the VertexArray to use as the source of vertex attribute values.
51         The array's format must match the VertexSetup's vertex format. */
52         void set_vertex_array(const VertexArray &);
53
54         /** Sets the VertexArray to use as the source of instance attribute values.
55         An instance format must be defined and the array's format must match it. */
56         void set_instance_array(const VertexArray &);
57
58         /** Sets the buffer containing index data and the type of indices. */
59         void set_index_buffer(const Buffer &, DataType);
60
61         const VertexArray *get_vertex_array() const { return vertex_array; }
62         const VertexArray *get_instance_array() const { return inst_array; }
63         const Buffer *get_index_buffer() const { return index_buffer; }
64         DataType get_index_type() const { return index_type; }
65
66 private:
67         static bool verify_format(const VertexFormat &);
68         void update() const;
69
70 public:
71         void refresh() const { if(dirty) update(); }
72
73         void unload();
74
75         using VertexSetupBackend::set_debug_name;
76 };
77
78 } // namespace GL
79 } // namespace Msp
80
81 #endif