From: Mikko Rasa Date: Fri, 8 Apr 2011 22:56:45 +0000 (+0000) Subject: Add an element offset to PrimitiveBuilder X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=df6f8f1f26b1f230dcb1d626d278c43fd48d468d;p=libs%2Fgl.git Add an element offset to PrimitiveBuilder --- diff --git a/source/geometrybuilder.cpp b/source/geometrybuilder.cpp index 6ed52ed2..327e8fcf 100644 --- a/source/geometrybuilder.cpp +++ b/source/geometrybuilder.cpp @@ -49,6 +49,7 @@ void GeometryBuilder::adjust_texture_scale(float &u_scale, float &v_scale, float void GeometryBuilder::build(Mesh &mesh) const { MeshBuilder builder(mesh); + builder.auto_offset(); build(builder); } diff --git a/source/meshbuilder.cpp b/source/meshbuilder.cpp index b238ae63..6f90f67d 100644 --- a/source/meshbuilder.cpp +++ b/source/meshbuilder.cpp @@ -1,7 +1,7 @@ /* $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 */ @@ -17,6 +17,11 @@ MeshBuilder::MeshBuilder(Mesh &m): batch(0) { } +void MeshBuilder::auto_offset() +{ + offset(mesh.get_vertices().size()); +} + void MeshBuilder::begin_() { batch = new Batch(type); diff --git a/source/meshbuilder.h b/source/meshbuilder.h index c8354b9e..6118c686 100644 --- a/source/meshbuilder.h +++ b/source/meshbuilder.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2008, 2011 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -24,6 +24,7 @@ private: public: MeshBuilder(Mesh &); + void auto_offset(); private: virtual void begin_(); virtual void end_(); diff --git a/source/primitivebuilder.cpp b/source/primitivebuilder.cpp index 42e9d39c..61bde9b9 100644 --- a/source/primitivebuilder.cpp +++ b/source/primitivebuilder.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of libmspgl -Copyright © 2008, 2010 Mikko Rasa, Mikkosoft Productions +Copyright © 2008, 2010-2011 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -13,7 +13,8 @@ namespace GL { PrimitiveBuilder::PrimitiveBuilder(VertexArray &a): array(a), vab(array), - in_batch(false) + in_batch(false), + offs(0) { } void PrimitiveBuilder::begin(PrimitiveType t) @@ -37,13 +38,20 @@ void PrimitiveBuilder::end() 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 diff --git a/source/primitivebuilder.h b/source/primitivebuilder.h index a4e34a67..b8b90f44 100644 --- a/source/primitivebuilder.h +++ b/source/primitivebuilder.h @@ -1,7 +1,7 @@ /* $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 */ @@ -30,11 +30,13 @@ protected: VertexArrayBuilder vab; PrimitiveType type; bool in_batch; + unsigned offs; PrimitiveBuilder(VertexArray &); public: void begin(PrimitiveType); void end(); + void offset(unsigned); void element(unsigned); PrimitiveType get_type() const; protected: