]> git.tdb.fi Git - libs/gl.git/blob - source/vertexformat.h
Style update: add spaces around assignment operators
[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         TEXCOORD1 = 8,
23         TEXCOORD2,
24         TEXCOORD3,
25         TEXCOORD4,
26         COLOR4_UBYTE = 12,
27         COLOR3_FLOAT = 14,
28         COLOR4_FLOAT,
29         ATTRIB1 = 16,
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 };
50
51 VertexFormat operator,(const VertexFormat &f, VertexComponent c);
52 inline VertexFormat operator,(VertexComponent c1, VertexComponent c2)
53 { return (VertexFormat(c1), c2); }
54
55 VertexFormat operator,(const VertexFormat &f, unsigned i);
56 inline VertexFormat operator,(VertexComponent c, unsigned i)
57 { return (VertexFormat(c), i); }
58
59 inline unsigned get_stride(const VertexFormat &f)
60 { return f.stride(); }
61
62 std::istream &operator>>(std::istream &, VertexFormat &);
63
64 } // namespace GL
65 } // namespace Msp
66
67 #endif