]> git.tdb.fi Git - libs/gl.git/commitdiff
Add inline data items to the collection
authorMikko Rasa <tdb@tdb.fi>
Sun, 9 May 2021 10:53:13 +0000 (13:53 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 9 May 2021 10:53:13 +0000 (13:53 +0300)
This simplifies the internals of various objects and does away with
the special keep() semantic of RefPtr.

Blend and DepthTest will be handled separately as part of rendering
state rework.

21 files changed:
source/animation/animation.cpp
source/animation/animation.h
source/animation/keyframe.cpp
source/animation/keyframe.h
source/builders/font.cpp
source/builders/font.h
source/builders/sequencebuilder.cpp
source/builders/sequencetemplate.cpp
source/builders/sequencetemplate.h
source/materials/lighting.cpp
source/materials/lighting.h
source/materials/renderpass.cpp
source/materials/renderpass.h
source/materials/technique.cpp
source/materials/technique.h
source/render/object.cpp
source/render/object.h
source/render/scene.cpp
source/render/scene.h
source/render/sequence.cpp
source/render/sequence.h

index a8d9e9698625b027997586745cd71b9c73c1d305..b62f5dd9c74e035ed7fe0ab39ef69c46b3cbf714 100644 (file)
@@ -1,7 +1,9 @@
 #include <cmath>
 #include <msp/core/maputils.h>
 #include <msp/datafile/collection.h>
+#include <msp/fs/utils.h>
 #include <msp/interpolate/bezierspline.h>
+#include <msp/strings/format.h>
 #include "animation.h"
 #include "animationeventobserver.h"
 #include "armature.h"
@@ -20,6 +22,9 @@ Animation::Animation():
 
 Animation::~Animation()
 {
+       for(vector<TimedKeyFrame>::iterator i=keyframes.begin(); i!=keyframes.end(); ++i)
+               if(i->owned)
+                       delete i->keyframe;
        for(vector<Curve *>::iterator i=curves.begin(); i!=curves.end(); ++i)
                delete *i;
 }
@@ -155,9 +160,8 @@ void Animation::add_keyframe(const Time::TimeDelta &t, const KeyFrame *kf, bool
        TimedKeyFrame tkf;
        tkf.time = t;
        tkf.keyframe = kf;
-       if(!owned)
-               tkf.keyframe.keep();
        tkf.control = c;
+       tkf.owned = owned;
 
        keyframes.push_back(tkf);
 
@@ -553,7 +557,11 @@ void Animation::Loader::load_kf_inline(bool c)
 {
        RefPtr<KeyFrame> kf = new KeyFrame;
        if(coll)
-               load_sub(*kf, get_collection());
+       {
+               KeyFrame::Loader ldr(*kf, get_collection());
+               ldr.set_inline_base_name(format("%s/%d.kframe", FS::basename(get_source()), obj.keyframes.size()));
+               load_sub_with(ldr);
+       }
        else
                load_sub(*kf);
 
index 6845d23ee3e1652c9f7e49a86e5145f3faa6aa52..3d247cf5f74bc0821481fc9a2cdbf10f24a0e8ca 100644 (file)
@@ -121,8 +121,9 @@ private:
        struct TimedKeyFrame
        {
                Time::TimeDelta time;
-               RefPtr<const KeyFrame> keyframe;
+               const KeyFrame *keyframe;
                bool control;
+               bool owned;
        };
 
        struct Event
index f610de2d42afbd08dd118cf97e7f54afa75da7de..6cb8ce6ad1b5d9d5260115bae32821f62961c426 100644 (file)
@@ -1,4 +1,5 @@
 #include <msp/datafile/collection.h>
+#include <msp/fs/utils.h>
 #include "keyframe.h"
 #include "pose.h"
 
@@ -33,7 +34,6 @@ void KeyFrame::set_uniform(const string &n, const AnimatedUniform &u)
 void KeyFrame::set_pose(const Pose &p)
 {
        pose = &p;
-       pose.keep();
 }
 
 
@@ -73,17 +73,22 @@ void KeyFrame::Loader::init()
        add("scaling", &Loader::scaling);
 }
 
+void KeyFrame::Loader::set_inline_base_name(const string &n)
+{
+       inline_base_name = n;
+}
+
 void KeyFrame::Loader::pose(const string &n)
 {
        obj.pose = &get_collection().get<Pose>(n);
-       obj.pose.keep();
 }
 
 void KeyFrame::Loader::pose_inline()
 {
        RefPtr<Pose> p = new Pose;
        load_sub(*p, get_collection());
-       obj.pose = p;
+       get_collection().add((inline_base_name.empty() ? FS::basename(get_source()) : inline_base_name)+".pose", p.get());
+       obj.pose = p.release();
 }
 
 void KeyFrame::Loader::position(float x, float y, float z)
index 5b748add113c5432c0d3c5836e6fceaf4db8b590..7a96447e656d5ef533a381b099a9e39e17abc44d 100644 (file)
@@ -19,12 +19,19 @@ class KeyFrame
 public:
        class Loader: public DataFile::CollectionObjectLoader<KeyFrame>
        {
+       private:
+               std::string inline_base_name;
+
        public:
                Loader(KeyFrame &);
                Loader(KeyFrame &, Collection &);
        private:
                void init();
 
+       public:
+               void set_inline_base_name(const std::string &);
+
+       private:
                void pose(const std::string &);
                void pose_inline();
                void position(float, float, float);
@@ -60,7 +67,7 @@ public:
 private:
        Transform transform;
        UniformMap uniforms;
-       RefPtr<const Pose> pose;
+       const Pose *pose;
 
 public:
        KeyFrame();
@@ -73,7 +80,7 @@ public:
        const Transform &get_transform() const { return transform; }
        Matrix get_matrix() const { return transform.to_matrix(); }
        const UniformMap &get_uniforms() const { return uniforms; }
-       const Pose *get_pose() const { return pose.get(); }
+       const Pose *get_pose() const { return pose; }
 };
 
 } // namespace GL
index 5990c57d7223771410edadcfb69a9df13ea39fe0..7281bf418aba8118ab479abf79778f542cb0fb4f 100644 (file)
@@ -1,5 +1,6 @@
 #include <msp/core/maputils.h>
 #include <msp/datafile/collection.h>
+#include <msp/fs/utils.h>
 #include "bindable.h"
 #include "gl.h"
 #include "font.h"
@@ -26,7 +27,6 @@ Font::~Font()
 void Font::set_texture(const Texture2D &t)
 {
        texture = &t;
-       texture.keep();
 }
 
 const Texture2D &Font::get_texture() const
@@ -193,13 +193,13 @@ void Font::Loader::texture()
 {
        RefPtr<Texture2D> tex = new Texture2D;
        load_sub(*tex);
-       obj.texture = tex;
+       get_collection().add(FS::basename(get_source())+".tex2d", tex.get());
+       obj.texture = tex.release();
 }
 
 void Font::Loader::texture_ref(const string &name)
 {
        obj.texture = &get_collection().get<Texture2D>(name);
-       obj.texture.keep();
 }
 
 
index 9f040dc99d0e45cc5ffdec41153dfc71e5149778..18c225c13a3dd0399f6f767b3f168a5588d76daa 100644 (file)
@@ -60,7 +60,7 @@ private:
        typedef std::map<CodePair, float> KerningMap;
        typedef std::map<CodePair, unsigned> LigatureMap;
 
-       RefPtr<const Texture2D> texture;
+       const Texture2D *texture;
        float native_size;
        float ascent;
        float descent;
index c45d0cc67c6b2b8ba03f6688aa5e6709bf890fb8..317b68846126b3330a5e5592dfbc3deee01cf2af 100644 (file)
@@ -53,7 +53,7 @@ void SequenceBuilder::build(Sequence &sequence) const
                Sequence::Step &step = sequence.add_step(i->tag, *renderable);
                step.set_blend(i->blend.get());
                step.set_depth_test(i->depth_test.get());
-               step.set_lighting(i->lighting.get());
+               step.set_lighting(i->lighting);
        }
 
        const SequenceTemplate::PostProcessorArray &postprocs = tmpl.get_postprocessors();
