]> git.tdb.fi Git - libs/gl.git/blob - source/effects/effect.h
Rename "renderable" to "content" in Effects and Scenes
[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 Base class for visual effects.
13
14 Effects wrap other renderables and provide additional textures or uniform
15 values which can be used by shaders to modify the appearance of the content
16 renderable.  Some material properties require certain Effects to be present in
17 order to function properly.
18
19 If an Effect subclass needs to do any sideband rendering to prepare for a
20 frame, that should be done in setup_frame().  The render() function should only
21 set up the necessary state and call the content renderable's render() function.
22 */
23 class Effect: public Renderable
24 {
25 public:
26         /**
27         Holds the parameters for an Effect.  Used with SequenceTemplate.
28         */
29         struct Template
30         {
31                 class Loader: public DataFile::CollectionObjectLoader<Template>
32                 {
33                 public:
34                         Loader(Template &, Collection &);
35                 protected:
36                         virtual void init_actions();
37                 };
38
39                 std::string content_name;
40
41                 virtual ~Template() = default;
42
43                 virtual Effect *create(const std::map<std::string, Renderable *> &) const = 0;
44         };
45
46 protected:
47         Renderable &content;
48         std::vector<Tag> enabled_methods;
49
50 protected:
51         Effect(Renderable &);
52 public:
53         virtual ~Effect() { }
54
55         void enable_for_method(Tag);
56         void disable_for_method(Tag);
57         bool is_enabled_for_method(Tag) const;
58
59         virtual const Matrix *get_matrix() const { return content.get_matrix(); }
60         virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return content.get_bounding_sphere(); }
61
62         virtual void setup_frame(Renderer &r) { content.setup_frame(r); }
63         virtual void finish_frame() { content.finish_frame(); }
64
65         virtual void set_debug_name(const std::string &) = 0;
66 };
67
68 } // namespace GL
69 } // namespace Msp
70
71 #endif