]> git.tdb.fi Git - libs/gl.git/commitdiff
Better lifecycle management of the fullscreen quad in PostProcessor
authorMikko Rasa <tdb@tdb.fi>
Mon, 8 Feb 2021 11:51:44 +0000 (13:51 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 8 Feb 2021 11:51:44 +0000 (13:51 +0200)
It's now stored in a WeakPtr and the postprocessor instances hold
a RefPtr to it, so it will be deleted together with the last
postprocessor.

source/ambientocclusion.cpp
source/ambientocclusion.h
source/bloom.cpp
source/bloom.h
source/colorcurve.cpp
source/colorcurve.h
source/postprocessor.cpp
source/postprocessor.h

index 1cfdff09e8572b83f83442d834008b1724191610..17e4789d0ace5a1ef520d4169a66599aae6a3fa1 100644 (file)
@@ -103,11 +103,11 @@ void AmbientOcclusion::render(Renderer &renderer, const Texture2D &color, const
 
        {
                BindRestore bind_fbo(occlude_target.get_framebuffer());
-               quad.draw(renderer);
+               quad->draw(renderer);
        }
 
        renderer.set_shader_program(&combine_shader);
-       quad.draw(renderer);
+       quad->draw(renderer);
 }
 
 
index ff1e82443c972bb7d8fee12bf011aa2e3b3e9ea9..5a779979c8829d0c3d724a78200534e1386469c7 100644 (file)
@@ -46,7 +46,7 @@ private:
        Program occlude_shader;
        Program combine_shader;
        mutable ProgramData shdata;
-       const Mesh &quad;
+       RefPtr<Mesh> quad;
 
 public:
        AmbientOcclusion(unsigned, unsigned, float = 1.0f);
index 6484d052fdb2691b80747cd3965bc2925a799517..c7bfd467418b12f58cc3eb9c08afb46878a143c0 100644 (file)
@@ -76,13 +76,13 @@ void Bloom::render(Renderer &renderer, const Texture2D &src, const Texture2D &)
                Renderer::Push push2(renderer);
                renderer.set_texture(i ? &target[0]->get_target_texture(RENDER_COLOR) : &src);
                renderer.add_shader_data(blur_shdata[i]);
-               quad.draw(renderer);
+               quad->draw(renderer);
        }
 
        combine_texturing.attach(0, src);
        renderer.set_texturing(&combine_texturing);
        renderer.set_shader_program(&combine_shader);
-       quad.draw(renderer);
+       quad->draw(renderer);
 }
 
 
index d8bb61acd24ed8f9d1d643683754ab314b57b74e..ddf46fe96ea1f3b881936ddb7bc80c16c6e0b423 100644 (file)
@@ -47,7 +47,7 @@ private:
        ProgramData blur_shdata[2];
        Program combine_shader;
        Texturing combine_texturing;
-       const Mesh &quad;
+       RefPtr<Mesh> quad;
 
 public:
        Bloom(unsigned, unsigned);
index 78a7fc168f13439bcfbeb7f772e125cdd6519493..0b62583fc4e810e9ea8a772a99dde7fb74db6e4c 100644 (file)
@@ -77,7 +77,7 @@ void ColorCurve::render(Renderer &renderer, const Texture2D &color_buf, const Te
        Renderer::Push push(renderer);
        renderer.set_shader_program(&shprog, &shdata);
        renderer.set_texturing(&texturing);
-       quad.draw(renderer);
+       quad->draw(renderer);
 }
 
 
index d8697d837b26a689e78ef64be5a6e17d44c6c091..87d43353c80c1dcbadcc329c30992e82c16ce835 100644 (file)
@@ -49,7 +49,7 @@ private:
        ProgramData shdata;
        Texture1D curve;
        Texturing texturing;
-       const Mesh &quad;
+       RefPtr<Mesh> quad;
 
 public:
        ColorCurve();
index f67bf4cf701407feb086ddb45669394d51c7ff4b..ffc753e4b11ed658280b647e05af688ccec0039b 100644 (file)
@@ -6,27 +6,29 @@
 namespace Msp {
 namespace GL {
 
+WeakPtr<Mesh> PostProcessor::fullscreen_quad;
+
 void PostProcessor::render(Renderer &, const Texture2D &color, const Texture2D &depth)
 {
        render(color, depth);
 }
 
-const Mesh &PostProcessor::get_fullscreen_quad()
-{
-       static const Mesh &mesh = create_fullscreen_quad();
-       return mesh;
-}
-
-const Mesh &PostProcessor::create_fullscreen_quad()
+RefPtr<Mesh> PostProcessor::get_fullscreen_quad()
 {
-       static Mesh mesh(VERTEX2);
-       MeshBuilder builder(mesh);
-       builder.begin(TRIANGLE_STRIP);
-       builder.vertex(-1, 1);
-       builder.vertex(-1, -1);
-       builder.vertex(1, 1);
-       builder.vertex(1, -1);
-       builder.end();
+       RefPtr<Mesh> mesh;
+       mesh = fullscreen_quad;
+       if(!mesh)
+       {
+               mesh = new Mesh(VERTEX2);
+               MeshBuilder builder(*mesh);
+               builder.begin(TRIANGLE_STRIP);
+               builder.vertex(-1, 1);
+               builder.vertex(-1, -1);
+               builder.vertex(1, 1);
+               builder.vertex(1, -1);
+               builder.end();
+               fullscreen_quad = mesh;
+       }
        return mesh;
 }
 
index ae864c07698b7fe0dd882a0f9a679518534de674..daaf434efe06028c7891cfa3f1685139099a152a 100644 (file)
@@ -35,6 +35,9 @@ public:
                virtual PostProcessor *create(unsigned, unsigned) const = 0;
        };
 
+private:
+       static WeakPtr<Mesh> fullscreen_quad;
+
 protected:
        PostProcessor() { }
 public:
@@ -48,10 +51,7 @@ public:
 protected:
        /** Returns a mesh consisting of a single quad, covering the entire screen.
        The vertices are in normalized device coordinates. */
-       static const Mesh &get_fullscreen_quad();
-
-private:
-       static const Mesh &create_fullscreen_quad();
+       static RefPtr<Mesh> get_fullscreen_quad();
 };
 
 } // namespace GL