]> git.tdb.fi Git - libs/gl.git/blob - source/vertexformat.h
Update deprecated things
[libs/gl.git] / source / vertexformat.h
1 #ifndef MSP_GL_VERTEXFORMAT_H_
2 #define MSP_GL_VERTEXFORMAT_H_
3
4 #include <msp/strings/lexicalcast.h>
5
6 namespace Msp {
7 namespace GL {
8
9 /** A single vertex component.  Nvidia drivers have aliasing between the
10 fixed-functions and generic vertex attributes, despite the standard not
11 allowing it.  We use the same attribute indices here to avoid problems. */
12 enum VertexComponent
13 {
14         VERTEX2 = 1,
15         VERTEX3,
16         VERTEX4,
17         NORMAL3 = 10,
18         COLOR4_UBYTE = 12,
19         COLOR3_FLOAT = 14,
20         COLOR4_FLOAT,
21         TANGENT3 = 18,
22         BINORMAL3 = 22,
23         TEXCOORD1 = 32,
24         TEXCOORD2,
25         TEXCOORD3,
26         TEXCOORD4,
27         ATTRIB1 = 64,
28         ATTRIB2,
29         ATTRIB3,
30         ATTRIB4
31 };
32
33 class VertexFormat
34 {
35 private:
36         enum { MAX_COMPONENTS = 15 };
37
38         unsigned char count;
39         unsigned char components[MAX_COMPONENTS];
40
41 public:
42         VertexFormat();
43         VertexFormat(VertexComponent);
44
45         VertexFormat operator,(VertexComponent c) const;
46         VertexFormat operator,(unsigned i) const;
47
48         bool empty() const { return !count; }
49         const unsigned char *begin() const { return components; }
50         const unsigned char *end() const { return components+count; }
51         unsigned stride() const;
52         int offset(VertexComponent) const;
53 };
54
55 inline VertexFormat operator,(VertexComponent c1, VertexComponent c2)
56 { return (VertexFormat(c1), c2); }
57
58 inline VertexFormat operator,(VertexComponent c, unsigned i)
59 { return (VertexFormat(c), i); }
60
61 VertexComponent make_indexed_component(VertexComponent, unsigned);
62
63 inline unsigned get_component_type(unsigned char c)
64 { return c>>2; }
65
66 inline unsigned get_component_size(unsigned char c)
67 { return (c&3)+1; }
68
69 inline unsigned get_stride(const VertexFormat &f)
70 { return f.stride(); }
71
72 void operator>>(const LexicalConverter &, VertexComponent &);
73
74 } // namespace GL
75 } // namespace Msp
76
77 #endif