+#include <msp/core/algorithm.h>
#include "effect.h"
namespace Msp {
Effect::Effect(Renderable &r):
renderable(r)
{
- enabled_methods.insert(Tag());
+ enable_for_method(Tag());
}
void Effect::enable_for_method(Tag tag)
{
- enabled_methods.insert(tag);
+ auto i = lower_bound(enabled_methods, tag);
+ if(i==enabled_methods.end() || *i!=tag)
+ enabled_methods.insert(i, tag);
}
void Effect::disable_for_method(Tag tag)
{
- enabled_methods.erase(tag);
+ auto i = lower_bound(enabled_methods, tag);
+ if(i!=enabled_methods.end() && *i==tag)
+ enabled_methods.erase(i);
+}
+
+bool Effect::is_enabled_for_method(Tag tag) const
+{
+ auto i = lower_bound(enabled_methods, tag);
+ return (i!=enabled_methods.end() && *i==tag);
}
protected:
Renderable &renderable;
- std::set<Tag> enabled_methods;
+ std::vector<Tag> enabled_methods;
protected:
Effect(Renderable &);
void enable_for_method(Tag);
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(); }
{
if(in_setup_frame)
return;
- if(!enabled_methods.count(tag))
+ if(!is_enabled_for_method(tag))
return renderable.render(renderer, tag);
Renderer::Push _push_rend(renderer);
void ShadowMap::render(Renderer &renderer, Tag tag) const
{
- if(!enabled_methods.count(tag))
+ if(!is_enabled_for_method(tag))
return renderable.render(renderer, tag);
Renderer::Push _push_rend(renderer);
{
renderable.render(renderer, tag);
- if(!enabled_methods.count(tag))
+ if(!is_enabled_for_method(tag))
return;
Renderer::Push push(renderer);
-#include <algorithm>
+#include <msp/core/algorithm.h>
#include "camera.h"
#include "mesh.h"
#include "occludedscene.h"
void OccludedScene::add(Renderable &r)
{
- renderables.insert(&r);
- cache_dirty = true;
+ auto i = lower_bound(renderables, &r);
+ if(i==renderables.end() || *i!=&r)
+ {
+ renderables.insert(i, &r);
+ cache_dirty = true;
+ }
}
void OccludedScene::remove(Renderable &r)
{
- renderables.erase(&r);
- cache_dirty = true;
+ auto i = lower_bound(renderables, &r);
+ if(i!=renderables.end() && *i==&r)
+ {
+ renderables.erase(i);
+ cache_dirty = true;
+ }
}
void OccludedScene::populate_cache() const
const Program &bounding_shader;
Blend no_color_write;
DepthTest no_depth_write = { LEQUAL, false };
- std::set<Renderable *> renderables;
+ std::vector<Renderable *> renderables;
float occluder_min_size = 0.25f;
mutable QueryPool queries;
mutable std::vector<OccludedRenderable> occluded_cache;
+#include <msp/core/algorithm.h>
#include "renderer.h"
#include "simplescene.h"
void SimpleScene::add(Renderable &r)
{
- // Add to cache as well if the cache is valid
- if(renderables.insert(&r).second && !cache.empty())
- cache.push_back(&r);
+ auto i = lower_bound(renderables, &r);
+ if(i==renderables.end() || *i!=&r)
+ renderables.insert(i, &r);
}
void SimpleScene::remove(Renderable &r)
{
- renderables.erase(&r);
- cache.clear();
-}
-
-void SimpleScene::populate_cache() const
-{
- if(cache.empty() && !renderables.empty())
- {
- cache.reserve(renderables.size());
- cache.insert(cache.end(), renderables.begin(), renderables.end());
- }
+ auto i = find(renderables, &r);
+ if(i!=renderables.end())
+ renderables.erase(i);
}
void SimpleScene::setup_frame(Renderer &renderer)
{
- populate_cache();
- for(Renderable *r: cache)
+ for(Renderable *r: renderables)
r->setup_frame(renderer);
}
void SimpleScene::finish_frame()
{
- for(Renderable *r: cache)
+ for(Renderable *r: renderables)
r->finish_frame();
}
void SimpleScene::render(Renderer &renderer, Tag tag) const
{
- populate_cache();
if(setup_frustum(renderer))
{
- for(Renderable *r: cache)
+ for(Renderable *r: renderables)
if(!frustum_cull(*r))
r->render(renderer, tag);
}
else
{
- for(Renderable *r: cache)
+ for(Renderable *r: renderables)
r->render(renderer, tag);
}
}
using Scene::Loader;
private:
- std::set<Renderable *> renderables;
- mutable std::vector<Renderable *> cache;
+ std::vector<Renderable *> renderables;
public:
virtual void add(Renderable &);
virtual void remove(Renderable &);
-private:
- void populate_cache() const;
-
-public:
virtual void setup_frame(Renderer &);
virtual void finish_frame();
+#include <msp/core/algorithm.h>
#include "camera.h"
#include "renderer.h"
#include "zsortedscene.h"
void ZSortedScene::add(Renderable &r)
{
- if(renderables.insert(&r).second && !sorted_cache.empty())
- sorted_cache.push_back(&r);
+ auto i = lower_bound(renderables, &r);
+ if(i==renderables.end() || *i!=&r)
+ {
+ renderables.insert(i, &r);
+ if(!sorted_cache.empty())
+ sorted_cache.push_back(&r);
+ }
}
void ZSortedScene::remove(Renderable &r)
{
- renderables.erase(&r);
- sorted_cache.clear();
+ auto i = lower_bound(renderables, &r);
+ if(i!=renderables.end() && *i==&r)
+ {
+ renderables.erase(i);
+ sorted_cache.clear();
+ }
}
void ZSortedScene::set_order(SortOrder o)
bool operator<(const SortedRenderable &o) const { return depth<o.depth; }
};
- std::set<Renderable *> renderables;
+ std::vector<Renderable *> renderables;
SortOrder order = BACK_TO_FRONT;
DepthReference reference = FURTHEST;
mutable std::vector<SortedRenderable> sorted_cache;