]> git.tdb.fi Git - libs/gl.git/blob - source/vertexarraybuilder.cpp
Drop Id tags and copyright notices from files
[libs/gl.git] / source / vertexarraybuilder.cpp
1 #include "vertexarray.h"
2 #include "vertexarraybuilder.h"
3
4 namespace Msp {
5 namespace GL {
6
7 VertexArrayBuilder::VertexArrayBuilder(VertexArray &a):
8         array(a)
9 { }
10
11 void VertexArrayBuilder::vertex_(const Vector4 &v)
12 {
13         float *ptr = array.append();
14         for(const unsigned char *c=array.get_format().begin(); c!=array.get_format().end(); ++c)
15         {
16                 unsigned sz = (*c&3)+1;
17                 unsigned t = *c>>2;
18                 switch(t)
19                 {
20                 case 0:
21                         *ptr++ = v.x;
22                         *ptr++ = v.y;
23                         if(sz>=3) *ptr++ = v.z;
24                         if(sz>=4) *ptr++ = v.w;
25                         break;
26                 case 1:
27                         *ptr++ = nor.x;
28                         *ptr++ = nor.y;
29                         *ptr++ = nor.z;
30                         break;
31                 case 2:
32                         if(sz==1)
33                         {
34                                 union { unsigned char c[4]; float f; } u;
35                                 u.c[0] = static_cast<unsigned char>(col.r*255);
36                                 u.c[1] = static_cast<unsigned char>(col.g*255);
37                                 u.c[2] = static_cast<unsigned char>(col.b*255);
38                                 u.c[3] = static_cast<unsigned char>(col.a*255);
39                                 *ptr++ = u.f;
40                         }
41                         else
42                         {
43                                 *ptr++ = col.r;
44                                 *ptr++ = col.g;
45                                 *ptr++ = col.b;
46                                 if(sz>=4) *ptr++ = col.a;
47                         }
48                         break;
49                 default:
50                         const Vector4 &a = (t<11 ? texc[t-3] : attr[t-11]);
51                         *ptr++ = a.x;
52                         if(sz>=2) *ptr++ = a.y;
53                         if(sz>=3) *ptr++ = a.z;
54                         if(sz>=4) *ptr++ = a.w;
55                         break;
56                 }
57         }
58 }
59
60 } // namespace GL
61 } // namespace Msp