]> git.sesse.net Git - movit/blob - effect.h
Make a new system for meta-effects, and convert the blur to use it. Hides the two...
[movit] / effect.h
1 #ifndef _EFFECT_H
2 #define _EFFECT_H 1
3
4 #include <map>
5 #include <string>
6 #include <vector>
7
8 #include <GL/gl.h>
9
10 // Can alias on a float[2].
11 struct Point2D {
12         Point2D(float x, float y)
13                 : x(x), y(y) {}
14
15         float x, y;
16 };
17
18 // Can alias on a float[3].
19 struct RGBTriplet {
20         RGBTriplet(float r, float g, float b)
21                 : r(r), g(g), b(b) {}
22
23         float r, g, b;
24 };
25
26 // Convenience functions that deal with prepending the prefix.
27 void set_uniform_int(GLuint glsl_program_num, const std::string &prefix, const std::string &key, int value);
28 void set_uniform_float(GLuint glsl_program_num, const std::string &prefix, const std::string &key, float value);
29 void set_uniform_float_array(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values, size_t num_values);
30 void set_uniform_vec2(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values);
31 void set_uniform_vec3(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values);
32 void set_uniform_vec4_array(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values, size_t num_values);
33
34 class Effect {
35 public: 
36         virtual bool needs_linear_light() const { return true; }
37         virtual bool needs_srgb_primaries() const { return true; }
38         virtual bool needs_many_samples() const { return false; }
39         virtual bool needs_mipmaps() const { return false; }
40         virtual void add_self_to_effect_chain(std::vector<Effect *> *chain) {
41                 chain->push_back(this);
42         }
43
44         virtual std::string output_convenience_uniforms() const;
45         virtual std::string output_fragment_shader() = 0;
46
47         virtual void set_uniforms(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num);
48
49         // Neither of these take ownership.
50         virtual bool set_int(const std::string&, int value);
51         virtual bool set_float(const std::string &key, float value);
52         virtual bool set_vec2(const std::string &key, const float *values);
53         virtual bool set_vec3(const std::string &key, const float *values);
54
55 protected:
56         // Neither of these take ownership.
57         void register_int(const std::string &key, int *value);
58         void register_float(const std::string &key, float *value);
59         void register_vec2(const std::string &key, float *values);
60         void register_vec3(const std::string &key, float *values);
61         void register_1d_texture(const std::string &key, float *values, size_t size);
62         void invalidate_1d_texture(const std::string &key);
63         
64 private:
65         struct Texture1D {
66                 float *values;
67                 size_t size;
68                 bool needs_update;
69                 GLuint texture_num;
70         };
71
72         std::map<std::string, int *> params_int;
73         std::map<std::string, float *> params_float;
74         std::map<std::string, float *> params_vec2;
75         std::map<std::string, float *> params_vec3;
76         std::map<std::string, Texture1D> params_tex_1d;
77 };
78
79 #endif // !defined(_EFFECT_H)