X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fprimitivebuilder.cpp;h=dd869908d9240df76b2f48a2308a0396613a35ad;hp=e461cf211bf77f2fe79b7f25b67a579c2d99fca3;hb=d713e5391dc5d85759c7aab36f6df7a85c3d8eff;hpb=c2c33868bacd86f124cc61e35cd6690ee8181ca7 diff --git a/source/primitivebuilder.cpp b/source/primitivebuilder.cpp index e461cf21..dd869908 100644 --- a/source/primitivebuilder.cpp +++ b/source/primitivebuilder.cpp @@ -1,28 +1,25 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - +#include "error.h" #include "primitivebuilder.h" +using namespace std; + namespace Msp { namespace GL { PrimitiveBuilder::PrimitiveBuilder(VertexArray &a): array(a), - in_batch(false) + vab(array), + in_batch(false), + offs(0) { } void PrimitiveBuilder::begin(PrimitiveType t) { if(in_batch) - throw InvalidState("begin() already called"); + throw invalid_operation("PrimitiveBuilder::begin"); - type=t; - in_batch=true; - builder=array.modify(); + type = t; + in_batch = true; begin_(); } @@ -30,30 +27,48 @@ void PrimitiveBuilder::begin(PrimitiveType t) void PrimitiveBuilder::end() { if(!in_batch) - throw InvalidState("end() called without begin()"); + throw invalid_operation("PrimitiveBuilder::end"); - builder=0; - in_batch=false; + in_batch = false; end_(); } +void PrimitiveBuilder::offset(unsigned o) +{ + if(o>array.size()) + throw out_of_range("PrimitiveBuilder::offset"); + offs = o; +} + +void PrimitiveBuilder::element(unsigned i) +{ + if(!in_batch) + throw invalid_operation("PrimitiveBuilder::element"); + if(offs+i>=array.size()) + throw out_of_range("PrimitiveBuilder::element"); + element_(offs+i); +} + PrimitiveType PrimitiveBuilder::get_type() const { if(!in_batch) - throw InvalidState("Not between begin() and end()"); + throw invalid_operation("PrimitiveBuilder::get_type"); return type; } -void PrimitiveBuilder::vertex_(float x, float y, float z, float w) +void PrimitiveBuilder::vertex_(const Vector4 &v) { - if(!in_batch) - throw InvalidState("Vertex specification not between begin() and end()"); + vab.color(col); + vab.normal(nor); + for(std::map::iterator i=texc.begin(); i!=texc.end(); ++i) + vab.multitexcoord(i->first, i->second); + for(std::map::iterator i=attr.begin(); i!=attr.end(); ++i) + vab.attrib(i->first, i->second); + vab.vertex(v); - builder->texcoord(ts, tt, tr,tq); - builder->color(cr, cg, cb, ca); - builder->normal(nx, ny, nz); - builder->vertex(x, y, z, w); + if(in_batch) + element_(array.size()-1); } } // namespace GL