]> git.tdb.fi Git - libs/gl.git/blob - source/vertexformat.cpp
Make the use of DevIL optional
[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;
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         f=NODATA;
28
29         while(1)
30         {
31                 unsigned underscore=str.find('_', start);
32                 if(!str.compare(start, underscore-start, "VERTEX2"))
33                         f=(f,VERTEX2);
34                 else if(!str.compare(start, underscore-start, "VERTEX3"))
35                         f=(f,VERTEX3);
36                 else if(!str.compare(start, underscore-start, "VERTEX4"))
37                         f=(f,VERTEX4);
38                 else if(!str.compare(start, underscore-start, "NORMAL3"))
39                         f=(f,NORMAL3);
40                 else if(!str.compare(start, underscore-start, "TEXCOORD1"))
41                         f=(f,TEXCOORD1);
42                 else if(!str.compare(start, underscore-start, "TEXCOORD2"))
43                         f=(f,TEXCOORD2);
44                 else if(!str.compare(start, underscore-start, "TEXCOORD3"))
45                         f=(f,TEXCOORD3);
46                 else if(!str.compare(start, underscore-start, "TEXCOORD4"))
47                         f=(f,TEXCOORD4);
48                 else if(!str.compare(start, underscore-start, "COLOR4UB"))
49                         f=(f,COLOR4_UBYTE);
50                 else if(!str.compare(start, underscore-start, "COLOR3F"))
51                         f=(f,COLOR3_FLOAT);
52                 else if(!str.compare(start, underscore-start, "COLOR4F"))
53                         f=(f,COLOR4_FLOAT);
54                 else
55                 {
56                         in.setstate(std::ios_base::failbit);
57                         break;
58                 }
59
60                 if(underscore==std::string::npos)
61                         break;
62                 start=underscore+1;
63         }
64
65         return in;
66 }
67
68 } // namespace GL
69 } // namespace Msp