Merge branch 'master' into epoxy
[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           aspect_correction(1.0f, 1.0f),
16           radius(0.3f),
17           inner_radius(0.3f)
18 {
19         register_vec2("center", (float *)&center);
20         register_float("radius", (float *)&radius);
21         register_float("inner_radius", (float *)&inner_radius);
22 }
23
24 string VignetteEffect::output_fragment_shader()
25 {
26         return read_file("vignette_effect.frag");
27 }
28
29 void VignetteEffect::inform_input_size(unsigned input_num, unsigned width, unsigned height) {
30         assert(input_num == 0);
31         if (width >= height) {
32                 aspect_correction = Point2D(float(width) / float(height), 1.0f);
33         } else {
34                 aspect_correction = Point2D(1.0f, float(height) / float(width));
35         }
36 }
37
38 void VignetteEffect::set_gl_state(GLuint glsl_program_num, const string &prefix, unsigned *sampler_num)
39 {
40         Effect::set_gl_state(glsl_program_num, prefix, sampler_num);
41
42         set_uniform_float(glsl_program_num, prefix, "pihalf_div_radius", 0.5 * M_PI / radius);
43         set_uniform_vec2(glsl_program_num, prefix, "aspect_correction", (float *)&aspect_correction);
44
45         Point2D flipped_center(center.x, 1.0f - center.y);
46         set_uniform_vec2(glsl_program_num, prefix, "flipped_center", (float *)&flipped_center);
47 }
48
49 }  // namespace movit