]> git.tdb.fi Git - libs/gl.git/commitdiff
Use pipeline keys for objects and effects
authorMikko Rasa <tdb@tdb.fi>
Wed, 19 Jan 2022 13:00:52 +0000 (15:00 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 19 Jan 2022 13:00:52 +0000 (15:00 +0200)
source/effects/ambientocclusion.cpp
source/effects/bloom.cpp
source/effects/colorcurve.cpp
source/effects/environmentmap.cpp
source/effects/sky.cpp
source/render/instancearray.cpp
source/render/object.cpp
source/render/renderer.h

index 350c6423dd4ac21c5335f91402cd08eeb7d23494..a519b80aaf7e67090908f159bd076b72cb624b8c 100644 (file)
@@ -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);
index 5204adb7ab41d27818de8f1463f66d7067d9029b..b9b63bcbc1d3505758dd347ae869fe29be98b554 100644 (file)
@@ -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);
index ba76a9647d2ff789e2991276d2742c520bd0ba63..ac1ed9aa64bac9d50b3910c14c0356658afd782b 100644 (file)
@@ -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);
index f6e1c41186442791a98b19d0cad600d829e61aba..0047e5844abbe8b9968075d8559e64e9999e0f01 100644 (file)
@@ -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<specular_fbos.size(); ++i)
        {
                prefilter_shdata.uniform("roughness", 1.0f-sqrt(1.0f-static_cast<float>(i+1)/specular_fbos.size()));
+               renderer.set_pipeline_key(this, 1+i);
                renderer.set_framebuffer(&specular_fbos[i]);
                fullscreen_mesh.draw(renderer);
        }
index a11a76a971bad75f2c6b82f9933af39ddf0db193..eef6a58c4ccdedb622541fb828e2f925a3c17145 100644 (file)
@@ -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);
index 93985578ef08e04a0aaff4b9a66b2d567a5c8634..a838b948cf57600bf9c7a58d41439847a69126d0 100644 (file)
@@ -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());
 }
index 65e9a7ef083fc52db1f899906b7febaed96264a5..e46274f6362a44fb2dc569269c8e39f5123eeadf 100644 (file)
@@ -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);
index 79bd5cd913931a7eeca01f0e79e358b6965fd329..75c8cc8b58aaada99b371eb1bfc553d47d3d4ad7 100644 (file)
@@ -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<uintptr_t>(p)); }
+
+       template<typename T>
+       void set_pipeline_key(std::uintptr_t k, T d)
+       { set_pipeline_key(k^(static_cast<uintptr_t>(d)<<((sizeof(std::uintptr_t)-sizeof(T))*std::numeric_limits<char>::digits))); }
+
+       template<typename T>
+       void set_pipeline_key(const void *p, T d) { set_pipeline_key(reinterpret_cast<uintptr_t>(p), d); }
 
        /** Sets the camera to render from.  The model matrix is reset to identity. */
        void set_camera(const Camera &);