]> git.tdb.fi Git - libs/gl.git/blob - source/vertexformat.h
Drop Id tags and copyright notices from files
[libs/gl.git] / source / vertexformat.h
1 #ifndef MSP_GL_VERTEXFORMAT_H_
2 #define MSP_GL_VERTEXFORMAT_H_
3
4 #include <istream>
5
6 namespace Msp {
7 namespace GL {
8
9 enum VertexComponent
10 {
11         VERTEX2 = 1,
12         VERTEX3,
13         VERTEX4,
14         NORMAL3 = 6,
15         COLOR4_UBYTE = 8,
16         COLOR3_FLOAT = 10,
17         COLOR4_FLOAT,
18         TEXCOORD1 = 12,
19         TEXCOORD2,
20         TEXCOORD3,
21         TEXCOORD4,
22         ATTRIB1 = 44,
23         ATTRIB2,
24         ATTRIB3,
25         ATTRIB4
26 };
27
28 struct VertexFormat
29 {
30         unsigned char *data;
31
32         VertexFormat();
33         VertexFormat(VertexComponent);
34         VertexFormat(const VertexFormat &);
35         VertexFormat &operator=(const VertexFormat &);
36         ~VertexFormat();
37
38         bool empty() const { return !data || !data[0]; }
39         const unsigned char *begin() const { return data ? data+1 : 0; }
40         const unsigned char *end() const { return data ? data+1+data[0] : 0; }
41         unsigned stride() const;
42         int offset(VertexComponent, unsigned = 0) const;
43 };
44
45 VertexFormat operator,(const VertexFormat &f, VertexComponent c);
46 inline VertexFormat operator,(VertexComponent c1, VertexComponent c2)
47 { return (VertexFormat(c1), c2); }
48
49 VertexFormat operator,(const VertexFormat &f, unsigned i);
50 inline VertexFormat operator,(VertexComponent c, unsigned i)
51 { return (VertexFormat(c), i); }
52
53 inline unsigned get_stride(const VertexFormat &f)
54 { return f.stride(); }
55
56 void operator>>(const LexicalConverter &, VertexComponent &);
57 void operator>>(const LexicalConverter &, VertexFormat &);
58
59 } // namespace GL
60 } // namespace Msp
61
62 #endif