]> git.tdb.fi Git - libs/gl.git/commitdiff
Use a type registry to manage postprocessor types for pipeline templates
authorMikko Rasa <tdb@tdb.fi>
Wed, 12 Jun 2019 17:07:00 +0000 (20:07 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 12 Jun 2019 17:07:00 +0000 (20:07 +0300)
source/pipelinetemplate.cpp
source/pipelinetemplate.h

index 6fc63227c061c740bcbf4a7257c2c72baff58cd4..8c6dbe501203e0ee9bbcfb7a22fc27e3d869b7d8 100644 (file)
@@ -26,6 +26,21 @@ PipelineTemplate::~PipelineTemplate()
 }
 
 
+PipelineTemplate::PostProcessorRegistry &PipelineTemplate::get_postprocessor_registry()
+{
+       static PostProcessorRegistry registry;
+       static bool initialized = false;
+       if(!initialized)
+       {
+               registry.register_type<AmbientOcclusion>("ambient_occlusion");
+               registry.register_type<Bloom>("bloom");
+               registry.register_type<ColorCurve>("colorcurve");
+               initialized = true;
+       }
+       return registry;
+}
+
+
 PipelineTemplate::Pass::~Pass()
 { }
 
@@ -44,13 +59,12 @@ PipelineTemplate::Loader::Loader(PipelineTemplate &t, Collection &c):
 
 void PipelineTemplate::Loader::init()
 {
-       add("ambient_occlusion", &Loader::postprocessor<AmbientOcclusion>);
-       add("bloom", &Loader::postprocessor<Bloom>);
-       add("colorcurve", &Loader::postprocessor<ColorCurve>);
        add("hdr", &PipelineTemplate::hdr);
        add("multisample", &Loader::multisample);
        add("multisample", &Loader::multisample_range);
        add("pass", &Loader::pass);
+
+       get_postprocessor_registry().add_all(*this);
 }
 
 void PipelineTemplate::Loader::multisample(unsigned samples)
@@ -78,14 +92,6 @@ void PipelineTemplate::Loader::pass(const string &tag, const string &rend)
        obj.passes.push_back(pss);
 }
 
-template<typename T>
-void PipelineTemplate::Loader::postprocessor()
-{
-       RefPtr<typename T::Template> postproc = new typename T::Template;
-       load_sub(*postproc);
-       obj.postprocessors.push_back(postproc.release());
-}
-
 
 PipelineTemplate::Pass::Loader::Loader(Pass &p):
        DataFile::CollectionObjectLoader<Pass>(p, 0)
index cdf73ac7c01c465764464863218e2ff5cc67db6b..d98633539e06dff0dac89b3ef71d5f1478243676 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <string>
 #include <vector>
+#include <msp/datafile/loadabletyperegistry.h>
 #include <msp/datafile/objectloader.h>
 #include "blend.h"
 #include "postprocessor.h"
@@ -19,6 +20,13 @@ class PipelineTemplate
 public:
        class Loader: public DataFile::CollectionObjectLoader<PipelineTemplate>
        {
+       private:
+               template<typename T>
+               struct AddPostProc
+               {
+                       static void add(Loader &ldr, const std::string &kw) { ldr.add(kw, &Loader::postprocessor<T>); }
+               };
+
        public:
                Loader(PipelineTemplate &);
                Loader(PipelineTemplate &, Collection &);
@@ -31,6 +39,8 @@ public:
 
                template<typename T>
                void postprocessor();
+
+               friend class PipelineTemplate;
        };
 
        struct Pass
@@ -67,6 +77,8 @@ public:
        typedef std::vector<PostProcessor::Template *> PostProcessorArray;
 
 private:
+       typedef DataFile::LoadableTypeRegistry<Loader, Loader::AddPostProc> PostProcessorRegistry;
+
        bool hdr;
        unsigned required_multisample;
        unsigned max_multisample;
@@ -82,8 +94,27 @@ public:
        unsigned get_maximum_multisample() const { return max_multisample; }
        const PassArray &get_passes() const { return passes; }
        const PostProcessorArray &get_postprocessors() const { return postprocessors; }
+
+       template<typename T>
+       static void register_postprocessor(const std::string &);
+private:
+       static PostProcessorRegistry &get_postprocessor_registry();
 };
 
+template<typename T>
+void PipelineTemplate::register_postprocessor(const std::string &kw)
+{
+       get_postprocessor_registry().register_type<T>(kw);
+}
+
+template<typename T>
+void PipelineTemplate::Loader::postprocessor()
+{
+       RefPtr<typename T::Template> postproc = new typename T::Template;
+       load_sub(*postproc);
+       obj.postprocessors.push_back(postproc.release());
+}
+
 } // namespace GL
 } // namespace Msp