From: Mikko Rasa Date: Wed, 19 Jan 2022 13:00:52 +0000 (+0200) Subject: Use pipeline keys for objects and effects X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=7515dea78777a7184f207d353d23f9ad9917675e;p=libs%2Fgl.git Use pipeline keys for objects and effects --- diff --git a/source/effects/ambientocclusion.cpp b/source/effects/ambientocclusion.cpp index 350c6423..a519b80a 100644 --- a/source/effects/ambientocclusion.cpp +++ b/source/effects/ambientocclusion.cpp @@ -109,10 +109,12 @@ void AmbientOcclusion::render(Renderer &renderer, const Texture2D &color, const renderer.set_texture("rotate", &rotate_lookup, &nearest_sampler); renderer.set_shader_program(&occlude_shader, &shdata); + renderer.set_pipeline_key(this); renderer.set_framebuffer(&occlude_target.get_framebuffer()); renderer.clear(0); quad.draw(renderer); + renderer.set_pipeline_key(this, 1); renderer.set_framebuffer(out_fbo); renderer.clear(0); renderer.set_shader_program(&combine_shader); diff --git a/source/effects/bloom.cpp b/source/effects/bloom.cpp index 5204adb7..b9b63bcb 100644 --- a/source/effects/bloom.cpp +++ b/source/effects/bloom.cpp @@ -67,6 +67,7 @@ void Bloom::render(Renderer &renderer, const Texture2D &src, const Texture2D &) for(unsigned i=0; i<2; ++i) { Renderer::Push push2(renderer); + renderer.set_pipeline_key(this, i); renderer.set_framebuffer(&target[i]->get_framebuffer()); renderer.clear(0); renderer.set_texture("source", (i ? &target[0]->get_target_texture(COLOR_ATTACHMENT) : &src), &nearest_sampler); @@ -74,6 +75,7 @@ void Bloom::render(Renderer &renderer, const Texture2D &src, const Texture2D &) quad.draw(renderer); } + renderer.set_pipeline_key(this, 2); renderer.clear(0); renderer.set_texture("source", &src, &nearest_sampler); renderer.set_texture("blurred", &target[1]->get_target_texture(COLOR_ATTACHMENT), &linear_sampler); diff --git a/source/effects/colorcurve.cpp b/source/effects/colorcurve.cpp index ba76a964..ac1ed9aa 100644 --- a/source/effects/colorcurve.cpp +++ b/source/effects/colorcurve.cpp @@ -69,6 +69,7 @@ void ColorCurve::set_linear() void ColorCurve::render(Renderer &renderer, const Texture2D &color_buf, const Texture2D &) { Renderer::Push push(renderer); + renderer.set_pipeline_key(this); renderer.clear(0); renderer.set_shader_program(&shprog, &shdata); renderer.set_texture("source", &color_buf, &nearest_sampler); diff --git a/source/effects/environmentmap.cpp b/source/effects/environmentmap.cpp index f6e1c411..0047e584 100644 --- a/source/effects/environmentmap.cpp +++ b/source/effects/environmentmap.cpp @@ -141,6 +141,7 @@ void EnvironmentMap::setup_frame(Renderer &renderer) environment.render(renderer); } + renderer.set_pipeline_key(this); renderer.set_framebuffer(&irradiance_fbo); renderer.set_shader_program(&irradiance_shprog, &prefilter_shdata); renderer.set_texture("environment_map", &env_tex, 0, &sampler); @@ -150,6 +151,7 @@ void EnvironmentMap::setup_frame(Renderer &renderer) for(unsigned i=0; i(i+1)/specular_fbos.size())); + renderer.set_pipeline_key(this, 1+i); renderer.set_framebuffer(&specular_fbos[i]); fullscreen_mesh.draw(renderer); } diff --git a/source/effects/sky.cpp b/source/effects/sky.cpp index a11a76a9..eef6a58c 100644 --- a/source/effects/sky.cpp +++ b/source/effects/sky.cpp @@ -109,11 +109,13 @@ void Sky::setup_frame(Renderer &renderer) if(transmittance_lookup_dirty) { transmittance_lookup_dirty = false; + renderer.set_pipeline_key(this); renderer.set_framebuffer(&transmittance_lookup.get_framebuffer()); renderer.set_shader_program(&transmittance_shprog); fullscreen_mesh.draw(renderer); } + renderer.set_pipeline_key(this, 1); renderer.set_framebuffer(&distant.get_framebuffer()); renderer.set_shader_program(&distant_shprog); renderer.set_texture("transmittance_lookup", &transmittance_lookup.get_target_texture(0), &sampler); @@ -141,6 +143,7 @@ void Sky::render(Renderer &renderer, Tag tag) const Renderer::Push push(renderer); + renderer.set_pipeline_key(this, 2); renderer.set_shader_program(&backdrop_shprog, &shdata); renderer.set_texture("distant", &distant.get_target_texture(0), &wrap_sampler); fullscreen_mesh.draw(renderer); diff --git a/source/render/instancearray.cpp b/source/render/instancearray.cpp index 93985578..a838b948 100644 --- a/source/render/instancearray.cpp +++ b/source/render/instancearray.cpp @@ -107,6 +107,7 @@ void InstanceArray::render(Renderer &renderer, Tag tag) const instance_buffer->storage(instance_data.get_required_buffer_size(), STREAMING); Renderer::Push push(renderer); + renderer.set_pipeline_key(this, tag.id); method->apply(renderer); mesh->draw_instanced(renderer, vtx_setup, instances.size()); } diff --git a/source/render/object.cpp b/source/render/object.cpp index 65e9a7ef..e46274f6 100644 --- a/source/render/object.cpp +++ b/source/render/object.cpp @@ -156,6 +156,7 @@ void Object::render(Renderer &renderer, Tag tag) const throw logic_error("no mesh"); Renderer::Push push(renderer); + renderer.set_pipeline_key(this, tag.id); method->apply(renderer); setup_render(renderer, tag); @@ -175,6 +176,7 @@ void Object::render(Renderer &renderer, const ObjectInstance &inst, Tag tag) con throw logic_error("no mesh"); Renderer::Push push(renderer); + renderer.set_pipeline_key(this, tag.id); method->apply(renderer); setup_render(renderer, tag); diff --git a/source/render/renderer.h b/source/render/renderer.h index 79bd5cd9..75c8cc8b 100644 --- a/source/render/renderer.h +++ b/source/render/renderer.h @@ -144,6 +144,14 @@ private: public: void set_pipeline_key(std::uintptr_t); + void set_pipeline_key(const void *p) { set_pipeline_key(reinterpret_cast(p)); } + + template + void set_pipeline_key(std::uintptr_t k, T d) + { set_pipeline_key(k^(static_cast(d)<<((sizeof(std::uintptr_t)-sizeof(T))*std::numeric_limits::digits))); } + + template + void set_pipeline_key(const void *p, T d) { set_pipeline_key(reinterpret_cast(p), d); } /** Sets the camera to render from. The model matrix is reset to identity. */ void set_camera(const Camera &);