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((comp<TEXCOORD1 && index>0) || (comp<ATTRIB1 && index>=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];
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((*c<TEXCOORD1 && i>0) || (*c<ATTRIB1 && i>=8) || i>=53)
throw invalid_argument("VertexFormat::operator,");
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((comp<TEXCOORD1 && index>0) || (comp<ATTRIB1 && index>=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();
ATTRIB4
};
-struct VertexFormat
+class VertexFormat
{
+private:
unsigned char *data;
+public:
VertexFormat();
VertexFormat(VertexComponent);
VertexFormat(const VertexFormat &);
VertexFormat &operator=(const VertexFormat &);
~VertexFormat();
+ VertexFormat operator,(VertexComponent c) const;
+ VertexFormat operator,(unsigned i) const;
+
bool empty() const { return !data || !data[0]; }
const unsigned char *begin() const { return data ? data+1 : 0; }
const unsigned char *end() const { return data ? data+1+data[0] : 0; }
int offset(VertexComponent, unsigned = 0) const;
};
-VertexFormat operator,(const VertexFormat &f, VertexComponent c);
inline VertexFormat operator,(VertexComponent c1, VertexComponent c2)
{ return (VertexFormat(c1), c2); }
-VertexFormat operator,(const VertexFormat &f, unsigned i);
inline VertexFormat operator,(VertexComponent c, unsigned i)
{ return (VertexFormat(c), i); }