X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fobject.cpp;h=0a03b7a81a151da82ac76c41e04159e23fc4a963;hb=ceae2a27dfc58310c5bab7e3aa3fedf0fa9a1f49;hp=edfe39e56008e580e85b292c7508395260de9e71;hpb=97015ec7bddd26aa746f5227e4109b7d32438cca;p=libs%2Fgl.git diff --git a/source/object.cpp b/source/object.cpp index edfe39e5..0a03b7a8 100644 --- a/source/object.cpp +++ b/source/object.cpp @@ -12,7 +12,6 @@ Distributed under the LGPL #include "mesh.h" #include "object.h" #include "objectinstance.h" -#include "objectpass.h" #include "program.h" #include "programdata.h" #include "technique.h" @@ -26,14 +25,17 @@ namespace GL { Object::Object(): meshes(1), - own_technique(false), - technique(0) + technique(0), + own_mesh(false), + own_technique(false) { } Object::~Object() { if(own_technique) delete technique; + if(own_mesh) + delete meshes[0]; } void Object::render(const Tag &tag) const @@ -73,11 +75,25 @@ void Object::render_instance(const ObjectInstance &inst, const Tag &tag) const } +Object::Loader::Loader(Object &o): + DataFile::CollectionObjectLoader(o, 0) +{ + init(); +} + Object::Loader::Loader(Object &o, Collection &c): DataFile::CollectionObjectLoader(o, &c) { + init(); +} + +void Object::Loader::init() +{ + allow_pointer_reload=false; + add("lod_mesh", &Loader::lod_mesh); - add("mesh", &Loader::mesh); + add("mesh", static_cast(&Loader::mesh)); + add("mesh", static_cast(&Loader::mesh)); add("technique", &Loader::technique); add("technique", &Object::technique); } @@ -88,8 +104,22 @@ void Object::Loader::lod_mesh(unsigned l, const string &n) obj.meshes[l]=get_collection().get(n); } -void Object::Loader::mesh(const string &n) +void Object::Loader::mesh() +{ + if(obj.meshes[0]) + throw InvalidState("A mesh is already loaded"); + + RefPtr msh=new Mesh; + load_sub(*msh); + obj.meshes[0]=msh.release(); + obj.own_mesh=true; +} + +void Object::Loader::mesh(const std::string &n) { + if(obj.meshes[0]) + throw InvalidState("A mesh is already loaded"); + obj.meshes[0]=get_collection().get(n); }