]> git.tdb.fi Git - libs/gl.git/commitdiff
Remove the exclusion mechanism from Renderer
authorMikko Rasa <tdb@tdb.fi>
Sat, 30 Oct 2021 18:35:15 +0000 (21:35 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 30 Oct 2021 22:28:08 +0000 (01:28 +0300)
It was only ever used by EnvironmentMap, which can do the filtering
itself.  Removing it makes the rendering process more straightforward,
with less function calls.

source/effects/environmentmap.cpp
source/effects/environmentmap.h
source/effects/shadowmap.cpp
source/render/occludedscene.cpp
source/render/orderedscene.cpp
source/render/renderer.cpp
source/render/renderer.h
source/render/sequence.cpp
source/render/simplescene.cpp
source/render/slot.cpp
source/render/zsortedscene.cpp

index 419f402b8d22287c89bfb89549190ed6a5ae8b07..b9a7124ccd93f786b7e03d816184d483f7de18ec 100644 (file)
@@ -1,5 +1,6 @@
 #include <algorithm>
 #include <cmath>
+#include <msp/core/raii.h>
 #include <msp/strings/format.h>
 #include "environmentmap.h"
 #include "error.h"
@@ -116,6 +117,8 @@ void EnvironmentMap::setup_frame(Renderer &renderer)
        update_delay = update_interval-1;
        environment.setup_frame(renderer);
 
+       SetFlag set_in(in_setup_frame);
+
        Vector3 center;
        if(use_fixed_pos)
                center = fixed_position;
@@ -129,15 +132,13 @@ void EnvironmentMap::setup_frame(Renderer &renderer)
        }
 
        Renderer::Push push(renderer);
-       Renderer::Exclude exclude1(renderer, renderable);
-       Renderer::Exclude exclude2(renderer, *this);
 
        for(unsigned i=0; i<6; ++i)
        {
                faces[i].camera.set_position(center);
                renderer.set_framebuffer(&faces[i].fbo);
                renderer.set_camera(faces[i].camera);
-               renderer.render(environment);
+               environment.render(renderer);
        }
 
        renderer.set_framebuffer(&irradiance_fbo);
@@ -166,15 +167,17 @@ void EnvironmentMap::finish_frame()
 
 void EnvironmentMap::render(Renderer &renderer, Tag tag) const
 {
+       if(in_setup_frame)
+               return;
        if(!enabled_methods.count(tag))
-               return renderer.render(renderable, tag);
+               return renderable.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);
-       renderer.render(renderable, tag);
+       renderable.render(renderer, tag);
 }
 
 void EnvironmentMap::set_debug_name(const string &name)
index 0c80012501baab724ae5845aab1b786363c32996..4338581648b5b05917f48d8024ff98fc14bc56ea 100644 (file)
@@ -81,6 +81,7 @@ protected:
        const Sampler &mip_sampler;
        ProgramData shdata;
        bool rendered = false;
+       bool in_setup_frame = false;
        unsigned update_interval = 1;
        unsigned update_delay = 0;
 
index 27b695443341c860337242d5c2908d0479b502d7..55da7301803f76f9aef0a44cf625aa20e728399f 100644 (file)
@@ -235,7 +235,7 @@ void ShadowMap::setup_frame(Renderer &renderer)
                renderer.set_scissor(&light.region);
                renderer.set_camera(v.camera);
 
-               renderer.render(*light.shadow_caster, (v.face>0 ? "noclear" : ""));
+               light.shadow_caster->render(renderer, (v.face>0 ? "noclear" : ""));
        }
 }
 
@@ -251,13 +251,13 @@ void ShadowMap::finish_frame()
 void ShadowMap::render(Renderer &renderer, Tag tag) const
 {
        if(!enabled_methods.count(tag))
-               return renderer.render(renderable, tag);
+               return renderable.render(renderer, tag);
 
        Renderer::Push _push_rend(renderer);
 
        renderer.set_texture("shadow_map", &depth_buf, &sampler);
        renderer.add_shader_data(shdata);
-       renderer.render(renderable, tag);
+       renderable.render(renderer, tag);
 }
 
 void ShadowMap::set_debug_name(const string &name)
index edd45c47ac81f855f06e826c1daf95a6ee536524..5d85b5d5bf762d43f056d114e383cd613ef67198 100644 (file)
@@ -77,7 +77,7 @@ void OccludedScene::render(Renderer &renderer, Tag tag) const
        if(!camera)
        {
                for(const OccludedRenderable &o: occluded_cache)
-                       renderer.render(*o.renderable, tag);
+                       o.renderable->render(renderer, tag);
                return;
        }
 
@@ -107,7 +107,7 @@ void OccludedScene::render(Renderer &renderer, Tag tag) const
                        i->occluder = true;
 
                if(i->occluder)
-                       renderer.render(*i->renderable, tag);
+                       i->renderable->render(renderer, tag);
        }
 
        // Move all objects within the frustum to the beginning of the array
@@ -145,7 +145,7 @@ void OccludedScene::render(Renderer &renderer, Tag tag) const
        // Render anything that has a chance of being visible
        for(auto i=occluded_cache.begin(); (i!=occluded_cache.end() && i->in_frustum); ++i)
                if(!i->occluder && queries.get_result(i-occluded_cache.begin()))
