- if(format.empty())
- throw InvalidState("Trying to apply a vertex array with no data");
-
- if(vbuf)
- vbuf->bind();
-
- const float *base=vbuf?0:&data[0];
- uint offset=0;
- uint found=0;
- uint bpv=stride*sizeof(float);
- for(const unsigned char *c=format.begin(); c!=format.end(); ++c)
- {
- uint sz=(*c&3)+1;
- uint t=*c>>2;
- switch(t)
- {
- case 0:
- glVertexPointer(sz, GL_FLOAT, bpv, base+offset);
- break;
- case 1:
- glNormalPointer(GL_FLOAT, bpv, base+offset);
- break;
- case 2:
- glTexCoordPointer(sz, GL_FLOAT, bpv, base+offset);
- break;
- case 3:
- if(sz==1)
- glColorPointer(4, GL_UNSIGNED_BYTE, bpv, base+offset);
- else
- glColorPointer(sz, GL_FLOAT, bpv, base+offset);
- break;
- default:
- glVertexAttribPointerARB(t-4, sz, GL_FLOAT, false, bpv, base+offset);
- break;
- }
- found|=1<<t;
- offset+=sz;
- }
-
- set_array(GL_VERTEX_ARRAY, found&1, 1);
- set_array(GL_NORMAL_ARRAY, found&2, 2);
- set_array(GL_TEXTURE_COORD_ARRAY, found&4, 4);
- set_array(GL_COLOR_ARRAY, found&8, 8);
- for(unsigned i=4; i<32; ++i)
- set_array(i-3, (found>>i)&1, 1<<i);