]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/vertexformat.cpp
Use C++11 features with containers
[libs/gl.git] / source / core / vertexformat.cpp
index 5d0b078fe06f154b2821ab176a2bf9310132c253..3d15705a01765c18abe9244dbd8ae0f39261f357 100644 (file)
@@ -97,6 +97,8 @@ VertexAttribute make_typed_attribute(VertexAttribute attr, DataType type)
 {
        if(is_matrix(type) || is_vector(type) || is_image(type))
                throw invalid_argument("make_typed_attribute");
+       if(is_integer_attribute(attr) && is_float(type))
+               throw invalid_argument("make_typed_attribute");
 
        return static_cast<VertexAttribute>((attr&0xFC0F) | (type&0x0F)<<4 | (type&0x300)>>1);
 }
@@ -123,7 +125,7 @@ VertexAttribute make_indexed_attribute(VertexAttribute attr, unsigned index)
 
 bool convert_attribute_type(string::const_iterator &i, string::const_iterator end, const char *name, VertexAttribute &attr, DataType type)
 {
-       string::const_iterator j = i;
+       auto j = i;
        for(; (j!=end && *j!='_' && *name); ++name, ++j)
                if(*j!=*name)
                        return false;
@@ -136,13 +138,23 @@ bool convert_attribute_type(string::const_iterator &i, string::const_iterator en
 
 bool convert_attribute(const string &str, const char *name, int min_size, int max_size, VertexAttribute &attr, VertexAttribute base_attr)
 {
-       string::const_iterator i = str.begin();
+       auto i = str.begin();
        for(; *name; ++name, ++i)
                if(*i!=*name)
                        return false;
+
+       VertexAttribute result = base_attr;
+
+       if(i!=str.end() && *i=='_')
+       {
+               if(*(++i)++!='I')
+                       return false;
+               result = static_cast<VertexAttribute>(result|8);
+       }
+
        if(i==str.end() || *i<'0'+min_size || *i>'0'+max_size)
                return false;
-       VertexAttribute result = static_cast<VertexAttribute>(base_attr+(*i++-'0'-min_size));
+       result = static_cast<VertexAttribute>(result+(*i++-'0'-min_size));
 
        while(i!=str.end())
        {