X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fvertexformat.cpp;h=adb33c2afa48178d794a0476263a8d029f8519ac;hb=8ac93980ef87834fd431c97104baa441561a7ce0;hp=2b18178b26db4734bcc3e3f673abb32324a10779;hpb=f1cbab0dca940fd5db6d459f9e91661efe3d6052;p=libs%2Fgl.git diff --git a/source/vertexformat.cpp b/source/vertexformat.cpp index 2b18178b..adb33c2a 100644 --- a/source/vertexformat.cpp +++ b/source/vertexformat.cpp @@ -64,6 +64,30 @@ unsigned VertexFormat::stride() const return s; } +int VertexFormat::offset(VertexComponent comp, unsigned index) const +{ + if((comp0) || (comp=8) || index>=53) + throw InvalidParameterValue("Vertex component index out of range"); + + unsigned type = (comp>>2)+index; + unsigned size = comp&3; + unsigned offs = 0; + for(const unsigned char *i=begin(); i!=end(); ++i) + { + if((*i>>2)==type) + { + if((*i&3)>=size) + return offs; + else + return -1; + } + else + offs += (*i&3)+1; + } + + return -1; +} + VertexFormat operator,(const VertexFormat &f, VertexComponent c) { VertexFormat r = f;