/* $Id$
This file is part of libmspgl
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2008, 2010-2011 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
PrimitiveBuilder::PrimitiveBuilder(VertexArray &a):
array(a),
vab(array),
- in_batch(false)
+ in_batch(false),
+ offs(0)
{ }
void PrimitiveBuilder::begin(PrimitiveType t)
if(in_batch)
throw InvalidState("begin() already called");
- type=t;
- in_batch=true;
+ type = t;
+ in_batch = true;
begin_();
}
if(!in_batch)
throw InvalidState("end() called without begin()");
- in_batch=false;
+ in_batch = false;
end_();
}
+void PrimitiveBuilder::offset(unsigned o)
+{
+ if(o>array.size())
+ throw InvalidParameterValue("Element offset out of range");
+ offs = o;
+}
+
void PrimitiveBuilder::element(unsigned i)
{
if(!in_batch)
throw InvalidState("Element specification not between begin() and end()");
- if(i>=array.size())
+ if(offs+i>=array.size())
throw InvalidParameterValue("Element index out of range");
- element_(i);
+ element_(offs+i);
}
PrimitiveType PrimitiveBuilder::get_type() const
return type;
}
-void PrimitiveBuilder::vertex_(float x, float y, float z, float w)
+void PrimitiveBuilder::vertex_(const Vector4 &v)
{
- vab.texcoord(ts, tt, tr,tq);
- vab.color(cr, cg, cb, ca);
- vab.normal(nx, ny, nz);
- vab.vertex(x, y, z, w);
+ vab.color(col);
+ vab.normal(nor);
+ for(std::map<unsigned, Vector4>::iterator i=texc.begin(); i!=texc.end(); ++i)
+ vab.multitexcoord(i->first, i->second);
+ for(std::map<unsigned, Vector4>::iterator i=attr.begin(); i!=attr.end(); ++i)
+ vab.attrib(i->first, i->second);
+ vab.vertex(v);
if(in_batch)
element_(array.size()-1);