Release Movit 1.3.2. (From a branch, since I do not want to break ABI compatibility...
[movit] / vignette_effect.cpp
1 #include <epoxy/gl.h>
2 #include <assert.h>
3 #include <math.h>
4
5 #include "effect_util.h"
6 #include "util.h"
7 #include "vignette_effect.h"
8
9 using namespace std;
10
11 namespace movit {
12
13 VignetteEffect::VignetteEffect()
14         : center(0.5f, 0.5f),
15           uniform_aspect_correction(1.0f, 1.0f),
16           uniform_flipped_center(0.5f, 0.5f),
17           radius(0.3f),
18           inner_radius(0.3f)
19 {
20         register_vec2("center", (float *)&center);
21         register_float("radius", (float *)&radius);
22         register_float("inner_radius", (float *)&inner_radius);
23         register_uniform_float("pihalf_div_radius", &uniform_pihalf_div_radius);
24         register_uniform_vec2("aspect_correction", (float *)&uniform_aspect_correction);
25         register_uniform_vec2("flipped_center", (float *)&uniform_flipped_center);
26 }
27
28 string VignetteEffect::output_fragment_shader()
29 {
30         return read_file("vignette_effect.frag");
31 }
32
33 void VignetteEffect::inform_input_size(unsigned input_num, unsigned width, unsigned height) {
34         assert(input_num == 0);
35         if (width >= height) {
36                 uniform_aspect_correction = Point2D(float(width) / float(height), 1.0f);
37         } else {
38                 uniform_aspect_correction = Point2D(1.0f, float(height) / float(width));
39         }
40 }
41
42 void VignetteEffect::set_gl_state(GLuint glsl_program_num, const string &prefix, unsigned *sampler_num)
43 {
44         Effect::set_gl_state(glsl_program_num, prefix, sampler_num);
45
46         uniform_pihalf_div_radius = 0.5 * M_PI / radius;
47         uniform_flipped_center = Point2D(center.x, 1.0f - center.y);
48 }
49
50 }  // namespace movit