]> git.tdb.fi Git - libs/gl.git/blobdiff - source/vertexarraybuilder.cpp
Add append() method and and operator[] to VertexArray
[libs/gl.git] / source / vertexarraybuilder.cpp
index 32fa8392bda138029e5b1bae3d89163fbfea6d9c..c64c8ebfc882fca127b9771b2d1818af9ddeabaa 100644 (file)
@@ -12,7 +12,6 @@ namespace Msp {
 namespace GL {
 
 VertexArrayBuilder::VertexArrayBuilder(VertexArray &a):
-       data(a.data),
        array(a)
 { }
 
@@ -23,27 +22,28 @@ VertexArrayBuilder::~VertexArrayBuilder()
 
 void VertexArrayBuilder::vertex_(float x, float y, float z, float w)
 {
+       float *ptr=array.append();
        for(uint fmt=array.get_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);
+                       *ptr++=x;
+                       *ptr++=y;
+                       if(size>=3) *ptr++=z;
+                       if(size>=4) *ptr++=w;
                        break;
                case 4:
-                       data.push_back(nx);
-                       data.push_back(ny);
-                       data.push_back(nz);
+                       *+ptr++=nx;
+                       *+ptr++=ny;
+                       *+ptr++=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);
+                       *+ptr++=ts;
+                       if(size>=2) *+ptr++=tt;
+                       if(size>=3) *+ptr++=tr;
+                       if(size>=4) *+ptr++=tq;
                        break;
                case 12:
                        if(size==1)
@@ -53,14 +53,14 @@ void VertexArrayBuilder::vertex_(float x, float y, float z, float w)
                                u.c[1]=(ubyte)(cg*255);
                                u.c[2]=(ubyte)(cb*255);
                                u.c[3]=(ubyte)(ca*255);
-                               data.push_back(u.f);
+                               *+ptr++=u.f;
                        }
                        else
                        {
-                               data.push_back(cr);
-                               data.push_back(cg);
-                               data.push_back(cb);
-                               if(size>=4) data.push_back(ca);
+                               *+ptr++=cr;
+                               *+ptr++=cg;
+                               *+ptr++=cb;
+                               if(size>=4) *+ptr++=ca;
                        }
                        break;
                }