]> git.tdb.fi Git - libs/gl.git/blobdiff - source/vertexformat.cpp
Support multiple sets of texture coordinates in VertexArrays
[libs/gl.git] / source / vertexformat.cpp
index e56397e2b088cb93a1204d80027ef875b1c91a73..dc8ff23eeaa2a7b52f194ef72c94a11c705d5f77 100644 (file)
@@ -31,7 +31,7 @@ VertexFormat::VertexFormat(const VertexFormat &f):
 {
        if(f.data)
        {
-               data = new unsigned char[f.data[0]/8+8];
+               data = new unsigned char[(f.data[0]&~7)+8];
                memcpy(data, f.data, f.data[0]+1);
        }
 }
@@ -41,7 +41,7 @@ VertexFormat &VertexFormat::operator=(const VertexFormat &f)
        delete[] data;
        if(f.data)
        {
-               data = new unsigned char[f.data[0]/8+8];
+               data = new unsigned char[(f.data[0]&~7)+8];
                memcpy(data, f.data, f.data[0]+1);
        }
        else
@@ -94,11 +94,8 @@ VertexFormat operator,(const VertexFormat &f, unsigned i)
                throw InvalidState("VertexFormat has no components");
        VertexFormat r = f;
        unsigned char *c = r.data+r.data[0];
-       if(*c<ATTRIB1)
-               throw InvalidState("Last component is not a generic attribute");
-       // VertexArray uses an unsigned to store flags for enabled arrays
-       if(i>=28)
-               throw InvalidParameterValue("Generic attribute index out of range");
+       if((*c<TEXCOORD1 && i>0) || (*c<ATTRIB1 && i>=8) || i>=53)
+               throw InvalidParameterValue("Vertex component index out of range");
        *c += i*4;
 
        return r;