]> git.tdb.fi Git - libs/gl.git/commitdiff
Add a method to get the offset of a single component of a VertexFormat
authorMikko Rasa <tdb@tdb.fi>
Mon, 4 Apr 2011 16:44:40 +0000 (16:44 +0000)
committerMikko Rasa <tdb@tdb.fi>
Mon, 4 Apr 2011 16:44:40 +0000 (16:44 +0000)
source/vertexformat.cpp
source/vertexformat.h

index 2b18178b26db4734bcc3e3f673abb32324a10779..adb33c2afa48178d794a0476263a8d029f8519ac 100644 (file)
@@ -64,6 +64,30 @@ unsigned VertexFormat::stride() const
        return s;
 }
 
+int VertexFormat::offset(VertexComponent comp, unsigned index) const
+{
+       if((comp<TEXCOORD1 && index>0) || (comp<ATTRIB1 && index>=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;
index 53562ef922ba3ccf4bc1cf44ffb5feeef3691f3d..27033200f634ac00c2ba5c6fe7d89eebc5d9160d 100644 (file)
@@ -46,6 +46,7 @@ struct VertexFormat
        const unsigned char *begin() const { return data ? data+1 : 0; }
        const unsigned char *end() const { return data ? data+1+data[0] : 0; }
        unsigned stride() const;
+       int offset(VertexComponent, unsigned = 0) const;
 };
 
 VertexFormat operator,(const VertexFormat &f, VertexComponent c);