]> git.tdb.fi Git - libs/gl.git/commitdiff
Support specifying enabled methods in effect templates
authorMikko Rasa <tdb@tdb.fi>
Fri, 11 Mar 2022 09:24:39 +0000 (11:24 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 11 Mar 2022 09:24:39 +0000 (11:24 +0200)
source/effects/effect.cpp
source/effects/effect.h
source/effects/environmentmap.cpp
source/effects/shadowmap.cpp
source/effects/sky.cpp

index 878e23fb571cf1881e0af3cf163a1696a3cfd661..0ead01c32fb22ea3d91c43d0cfa1b677c37faf05 100644 (file)
@@ -1,6 +1,8 @@
 #include <msp/core/algorithm.h>
 #include "effect.h"
 
+using namespace std;
+
 namespace Msp {
 namespace GL {
 
@@ -31,6 +33,13 @@ bool Effect::is_enabled_for_method(Tag tag) const
 }
 
 
+void Effect::Template::create_base(Effect &effect) const
+{
+       for(Tag m: enabled_methods)
+               effect.enable_for_method(m);
+}
+
+
 Effect::Template::Loader::Loader(Template &t, Collection &c):
        CollectionObjectLoader<Template>(t, &c)
 { }
@@ -38,6 +47,12 @@ Effect::Template::Loader::Loader(Template &t, Collection &c):
 void Effect::Template::Loader::init_actions()
 {
        add("content", &Template::content_name);
+       add("enable_for_method", &Loader::enable_for_method);
+}
+
+void Effect::Template::Loader::enable_for_method(const string &m)
+{
+       obj.enabled_methods.push_back(m);
 }
 
 } // namespace GL
index e77b4cf5c8b110f1ca42a6dc35c2434629534ea3..a77cdb5abae46023305c605b1dd7966203c07126 100644 (file)
@@ -34,13 +34,18 @@ public:
                        Loader(Template &, Collection &);
                protected:
                        virtual void init_actions();
+
+               private:
+                       void enable_for_method(const std::string &);
                };
 
                std::string content_name;
+               std::vector<Tag> enabled_methods;
 
                virtual ~Template() = default;
 
                virtual Effect *create(const std::map<std::string, Renderable *> &) const = 0;
+               void create_base(Effect &) const;
        };
 
 protected:
index 0047e5844abbe8b9968075d8559e64e9999e0f01..7590579192b868951014adfa8072f71de493ba1a 100644 (file)
@@ -218,6 +218,8 @@ EnvironmentMap *EnvironmentMap::Template::create(const map<string, Renderable *>
                env_map->set_fixed_position(fixed_position);
        env_map->set_depth_clip(near_clip, far_clip);
 
+       create_base(*env_map);
+
        return env_map.release();
 }
 
index 123cae274bb698327c476dfa382f69e0d266487b..bbf602bc60f2ed483215074c0727eba0e8ea2634 100644 (file)
@@ -298,6 +298,8 @@ ShadowMap *ShadowMap::Template::create(const map<string, Renderable *> &renderab
                        throw invalid_operation("ShadowMap::Template::create");
        }
 
+       create_base(*shadow_map);
+
        return shadow_map.release();
 }
 
index 2732b7adb86d50834772d59f050de27b79700200..be4896fbbd9e725632d5d1dfd8f3fdf0fd9df140 100644 (file)
@@ -199,7 +199,11 @@ Sky *Sky::Template::create(const map<string, Renderable *> &renderables) const
        Renderable *content = get_item(renderables, content_name);
        if(!content || !sun)
                throw invalid_operation("Sky::Template::create");
-       return new Sky(*content, *sun);
+
+       RefPtr<Sky> sky = new Sky(*content, *sun);
+       create_base(*sky);
+
+       return sky.release();
 }