This name better describes the relationship.
namespace Msp {
namespace GL {
-Effect::Effect(Renderable &r):
- renderable(r)
+Effect::Effect(Renderable &c):
+ content(c)
{
enable_for_method(Tag());
}
};
protected:
- Renderable &renderable;
+ Renderable &content;
std::vector<Tag> enabled_methods;
protected:
void disable_for_method(Tag);
bool is_enabled_for_method(Tag) const;
- virtual const Matrix *get_matrix() const { return renderable.get_matrix(); }
- virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return renderable.get_bounding_sphere(); }
+ virtual const Matrix *get_matrix() const { return content.get_matrix(); }
+ virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return content.get_bounding_sphere(); }
- virtual void setup_frame(Renderer &r) { renderable.setup_frame(r); }
- virtual void finish_frame() { renderable.finish_frame(); }
+ virtual void setup_frame(Renderer &r) { content.setup_frame(r); }
+ virtual void finish_frame() { content.finish_frame(); }
virtual void set_debug_name(const std::string &) = 0;
};
namespace Msp {
namespace GL {
-EnvironmentMap::EnvironmentMap(unsigned s, PixelFormat f, Renderable &r, Renderable &e):
- EnvironmentMap(s, f, 1, r, e)
+EnvironmentMap::EnvironmentMap(unsigned s, PixelFormat f, Renderable &c, Renderable &e):
+ EnvironmentMap(s, f, 1, c, e)
{ }
-EnvironmentMap::EnvironmentMap(unsigned s, PixelFormat f, unsigned l, Renderable &r, Renderable &e):
- Effect(r),
+EnvironmentMap::EnvironmentMap(unsigned s, PixelFormat f, unsigned l, Renderable &c, Renderable &e):
+ Effect(c),
size(s),
environment(e),
irradiance_shprog(Resources::get_global().get<Program>("_envmap_irradiance.glsl.shader")),
return;
rendered = true;
- renderable.setup_frame(renderer);
+ content.setup_frame(renderer);
if(update_delay)
{
center = fixed_position;
else
{
- const Matrix *matrix = renderable.get_matrix();
+ const Matrix *matrix = content.get_matrix();
if(!matrix)
return;
if(rendered)
{
rendered = false;
- renderable.finish_frame();
+ content.finish_frame();
environment.finish_frame();
}
}
if(in_setup_frame)
return;
if(!is_enabled_for_method(tag))
- return renderable.render(renderer, tag);
+ return content.render(renderer, tag);
Renderer::Push _push_rend(renderer);
renderer.set_texture("environment_map", &env_tex, &mip_sampler);
renderer.set_texture("irradiance_map", &irradiance, &sampler);
renderer.add_shader_data(shdata);
- renderable.render(renderer, tag);
+ content.render(renderer, tag);
}
void EnvironmentMap::set_debug_name(const string &name)
namespace Msp {
namespace GL {
-ShadowMap::ShadowMap(unsigned w, unsigned h, Renderable &r, const Lighting *l):
- Effect(r),
+ShadowMap::ShadowMap(unsigned w, unsigned h, Renderable &c, const Lighting *l):
+ Effect(c),
width(w),
height(h),
lighting(l),
shdata.uniform_array("shd_world_matrix", 1, &dummy_matrix);
}
-ShadowMap::ShadowMap(unsigned s, Renderable &r, const DirectionalLight &l, Renderable &c):
- ShadowMap(s, s, r, 0)
+ShadowMap::ShadowMap(unsigned s, Renderable &c, const DirectionalLight &l, Renderable &sc):
+ ShadowMap(s, s, c, 0)
{
- add_light(l, s, c);
+ add_light(l, s, sc);
}
ShadowMap::ShadowMap(unsigned w, unsigned h, Renderable &r, const Lighting &l):
return;
rendered = true;
- renderable.setup_frame(renderer);
+ content.setup_frame(renderer);
for(const ShadowedLight &l: lights)
l.shadow_caster->setup_frame(renderer);
if(rendered)
{
rendered = false;
- renderable.finish_frame();
+ content.finish_frame();
}
}
void ShadowMap::render(Renderer &renderer, Tag tag) const
{
if(!is_enabled_for_method(tag))
- return renderable.render(renderer, tag);
+ return content.render(renderer, tag);
Renderer::Push _push_rend(renderer);
renderer.set_texture("shadow_map", &depth_buf, &sampler);
renderer.add_shader_data(shdata);
- renderable.render(renderer, tag);
+ content.render(renderer, tag);
}
void ShadowMap::set_debug_name(const string &name)
namespace Msp {
namespace GL {
-Sky::Sky(Renderable &r, DirectionalLight &s):
- Effect(r),
+Sky::Sky(Renderable &c, DirectionalLight &s):
+ Effect(c),
sun(s),
transmittance_lookup(128, 64, (COLOR_ATTACHMENT,RGB16F)),
transmittance_shprog(Resources::get_global().get<Program>("_sky_transmittance.glsl.shader")),
renderer.set_texture("transmittance_lookup", &transmittance_lookup.get_target_texture(0), &sampler);
fullscreen_mesh.draw(renderer);
- renderable.setup_frame(renderer);
+ content.setup_frame(renderer);
}
void Sky::finish_frame()
if(rendered)
{
rendered = false;
- renderable.finish_frame();
+ content.finish_frame();
}
}
void Sky::render(Renderer &renderer, Tag tag) const
{
- renderable.render(renderer, tag);
+ content.render(renderer, tag);
if(!is_enabled_for_method(tag))
return;
void OccludedScene::add(Renderable &r)
{
- auto i = lower_bound(renderables, &r);
- if(i==renderables.end() || *i!=&r)
+ auto i = lower_bound(content, &r);
+ if(i==content.end() || *i!=&r)
{
- renderables.insert(i, &r);
+ content.insert(i, &r);
cache_dirty = true;
}
}
void OccludedScene::remove(Renderable &r)
{
- auto i = lower_bound(renderables, &r);
- if(i!=renderables.end() && *i==&r)
+ auto i = lower_bound(content, &r);
+ if(i!=content.end() && *i==&r)
{
- renderables.erase(i);
+ content.erase(i);
cache_dirty = true;
}
}
if(!cache_dirty)
return;
- if(queries.get_size()<renderables.size())
- queries.resize(renderables.size());
- if(occluded_cache.size()<renderables.size())
- occluded_cache.resize(renderables.size());
+ if(queries.get_size()<content.size())
+ queries.resize(content.size());
+ if(occluded_cache.size()<content.size())
+ occluded_cache.resize(content.size());
auto j = occluded_cache.begin();
- for(Renderable *r: renderables)
+ for(Renderable *r: content)
j++->renderable = r;
for(; j!=occluded_cache.end(); ++j)
{
void OccludedScene::render(Renderer &renderer, Tag tag) const
{
- if(renderables.empty())
+ if(content.empty())
return;
populate_cache();
}
// Move all objects within the frustum to the beginning of the array
- for(auto i=occluded_cache.begin(), j=i+renderables.size()-1; i!=j; )
+ for(auto i=occluded_cache.begin(), j=i+content.size()-1; i!=j; )
{
if(i->in_frustum)
++i;
const Program &bounding_shader;
Blend no_color_write;
DepthTest no_depth_write = { LEQUAL, false };
- std::vector<Renderable *> renderables;
+ std::vector<Renderable *> content;
float occluder_min_size = 0.25f;
mutable QueryPool queries;
mutable std::vector<OccludedRenderable> occluded_cache;
void OrderedScene::add(Renderable &r)
{
- renderables.push_back(&r);
+ content.push_back(&r);
}
void OrderedScene::remove(Renderable &r)
{
- auto end = std::remove(renderables.begin(), renderables.end(), &r);
- renderables.erase(end, renderables.end());
+ auto end = std::remove(content.begin(), content.end(), &r);
+ content.erase(end, content.end());
}
void OrderedScene::prepend(Renderable &r)
{
- renderables.insert(renderables.begin(), &r);
+ content.insert(content.begin(), &r);
}
void OrderedScene::insert(unsigned index, Renderable &r)
{
- auto i = renderables.begin();
- for(; (i!=renderables.end() && index); ++i, --index) ;
- renderables.insert(i, &r);
+ auto i = content.begin();
+ for(; (i!=content.end() && index); ++i, --index) ;
+ content.insert(i, &r);
}
void OrderedScene::insert_after(Renderable &after, Renderable &r)
{
- auto i = find(renderables, &after);
- renderables.insert(i, &r);
+ auto i = find(content, &after);
+ content.insert(i, &r);
}
void OrderedScene::setup_frame(Renderer &renderer)
{
- for(Renderable *r: renderables)
+ for(Renderable *r: content)
r->setup_frame(renderer);
}
void OrderedScene::finish_frame()
{
- for(Renderable *r: renderables)
+ for(Renderable *r: content)
r->finish_frame();
}
{
if(setup_frustum(renderer))
{
- for(Renderable *r: renderables)
+ for(Renderable *r: content)
if(!frustum_cull(*r))
r->render(renderer, tag);
}
else
{
- for(Renderable *r: renderables)
+ for(Renderable *r: content)
r->render(renderer, tag);
}
}
using Scene::Loader;
private:
- std::vector<Renderable *> renderables;
+ std::vector<Renderable *> content;
public:
virtual void add(Renderable &);
void SimpleScene::add(Renderable &r)
{
- auto i = lower_bound(renderables, &r);
- if(i==renderables.end() || *i!=&r)
- renderables.insert(i, &r);
+ auto i = lower_bound(content, &r);
+ if(i==content.end() || *i!=&r)
+ content.insert(i, &r);
}
void SimpleScene::remove(Renderable &r)
{
- auto i = find(renderables, &r);
- if(i!=renderables.end())
- renderables.erase(i);
+ auto i = find(content, &r);
+ if(i!=content.end())
+ content.erase(i);
}
void SimpleScene::setup_frame(Renderer &renderer)
{
- for(Renderable *r: renderables)
+ for(Renderable *r: content)
r->setup_frame(renderer);
}
void SimpleScene::finish_frame()
{
- for(Renderable *r: renderables)
+ for(Renderable *r: content)
r->finish_frame();
}
{
if(setup_frustum(renderer))
{
- for(Renderable *r: renderables)
+ for(Renderable *r: content)
if(!frustum_cull(*r))
r->render(renderer, tag);
}
else
{
- for(Renderable *r: renderables)
+ for(Renderable *r: content)
r->render(renderer, tag);
}
}
using Scene::Loader;
private:
- std::vector<Renderable *> renderables;
+ std::vector<Renderable *> content;
public:
virtual void add(Renderable &);
namespace Msp {
namespace GL {
-void Slot::set(Renderable *r)
+void Slot::set(Renderable *c)
{
- renderable = r;
+ content = c;
}
const Matrix *Slot::get_matrix() const
{
- return renderable ? renderable->get_matrix() : 0;
+ return content ? content->get_matrix() : 0;
}
const Geometry::BoundingSphere<float, 3> *Slot::get_bounding_sphere() const
{
- return renderable ? renderable->get_bounding_sphere() : 0;
+ return content ? content->get_bounding_sphere() : 0;
}
void Slot::setup_frame(Renderer &renderer)
{
- if(renderable)
- renderable->setup_frame(renderer);
+ if(content)
+ content->setup_frame(renderer);
}
void Slot::finish_frame()
{
- if(renderable)
- renderable->finish_frame();
+ if(content)
+ content->finish_frame();
}
void Slot::render(Renderer &renderer, Tag tag) const
{
- if(renderable)
- renderable->render(renderer, tag);
+ if(content)
+ content->render(renderer, tag);
}
} // namespace GL
class Slot: public Renderable
{
private:
- Renderable *renderable = 0;
+ Renderable *content = 0;
public:
void set(Renderable *);
- Renderable *get() const { return renderable; }
+ Renderable *get() const { return content; }
virtual const Matrix *get_matrix() const;
virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const;
void ZSortedScene::add(Renderable &r)
{
- auto i = lower_bound(renderables, &r);
- if(i==renderables.end() || *i!=&r)
+ auto i = lower_bound(content, &r);
+ if(i==content.end() || *i!=&r)
{
- renderables.insert(i, &r);
+ content.insert(i, &r);
if(!sorted_cache.empty())
sorted_cache.push_back(&r);
}
void ZSortedScene::remove(Renderable &r)
{
- auto i = lower_bound(renderables, &r);
- if(i!=renderables.end() && *i==&r)
+ auto i = lower_bound(content, &r);
+ if(i!=content.end() && *i==&r)
{
- renderables.erase(i);
+ content.erase(i);
sorted_cache.clear();
}
}
void ZSortedScene::populate_cache() const
{
- if(sorted_cache.empty() && !renderables.empty())
+ if(sorted_cache.empty() && !content.empty())
{
- sorted_cache.reserve(renderables.size());
- sorted_cache.insert(sorted_cache.end(), renderables.begin(), renderables.end());
+ sorted_cache.reserve(content.size());
+ sorted_cache.insert(sorted_cache.end(), content.begin(), content.end());
}
}
void ZSortedScene::render(Renderer &renderer, Tag tag) const
{
- if(renderables.empty())
+ if(content.empty())
return;
populate_cache();
bool operator<(const SortedRenderable &o) const { return depth<o.depth; }
};
- std::vector<Renderable *> renderables;
+ std::vector<Renderable *> content;
SortOrder order = BACK_TO_FRONT;
DepthReference reference = FURTHEST;
mutable std::vector<SortedRenderable> sorted_cache;