From: Mikko Rasa Date: Sat, 30 Oct 2021 18:35:15 +0000 (+0300) Subject: Remove the exclusion mechanism from Renderer X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=0fa506250545acb83bc86f1734826544d6f1eda6;p=libs%2Fgl.git Remove the exclusion mechanism from Renderer 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. --- diff --git a/source/effects/environmentmap.cpp b/source/effects/environmentmap.cpp index 419f402b..b9a7124c 100644 --- a/source/effects/environmentmap.cpp +++ b/source/effects/environmentmap.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #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) diff --git a/source/effects/environmentmap.h b/source/effects/environmentmap.h index 0c800125..43385816 100644 --- a/source/effects/environmentmap.h +++ b/source/effects/environmentmap.h @@ -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; diff --git a/source/effects/shadowmap.cpp b/source/effects/shadowmap.cpp index 27b69544..55da7301 100644 --- a/source/effects/shadowmap.cpp +++ b/source/effects/shadowmap.cpp @@ -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) diff --git a/source/render/occludedscene.cpp b/source/render/occludedscene.cpp index edd45c47..5d85b5d5 100644 --- a/source/render/occludedscene.cpp +++ b/source/render/occludedscene.cpp @@ -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 diff --git a/source/render/orderedscene.cpp b/source/render/orderedscene.cpp index bf1a6248..2d018c70 100644 --- a/source/render/orderedscene.cpp +++ b/source/render/orderedscene.cpp @@ -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); } } diff --git a/source/render/renderer.cpp b/source/render/renderer.cpp index 447ab4e3..8a2833b8 100644 --- a/source/render/renderer.cpp +++ b/source/render/renderer.cpp @@ -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); diff --git a/source/render/renderer.h b/source/render/renderer.h index 0496aaf3..eb23e96d 100644 --- a/source/render/renderer.h +++ b/source/render/renderer.h @@ -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 texture_stack; ProgramData standard_shdata; std::vector shdata_stack; - std::set 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); diff --git a/source/render/sequence.cpp b/source/render/sequence.cpp index 5d003753..2a5b351c 100644 --- a/source/render/sequence.cpp +++ b/source/render/sequence.cpp @@ -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]) diff --git a/source/render/simplescene.cpp b/source/render/simplescene.cpp index bcc4af21..4ddbeca6 100644 --- a/source/render/simplescene.cpp +++ b/source/render/simplescene.cpp @@ -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); } } diff --git a/source/render/slot.cpp b/source/render/slot.cpp index 7b77f45e..adbf535e 100644 --- a/source/render/slot.cpp +++ b/source/render/slot.cpp @@ -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 diff --git a/source/render/zsortedscene.cpp b/source/render/zsortedscene.cpp index b9833dad..dd5f1f3a 100644 --- a/source/render/zsortedscene.cpp +++ b/source/render/zsortedscene.cpp @@ -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); }