X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fobject.cpp;fp=source%2Fobject.cpp;h=efd84db89168b85598b278f79147b70214eee493;hp=637af62a3753becb9407e346fb471bad9213f94a;hb=e2765175f4a083623c1a9549695140ca902ce0b2;hpb=3c09b67afba6d560eab5817016a98268e1544bc4 diff --git a/source/object.cpp b/source/object.cpp index 637af62a..efd84db8 100644 --- a/source/object.cpp +++ b/source/object.cpp @@ -7,6 +7,7 @@ #include "program.h" #include "programdata.h" #include "renderer.h" +#include "resourcemanager.h" #include "technique.h" #include "texturing.h" @@ -27,7 +28,11 @@ Object::Object(const Mesh *m, const Technique *t) // Avoid synthesizing ~RefPtr in files including object.h Object::~Object() -{ } +{ + if(meshes[0]) + if(ResourceManager *rm = meshes[0]->get_manager()) + rm->unwatch_resource(*meshes[0], *this); +} void Object::set_mesh(unsigned i, const Mesh *m) { @@ -37,8 +42,17 @@ void Object::set_mesh(unsigned i, const Mesh *m) if(i==meshes.size()) meshes.push_back(m); else + { + if(i==0 && meshes[i]) + if(ResourceManager *rm = meshes[i]->get_manager()) + rm->unwatch_resource(*meshes[i], *this); meshes[i] = m; + } meshes[i].keep(); + + if(i==0 && m) + if(ResourceManager *rm = m->get_manager()) + rm->watch_resource(*m, *this); } void Object::update_bounding_sphere() @@ -136,6 +150,12 @@ const RenderPass *Object::get_pass(const Tag &tag) const return &technique->get_pass(tag); } +void Object::resource_loaded(Resource &res) +{ + if(!meshes.empty() && &res==meshes.front().get() && bounding_sphere.is_empty()) + update_bounding_sphere(); +} + Object::Loader::Loader(Object &o): DataFile::CollectionObjectLoader(o, 0)