-                       renderer.render(*i->renderable, tag);
+                       i->renderable->render(renderer, tag);
 }
 
 } // namespace GL
index bf1a62481310d4b5fe9e556ee24cdb27b9d8b25a..2d018c7080901af2a837d238caef16eb22a26789 100644 (file)
@@ -52,12 +52,12 @@ void OrderedScene::render(Renderer &renderer, Tag tag) const
        {
                for(Renderable *r: renderables)
                        if(!frustum_cull(*r))
-                               renderer.render(*r, tag);
+                               r->render(renderer, tag);
        }
        else
        {
                for(Renderable *r: renderables)
-                       renderer.render(*r, tag);
+                       r->render(renderer, tag);
        }
 }
 
index 447ab4e35de83faaad278b5df44e8861c7ea5d18..8a2833b8b55b5551a5ae992d7cd8a22ef0108299 100644 (file)
@@ -212,27 +212,10 @@ void Renderer::end()
        *state = State();
        shdata_stack.clear();
        add_shader_data(standard_shdata);
-       excluded.clear();
 
        commands.use_pipeline(0);
 }
 
-void Renderer::exclude(const Renderable &renderable)
-{
-       excluded.insert(&renderable);
-}
-
-void Renderer::include(const Renderable &renderable)
-{
-       excluded.erase(&renderable);
-}
-
-void Renderer::render(const Renderable &renderable, Tag tag)
-{
-       if(!excluded.count(&renderable))
-               renderable.render(*this, tag);
-}
-
 void Renderer::clear(const ClearValue *values)
 {
        pipeline_state.set_framebuffer(state->framebuffer);
index 0496aaf3f68584496b5f13bf754338e6c5d91ec3..eb23e96dab8deb8d8c10ec384bca387ef21b7085 100644 (file)
@@ -53,17 +53,6 @@ public:
                ~Push() { renderer.pop_state(); }
        };
 
-       class Exclude
-       {
-       private:
-               Renderer &renderer;
-               const Renderable &renderable;
-
-       public:
-               Exclude(Renderer &r, const Renderable &e): renderer(r), renderable(e) { renderer.exclude(renderable); }
-               ~Exclude() { renderer.include(renderable); }
-       };
-
 private:
        struct BoundTexture
        {
@@ -113,7 +102,6 @@ private:
        std::vector<BoundTexture> texture_stack;
        ProgramData standard_shdata;
        std::vector<BoundProgramData> shdata_stack;
-       std::set<const Renderable *> excluded;
        PipelineState pipeline_state;
        Commands commands;
 
@@ -186,12 +174,8 @@ public:
        further rendering. */
        void end();
 
-       void exclude(const Renderable &);
-       void include(const Renderable &);
-
        void clear(const ClearValue *);
 
-       void render(const Renderable &, Tag = Tag());
        void draw(const Batch &);
        void draw_instanced(const Batch &, unsigned);
 
index 5d003753bc2738d89fc49d5e34d26956b466ca78..2a5b351c888d2b7e3c609706061f8ae352301bda 100644 (file)
@@ -138,7 +138,7 @@ void Sequence::render(Renderer &renderer, Tag tag) const
                        renderer.add_shader_data(lighting->get_shader_data());
 
                if(const Renderable *renderable = s.get_renderable())
-                       renderer.render(*renderable, s.get_tag());
+                       renderable->render(renderer, s.get_tag());
        }
 
        if(target[0])
index bcc4af21dc1779f086348c1b054883733cf01425..4ddbeca6732d78a90695cb76833ae8b8b2dd037c 100644 (file)
@@ -46,12 +46,12 @@ void SimpleScene::render(Renderer &renderer, Tag tag) const
        {
                for(Renderable *r: cache)
                        if(!frustum_cull(*r))
-                               renderer.render(*r, tag);
+                               r->render(renderer, tag);
        }
        else
        {
                for(Renderable *r: cache)
-                       renderer.render(*r, tag);
+                       r->render(renderer, tag);
        }
 }
 
index 7b77f45ecf82d8b9262f1a1effa4f4a108036302..adbf535e0390419a06699e8a5b0434ae4ee8d7ab 100644 (file)
@@ -34,7 +34,7 @@ void Slot::finish_frame()
 void Slot::render(Renderer &renderer, Tag tag) const
 {
        if(renderable)
-               renderer.render(*renderable, tag);
+               renderable->render(renderer, tag);
 }
 
 } // namespace GL
index b9833dadff84ed31f5418bd2a526b3a905d9cd51..dd5f1f3ac701f727cd81b67b44f153eaa99d6282 100644 (file)
@@ -62,7 +62,7 @@ void ZSortedScene::render(Renderer &renderer, Tag tag) const
        if(!camera)
        {
                for(const SortedRenderable &r: sorted_cache)
-                       renderer.render(*r.renderable, tag);
+                       r.renderable->render(renderer, tag);
                return;
        }
 
@@ -113,7 +113,7 @@ void ZSortedScene::render(Renderer &renderer, Tag tag) const
                }
 
        for(auto i=sorted_cache.begin(); (i!=sorted_cache.end() && i->in_frustum); ++i)
-               renderer.render(*i->renderable, tag);
+               i->renderable->render(renderer, tag);
 }