]> git.tdb.fi Git - libs/gl.git/blobdiff - source/vertexformat.cpp
Drop Id tags and copyright notices from files
[libs/gl.git] / source / vertexformat.cpp
index 2b18178b26db4734bcc3e3f673abb32324a10779..f5e175714187a9eb5a853abc9ba84aa3728864a9 100644 (file)
@@ -1,10 +1,3 @@
-/* $Id$
-
-This file is part of libmspgl
-Copyright © 2007-2010  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include <cstring>
 #include <msp/strings/lexicalcast.h>
 #include <msp/strings/utils.h>
@@ -64,6 +57,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(static_cast<unsigned>(*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;