]> git.tdb.fi Git - libs/gl.git/blob - source/effects/effect.h
Support effects and subordinate sequences inside sequence templates
[libs/gl.git] / source / effects / effect.h
1 #ifndef MSP_GL_EFFECT_H_
2 #define MSP_GL_EFFECT_H_
3
4 #include <set>
5 #include <msp/datafile/objectloader.h>
6 #include "renderable.h"
7
8 namespace Msp {
9 namespace GL {
10
11 /**
12 Effects are used to wrap other renderables and give them additional visual
13 properties.  An Effect's render method should set up the necessary state, call
14 the wrapped Renderable's render method, and clean up after itself.
15 */
16 class Effect: public Renderable
17 {
18 public:
19         struct Template
20         {
21                 class Loader: public DataFile::CollectionObjectLoader<Template>
22                 {
23                 public:
24                         Loader(Template &, Collection &);
25                 protected:
26                         virtual void init_actions();
27                 };
28
29                 std::string content_name;
30
31                 virtual ~Template() = default;
32
33                 virtual Effect *create(const std::map<std::string, Renderable *> &) const = 0;
34         };
35
36 protected:
37         Renderable &renderable;
38         std::set<Tag> enabled_methods;
39
40 protected:
41         Effect(Renderable &);
42 public:
43         virtual ~Effect() { }
44
45         void enable_for_method(Tag);
46         void disable_for_method(Tag);
47
48         virtual const Matrix *get_matrix() const { return renderable.get_matrix(); }
49         virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return renderable.get_bounding_sphere(); }
50
51         virtual void setup_frame(Renderer &r) { renderable.setup_frame(r); }
52         virtual void finish_frame() { renderable.finish_frame(); }
53
54         virtual void set_debug_name(const std::string &) = 0;
55 };
56
57 } // namespace GL
58 } // namespace Msp
59
60 #endif