]> git.tdb.fi Git - libs/gl.git/blob - source/vertexarraybuilder.cpp
Get rid of the typedefs for fundamental types
[libs/gl.git] / source / vertexarraybuilder.cpp
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007-2009  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "vertexarray.h"
9 #include "vertexarraybuilder.h"
10
11 namespace Msp {
12 namespace GL {
13
14 VertexArrayBuilder::VertexArrayBuilder(VertexArray &a):
15         array(a)
16 { }
17
18 VertexArrayBuilder::~VertexArrayBuilder()
19 {
20         array.update_data();
21 }
22
23 void VertexArrayBuilder::vertex_(float x, float y, float z, float w)
24 {
25         float *ptr=array.append();
26         for(const unsigned char *c=array.get_format().begin(); c!=array.get_format().end(); ++c)
27         {
28                 unsigned size=(*c&3)+1;
29                 unsigned type=*c>>2;
30                 switch(type)
31                 {
32                 case 0:
33                         *ptr++=x;
34                         *ptr++=y;
35                         if(size>=3) *ptr++=z;
36                         if(size>=4) *ptr++=w;
37                         break;
38                 case 1:
39                         *ptr++=nx;
40                         *ptr++=ny;
41                         *ptr++=nz;
42                         break;
43                 case 2:
44                         *ptr++=ts;
45                         if(size>=2) *ptr++=tt;
46                         if(size>=3) *ptr++=tr;
47                         if(size>=4) *ptr++=tq;
48                         break;
49                 case 3:
50                         if(size==1)
51                         {
52                                 union { unsigned char c[4]; float f; } u;
53                                 u.c[0]=static_cast<unsigned char>(cr*255);
54                                 u.c[1]=static_cast<unsigned char>(cg*255);
55                                 u.c[2]=static_cast<unsigned char>(cb*255);
56                                 u.c[3]=static_cast<unsigned char>(ca*255);
57                                 *ptr++=u.f;
58                         }
59                         else
60                         {
61                                 *ptr++=cr;
62                                 *ptr++=cg;
63                                 *ptr++=cb;
64                                 if(size>=4) *+ptr++=ca;
65                         }
66                         break;
67                 default:
68                         const Attrib &a=av[type-4];
69                         *ptr++=a.x;
70                         if(size>=2) *ptr++=a.y;
71                         if(size>=3) *ptr++=a.z;
72                         if(size>=4) *ptr++=a.w;
73                         break;
74                 }
75         }
76 }
77
78 } // namespace GL
79 } // namespace Msp