1 #ifndef MSP_GL_VERTEXFORMAT_H_
2 #define MSP_GL_VERTEXFORMAT_H_
4 #include <msp/core/inttypes.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 │ │ │ └─────╴Size of one component
26 │ │ └────────╴Signed flag
27 │ └──────────╴Floating-point flag
28 └────────────╴Attribute index (semantic)
30 This information is presented for internal documentation purposes only; it is
31 inadvisable for programs to rely on it.
67 enum { MAX_ATTRIBUTES = 15 };
70 UInt16 attributes[MAX_ATTRIBUTES];
74 VertexFormat(VertexAttribute);
76 VertexFormat operator,(VertexAttribute) const;
77 VertexFormat operator,(DataType) const;
78 VertexFormat operator,(unsigned) const;
79 bool operator==(const VertexFormat &) const;
80 bool operator!=(const VertexFormat &other) const { return !(*this==other); }
82 bool empty() const { return !count; }
83 const UInt16 *begin() const { return attributes; }
84 const UInt16 *end() const { return attributes+count; }
85 unsigned stride() const;
86 int offset(VertexAttribute) const;
89 inline VertexFormat operator,(VertexAttribute a1, VertexAttribute a2)
90 { return (VertexFormat(a1), a2); }
92 VertexAttribute make_typed_attribute(VertexAttribute, DataType);
94 inline VertexAttribute operator,(VertexAttribute a, DataType t)
95 { return make_typed_attribute(a, t); }
97 VertexAttribute make_indexed_attribute(VertexAttribute, unsigned);
99 inline VertexAttribute operator,(VertexAttribute a, unsigned i)
100 { return make_indexed_attribute(a, i); }
102 inline unsigned get_attribute_semantic(UInt16 a)
105 inline DataType get_attribute_source_type(UInt16 a)
106 { return static_cast<DataType>((a&0x70)>>4 | (a&0x180)<<1); }
108 inline unsigned get_attribute_component_count(UInt16 a)
111 inline unsigned get_attribute_size(UInt16 a)
112 { return get_attribute_component_count(a)*get_type_size(get_attribute_source_type(a)); }
114 void operator>>(const LexicalConverter &, VertexAttribute &);