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