From: Mikko Rasa Date: Wed, 12 Jun 2019 17:07:00 +0000 (+0300) Subject: Use a type registry to manage postprocessor types for pipeline templates X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e16855bccb78c721e2fe3f2ea8fc0310e041cb43;p=libs%2Fgl.git Use a type registry to manage postprocessor types for pipeline templates --- diff --git a/source/pipelinetemplate.cpp b/source/pipelinetemplate.cpp index 6fc63227..8c6dbe50 100644 --- a/source/pipelinetemplate.cpp +++ b/source/pipelinetemplate.cpp @@ -26,6 +26,21 @@ PipelineTemplate::~PipelineTemplate() } +PipelineTemplate::PostProcessorRegistry &PipelineTemplate::get_postprocessor_registry() +{ + static PostProcessorRegistry registry; + static bool initialized = false; + if(!initialized) + { + registry.register_type("ambient_occlusion"); + registry.register_type("bloom"); + registry.register_type("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); - add("bloom", &Loader::postprocessor); - add("colorcurve", &Loader::postprocessor); 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 -void PipelineTemplate::Loader::postprocessor() -{ - RefPtr postproc = new typename T::Template; - load_sub(*postproc); - obj.postprocessors.push_back(postproc.release()); -} - PipelineTemplate::Pass::Loader::Loader(Pass &p): DataFile::CollectionObjectLoader(p, 0) diff --git a/source/pipelinetemplate.h b/source/pipelinetemplate.h index cdf73ac7..d9863353 100644 --- a/source/pipelinetemplate.h +++ b/source/pipelinetemplate.h @@ -3,6 +3,7 @@ #include #include +#include #include #include "blend.h" #include "postprocessor.h" @@ -19,6 +20,13 @@ class PipelineTemplate public: class Loader: public DataFile::CollectionObjectLoader { + private: + template + struct AddPostProc + { + static void add(Loader &ldr, const std::string &kw) { ldr.add(kw, &Loader::postprocessor); } + }; + public: Loader(PipelineTemplate &); Loader(PipelineTemplate &, Collection &); @@ -31,6 +39,8 @@ public: template void postprocessor(); + + friend class PipelineTemplate; }; struct Pass @@ -67,6 +77,8 @@ public: typedef std::vector PostProcessorArray; private: + typedef DataFile::LoadableTypeRegistry 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 + static void register_postprocessor(const std::string &); +private: + static PostProcessorRegistry &get_postprocessor_registry(); }; +template +void PipelineTemplate::register_postprocessor(const std::string &kw) +{ + get_postprocessor_registry().register_type(kw); +} + +template +void PipelineTemplate::Loader::postprocessor() +{ + RefPtr postproc = new typename T::Template; + load_sub(*postproc); + obj.postprocessors.push_back(postproc.release()); +} + } // namespace GL } // namespace Msp