]> git.sesse.net Git - movit/blob - effect.h
eb3313a124161612e4e1ea32deb85c29ae96d8ec
[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 GLint get_uniform_location(GLuint glsl_program_num, const std::string &prefix, const std::string &key);
28 void set_uniform_int(GLuint glsl_program_num, const std::string &prefix, const std::string &key, int value);
29 void set_uniform_float(GLuint glsl_program_num, const std::string &prefix, const std::string &key, float value);
30 void set_uniform_float_array(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values, size_t num_values);
31 void set_uniform_vec2(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values);
32 void set_uniform_vec3(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values);
33 void set_uniform_vec4_array(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values, size_t num_values);
34
35 class Effect {
36 public: 
37         virtual bool needs_linear_light() const { return true; }
38         virtual bool needs_srgb_primaries() const { return true; }
39         virtual bool needs_many_samples() const { return false; }
40         virtual bool needs_mipmaps() const { return false; }
41         virtual void add_self_to_effect_chain(std::vector<Effect *> *chain) {
42                 chain->push_back(this);
43         }
44
45         virtual std::string output_convenience_uniforms() const;
46         virtual std::string output_fragment_shader() = 0;
47
48         virtual void set_uniforms(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num);
49
50         // Neither of these take ownership.
51         virtual bool set_int(const std::string&, int value);
52         virtual bool set_float(const std::string &key, float value);
53         virtual bool set_vec2(const std::string &key, const float *values);
54         virtual bool set_vec3(const std::string &key, const float *values);
55
56 protected:
57         // Neither of these take ownership.
58         void register_int(const std::string &key, int *value);
59         void register_float(const std::string &key, float *value);
60         void register_vec2(const std::string &key, float *values);
61         void register_vec3(const std::string &key, float *values);
62         void register_1d_texture(const std::string &key, float *values, size_t size);
63         void invalidate_1d_texture(const std::string &key);
64         
65 private:
66         struct Texture1D {
67                 float *values;
68                 size_t size;
69                 bool needs_update;
70                 GLuint texture_num;
71         };
72
73         std::map<std::string, int *> params_int;
74         std::map<std::string, float *> params_float;
75         std::map<std::string, float *> params_vec2;
76         std::map<std::string, float *> params_vec3;
77         std::map<std::string, Texture1D> params_tex_1d;
78 };
79
80 #endif // !defined(_EFFECT_H)