]> git.tdb.fi Git - libs/gl.git/blob - source/core/vertexformat.h
Rearrange soucre files into subdirectories
[libs/gl.git] / source / core / 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.  Symbolic names are provided for commonly used
10 attributes.  These are aliased with with generic attributes, so be careful when
11 picking your attribute indices. */
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         bool operator==(const VertexFormat &) const;
48         bool operator!=(const VertexFormat &other) const { return !(*this==other); }
49
50         bool empty() const { return !count; }
51         const unsigned char *begin() const { return components; }
52         const unsigned char *end() const { return components+count; }
53         unsigned stride() const;
54         int offset(VertexComponent) const;
55 };
56
57 inline VertexFormat operator,(VertexComponent c1, VertexComponent c2)
58 { return (VertexFormat(c1), c2); }
59
60 inline VertexFormat operator,(VertexComponent c, unsigned i)
61 { return (VertexFormat(c), i); }
62
63 VertexComponent make_indexed_component(VertexComponent, unsigned);
64
65 inline unsigned get_component_type(unsigned char c)
66 { return c>>2; }
67
68 inline unsigned get_component_size(unsigned char c)
69 { return (c&3)+1; }
70
71 inline unsigned get_stride(const VertexFormat &f)
72 { return f.stride(); }
73
74 void operator>>(const LexicalConverter &, VertexComponent &);
75
76 } // namespace GL
77 } // namespace Msp
78
79 #endif