]> git.tdb.fi Git - libs/gl.git/blobdiff - source/vertexformat.cpp
Helper functions for extracting vertex component type and size
[libs/gl.git] / source / vertexformat.cpp
index e3f8bf97a5c49e5fe245975d09308de0e57295c9..02410857bff6e8873570055499b4be71800a6c02 100644 (file)
@@ -54,7 +54,7 @@ unsigned VertexFormat::stride() const
 {
        unsigned s = 0;
        for(const unsigned char *i=begin(); i!=end(); ++i)
-               s += (*i&3)+1;
+               s += get_component_size(*i);
        return s;
 }
 
@@ -63,20 +63,20 @@ int VertexFormat::offset(VertexComponent comp, unsigned index) const
        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;