]> git.tdb.fi Git - libs/gl.git/commitdiff
Add setup/finish_frame methods to OccludedScene and ZSortedScene
authorMikko Rasa <tdb@tdb.fi>
Mon, 5 Dec 2016 17:21:34 +0000 (19:21 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 5 Dec 2016 17:50:15 +0000 (19:50 +0200)
source/occludedscene.cpp
source/occludedscene.h
source/zsortedscene.cpp
source/zsortedscene.h

index 2e140a534537c076b54b804dd0a09db16d7878bc..b3219123e8a2ed777d1a3a75d3691864e943712b 100644 (file)
@@ -48,41 +48,59 @@ void OccludedScene::remove(Renderable &r)
        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();
index 4d26483a26bd0bbf7cec514181f06e40b30ec8ac..6f5e23bd0d175c4572bb67df608d43328444ebd3 100644 (file)
@@ -45,6 +45,13 @@ public:
        virtual void add(Renderable &);
        virtual void remove(Renderable &);
 
+private:
+       void populate_cache() const;
+
+public:
+       virtual void setup_frame(Renderer &);
+       virtual void finish_frame();
+
        virtual void render(Renderer &, const Tag &) const;
 };
 
index fe60803a54d8e3ff323a33f5e6f23d654044e6d8..46b14dbb6a672dbfd044b1ffa7463695e9212244 100644 (file)
@@ -34,25 +34,43 @@ void ZSortedScene::set_reference(DepthReference r)
        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;
index d417777e0a9c8f37c3de1b5c4b778df17a0aa61f..f7a7f6a25227102c40716d2a99c435cfac49ed1a 100644 (file)
@@ -59,6 +59,13 @@ public:
        /// Sets the reference point for sorting.  Default is furthest from camera.
        void set_reference(DepthReference);
 
+private:
+       void populate_cache() const;
+
+public:
+       virtual void setup_frame(Renderer &);
+       virtual void finish_frame();
+
        virtual void render(Renderer &, const Tag &) const;
 };