]> git.tdb.fi Git - libs/gl.git/blob - source/effects/effect.h
Check the flat qualifier from the correct member
[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                 private:
39                         void enable_for_method(const std::string &);
40                 };
41
42                 std::string content_name;
43                 std::vector<Tag> enabled_methods;
44
45                 virtual ~Template() = default;
46
47                 virtual Effect *create(const std::map<std::string, Renderable *> &) const = 0;
48                 void create_base(Effect &) const;
49         };
50
51 protected:
52         Renderable &content;
53         std::vector<Tag> enabled_methods;
54
55 protected:
56         Effect(Renderable &);
57 public:
58         virtual ~Effect() { }
59
60         void enable_for_method(Tag);
61         void disable_for_method(Tag);
62         bool is_enabled_for_method(Tag) const;
63
64         virtual const Matrix *get_matrix() const { return content.get_matrix(); }
65         virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return content.get_bounding_sphere(); }
66
67         virtual void setup_frame(Renderer &r) { content.setup_frame(r); }
68         virtual void finish_frame() { content.finish_frame(); }
69
70         virtual void set_debug_name(const std::string &) = 0;
71 };
72
73 } // namespace GL
74 } // namespace Msp
75
76 #endif