]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/sequence.h
Refactor owned postprocessors in Sequence into a more generic mechanism
[libs/gl.git] / source / render / sequence.h
index 13431ac469e824c4b9e5d1a4283678d710011090..f51d28b948fc783520f124d44812cb78ebf75843 100644 (file)
@@ -56,16 +56,16 @@ public:
        };
 
 private:
-       struct PostProcStep
+       struct OwnedObject
        {
-               PostProcessor *postproc;
-               bool owned;
+               void *pointer = 0;
+               void (*delete_func)(void *) = 0;
 
-               PostProcStep(PostProcessor *pp, bool o): postproc(pp), owned(o) { }
+               OwnedObject(void *p, void (*d)(void *)): pointer(p), delete_func(d) { }
        };
 
        std::vector<Step> steps;
-       std::vector<PostProcStep> postproc;
+       std::vector<PostProcessor *> postproc;
        unsigned width = 0;
        unsigned height = 0;
        FrameFormat target_format;
@@ -75,6 +75,7 @@ private:
        std::vector<Color> clear_colors;
        float clear_depth = 1.0f;
        int clear_stencil = 0;
+       std::vector<OwnedObject> owned_data;
 
        static Tag noclear_tag;
 
@@ -99,15 +100,11 @@ public:
        /** Adds a postprocessor to the sequence. */
        void add_postprocessor(PostProcessor &);
 
-       /** Adds a postprocessor to the sequence, transferring ownership.  The
-       postprocessor will be deleted together with with sequence.  It is also
-       deleted if this call throws an exception. */
-       void add_postprocessor_owned(PostProcessor *);
+       /** Adds an owned object, which will be deleted together with the sequence. */
+       template<typename T>
+       void add_owned(T *p)
+       { owned_data.push_back({ p, [](void *ptr){ delete static_cast<T *>(ptr); } }); }
 
-private:
-       void add_postprocessor(PostProcessor *, bool);
-
-public:
        virtual void setup_frame(Renderer &);
        virtual void finish_frame();