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