]> git.tdb.fi Git - libs/gl.git/blob - source/vertexarraybuilder.cpp
Clear Texture2D's allocation flags when unloading
[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 &ver)
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 = get_component_size(*c);
17                 unsigned t = get_component_type(*c);
18                 if(*c==COLOR4_UBYTE)
19                 {
20                         union { unsigned char c[4]; float f; } u;
21                         u.c[0] = static_cast<unsigned char>(col.r*255);
22                         u.c[1] = static_cast<unsigned char>(col.g*255);
23                         u.c[2] = static_cast<unsigned char>(col.b*255);
24                         u.c[3] = static_cast<unsigned char>(col.a*255);
25                         *ptr++ = u.f;
26                 }
27                 else if(*c==NORMAL3)
28                 {
29                         *ptr++ = nor.x;
30                         *ptr++ = nor.y;
31                         *ptr++ = nor.z;
32                 }
33                 else if(t==get_component_type(COLOR4_FLOAT))
34                 {
35                         *ptr++ = col.r;
36                         *ptr++ = col.g;
37                         *ptr++ = col.b;
38                         if(sz>=4) *ptr++ = col.a;
39                 }
40                 else
41                 {
42                         const Vector4 *v = 0;
43                         if(t==get_component_type(VERTEX3))
44                                 v = &ver;
45                         else if(*c>=TEXCOORD1 && *c<=TEXCOORD4+12)
46                                 v = &texc[t-get_component_type(TEXCOORD1)];
47                         else if(*c>=ATTRIB1)
48                                 v = &attr[t-get_component_type(ATTRIB1)];
49                         else
50                                 v = &attr[t];
51                         *ptr++ = v->x;
52                         if(sz>=2) *ptr++ = v->y;
53                         if(sz>=3) *ptr++ = v->z;
54                         if(sz>=4) *ptr++ = v->w;
55                 }
56         }
57 }
58
59 } // namespace GL
60 } // namespace Msp