index d852643301fa0ecac87fe0114b514bbe4478b45e..3ad973139010ae60b6e5cc5d602a9a0e1aca8aef 100644 (file)
@@ -113,7 +113,11 @@ void SequenceTemplate::Loader::step_with_slot(const string &tag, const string &r
        stp.tag = tag;
        stp.slot_name = rend;
        if(coll)
-               load_sub(stp, *coll);
+       {
+               Step::Loader ldr(stp, *coll);
+               ldr.set_inline_base_name(format("%s/%d.step", get_source(), obj.steps.size()));
+               load_sub_with(ldr);
+       }
        else
                load_sub(stp);
 
@@ -145,6 +149,11 @@ void SequenceTemplate::Step::Loader::init()
        add("scene", &Loader::scene);
 }
 
+void SequenceTemplate::Step::Loader::set_inline_base_name(const string &n)
+{
+       inline_base_name = n;
+}
+
 void SequenceTemplate::Step::Loader::blend_predefined(const string &name)
 {
        const Blend *bln = 0;
@@ -187,13 +196,13 @@ void SequenceTemplate::Step::Loader::lighting_inline()
 {
        RefPtr<Lighting> lightn = new Lighting;
        load_sub(*lightn);
-       obj.lighting = lightn;
+       get_collection().add(inline_base_name+".lightn", lightn.get());
+       obj.lighting = lightn.release();
 }
 
 void SequenceTemplate::Step::Loader::lighting(const string &name)
 {
        obj.lighting = &get_collection().get<Lighting>(name);
-       obj.lighting.keep();
 }
 
 void SequenceTemplate::Step::Loader::object(const string &name)
index 4c195a000bc925983abdf885aace11d68e8dda4d..32736d8ee7645e255255d9275abb6156db354b1a 100644 (file)
@@ -64,12 +64,19 @@ public:
        {
                class Loader: public DataFile::CollectionObjectLoader<Step>
                {
+               private:
+                       std::string inline_base_name;
+
                public:
                        Loader(Step &);
                        Loader(Step &, Collection &);
                private:
                        void init();
 
+               public:
+                       void set_inline_base_name(const std::string &);
+
+               private:
                        void blend(BlendFactor, BlendFactor);
                        void blend_predefined(const std::string &);
                        void depth_test(Predicate);
@@ -81,7 +88,7 @@ public:
                };
 
                std::string tag;
-               RefPtr<Lighting> lighting;
+               const Lighting *lighting;
                RefPtr<const DepthTest> depth_test;
                RefPtr<const Blend> blend;
                std::string slot_name;
index 3bbc01a3fa8e4bd4d51fd0fafc924b95651b492d..699aabc02c7daa8679d60b2ab6fd8eaf8d99723b 100644 (file)
@@ -1,6 +1,7 @@
 #include <stdexcept>
 #include <cmath>
 #include <msp/core/algorithm.h>
+#include <msp/fs/utils.h>
 #include "error.h"
 #include "light.h"
 #include "lighting.h"
@@ -21,12 +22,6 @@ Lighting::Lighting():
        set_fog_density(0.0f);
 }
 
-Lighting::~Lighting()
-{
-       for(vector<Light *>::iterator i=owned_data.begin(); i!=owned_data.end(); ++i)
-               delete *i;
-}
-
 void Lighting::set_ambient(const Color &a)
 {
        ambient = a;
@@ -200,8 +195,8 @@ void Lighting::Loader::light_inline()
 {
        RefPtr<Light> lgt = new Light;
        load_sub(*lgt);
-       obj.attach(*lgt);
-       obj.owned_data.push_back(lgt.release());
+       get_collection().add(format("%s/%d.light", FS::basename(get_source()), obj.lights.size()), lgt.get());
+       obj.attach(*lgt.release());
 }
 
 void Lighting::Loader::light_inline_index(unsigned)
index a2f84c32e7105f5c189fb470410cf5d757794f7f..9fe37ca665e943f18c5afd51586b1a8679dcab80 100644 (file)
@@ -59,12 +59,10 @@ private:
        Color fog_color;
        float fog_density;
        std::vector<AttachedLight> lights;
-       std::vector<Light *> owned_data;
        mutable ProgramData shdata;
 
 public:
        Lighting();
-       ~Lighting();
 
        /** Sets the ambient lighting color.  Affects all surfaces in the scene. */
        void set_ambient(const Color &);
index 6e33b5d1f7256a638ab754267b0e010057e277ef..62056ff9f56c63f103edb920ee8b546c7b13fe91 100644 (file)
@@ -46,10 +46,9 @@ void RenderPass::maybe_create_material_shader()
                extra_spec["use_image_based_lighting"] = true;
 
        shprog = material->create_compatible_shader(extra_spec);
-       shprog.keep();
 
        if(shdata)
-               shdata = new ProgramData(*shdata, shprog.get());
+               shdata = new ProgramData(*shdata, shprog);
 
        shprog_from_material = true;
 }
@@ -57,7 +56,6 @@ void RenderPass::maybe_create_material_shader()
 void RenderPass::set_shader_program(const Program *prog, const ProgramData *data)
 {
        shprog = prog;
-       shprog.keep();
        shprog_from_material = false;
        shdata = (data ? new ProgramData(*data) : 0);
 }
@@ -73,7 +71,6 @@ Tag RenderPass::get_slotted_uniform_tag(Tag slot) const
 void RenderPass::set_material(const Material *mat)
 {
        material = mat;
-       material.keep();
        maybe_create_material_shader();
        set_material_textures();
 }
@@ -142,8 +139,8 @@ void RenderPass::apply(Renderer &renderer) const
 {
        for(vector<TextureSlot>::const_iterator i=textures.begin(); i!=textures.end(); ++i)
                renderer.set_texture(i->tag, i->texture, i->sampler);
-       renderer.set_material(material.get());
-       renderer.set_shader_program(shprog.get(), shdata.get());
+       renderer.set_material(material);
+       renderer.set_shader_program(shprog, shdata.get());
        renderer.set_reverse_winding(back_faces);
 }
 
@@ -192,6 +189,11 @@ void RenderPass::Loader::init_actions()
        add("texunit",  &Loader::texunit_named);
 }
 
