]> git.tdb.fi Git - libs/gl.git/blob - source/vertexformat.cpp
Move VertexFormat and VertexArrayBuilder to their own files
[libs/gl.git] / source / vertexformat.cpp
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "vertexformat.h"
9
10 namespace Msp {
11 namespace GL {
12
13 uint get_stride(VertexFormat f)
14 {
15         uint stride=0;
16         for(uint fmt=f; fmt; fmt>>=4)
17                 stride+=(fmt&3)+1;
18         return stride*sizeof(float);
19 }
20
21 std::istream &operator>>(std::istream &in, VertexFormat &f)
22 {
23         std::string str;
24         in>>str;
25
26         unsigned start=0;
27         unsigned comma;
28         f=NODATA;
29
30         while(1)
31         {
32                 comma=str.find(',', start);
33                 if(str.compare(start, comma-start, "VERTEX2"))
34                         f=f,VERTEX2;
35                 else if(str.compare(start, comma-start, "VERTEX3"))
36                         f=f,VERTEX3;
37                 else if(str.compare(start, comma-start, "VERTEX4"))
38                         f=f,VERTEX4;
39                 else if(str.compare(start, comma-start, "NORMAL3"))
40                         f=f,NORMAL3;
41                 else if(str.compare(start, comma-start, "TEXCOORD1"))
42                         f=f,TEXCOORD1;
43                 else if(str.compare(start, comma-start, "TEXCOORD2"))
44                         f=f,TEXCOORD2;
45                 else if(str.compare(start, comma-start, "TEXCOORD3"))
46                         f=f,TEXCOORD3;
47                 else if(str.compare(start, comma-start, "TEXCOORD4"))
48                         f=f,TEXCOORD4;
49                 else if(str.compare(start, comma-start, "COLOR4_UBYTE"))
50                         f=f,COLOR4_UBYTE;
51                 else if(str.compare(start, comma-start, "COLOR3_FLOAT"))
52                         f=f,COLOR3_FLOAT;
53                 else if(str.compare(start, comma-start, "COLOR4_FLOAT"))
54                         f=f,COLOR4_FLOAT;
55                 else
56                 {
57                         in.setstate(std::ios_base::failbit);
58                         break;
59                 }
60                 start=comma+1;
61                 if(comma==std::string::npos)
62                         break;
63         }
64
65         return in;
66 }
67
68 } // namespace GL
69 } // namespace Msp