void SimpleScene::add(const Renderable &r)
{
renderables.insert(&r);
+ cache.clear();
}
void SimpleScene::remove(const 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());
+ }
}
void SimpleScene::setup_frame() const
{
- for(RenderableSet::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
+ populate_cache();
+ for(RenderableArray::const_iterator i=cache.begin(); i!=cache.end(); ++i)
(*i)->setup_frame();
}
void SimpleScene::finish_frame() const
{
- for(RenderableSet::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
+ for(RenderableArray::const_iterator i=cache.begin(); i!=cache.end(); ++i)
(*i)->finish_frame();
}
void SimpleScene::render(Renderer &renderer, const Tag &tag) const
{
+ populate_cache();
if(setup_frustum(renderer))
{
- for(RenderableSet::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
+ for(RenderableArray::const_iterator i=cache.begin(); i!=cache.end(); ++i)
if(!frustum_cull(**i))
renderer.render(**i, tag);
}
else
{
- for(RenderableSet::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
+ for(RenderableArray::const_iterator i=cache.begin(); i!=cache.end(); ++i)
renderer.render(**i, tag);
}
}
namespace GL {
/**
-The simplest possible Scene. Rendering order is unspecified.
+A simple yet efficient scene. Rendering order is unspecified.
*/
class SimpleScene: public Scene
{
protected:
typedef std::set<const Renderable *> RenderableSet;
+ typedef std::vector<const Renderable *> RenderableArray;
RenderableSet renderables;
+ mutable RenderableArray cache;
public:
virtual void add(const Renderable &);
virtual void remove(const Renderable &);
+private:
+ void populate_cache() const;
+
+public:
virtual void setup_frame() const;
virtual void finish_frame() const;