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