]> git.tdb.fi Git - libs/gl.git/commitdiff
Update Object's bounding sphere when mesh is loaded
authorMikko Rasa <tdb@tdb.fi>
Wed, 24 Sep 2014 17:34:24 +0000 (20:34 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 26 Sep 2014 10:24:20 +0000 (13:24 +0300)
source/object.cpp
source/object.h
source/resource.h

index 637af62a3753becb9407e346fb471bad9213f94a..efd84db89168b85598b278f79147b70214eee493 100644 (file)
@@ -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<Object>(o, 0)
index 82e12f14461f0b0b54d03fb3b83ab8b4a62c0c28..f432177e7ebfd7cb221491d58ce35543af66f989 100644 (file)
@@ -5,6 +5,7 @@
 #include "bindable.h"
 #include "renderable.h"
 #include "renderpass.h"
+#include "resourcewatcher.h"
 
 namespace Msp {
 namespace GL {
@@ -23,7 +24,7 @@ In many cases, it's desirable to include multiple copies of an Object in a
 Scene, with different model matrices.  ObjectInstances can be used to alter the
 rendering of an object on a per-instance basis.
 */
-class Object: public Renderable
+class Object: public Renderable, private ResourceWatcher
 {
 public:
        class Loader: public DataFile::CollectionObjectLoader<Object>
@@ -78,6 +79,8 @@ protected:
 
 private:
        const RenderPass *get_pass(const Tag &) const;
+
+       virtual void resource_loaded(Resource &);
 };
 
 } // namespace GL
index b3bce17e32cf86b95b1ba3914dd0ab8ab1d72d40..0ecba526ef956e7da5e701d67df007dba13989c2 100644 (file)
@@ -32,6 +32,7 @@ public:
        virtual ~Resource();
 
        void set_manager(ResourceManager *);
+       ResourceManager *get_manager() const { return manager; }
        void *get_manager_data() const { return manager_data; }
        virtual AsyncLoader *load(IO::Seekable &) = 0;
        virtual UInt64 get_data_size() const = 0;