+void RenderPass::Loader::set_inline_base_name(const string &n)
+{
+       inline_base_name = n;
+}
+
 void RenderPass::Loader::finish()
 {
        if(obj.material)
@@ -213,24 +215,24 @@ void RenderPass::Loader::material_inline()
 {
        Material::GenericLoader ldr(coll);
        load_sub_with(ldr);
-       obj.material = ldr.get_material();
+       RefPtr<Material> mat = ldr.get_material();
+       get_collection().add(inline_base_name+".mat", mat.get());
+       obj.material = mat.release();
        obj.set_material_textures();
 }
 
 void RenderPass::Loader::material(const string &name)
 {
        obj.material = &get_collection().get<Material>(name);
-       obj.material.keep();
        obj.set_material_textures();
 }
 
 void RenderPass::Loader::shader(const string &n)
 {
        obj.shprog = &get_collection().get<Program>(get_shader_name(n));
-       obj.shprog.keep();
        obj.shprog_from_material = false;
        if(obj.shdata)
-               obj.shdata = new ProgramData(*obj.shdata, obj.shprog.get());
+               obj.shdata = new ProgramData(*obj.shdata, obj.shprog);
 }
 
 void RenderPass::Loader::texture(const string &n)
@@ -280,7 +282,7 @@ void RenderPass::Loader::uniforms()
        if(!obj.shprog || obj.shprog_from_material)
                throw runtime_error("Shader is required for uniforms");
        if(!obj.shdata)
-               obj.shdata = new ProgramData(obj.shprog.get());
+               obj.shdata = new ProgramData(obj.shprog);
        else if(obj.shdata.refcount()>1)
                obj.shdata = new ProgramData(*obj.shdata);
        load_sub(*obj.shdata);
index de04461af05f3510f96630c23968773ab9ef19bb..d149a7d029dd17d552c862b35f5e5c3e98094b44 100644 (file)
@@ -25,14 +25,20 @@ public:
        class Loader: public DataFile::CollectionObjectLoader<RenderPass>
        {
        private:
+               std::string inline_base_name;
+
                static ActionMap shared_actions;
 
        public:
                Loader(RenderPass &);
                Loader(RenderPass &, Collection &);
-
        private:
                virtual void init_actions();
+       
+       public:
+               void set_inline_base_name(const std::string &);
+
+       private:
                virtual void finish();
 
                static std::string get_shader_name(const std::string &);
@@ -71,11 +77,11 @@ private:
                TextureSlot(Tag t): tag(t), texture(0), sampler(0) { }
        };
 
-       RefPtr<const Program> shprog;
+       const Program *shprog;
        bool shprog_from_material;
        RefPtr<ProgramData> shdata;
        std::map<Tag, Tag> uniform_slots;
-       RefPtr<const Material> material;
+       const Material *material;
        std::string material_slot;
        std::vector<TextureSlot> textures;
        bool back_faces;
@@ -91,11 +97,11 @@ private:
 
 public:
        void set_shader_program(const Program *, const ProgramData *);
-       const Program *get_shader_program() const { return shprog.get(); }
+       const Program *get_shader_program() const { return shprog; }
        const ProgramData *get_shader_data() const { return shdata.get(); }
        Tag get_slotted_uniform_tag(Tag) const;
        void set_material(const Material *);
-       const Material *get_material() const { return material.get(); }
+       const Material *get_material() const { return material; }
        const std::string &get_material_slot_name() const { return material_slot; }
        void set_texture(Tag, const Texture *, const Sampler * = 0);
        Tag get_texture_tag(const std::string &) const;
index b5ed6447c314c3e69be3bfe0fcb0c08be67cfc07..26a70a018dde6042ce7ddc5f8b21a2e942257ad5 100644 (file)
@@ -1,5 +1,6 @@
 #include <msp/core/refptr.h>
 #include <msp/datafile/collection.h>
+#include <msp/fs/utils.h>
 #include <msp/strings/format.h>
 #include "material.h"
 #include "program.h"
@@ -132,6 +133,11 @@ void Technique::Loader::init_actions()
        add("pass", &Loader::pass);
 }
 
