]> git.tdb.fi Git - libs/gl.git/commitdiff
Access builtin resources through a global instance
authorMikko Rasa <tdb@tdb.fi>
Tue, 4 May 2021 20:13:33 +0000 (23:13 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 4 May 2021 20:30:07 +0000 (23:30 +0300)
Explicitly passing the Resources reference causes problems when some
classes in a hierarchy need it and others don't.  It's also awkward in
RenderPass::set_material and PostProcessor templates.  It doesn't even
matter which instance is passed in since the data is builtin anyway.

The first created Resources instance is now registered as the one to use
for builtin data, unless suppressed by a constructor parameter.

25 files changed:
demos/desertpillars/source/desertpillars.cpp
source/builders/sequencebuilder.cpp
source/builders/sequencetemplate.cpp
source/builders/sequencetemplate.h
source/effects/ambientocclusion.cpp
source/effects/ambientocclusion.h
source/effects/bloom.cpp
source/effects/bloom.h
source/effects/colorcurve.cpp
source/effects/colorcurve.h
source/effects/environmentmap.cpp
source/effects/environmentmap.h
source/effects/postprocessor.h
source/effects/shadowmap.cpp
source/effects/shadowmap.h
source/effects/sky.cpp
source/effects/sky.h
source/materials/material.cpp
source/materials/material.h
source/materials/renderpass.cpp
source/materials/renderpass.h
source/render/occludedscene.cpp
source/render/occludedscene.h
source/resources/resources.cpp
source/resources/resources.h

index 41d150b0a8e6c7bffd0b8fb62722ec0df653e9d3..fc70af117ef7ca05813c61c6f98fe043f7458ac6 100644 (file)
@@ -35,14 +35,14 @@ DesertPillars::DesertPillars(int, char **):
        keyboard.signal_button_press.connect(sigc::bind_return(sigc::mem_fun(this, &DesertPillars::key_press), false));
 
        const GL::Light &sun = resources.get<GL::Light>("Sun.light");
-       sky = make_unique<GL::Sky>(resources, content, sun);
+       sky = make_unique<GL::Sky>(content, sun);
 
        unsigned shadow_size = 8192;
        shadow_seq = make_unique<GL::Sequence>(shadow_size, shadow_size);
        GL::Sequence::Step *step = &shadow_seq->add_step("shadow", content);
        step->set_depth_test(&GL::DepthTest::lequal());
 
-       shadow_map = make_unique<GL::ShadowMap>(resources, shadow_size, *sky, sun, *shadow_seq);
+       shadow_map = make_unique<GL::ShadowMap>(shadow_size, *sky, sun, *shadow_seq);
        shadow_map->set_darkness(0.9f);
        shadow_map->set_target(GL::Vector3(0.0f, 0.0f, 0.0f), 20.0f);
 
@@ -56,7 +56,7 @@ DesertPillars::DesertPillars(int, char **):
        step->set_lighting(&resources.get<GL::Lighting>("Desert.lightn"));
        step->set_depth_test(&GL::DepthTest::lequal());
 
-       env_map = make_unique<GL::EnvironmentMap>(resources, 256, GL::RGB16F, sphere, *env_seq);
+       env_map = make_unique<GL::EnvironmentMap>(256, GL::RGB16F, sphere, *env_seq);
        sphere.set_matrix(GL::Matrix::translation(GL::Vector3(0.0f, 0.0f, 3.3f)));
 
        content.add(resources.get<GL::Scene>("Background.scene"));
index 658ded0bc697a57bc36f8ca8b6548c4083d7ec25..c45d0cc67c6b2b8ba03f6688aa5e6709bf890fb8 100644 (file)
@@ -66,7 +66,7 @@ void SequenceBuilder::build(Sequence &sequence) const
                        sequence.add_postprocessor(*proc);
                else if(i->postprocessor_template)
                {
-                       proc = i->postprocessor_template->create(tmpl.get_resources(), sequence.get_width(), sequence.get_height());
+                       proc = i->postprocessor_template->create(sequence.get_width(), sequence.get_height());
                        if(proc)
                                sequence.add_postprocessor_owned(proc);
                }
index f158c630083b8e82110028c031c4edfe63bb2396..d852643301fa0ecac87fe0114b514bbe4478b45e 100644 (file)
@@ -17,7 +17,6 @@ namespace Msp {
 namespace GL {
 
 SequenceTemplate::SequenceTemplate():
-       resources(0),
        hdr(false),
        alpha(false),
        required_multisample(0),
@@ -30,13 +29,6 @@ SequenceTemplate::~SequenceTemplate()
                delete i->postprocessor_template;
 }
 
-Resources &SequenceTemplate::get_resources() const
-{
-       if(!resources)  
-               throw logic_error("no resources");
-       return *resources;
-}
-
 
 SequenceTemplate::PostProcessorRegistry &SequenceTemplate::get_postprocessor_registry()
 {
@@ -81,8 +73,6 @@ SequenceTemplate::Loader::Loader(SequenceTemplate &t, Collection &c):
 
        // Deprecated
        add("pass", &Loader::step_with_slot);
-
-       obj.resources = &c;
 }
 
 void SequenceTemplate::Loader::postprocessor_loaded()
index 596def5064950d9741ff64d8626a11756c3c1c9d..4c195a000bc925983abdf885aace11d68e8dda4d 100644 (file)
@@ -103,7 +103,6 @@ public:
 private:
        typedef TypeRegistry<PostProcLoader::AddPostProc, PostProcLoader &> PostProcessorRegistry;
 
-       Resources *resources;
        bool hdr;
        bool alpha;
        unsigned required_multisample;
@@ -115,7 +114,6 @@ public:
        SequenceTemplate();
        ~SequenceTemplate();
 
-       Resources &get_resources() const;
        bool get_hdr() const { return hdr; }
        bool get_alpha() const { return alpha; }
        unsigned get_required_multisample() const { return required_multisample; }
index d47d18aaa8a6f6992ffb800f29463ee70b87aea2..d23469edf8aeeac20a0a62cf285e47dde551f019 100644 (file)
@@ -12,13 +12,13 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-AmbientOcclusion::AmbientOcclusion(Resources &resources, unsigned w, unsigned h, float):
+AmbientOcclusion::AmbientOcclusion(unsigned w, unsigned h, float):
        occlude_target(w, h, (RENDER_COLOR,R8)),
-       occlude_shader(resources.get<Program>("_ambientocclusion_occlude.glsl.shader")),
-       combine_shader(resources.get<Program>("_ambientocclusion_combine.glsl.shader")),
-       quad(resources.get<Mesh>("_fullscreen_quad.mesh")),
-       linear_sampler(resources.get<Sampler>("_linear_clamp.samp")),
-       nearest_sampler(resources.get<Sampler>("_nearest_clamp.samp"))
+       occlude_shader(Resources::get_global().get<Program>("_ambientocclusion_occlude.glsl.shader")),
+       combine_shader(Resources::get_global().get<Program>("_ambientocclusion_combine.glsl.shader")),
+       quad(Resources::get_global().get<Mesh>("_fullscreen_quad.mesh")),
+       linear_sampler(Resources::get_global().get<Sampler>("_linear_clamp.samp")),
+       nearest_sampler(Resources::get_global().get<Sampler>("_nearest_clamp.samp"))
 {
        unsigned seed = 1;
        rotate_lookup.storage(RGBA8, 4, 4, 1);
@@ -111,9 +111,9 @@ AmbientOcclusion::Template::Template():
        edge_depth_threshold(0.1f)
 { }
 
-AmbientOcclusion *AmbientOcclusion::Template::create(Resources &res, unsigned width, unsigned height) const
+AmbientOcclusion *AmbientOcclusion::Template::create(unsigned width, unsigned height) const
 {
-       RefPtr<AmbientOcclusion> ao = new AmbientOcclusion(res, width/size_divisor, height/size_divisor);
+       RefPtr<AmbientOcclusion> ao = new AmbientOcclusion(width/size_divisor, height/size_divisor);
        ao->set_n_samples(n_samples);
        ao->set_occlusion_radius(occlusion_radius);
        ao->set_darkness(darkness);
index 2497d5b7fb4f2d2d150144a67062cdee72a558b0..b0030c5917d56e0c785600d336517448bf0cb805 100644 (file)
@@ -35,7 +35,7 @@ public:
 
                Template();
 
-               virtual AmbientOcclusion *create(Resources &, unsigned, unsigned) const;
+               virtual AmbientOcclusion *create(unsigned, unsigned) const;
        };
 
 private:
@@ -49,7 +49,7 @@ private:
        const Sampler &nearest_sampler;
 
 public:
-       AmbientOcclusion(Resources &, unsigned, unsigned, float = 1.0f);
+       AmbientOcclusion(unsigned, unsigned, float = 1.0f);
 
 private:
        static float random(unsigned &);
index 98afedfc17c924e1e1b1048488dd0e72497ce4dc..af2057d908a03afa25075330ddbbfe0b2ef6f0d5 100644 (file)
@@ -14,12 +14,12 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-Bloom::Bloom(Resources &resources, unsigned w, unsigned h):
-       blur_shader(resources.get<Program>("_bloom_blur.glsl.shader")),
-       combine_shader(resources.get<Program>("_bloom_combine.glsl.shader")),
-       quad(resources.get<Mesh>("_fullscreen_quad.mesh")),
-       nearest_sampler(resources.get<Sampler>("_nearest_clamp.samp")),
-       linear_sampler(resources.get<Sampler>("_linear_clamp.samp"))
+Bloom::Bloom(unsigned w, unsigned h):
+       blur_shader(Resources::get_global().get<Program>("_bloom_blur.glsl.shader")),
+       combine_shader(Resources::get_global().get<Program>("_bloom_combine.glsl.shader")),
+       quad(Resources::get_global().get<Mesh>("_fullscreen_quad.mesh")),
+       nearest_sampler(Resources::get_global().get<Sampler>("_nearest_clamp.samp")),
+       linear_sampler(Resources::get_global().get<Sampler>("_linear_clamp.samp"))
 {
        blur_shdata[0].uniform("delta", 1.0f/w, 0.0f);
        blur_shdata[1].uniform("delta", 0.0f, 1.0f/h);
@@ -88,9 +88,9 @@ Bloom::Template::Template():
        strength(0.2f)
 { }
 
-Bloom *Bloom::Template::create(Resources &res, unsigned width, unsigned height) const
+Bloom *Bloom::Template::create(unsigned width, unsigned height) const
 {
-       RefPtr<Bloom> bloom = new Bloom(res, width/size_divisor, height/size_divisor);
+       RefPtr<Bloom> bloom = new Bloom(width/size_divisor, height/size_divisor);
        bloom->set_radius(radius);
        bloom->set_strength(strength);
        return bloom.release();
index f2d9db7f01a99363da50219728a2d239b91fee76..7315075b1f68c43553ba1de7f103834ef4cc947c 100644 (file)
@@ -36,7 +36,7 @@ public:
 
                Template();
 
-               virtual Bloom *create(Resources &, unsigned, unsigned) const;
+               virtual Bloom *create(unsigned, unsigned) const;
        };
 
 private:
@@ -50,7 +50,7 @@ private:
        const Sampler &linear_sampler;
 
 public:
-       Bloom(Resources &, unsigned, unsigned);
+       Bloom(unsigned, unsigned);
        ~Bloom();
 
        /** Sets the σ value of the gaussian blur.  Values much larger than 4.0 are
index 9e242d1984007c2c5ea8565f3533630f323f8065..d35b7928e52c5ff7212a8869d3a01802cbf5667a 100644 (file)
@@ -12,11 +12,11 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-ColorCurve::ColorCurve(Resources &resources):
-       shprog(resources.get<Program>("_colorcurve.glsl.shader")),
-       quad(resources.get<Mesh>("_fullscreen_quad.mesh")),
-       linear_sampler(resources.get<Sampler>("_linear_clamp.samp")),
-       nearest_sampler(resources.get<Sampler>("_nearest_clamp.samp"))
+ColorCurve::ColorCurve():
+       shprog(Resources::get_global().get<Program>("_colorcurve.glsl.shader")),
+       quad(Resources::get_global().get<Mesh>("_fullscreen_quad.mesh")),
+       linear_sampler(Resources::get_global().get<Sampler>("_linear_clamp.samp")),
+       nearest_sampler(Resources::get_global().get<Sampler>("_nearest_clamp.samp"))
 {
        curve.storage(LUMINANCE8, 256, 1);
 
@@ -84,9 +84,9 @@ ColorCurve::Template::Template():
        srgb(false)
 { }
 
-ColorCurve *ColorCurve::Template::create(Resources &res, unsigned, unsigned) const
+ColorCurve *ColorCurve::Template::create(unsigned, unsigned) const
 {
-       RefPtr<ColorCurve> colorcurve = new ColorCurve(res);
+       RefPtr<ColorCurve> colorcurve = new ColorCurve();
        colorcurve->set_exposure_adjust(exposure_adjust);
        colorcurve->set_brightness_response(brightness_response);
        if(srgb)
index ee19a56f3835fadb225b56e48016d4f23b272f1a..f274bf06bde57040e7ae1f489fa6793d3f6560ac 100644 (file)
@@ -40,7 +40,7 @@ public:
 
                Template();
 
-               virtual ColorCurve *create(Resources &, unsigned, unsigned) const;
+               virtual ColorCurve *create(unsigned, unsigned) const;
        };
 
 private:
@@ -52,7 +52,7 @@ private:
        const Sampler &nearest_sampler;
 
 public:
-       ColorCurve(Resources &);
+       ColorCurve();
 
        /** Set exposure adjustment in EV units.  Positive values brighten the
        image, negative values darken it.  Zero is neutral. */
index 353f9841b27db9a72dab013343ada597d49924ca..bd44ae04fecac868c2852534726c3d0b4c58df87 100644 (file)
@@ -10,18 +10,18 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-EnvironmentMap::EnvironmentMap(Resources &resources, unsigned s, Renderable &r, Renderable &e):
+EnvironmentMap::EnvironmentMap(unsigned s, Renderable &r, Renderable &e):
        Effect(r),
        environment(e),
-       sampler(resources.get<Sampler>("_linear_clamp.samp"))
+       sampler(Resources::get_global().get<Sampler>("_linear_clamp.samp"))
 {
        init(s, RGB8);
 }
 
-EnvironmentMap::EnvironmentMap(Resources &resources, unsigned s, PixelFormat f, Renderable &r, Renderable &e):
+EnvironmentMap::EnvironmentMap(unsigned s, PixelFormat f, Renderable &r, Renderable &e):
        Effect(r),
        environment(e),
-       sampler(resources.get<Sampler>("_linear_clamp.samp"))
+       sampler(Resources::get_global().get<Sampler>("_linear_clamp.samp"))
 {
        init(s, f);
 }
index 36c72987b84e7327a0b35c5f5e5d92ac7f26bdb1..f22a5b4b8fea673e658cb7cf01ccea1aeada2760 100644 (file)
@@ -13,8 +13,6 @@
 namespace Msp {
 namespace GL {
 
-class Resources;
-
 /**
 Creates a cube map texture of the surroundings of the renderable.  This texture
 can then be used to implement effects such as reflections or refractions.
@@ -45,8 +43,8 @@ private:
        unsigned update_delay;
 
 public:
-       EnvironmentMap(Resources &, unsigned size, Renderable &rend, Renderable &env);
-       EnvironmentMap(Resources &, unsigned size, PixelFormat, Renderable &rend, Renderable &env);
+       EnvironmentMap(unsigned size, Renderable &rend, Renderable &env);
+       EnvironmentMap(unsigned size, PixelFormat, Renderable &rend, Renderable &env);
 private:
        void init(unsigned, PixelFormat);
 
index 3060e609868344ce4ec3379f34b07005e9e9d001..aabace6c94159aa120a6e59e4352ce18f5f4f9cc 100644 (file)
@@ -8,7 +8,6 @@ namespace GL {
 
 class Mesh;
 class Renderer;
-class Resources;
 class Sampler;
 class Shader;
 class Texture2D;
@@ -34,7 +33,7 @@ public:
                Template();
                virtual ~Template() { }
 
-               virtual PostProcessor *create(Resources &, unsigned, unsigned) const = 0;
+               virtual PostProcessor *create(unsigned, unsigned) const = 0;
        };
 
 protected:
index 11bb706e6afa3265562e277e3ac899783e888095..f11ea7a710558085c4ce059289fac848baff3cc9 100644 (file)
@@ -13,20 +13,20 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-ShadowMap::ShadowMap(Resources &resources, unsigned s, Renderable &r, const Light &l, Renderable &c):
+ShadowMap::ShadowMap(unsigned s, Renderable &r, const Light &l, Renderable &c):
        Effect(r),
        light(l),
        shadow_caster(c),
-       sampler(resources.get<Sampler>("_linear_clamp_shadow.samp"))
+       sampler(Resources::get_global().get<Sampler>("_linear_clamp_shadow.samp"))
 {
        init(s);
 }
 
-ShadowMap::ShadowMap(Resources &resources, unsigned s, Renderable &r, const Light &l):
+ShadowMap::ShadowMap(unsigned s, Renderable &r, const Light &l):
        Effect(r),
        light(l),
        shadow_caster(r),
-       sampler(resources.get<Sampler>("_linear_clamp_shadow.samp"))
+       sampler(Resources::get_global().get<Sampler>("_linear_clamp_shadow.samp"))
 {
        init(s);
 }
index d618c0616d748d89f97fecdb27e3d4dafa178305..a3c3a8f2f6335fb63a460887d25055a4e8e32943 100644 (file)
@@ -38,8 +38,8 @@ private:
        bool rendered;
 
 public:
-       ShadowMap(Resources &, unsigned, Renderable &, const Light &, Renderable &);
-       DEPRECATED ShadowMap(Resources &, unsigned, Renderable &, const Light &);
+       ShadowMap(unsigned, Renderable &, const Light &, Renderable &);
+       DEPRECATED ShadowMap(unsigned, Renderable &, const Light &);
 private:
        void init(unsigned);
 
index c7e748794a4e3a6f6dbf58d1771000c053721154..baf4864ad02256b1b83a332541369241c5e8f019 100644 (file)
@@ -9,18 +9,18 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-Sky::Sky(Resources &resources, Renderable &r, const Light &s):
+Sky::Sky(Renderable &r, const Light &s):
        Effect(r),
        sun(s),
        transmittance_lookup(128, 64, (RENDER_COLOR, RGB16F)),
-       transmittance_shprog(resources.get<Program>("_sky_transmittance.glsl.shader")),
+       transmittance_shprog(Resources::get_global().get<Program>("_sky_transmittance.glsl.shader")),
        transmittance_lookup_dirty(true),
        distant(256, 128, (RENDER_COLOR, RGB16F)),
-       distant_shprog(resources.get<Program>("_sky_distant.glsl.shader")),
-       fullscreen_mesh(resources.get<Mesh>("_fullscreen_quad.mesh")),
-       backdrop_shprog(resources.get<Program>("_sky_backdrop.glsl.shader")),
-       sampler(resources.get<Sampler>("_linear_clamp.samp")),
-       wrap_sampler(resources.get<Sampler>("_linear_clamp_v.samp")),
+       distant_shprog(Resources::get_global().get<Program>("_sky_distant.glsl.shader")),
+       fullscreen_mesh(Resources::get_global().get<Mesh>("_fullscreen_quad.mesh")),
+       backdrop_shprog(Resources::get_global().get<Program>("_sky_backdrop.glsl.shader")),
+       sampler(Resources::get_global().get<Sampler>("_linear_clamp.samp")),
+       wrap_sampler(Resources::get_global().get<Sampler>("_linear_clamp_v.samp")),
        rendered(false)
 {
        shdata.uniform("n_steps", 50);
index 5cc7bdaa668a6d6935be713f890f9c20991fc891..faa3eb033d594bc73f8eb7cff6eae6b664d6be96 100644 (file)
@@ -55,7 +55,7 @@ private:
        bool rendered;
 
 public:
-       Sky(Resources &, Renderable &, const Light &);
+       Sky(Renderable &, const Light &);
 
        void set_planet(const Planet &);
        void set_view_height(float);
index ace87e70954847d299061205826d9dacf9029919..b2ee973ad11c0b8d55fc4d6ea14dabaebf31a3a8 100644 (file)
@@ -13,7 +13,7 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-const Program *Material::create_compatible_shader(DataFile::Collection &coll, const map<string, int> &extra_spec) const
+const Program *Material::create_compatible_shader(const map<string, int> &extra_spec) const
 {
        string module_name;
        map<string, int> spec_values;
@@ -26,16 +26,17 @@ const Program *Material::create_compatible_shader(DataFile::Collection &coll, co
        for(map<string, int>::const_iterator i=spec_values.begin(); i!=spec_values.end(); ++i)
                info += format(",%s:%d", i->first, i->second);
 
+       Resources &res = Resources::get_global();
        string name = format("_material_%016x.shader", hash64(info));
-       Program *shprog = coll.find<Program>(name);
+       Program *shprog = res.find<Program>(name);
        if(shprog)
                return shprog;
 
-       const Module &module = coll.get<Module>(module_name);
+       const Module &module = res.get<Module>(module_name);
        shprog = new Program(module, spec_values);
        try
        {
-               coll.add(name, shprog);
+               res.add(name, shprog);
        }
        catch(...)
        {
index ae38f2444afdadbd3fc260e142bf1c83113660bf..a5ee59e5ee1ecb9b181e53ffda03bf5562d0d8dd 100644 (file)
@@ -97,7 +97,7 @@ protected:
 public:
        virtual ~Material() { }
 
-       virtual const Program *create_compatible_shader(DataFile::Collection &, const std::map<std::string, int> & = std::map<std::string, int>()) const;
+       virtual const Program *create_compatible_shader(const std::map<std::string, int> & = std::map<std::string, int>()) const;
 protected:
        virtual void fill_program_info(std::string &, std::map<std::string, int> &) const = 0;
 
index dde1fdb4f9847b39178cc412f8c6cdcde3576a6e..74b734128ba5d30710aedbc12ce30f505ea8ca3c 100644 (file)
@@ -33,7 +33,7 @@ void RenderPass::set_material_textures()
                set_texture(*tag, material->get_texture(*tag), material->get_sampler());
 }
 
-void RenderPass::maybe_create_material_shader(DataFile::Collection *coll)
+void RenderPass::maybe_create_material_shader()
 {
        if(shprog && !shprog_from_material)
                return;
@@ -42,13 +42,7 @@ void RenderPass::maybe_create_material_shader(DataFile::Collection *coll)
        if(receive_shadows)
                extra_spec["use_shadow_map"] = true;
 
-       if(coll)
-       {
-               shprog = material->create_compatible_shader(*coll, extra_spec);
-               shprog.keep();
-       }
-       else
-               throw invalid_operation("RenderPass::maybe_create_material_shader");
+       shprog = material->create_compatible_shader(extra_spec);
 
        if(shdata)
                shdata = new ProgramData(*shdata, shprog.get());
@@ -72,11 +66,11 @@ Tag RenderPass::get_slotted_uniform_tag(Tag slot) const
        return i->second;
 }
 
-void RenderPass::set_material(const Material *mat, DataFile::Collection *coll)
+void RenderPass::set_material(const Material *mat)
 {
        material = mat;
        material.keep();
-       maybe_create_material_shader(coll);
+       maybe_create_material_shader();
        set_material_textures();
 }
 
@@ -196,7 +190,7 @@ void RenderPass::Loader::init_actions()
 void RenderPass::Loader::finish()
 {
        if(obj.material)
-               obj.maybe_create_material_shader(coll);
+               obj.maybe_create_material_shader();
 }
 
 // Temporary compatibility feature
index f02303bc8865f91632723bfe160143dd201dabf8..91ff1b6c77f0e54590e4802981f80b16b7400e6a 100644 (file)
@@ -85,7 +85,7 @@ public:
        RenderPass();
 
 private:
-       void maybe_create_material_shader(DataFile::Collection *);
+       void maybe_create_material_shader();
        void set_material_textures();
 
 public:
@@ -93,7 +93,7 @@ public:
        const Program *get_shader_program() const { return shprog.get(); }
        const ProgramData *get_shader_data() const { return shdata.get(); }
        Tag get_slotted_uniform_tag(Tag) const;
-       void set_material(const Material *, DataFile::Collection * = 0);
+       void set_material(const Material *);
        const Material *get_material() const { return material.get(); }
        const std::string &get_material_slot_name() const { return material_slot; }
        void set_texture(Tag, const Texture *, const Sampler * = 0);
index b2e7ab3297d1decee09573fad21974e823b8391a..7c043fa691c5ab578fc7da430244db471632bdc0 100644 (file)
@@ -12,9 +12,9 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-OccludedScene::OccludedScene(Resources &resources):
-       bounding_mesh(resources.get<Mesh>("_occluder.mesh")),
-       bounding_shader(resources.get<Program>("_occluder.glsl.shader")),
+OccludedScene::OccludedScene():
+       bounding_mesh(Resources::get_global().get<Mesh>("_occluder.mesh")),
+       bounding_shader(Resources::get_global().get<Program>("_occluder.glsl.shader")),
        occluder_min_size(0.25f),
        cache_dirty(false)
 {
index 2fb463c641b9d826e5f664f3d57d99d3deb339a7..9140d13b62624b56ab1ce7e5f022f691df4a2302 100644 (file)
@@ -42,7 +42,7 @@ private:
        mutable bool cache_dirty;
 
 public:
-       OccludedScene(Resources &);
+       OccludedScene();
        ~OccludedScene();
 
        virtual void add(Renderable &);
index 66f6f082b927d2d6cdd5499a859f23bde6eadff2..79c95932b6c52b03f45c669d58a68f71d5e2bbeb 100644 (file)
@@ -3,6 +3,7 @@
 #include "animation.h"
 #include "armature.h"
 #include "camera.h"
+#include "error.h"
 #include "font.h"
 #include "keyframe.h"
 #include "light.h"
@@ -33,7 +34,9 @@ namespace GL {
 void init_shaderlib(DataFile::BuiltinSource &);
 void init_builtin_data(DataFile::BuiltinSource &);
 
-Resources::Resources():
+Resources *Resources::global_resources = 0;
+
+Resources::Resources(bool set_as_global):
        default_tex_filter(Texture::can_generate_mipmap() ? LINEAR_MIPMAP_LINEAR : LINEAR),
        default_tex_anisotropy(1.0f),
        srgb_conversion(false),
@@ -75,6 +78,22 @@ Resources::Resources():
                .notify(&Resources::set_debug_name<Texture2DArray>);
 
        add_source(get_builtins());
+
+       if(set_as_global && !global_resources)
+               global_resources = this;
+}
+
+Resources::~Resources()
+{
+       if(this==global_resources)
+               global_resources = 0;
+}
+
+Resources &Resources::get_global()
+{
+       if(!global_resources)
+               throw invalid_operation("no global resources");
+       return *global_resources;
 }
 
 const DataFile::CollectionSource &Resources::get_builtins()
index a50fdc0e022081602abcaea69c44b4e7d3b2ee9d..82d2f4c6798e4a9019380894b314aa56ad9aed57 100644 (file)
@@ -37,9 +37,13 @@ private:
        bool srgb_conversion;
        ResourceManager *resource_manager;
 
+       static Resources *global_resources;
+
 public:
-       Resources();
+       Resources(bool = true);
+       virtual ~Resources();
 
+       static Resources &get_global();
        static const DataFile::CollectionSource &get_builtins();
 
        void set_default_texture_filter(TextureFilter);