cache_dirty = true;
}
-void OccludedScene::render(Renderer &renderer, const Tag &tag) const
+void OccludedScene::populate_cache() const
{
- if(renderables.empty())
+ if(!cache_dirty)
return;
- const Camera *camera = renderer.get_camera();
- if(!camera)
+ if(occluded_cache.size()<renderables.size())
{
- for(RenderableSet::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
- renderer.render(**i, tag);
- return;
+ unsigned old_size = occluded_cache.size();
+ occluded_cache.resize(renderables.size());
+ vector<unsigned> new_queries(occluded_cache.size()-old_size);
+ glGenQueries(new_queries.size(), &new_queries[0]);
+ for(unsigned i=0; i<new_queries.size(); ++i)
+ occluded_cache[old_size+i].query = new_queries[i];
}
- if(cache_dirty)
+ OccludedArray::iterator j = occluded_cache.begin();
+ for(RenderableSet::iterator i=renderables.begin(); i!=renderables.end(); ++i, ++j)
+ j->renderable = *i;
+ for(; j!=occluded_cache.end(); ++j)
{
- if(occluded_cache.size()<renderables.size())
- {
- unsigned old_size = occluded_cache.size();
- occluded_cache.resize(renderables.size());
- vector<unsigned> new_queries(occluded_cache.size()-old_size);
- glGenQueries(new_queries.size(), &new_queries[0]);
- for(unsigned i=0; i<new_queries.size(); ++i)
- occluded_cache[old_size+i].query = new_queries[i];
- }
+ j->renderable = 0;
+ j->in_frustum = false;
+ }
- OccludedArray::iterator j = occluded_cache.begin();
- for(RenderableSet::iterator i=renderables.begin(); i!=renderables.end(); ++i, ++j)
- j->renderable = *i;
- for(; j!=occluded_cache.end(); ++j)
- {
- j->renderable = 0;
- j->in_frustum = false;
- }
+ cache_dirty = false;
+}
+
+void OccludedScene::setup_frame(Renderer &renderer)
+{
+ populate_cache();
+ for(OccludedArray::const_iterator i=occluded_cache.begin(); i!=occluded_cache.end(); ++i)
+ i->renderable->setup_frame(renderer);
+}
- cache_dirty = false;
+void OccludedScene::finish_frame()
+{
+ for(OccludedArray::const_iterator i=occluded_cache.begin(); i!=occluded_cache.end(); ++i)
+ i->renderable->finish_frame();
+}
+
+void OccludedScene::render(Renderer &renderer, const Tag &tag) const
+{
+ if(renderables.empty())
+ return;
+
+ populate_cache();
+
+ const Camera *camera = renderer.get_camera();
+ if(!camera)
+ {
+ for(OccludedArray::const_iterator i=occluded_cache.begin(); i!=occluded_cache.end(); ++i)
+ renderer.render(*i->renderable, tag);
+ return;
}
const Vector3 &camera_pos = camera->get_position();
reference = r;
}
+void ZSortedScene::populate_cache() const
+{
+ if(sorted_cache.empty() && !renderables.empty())
+ {
+ sorted_cache.reserve(renderables.size());
+ sorted_cache.insert(sorted_cache.end(), renderables.begin(), renderables.end());
+ }
+}
+
+void ZSortedScene::setup_frame(Renderer &renderer)
+{
+ populate_cache();
+ for(SortedArray::const_iterator i=sorted_cache.begin(); i!=sorted_cache.end(); ++i)
+ i->renderable->setup_frame(renderer);
+}
+
+void ZSortedScene::finish_frame()
+{
+ for(SortedArray::const_iterator i=sorted_cache.begin(); i!=sorted_cache.end(); ++i)
+ i->renderable->finish_frame();
+}
+
void ZSortedScene::render(Renderer &renderer, const Tag &tag) const
{
if(renderables.empty())
return;
+ populate_cache();
+
const Camera *camera = renderer.get_camera();
if(!camera)
{
- for(RenderableSet::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
- renderer.render(**i, tag);
+ for(SortedArray::const_iterator i=sorted_cache.begin(); i!=sorted_cache.end(); ++i)
+ renderer.render(*i->renderable, tag);
return;
}
- if(sorted_cache.empty())
- {
- sorted_cache.reserve(renderables.size());
- sorted_cache.insert(sorted_cache.end(), renderables.begin(), renderables.end());
- }
-
const Vector3 &camera_pos = camera->get_position();
const Vector3 &look_dir = camera->get_look_direction();
float radius_factor = reference-1.0f;