unsigned active_tex = 0;
for(const unsigned char *c=format.begin(); c!=format.end(); ++c)
{
- unsigned sz = (*c&3)+1;
- unsigned t = *c>>2;
+ unsigned sz = get_component_size(*c);
+ unsigned t = get_component_type(*c);
bool en = enabled_arrays.is_set(t);
- switch(t)
+ if(t==get_component_type(VERTEX3))
{
- case 0:
glVertexPointer(sz, GL_FLOAT, bpv, base+offset);
if(!en)
glEnableClientState(GL_VERTEX_ARRAY);
- break;
- case 1:
+ }
+ else if(t==get_component_type(NORMAL3))
+ {
glNormalPointer(GL_FLOAT, bpv, base+offset);
if(!en)
glEnableClientState(GL_NORMAL_ARRAY);
- break;
- case 2:
+ }
+ else if(t==get_component_type(COLOR4_FLOAT))
+ {
if(sz==1)
glColorPointer(4, GL_UNSIGNED_BYTE, bpv, base+offset);
else
glColorPointer(sz, GL_FLOAT, bpv, base+offset);
if(!en)
glEnableClientState(GL_COLOR_ARRAY);
- break;
- default:
- if(t<11)
- {
- if(t>3 || active_tex)
- {
- glClientActiveTexture(GL_TEXTURE0+(t-3));
- active_tex = t-3;
- }
- glTexCoordPointer(sz, GL_FLOAT, bpv, base+offset);
- if(!en)
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- }
- else
+ }
+ else if(*c>=TEXCOORD1 && *c<=TEXCOORD4+28)
+ {
+ t -= get_component_type(TEXCOORD1);
+ if(t>0 || active_tex)
{
- glVertexAttribPointer(t-11, sz, GL_FLOAT, false, bpv, base+offset);
- if(!en)
- glEnableVertexAttribArray(t-11);
+ glClientActiveTexture(GL_TEXTURE0+t);
+ active_tex = t;
}
- break;
+ glTexCoordPointer(sz, GL_FLOAT, bpv, base+offset);
+ if(!en)
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ }
+ else
+ {
+ t -= get_component_type(ATTRIB1);
+ glVertexAttribPointer(t, sz, GL_FLOAT, false, bpv, base+offset);
+ if(!en)
+ glEnableVertexAttribArray(t);
}
found.set(t);
offset += sz;
for(unsigned i=0; i<64; ++i)
if(enabled_arrays.is_set(i) && !found.is_set(i))
{
- if(i==0)
+ if(i==get_component_type(VERTEX3))
glDisableClientState(GL_VERTEX_ARRAY);
- else if(i==1)
+ else if(i==get_component_type(NORMAL3))
glDisableClientState(GL_NORMAL_ARRAY);
- else if(i==2)
+ else if(i==get_component_type(COLOR4_FLOAT))
glDisableClientState(GL_COLOR_ARRAY);
- else if(i>=3 && i<11)
+ else if(i>=get_component_type(TEXCOORD1) && i<=get_component_type(TEXCOORD1)+7)
{
- if(i>3 || active_tex)
- glClientActiveTexture(GL_TEXTURE0+(i-3));
+ unsigned j = i-get_component_type(TEXCOORD1);
+ if(j>0 || active_tex)
+ glClientActiveTexture(GL_TEXTURE0+j);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- active_tex = i-3;
+ active_tex = j;
}
else
- glDisableVertexAttribArray(i-11);
+ glDisableVertexAttribArray(i-get_component_type(ATTRIB1));
}
enabled_arrays = found;
array(a)
{ }
-void VertexArrayBuilder::vertex_(const Vector4 &v)
+void VertexArrayBuilder::vertex_(const Vector4 &ver)
{
float *ptr = array.append();
for(const unsigned char *c=array.get_format().begin(); c!=array.get_format().end(); ++c)
{
- unsigned sz = (*c&3)+1;
- unsigned t = *c>>2;
- switch(t)
+ unsigned sz = get_component_size(*c);
+ unsigned t = get_component_type(*c);
+ if(*c==COLOR4_UBYTE)
+ {
+ union { unsigned char c[4]; float f; } u;
+ u.c[0] = static_cast<unsigned char>(col.r*255);
+ u.c[1] = static_cast<unsigned char>(col.g*255);
+ u.c[2] = static_cast<unsigned char>(col.b*255);
+ u.c[3] = static_cast<unsigned char>(col.a*255);
+ *ptr++ = u.f;
+ }
+ else if(*c==NORMAL3)
{
- case 0:
- *ptr++ = v.x;
- *ptr++ = v.y;
- if(sz>=3) *ptr++ = v.z;
- if(sz>=4) *ptr++ = v.w;
- break;
- case 1:
*ptr++ = nor.x;
*ptr++ = nor.y;
*ptr++ = nor.z;
- break;
- case 2:
- if(sz==1)
- {
- union { unsigned char c[4]; float f; } u;
- u.c[0] = static_cast<unsigned char>(col.r*255);
- u.c[1] = static_cast<unsigned char>(col.g*255);
- u.c[2] = static_cast<unsigned char>(col.b*255);
- u.c[3] = static_cast<unsigned char>(col.a*255);
- *ptr++ = u.f;
- }
- else
- {
- *ptr++ = col.r;
- *ptr++ = col.g;
- *ptr++ = col.b;
- if(sz>=4) *ptr++ = col.a;
- }
- break;
- default:
- const Vector4 &a = (t<11 ? texc[t-3] : attr[t-11]);
- *ptr++ = a.x;
- if(sz>=2) *ptr++ = a.y;
- if(sz>=3) *ptr++ = a.z;
- if(sz>=4) *ptr++ = a.w;
- break;
+ }
+ else if(t==get_component_type(COLOR4_FLOAT))
+ {
+ *ptr++ = col.r;
+ *ptr++ = col.g;
+ *ptr++ = col.b;
+ if(sz>=4) *ptr++ = col.a;
+ }
+ else
+ {
+ const Vector4 *v = 0;
+ if(t==get_component_type(VERTEX3))
+ v = &ver;
+ else if(*c>=TEXCOORD1 && *c<=TEXCOORD4+28)
+ v = &texc[t-get_component_type(TEXCOORD1)];
+ else if(*c>=ATTRIB1)
+ v = &attr[t-get_component_type(ATTRIB1)];
+ *ptr++ = v->x;
+ if(sz>=2) *ptr++ = v->y;
+ if(sz>=3) *ptr++ = v->z;
+ if(sz>=4) *ptr++ = v->w;
}
}
}
{
unsigned s = 0;
for(const unsigned char *i=begin(); i!=end(); ++i)
- s += (*i&3)+1;
+ s += get_component_size(*i);
return s;
}
if((comp<TEXCOORD1 && index>0) || (comp<ATTRIB1 && index>=8) || index>=53)
throw out_of_range("VertexFormat::offset");
- unsigned type = (comp>>2)+index;
- unsigned size = comp&3;
+ unsigned type = get_component_type(comp)+index;
+ unsigned size = get_component_size(comp);
unsigned offs = 0;
for(const unsigned char *i=begin(); i!=end(); ++i)
{
- if(static_cast<unsigned>(*i>>2)==type)
+ if(get_component_type(*i)==type)
{
- if((*i&3)>=size)
+ if(get_component_size(*i)>=size)
return offs;
else
return -1;
}
else
- offs += (*i&3)+1;
+ offs += get_component_size(*i);
}
return -1;