+void Technique::Loader::set_inline_base_name(const string &n)
+{
+       inline_base_name = n;
+}
+
 void Technique::Loader::inherit(const string &n)
 {
        obj.passes = get_collection().get<Technique>(n).get_passes();
@@ -143,7 +149,11 @@ void Technique::Loader::pass(const string &n)
 {
        RenderPass p;
        if(coll)
-               load_sub(p, get_collection());
+       {
+               RenderPass::Loader ldr(p, get_collection());
+               ldr.set_inline_base_name(format("%s/%s.pass", (inline_base_name.empty() ? FS::basename(get_source()) : inline_base_name), n));
+               load_sub_with(ldr);
+       }
        else
                load_sub(p);
 
index 47a307c9af318b111ef2266b93fc9442ece058e1..a7999c0cf67652a140a219c24258e2a3e210ee39 100644 (file)
@@ -19,15 +19,20 @@ public:
        class Loader: public Msp::DataFile::CollectionObjectLoader<Technique>
        {
        private:
+               std::string inline_base_name;
+
                static ActionMap shared_actions;
 
        public:
                Loader(Technique &);
                Loader(Technique &, Collection &);
-
        private:
                virtual void init_actions();
 
+       public:
+               void set_inline_base_name(const std::string &);
+
+       private:
                void inherit(const std::string &);
                void pass(const std::string &);
        };
index 702faaf9217eb9b8ba1374c358f228c0952ccf68..caad3a0725caa8e1de4d18d7e27c985c351daac3 100644 (file)
@@ -1,4 +1,5 @@
 #include <msp/datafile/collection.h>
+#include <msp/fs/utils.h>
 #include <msp/strings/format.h>
 #include "error.h"
 #include "material.h"
@@ -56,12 +57,11 @@ Object::LevelOfDetail &Object::get_lod(unsigned i, const char *caller)
 
 void Object::set_mesh(unsigned i, const Mesh *m)
 {
-       RefPtr<const Mesh> &ptr = get_lod(i, "Object::set_mesh").mesh;
+       const Mesh *&ptr = get_lod(i, "Object::set_mesh").mesh;
        if(i==0 && ptr && lod0_watched)
                if(ResourceManager *rm = ptr->get_manager())
                        rm->unobserve_resource(*ptr, *this);
        ptr = m;
-       ptr.keep();
        lod0_watched = false;
 
        if(i==0 && m)
@@ -116,14 +116,12 @@ const Mesh *Object::get_mesh(unsigned i) const
        if(i>=lods.size())
                return 0;
 
-       return lods[i].mesh.get();
+       return lods[i].mesh;
 }
 
 void Object::set_technique(unsigned i, const Technique *t)
 {
-       RefPtr<const Technique> &ptr = get_lod(i, "Object::set_technique").technique;
-       ptr = t;
-       ptr.keep();
+       get_lod(i, "Object::set_technique").technique = t;
 }
 
 const Technique *Object::get_technique(unsigned i) const
@@ -131,7 +129,7 @@ const Technique *Object::get_technique(unsigned i) const
        if(i>=lods.size())
                return 0;
 
-       return lods[i].technique.get();
+       return lods[i].technique;
 }
 
 void Object::render(Renderer &renderer, Tag tag) const
@@ -140,7 +138,7 @@ void Object::render(Renderer &renderer, Tag tag) const
        if(!pass)
                return;
 
-       const Mesh *mesh = lods.front().mesh.get();
+       const Mesh *mesh = lods.front().mesh;
        if (!mesh)
                throw logic_error("no mesh");
 
@@ -159,7 +157,7 @@ void Object::render(Renderer &renderer, const ObjectInstance &inst, Tag tag) con
        if(!pass)
                return;
 
-       const Mesh *mesh = lods[lod].mesh.get();
+       const Mesh *mesh = lods[lod].mesh;
        if (!mesh)
                throw logic_error("no mesh");
 
@@ -175,7 +173,7 @@ void Object::render(Renderer &renderer, const ObjectInstance &inst, Tag tag) con
 
 const RenderPass *Object::get_pass(Tag tag, unsigned lod) const
 {
-       const Technique *tech = lods[lod].technique.get();
+       const Technique *tech = lods[lod].technique;
        if(!tech)
                throw logic_error("no technique");
        return tech->find_pass(tag);
@@ -183,13 +181,13 @@ const RenderPass *Object::get_pass(Tag tag, unsigned lod) const
 
 void Object::resource_loaded(Resource &res)
 {
-       if(&res==lods.front().mesh.get() && bounding_sphere.is_empty())
+       if(&res==lods.front().mesh && bounding_sphere.is_empty())
                update_bounding_sphere();
 }
 
 void Object::resource_removed(Resource &res)
 {
-       if(&res==lods.front().mesh.get())
+       if(&res==lods.front().mesh)
                lod0_watched = false;
 }
 
@@ -249,7 +247,8 @@ void Object::LodLoader::mesh_inline()
 {
        RefPtr<Mesh> msh = new Mesh;
        load_sub(*msh);
-       lod.mesh = msh;
+       get_collection().add(format("%s/lod%d.mesh", FS::basename(get_source()), index), msh.get());
+       lod.mesh = msh.release();
 }
 
 void Object::LodLoader::technique(const string &n)
@@ -260,11 +259,12 @@ void Object::LodLoader::technique(const string &n)
 void Object::LodLoader::technique_inline()
 {
        RefPtr<Technique> tech = new Technique;
-       if(coll)
-               load_sub(*tech, get_collection());
-       else
-               load_sub(*tech);
-       lod.technique = tech;
+       Technique::Loader ldr(*tech, get_collection());
+       string name = format("%s/lod%d.tech", FS::basename(get_source()), index);
+       ldr.set_inline_base_name(name);
+       load_sub(*tech, get_collection());
+       get_collection().add(name, tech.get());
+       lod.technique = tech.release();
 }
 
 } // namespace GL
index c97e951c16d04d7186d8c6bdeca2902041e05669..522d3adc335be01519e8c69df5a9a952c9b7129f 100644 (file)
@@ -66,8 +66,8 @@ public:
 private:
        struct LevelOfDetail
        {
-               RefPtr<const Mesh> mesh;
-               RefPtr<const Technique> technique;
+               const Mesh *mesh;
+               const Technique *technique;
        };
 
        std::vector<LevelOfDetail> lods;
index cec2683abd2f0303b0fe90e1b6d3fc7db90e6127..d916def84a95448a2dcababd938f3de16bc89322 100644 (file)
@@ -1,4 +1,5 @@
 #include <msp/datafile/collection.h>
+#include <msp/fs/utils.h>
 #include "camera.h"
 #include "objectinstance.h"
 #include "occludedscene.h"
@@ -13,12 +14,6 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-Scene::~Scene()
-{
-       for(vector<Renderable *>::iterator i=owned_data.begin(); i!=owned_data.end(); ++i)
-               delete *i;
-}
-
 bool Scene::setup_frustum(const Renderer &renderer) const
 {
        const Camera *camera = renderer.get_camera();
@@ -123,10 +118,10 @@ void Scene::Loader::object_tagged(const string &n, const string &t)
 {
        RefPtr<ObjectInstance> inst = new ObjectInstance(get_collection().get<GL::Object>(n));
        load_sub(*inst);
-       obj.add(*inst);
+       get_collection().add(format("%s/%d.inst", FS::basename(get_source()), inst_counter++), inst.get());
        if(content && !t.empty())
                (*content)[t] = inst.get();
-       obj.owned_data.push_back(inst.release());
+       obj.add(*inst.release());
 }
 
 void Scene::Loader::scene(const string &n)
index 33678b7998900fac18f25cb113f181f5d654e9f3..fcf5d33e8eb9645caccdbc9bff5f7d34a3427f27 100644 (file)
@@ -26,6 +26,7 @@ protected:
 
        private:
                ContentMap *content;
+               unsigned inst_counter;
 
        public:
                Loader(Scene &, Collection &);
@@ -71,8 +72,6 @@ private:
        typedef TypeRegistry<GenericLoader::CreateScene, GenericLoader &> SceneRegistry;
 
 protected:
-       // XXX If a loaded renderable is removed from the scene it needs to be removed from here as well
-       std::vector<Renderable *> owned_data;
        mutable Matrix culling_matrix;
        mutable Vector4 frustum_edges[6];
 
@@ -81,7 +80,7 @@ private:
        Scene(const Scene &);
        Scene &operator=(const Scene &);
 public:
-       virtual ~Scene();
+       virtual ~Scene() { }
 
        virtual void add(Renderable &) = 0;
        virtual void remove(Renderable &) = 0;
index b8fb6076e1fe5937ee8107aece475b5d3a763c44..06b1403bd827e934400a550cd29f2bcef919e64b 100644 (file)
@@ -47,6 +47,9 @@ void Sequence::init(unsigned w, unsigned h)
 
 Sequence::~Sequence()
 {
+       for(vector<PostProcStep>::iterator i=postproc.begin(); i!=postproc.end(); ++i)
+               if(i->owned)
+                       delete i->postproc;
        delete target[0];
        delete target[1];
        delete target_ms;
@@ -114,25 +117,25 @@ Sequence::Step &Sequence::add_step(Tag tag, Renderable &r)
 
 void Sequence::add_postprocessor(PostProcessor &pp)
 {
-       add_postprocessor(&pp, true);
+       add_postprocessor(&pp, false);
 }
 
 void Sequence::add_postprocessor_owned(PostProcessor *pp)
 {
-       add_postprocessor(pp, false);
+       add_postprocessor(pp, true);
 }
 
-void Sequence::add_postprocessor(PostProcessor *pp, bool keep)
+void Sequence::add_postprocessor(PostProcessor *pp, bool owned)
 {
-       postproc.push_back(pp);
-       if(keep)
-               postproc.back().keep();
+       postproc.push_back(PostProcStep(pp, owned));
        try
        {
                create_targets(0);
        }
        catch(...)
        {
+               if(!owned)
+                       delete pp;
                postproc.pop_back();
                throw;
        }
@@ -206,7 +209,7 @@ void Sequence::render(Renderer &renderer, Tag tag) const
                                out_fbo->bind();
                        const Texture2D &color = target[j]->get_target_texture(RENDER_COLOR);
                        const Texture2D &depth = target[j]->get_target_texture(RENDER_DEPTH);
-                       postproc[i]->render(renderer, color, depth);
+                       postproc[i].postproc->render(renderer, color, depth);
                }
        }
 }
index fb60e37159f7a4220753b093548afc2d9e6b1023..8a480add82050cf2575ecc451908b175f3f3ed82 100644 (file)
@@ -66,9 +66,17 @@ public:
        DEPRECATED typedef Step Pass;
 
 private:
+       struct PostProcStep
+       {
+               PostProcessor *postproc;
+               bool owned;
+
+               PostProcStep(PostProcessor *pp, bool o): postproc(pp), owned(o) { }
+       };
+
        std::vector<Step> steps;
        const Camera *camera;
-       std::vector<RefPtr<PostProcessor> > postproc;
+       std::vector<PostProcStep> postproc;
        unsigned width;
        unsigned height;
        bool hdr;