X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fprimitivebuilder.cpp;fp=source%2Fprimitivebuilder.cpp;h=ca8f4f3c5343ff973aef0ab1e33173b5d6e4adc4;hp=0000000000000000000000000000000000000000;hb=d1800d7ea80290f4913d0203241cef1409656522;hpb=a80b074c70ec991f27114efd13686038cf42c493 diff --git a/source/primitivebuilder.cpp b/source/primitivebuilder.cpp new file mode 100644 index 00000000..ca8f4f3c --- /dev/null +++ b/source/primitivebuilder.cpp @@ -0,0 +1,60 @@ +/* $Id$ + +This file is part of libmspgl +Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#include "primitivebuilder.h" + +namespace Msp { +namespace GL { + +PrimitiveBuilder::PrimitiveBuilder(VertexArray &a): + array(a), + in_batch(false) +{ } + +void PrimitiveBuilder::begin(PrimitiveType t) +{ + if(in_batch) + throw InvalidState("begin() already called"); + + type=t; + in_batch=true; + builder=array.modify(); + + begin_(); +} + +void PrimitiveBuilder::end() +{ + if(in_batch) + throw InvalidState("end() called without begin()"); + + builder=0; + in_batch=false; + + end_(); +} + +PrimitiveType PrimitiveBuilder::get_type() const +{ + if(!in_batch) + throw InvalidState("Not between begin() and end()"); + return type; +} + +void PrimitiveBuilder::vertex_(float x, float y, float z, float w) +{ + if(!in_batch) + throw InvalidState("Vertex specification not between begin() and end()"); + + builder->texcoord(ts, tt, tr,tq); + builder->color(cr, cg, cb, ca); + builder->normal(nx, ny, nz); + builder->vertex(x, y, z, w); +} + +} // namespace GL +} // namespace Msp