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);
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"));
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);
}
namespace GL {
SequenceTemplate::SequenceTemplate():
- resources(0),
hdr(false),
alpha(false),
required_multisample(0),
delete i->postprocessor_template;
}
-Resources &SequenceTemplate::get_resources() const
-{
- if(!resources)
- throw logic_error("no resources");
- return *resources;
-}
-
SequenceTemplate::PostProcessorRegistry &SequenceTemplate::get_postprocessor_registry()
{
// Deprecated
add("pass", &Loader::step_with_slot);
-
- obj.resources = &c;
}
void SequenceTemplate::Loader::postprocessor_loaded()
private:
typedef TypeRegistry<PostProcLoader::AddPostProc, PostProcLoader &> PostProcessorRegistry;
- Resources *resources;
bool hdr;
bool alpha;
unsigned required_multisample;
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; }
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);
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);
Template();
- virtual AmbientOcclusion *create(Resources &, unsigned, unsigned) const;
+ virtual AmbientOcclusion *create(unsigned, unsigned) const;
};
private:
const Sampler &nearest_sampler;
public:
- AmbientOcclusion(Resources &, unsigned, unsigned, float = 1.0f);
+ AmbientOcclusion(unsigned, unsigned, float = 1.0f);
private:
static float random(unsigned &);
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);
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();
Template();
- virtual Bloom *create(Resources &, unsigned, unsigned) const;
+ virtual Bloom *create(unsigned, unsigned) const;
};
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
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);
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)
Template();
- virtual ColorCurve *create(Resources &, unsigned, unsigned) const;
+ virtual ColorCurve *create(unsigned, unsigned) const;
};
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. */
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);
}
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.
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);
class Mesh;
class Renderer;
-class Resources;
class Sampler;
class Shader;
class Texture2D;
Template();
virtual ~Template() { }
- virtual PostProcessor *create(Resources &, unsigned, unsigned) const = 0;
+ virtual PostProcessor *create(unsigned, unsigned) const = 0;
};
protected:
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);
}
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);
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);
bool rendered;
public:
- Sky(Resources &, Renderable &, const Light &);
+ Sky(Renderable &, const Light &);
void set_planet(const Planet &);
void set_view_height(float);
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;
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(...)
{
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;
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;
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());
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();
}
void RenderPass::Loader::finish()
{
if(obj.material)
- obj.maybe_create_material_shader(coll);
+ obj.maybe_create_material_shader();
}
// Temporary compatibility feature
RenderPass();
private:
- void maybe_create_material_shader(DataFile::Collection *);
+ void maybe_create_material_shader();
void set_material_textures();
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);
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)
{
mutable bool cache_dirty;
public:
- OccludedScene(Resources &);
+ OccludedScene();
~OccludedScene();
virtual void add(Renderable &);
#include "animation.h"
#include "armature.h"
#include "camera.h"
+#include "error.h"
#include "font.h"
#include "keyframe.h"
#include "light.h"
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),
.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()
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);