]> git.sesse.net Git - movit/blob - blur_effect.h
Allow the EffectChainTester framebuffer to be in something else than float. This...
[movit] / blur_effect.h
1 #ifndef _BLUR_EFFECT_H
2 #define _BLUR_EFFECT_H 1
3
4 // A separable 2D blur implemented by a combination of mipmap filtering
5 // and convolution (essentially giving a convolution with a piecewise linear
6 // approximation to the true impulse response).
7 //
8 // Works in two passes; first horizontal, then vertical (BlurEffect,
9 // which is what the user is intended to use, instantiates two copies of
10 // SingleBlurPassEffect behind the scenes).
11
12 #include "effect.h"
13
14 class SingleBlurPassEffect;
15
16 class BlurEffect : public Effect {
17 public:
18         BlurEffect();
19
20         virtual std::string effect_type_id() const { return "BlurEffect"; }
21
22         // We want this for the same reason as ResizeEffect; we could end up scaling
23         // down quite a lot.
24         virtual bool needs_texture_bounce() const { return true; }
25         virtual bool needs_mipmaps() const { return true; }
26         virtual bool needs_srgb_primaries() const { return false; }
27
28         virtual void inform_input_size(unsigned input_num, unsigned width, unsigned height);
29
30         virtual std::string output_fragment_shader() {
31                 assert(false);
32         }
33         virtual void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) {
34                 assert(false);
35         }
36
37         virtual void rewrite_graph(EffectChain *graph, Node *self);
38         virtual bool set_float(const std::string &key, float value);
39         
40 private:
41         void update_radius();
42         
43         float radius;
44         SingleBlurPassEffect *hpass, *vpass;
45         unsigned input_width, input_height;
46 };
47
48 class SingleBlurPassEffect : public Effect {
49 public:
50         // If parent is non-NULL, calls to inform_input_size will be forwarded
51         // so that it can make reasonable decisions for both blur passes.
52         SingleBlurPassEffect(BlurEffect *parent);
53         virtual std::string effect_type_id() const { return "SingleBlurPassEffect"; }
54
55         std::string output_fragment_shader();
56
57         virtual bool needs_texture_bounce() const { return true; }
58         virtual bool needs_mipmaps() const { return true; }
59         virtual bool needs_srgb_primaries() const { return false; }
60
61         virtual void inform_input_size(unsigned input_num, unsigned width, unsigned height) {
62                 if (parent != NULL) {
63                         parent->inform_input_size(input_num, width, height);
64                 }
65         }
66         virtual bool changes_output_size() const { return true; }
67
68         virtual void get_output_size(unsigned *width, unsigned *height) const {
69                 *width = this->width;
70                 *height = this->height;
71         }
72
73         void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num);
74         void clear_gl_state();
75         
76         enum Direction { HORIZONTAL = 0, VERTICAL = 1 };
77
78 private:
79         BlurEffect *parent;
80         float radius;
81         Direction direction;
82         int width, height;
83 };
84
85 #endif // !defined(_BLUR_EFFECT_H)