X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fcore%2Fvertexformat.cpp;fp=source%2Fcore%2Fvertexformat.cpp;h=5d026e2ebbbfa919e6aa0369ed19d07f867b278e;hp=05364be81ae8075c55102c29c2d0c892fb9094c3;hb=68b74ce23dd20822b07d79dc25aa0a0a19ef27a5;hpb=ea7832c7c1ffab00cc1168bc8c41375fdd0eae86 diff --git a/source/core/vertexformat.cpp b/source/core/vertexformat.cpp index 05364be8..5d026e2e 100644 --- a/source/core/vertexformat.cpp +++ b/source/core/vertexformat.cpp @@ -3,7 +3,9 @@ #include #include #include "error.h" +#include "misc.h" #include "vertexformat.h" +#include using namespace std; @@ -82,19 +84,25 @@ int VertexFormat::offset(VertexAttribute attr) const VertexAttribute make_indexed_attribute(VertexAttribute attr, unsigned index) { + unsigned base = attr; if(attr>=TEXCOORD1 && attr<=TEXCOORD4) { if(index>=4) throw out_of_range("make_indexed_attribute"); } - else if(attr>=ATTRIB1 && attr<=ATTRIB4) - { - if(index>=24) - throw out_of_range("make_indexed_attribute"); - } - else + else if(attr>=RAW_ATTRIB1 && attr<=RAW_ATTRIB4) + base &= 7; + else if(attrGENERIC4) throw invalid_argument("make_indexed_attribute"); - return static_cast(attr+index*4); + + static int max_attribs = -1; + if(max_attribs<0) + max_attribs = get_i(GL_MAX_VERTEX_ATTRIBS); + + if(static_cast((base>>3)+index)>=max_attribs) + throw out_of_range("make_indexed_attribute"); + + return static_cast(base+index*8); } void operator>>(const LexicalConverter &conv, VertexAttribute &a) @@ -116,23 +124,23 @@ void operator>>(const LexicalConverter &conv, VertexAttribute &a) { if(str.size()==9) a = static_cast(TEXCOORD1+(str[8]-'1')); - else if(str.size()==11 && str[9]=='_' && str[10]>='0' && str[10]<='7') - a = static_cast(TEXCOORD1+(str[8]-'1')+(str[10]-'0')*4); + else if(str.size()==11 && str[9]=='_' && str[10]>='0' && str[10]<='3') + a = make_indexed_attribute(static_cast(TEXCOORD1+(str[8]-'1')), str[10]-'0'); else throw lexical_error(format("conversion of '%s' to VertexAttribute", str)); } - else if(str.size()>=9 && !str.compare(0, 6, "ATTRIB") && str[6]>='1' && str[6]<='4' && str[7]=='_') + else if(str.size()>=10 && !str.compare(0, 6, "GENERIC") && str[7]>='1' && str[7]<='4' && str[8]=='_') { unsigned n; try { - n = lexical_cast(str.substr(8)); + n = lexical_cast(str.substr(9)); } catch(const lexical_error &) { throw lexical_error(format("conversion of '%s' to VertexAttribute", str)); } - a = static_cast(ATTRIB1+(str[6]-'1')+n*4); + a = make_indexed_attribute(static_cast(GENERIC1+(str[7]-'1')), n); } else throw lexical_error(format("conversion of '%s' to VertexAttribute", str));