-uint get_stride(VertexFormat f)
-{
- uint stride=0;
- for(uint fmt=f; fmt; fmt>>=4)
- stride+=(fmt&3)+1;
- return stride*sizeof(float);
-}
-
-
-VertexArrayBuilder::VertexArrayBuilder(VertexArray &a, vector<float> &d):
- data(d),
- array(a),
- format(array.get_format()),
- stride(get_stride(format)),
- cr(1), cg(1), cb(1), ca(1),
- ts(0), tt(0), tr(0), tq(0),
- nx(0), ny(0), nz(1)
-{ }
-
-void VertexArrayBuilder::vertex(float x, float y, float z, float w)
-{
- for(uint fmt=format; fmt; fmt>>=4)
- {
- uint size=(fmt&3)+1;
- switch(fmt&12)
- {
- case 0:
- data.push_back(x);
- data.push_back(y);
- if(size>=3) data.push_back(z);
- if(size>=4) data.push_back(w);
- break;
- case 4:
- data.push_back(nx);
- data.push_back(ny);
- data.push_back(nz);
- break;
- case 8:
- data.push_back(ts);
- if(size>=2) data.push_back(tt);
- if(size>=3) data.push_back(tr);
- if(size>=4) data.push_back(tq);
- break;
- case 12:
- if(size==1)
- {
- union { ubyte c[4]; float f; } u;
- u.c[0]=(ubyte)(cr*255);
- u.c[1]=(ubyte)(cg*255);
- u.c[2]=(ubyte)(cb*255);
- u.c[3]=(ubyte)(ca*255);
- data.push_back(u.f);
- }
- else
- {
- data.push_back(cr);
- data.push_back(cg);
- data.push_back(cb);
- if(size>=4) data.push_back(ca);
- }
- break;
- }
- }
- //cout<<"Added vertex with "<<data.size()-old_size<<" floats\n";
-}
-
-VertexArrayBuilder::~VertexArrayBuilder()
-{
- array.update_data();
-}
-
-