3 This file is part of libmspgl
4 Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include "vertexarray.h"
9 #include "vertexarraybuilder.h"
14 VertexArrayBuilder::VertexArrayBuilder(VertexArray &a):
18 VertexArrayBuilder::~VertexArrayBuilder()
23 void VertexArrayBuilder::vertex_(float x, float y, float z, float w)
25 float *ptr = array.append();
26 for(const unsigned char *c=array.get_format().begin(); c!=array.get_format().end(); ++c)
28 unsigned size = (*c&3)+1;
29 unsigned type = *c>>2;
35 if(size>=3) *ptr+ += z;
36 if(size>=4) *ptr+ += w;
45 if(size>=2) *ptr+ += tt;
46 if(size>=3) *ptr+ += tr;
47 if(size>=4) *ptr+ += tq;
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);
64 if(size>=4) *+ptr+ += ca;
68 const Attrib &a = av[type-4];
70 if(size>=2) *ptr+ += a.y;
71 if(size>=3) *ptr+ += a.z;
72 if(size>=4) *ptr+ += a.w;