X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fvertexformat.cpp;h=65b276baa7115e5c5482fc0b39ac0a1ed4f85cb4;hb=ba5c731b8aa6430bb10e38848d42d8bfb59694a6;hp=02410857bff6e8873570055499b4be71800a6c02;hpb=e06ee659c66c92065dbd767475ac9bf9f0f14846;p=libs%2Fgl.git diff --git a/source/vertexformat.cpp b/source/vertexformat.cpp index 02410857..65b276ba 100644 --- a/source/vertexformat.cpp +++ b/source/vertexformat.cpp @@ -50,41 +50,9 @@ VertexFormat::~VertexFormat() delete[] data; } -unsigned VertexFormat::stride() const -{ - unsigned s = 0; - for(const unsigned char *i=begin(); i!=end(); ++i) - s += get_component_size(*i); - return s; -} - -int VertexFormat::offset(VertexComponent comp, unsigned index) const -{ - if((comp0) || (comp=8) || index>=53) - throw out_of_range("VertexFormat::offset"); - - 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(get_component_type(*i)==type) - { - if(get_component_size(*i)>=size) - return offs; - else - return -1; - } - else - offs += get_component_size(*i); - } - - return -1; -} - -VertexFormat operator,(const VertexFormat &f, VertexComponent c) +VertexFormat VertexFormat::operator,(VertexComponent c) const { - VertexFormat r = f; + VertexFormat r = *this; if(r.data) { const unsigned char n = ++r.data[0]; @@ -107,11 +75,11 @@ VertexFormat operator,(const VertexFormat &f, VertexComponent c) return r; } -VertexFormat operator,(const VertexFormat &f, unsigned i) +VertexFormat VertexFormat::operator,(unsigned i) const { - if(!f.data) + if(!data) throw invalid_operation("VertexFormat::operator,"); - VertexFormat r = f; + VertexFormat r = *this; unsigned char *c = r.data+r.data[0]; if((*c0) || (*c=8) || i>=53) throw invalid_argument("VertexFormat::operator,"); @@ -120,6 +88,38 @@ VertexFormat operator,(const VertexFormat &f, unsigned i) return r; } +unsigned VertexFormat::stride() const +{ + unsigned s = 0; + for(const unsigned char *i=begin(); i!=end(); ++i) + s += get_component_size(*i); + return s; +} + +int VertexFormat::offset(VertexComponent comp, unsigned index) const +{ + if((comp0) || (comp=8) || index>=53) + throw out_of_range("VertexFormat::offset"); + + 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(get_component_type(*i)==type) + { + if(get_component_size(*i)>=size) + return offs; + else + return -1; + } + else + offs += get_component_size(*i); + } + + return -1; +} + void operator>>(const LexicalConverter &conv, VertexComponent &c) { const string &str = conv.get();