1 #ifndef MSP_GL_VERTEXFORMAT_H_
2 #define MSP_GL_VERTEXFORMAT_H_
5 #include <msp/strings/lexicalcast.h>
11 /** A single vertex attribute. Commonly used attributes are named by their
12 semantical meaning in the standard shaders. Texture coordinates and generic
13 attributes can additionally be given an index. There are four texture
14 coordinate attributes available. The number of available generic attributes
15 depends on implementation limits, but is at least five.
17 RAW_ATTRIB is handled in a special way; creating an indexed attribute based on
18 it uses the index as raw attribute number. Only use it if you know what you
21 The values are bitfields laid as follows:
24 │ │ │ │ │ └╴Number of components
25 │ │ │ │ └───╴Integer attribute flag
26 │ │ │ └─────╴Size of one component
27 │ │ └────────╴Signed flag
28 │ └──────────╴Floating-point flag
29 └────────────╴Attribute index (semantic)
31 This information is presented for internal documentation purposes only; it is
32 inadvisable for programs to rely on it.
34 enum VertexAttribute: std::uint16_t
67 RAW_ATTRIB_I1 = 0xFCC9,
68 RAW_ATTRIB_I2 = 0xFCCA,
69 RAW_ATTRIB_I3 = 0xFCCB,
70 RAW_ATTRIB_I4 = 0xFCCC
76 enum { MAX_ATTRIBUTES = 15 };
79 VertexAttribute attributes[MAX_ATTRIBUTES];
83 VertexFormat(VertexAttribute);
85 VertexFormat operator,(VertexAttribute) const;
86 VertexFormat operator,(DataType) const;
87 VertexFormat operator,(unsigned) const;
88 bool operator==(const VertexFormat &) const;
89 bool operator!=(const VertexFormat &other) const { return !(*this==other); }
91 bool empty() const { return !count; }
92 const VertexAttribute *begin() const { return attributes; }
93 const VertexAttribute *end() const { return attributes+count; }
94 unsigned stride() const;
95 int offset(VertexAttribute) const;
98 inline VertexFormat operator,(VertexAttribute a1, VertexAttribute a2)
99 { return (VertexFormat(a1), a2); }
101 VertexAttribute make_typed_attribute(VertexAttribute, DataType);
103 inline VertexAttribute operator,(VertexAttribute a, DataType t)
104 { return make_typed_attribute(a, t); }
106 VertexAttribute make_indexed_attribute(VertexAttribute, unsigned);
108 inline VertexAttribute operator,(VertexAttribute a, unsigned i)
109 { return make_indexed_attribute(a, i); }
111 inline unsigned get_attribute_semantic(VertexAttribute a)
114 inline DataType get_attribute_source_type(VertexAttribute a)
115 { return static_cast<DataType>((a&0x70)>>4 | (a&0x180)<<1); }
117 inline unsigned get_attribute_component_count(VertexAttribute a)
120 inline unsigned get_attribute_size(VertexAttribute a)
121 { return get_attribute_component_count(a)*get_type_size(get_attribute_source_type(a)); }
123 inline bool is_integer_attribute(VertexAttribute a)
126 void operator>>(const LexicalConverter &, VertexAttribute &);