]> git.tdb.fi Git - libs/gl.git/blob - source/vertexformat.h
Add a tool to convert a mesh into C code
[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 #include "types.h"
13
14 namespace Msp {
15 namespace GL {
16
17 enum VertexComponent
18 {
19         VERTEX2=1,
20         VERTEX3,
21         VERTEX4,
22         NORMAL3=6,
23         TEXCOORD1=8,
24         TEXCOORD2,
25         TEXCOORD3,
26         TEXCOORD4,
27         COLOR4_UBYTE=12,
28         COLOR3_FLOAT=14,
29         COLOR4_FLOAT,
30         ATTRIB1=16,
31         ATTRIB2,
32         ATTRIB3,
33         ATTRIB4
34 };
35
36 struct VertexFormat
37 {
38         unsigned char *data;
39
40         VertexFormat();
41         VertexFormat(VertexComponent);
42         VertexFormat(const VertexFormat &);
43         VertexFormat &operator=(const VertexFormat &);
44         ~VertexFormat();
45
46         bool empty() const { return !data || !data[0]; }
47         const unsigned char *begin() const { return data ? data+1 : 0; }
48         const unsigned char *end() const { return data ? data+1+data[0] : 0; }
49         unsigned stride() 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 uint get_stride(const VertexFormat &f)
61 { return f.stride(); }
62
63 std::istream &operator>>(std::istream &, VertexFormat &);
64
65 } // namespace GL
66 } // namespace Msp
67
68 #endif