]> git.tdb.fi Git - libs/gl.git/blob - source/core/vertexformat.h
Remove deprecated things related to vertex formats and arrays
[libs/gl.git] / source / core / vertexformat.h
1 #ifndef MSP_GL_VERTEXFORMAT_H_
2 #define MSP_GL_VERTEXFORMAT_H_
3
4 #include <msp/strings/lexicalcast.h>
5
6 namespace Msp {
7 namespace GL {
8
9 /** A single vertex attribute.  Commonly used attributes are named by their
10 semantical meaning in the standard shaders.  Texture coordinates and generic
11 attributes can additionally be given an index.  There are four texture
12 coordinate attributes available.  The number of available generic attributes
13 depends on implementation limits, but is at least five.
14
15 RAW_ATTRIB is handled in a special way; creating an indexed attribute based on
16 it uses the index as raw attribute number.  Only use it if you know what you
17 are doing. */
18 enum VertexAttribute
19 {
20         VERTEX2 = 1,
21         VERTEX3,
22         VERTEX4,
23         COLOR4_UBYTE = 8,
24         COLOR3_FLOAT = 10,
25         COLOR4_FLOAT,
26         NORMAL3 = 18,
27         TANGENT3 = 26,
28         GROUP1 = 32,
29         GROUP2,
30         GROUP3,
31         GROUP4,
32         WEIGHT1 = 40,
33         WEIGHT2,
34         WEIGHT3,
35         WEIGHT4,
36         TEXCOORD1 = 48,
37         TEXCOORD2,
38         TEXCOORD3,
39         TEXCOORD4,
40         GENERIC1 = 80,
41         GENERIC2,
42         GENERIC3,
43         GENERIC4,
44         RAW_ATTRIB1 = 248,
45         RAW_ATTRIB2,
46         RAW_ATTRIB3,
47         RAW_ATTRIB4
48 };
49
50 class VertexFormat
51 {
52 private:
53         enum { MAX_ATTRIBUTES = 15 };
54
55         unsigned char count;
56         unsigned char attributes[MAX_ATTRIBUTES];
57
58 public:
59         VertexFormat();
60         VertexFormat(VertexAttribute);
61
62         VertexFormat operator,(VertexAttribute) const;
63         VertexFormat operator,(unsigned) const;
64         bool operator==(const VertexFormat &) const;
65         bool operator!=(const VertexFormat &other) const { return !(*this==other); }
66
67         bool empty() const { return !count; }
68         const unsigned char *begin() const { return attributes; }
69         const unsigned char *end() const { return attributes+count; }
70         unsigned stride() const;
71         int offset(VertexAttribute) const;
72 };
73
74 inline VertexFormat operator,(VertexAttribute a1, VertexAttribute a2)
75 { return (VertexFormat(a1), a2); }
76
77 VertexAttribute make_indexed_attribute(VertexAttribute, unsigned);
78
79 inline VertexAttribute operator,(VertexAttribute a, unsigned i)
80 { return make_indexed_attribute(a, i); }
81
82 inline unsigned get_attribute_semantic(unsigned char a)
83 { return a>>3; }
84
85 inline unsigned get_attribute_size(unsigned char a)
86 { return (a&3)+1; }
87
88 void operator>>(const LexicalConverter &, VertexAttribute &);
89
90 } // namespace GL
91 } // namespace Msp
92
93 #endif