3 #include "effect_chain.h"
4 #include "slice_effect.h"
5 #include "effect_util.h"
12 SliceEffect::SliceEffect()
13 : input_slice_size(1),
18 register_int("input_slice_size", &input_slice_size);
19 register_int("output_slice_size", &output_slice_size);
20 register_int("offset", &offset);
21 register_int("direction", (int *)&direction);
24 string SliceEffect::output_fragment_shader()
27 sprintf(buf, "#define DIRECTION_VERTICAL %d\n", (direction == VERTICAL));
28 return buf + read_file("slice_effect.frag");
31 void SliceEffect::inform_input_size(unsigned input_num, unsigned width, unsigned height)
33 assert(input_num == 0);
35 input_height = height;
38 void SliceEffect::get_output_size(unsigned *width, unsigned *height,
39 unsigned *virtual_width, unsigned *virtual_height) const
41 if (direction == HORIZONTAL) {
42 *width = div_round_up(input_width, input_slice_size) * output_slice_size;
43 *height = input_height;
46 *height = div_round_up(input_height, input_slice_size) * output_slice_size;
48 *virtual_width = *width;
49 *virtual_height = *height;
52 void SliceEffect::set_gl_state(GLuint glsl_program_num, const string &prefix, unsigned *sampler_num)
54 Effect::set_gl_state(glsl_program_num, prefix, sampler_num);
56 unsigned output_width, output_height;
57 get_output_size(&output_width, &output_height, &output_width, &output_height);
59 if (direction == HORIZONTAL) {
60 set_uniform_float(glsl_program_num, prefix, "output_coord_to_slice_num", float(output_width) / float(output_slice_size));
61 set_uniform_float(glsl_program_num, prefix, "slice_num_to_input_coord", float(input_slice_size) / float(input_width));
62 set_uniform_float(glsl_program_num, prefix, "slice_offset_to_input_coord", float(output_slice_size) / float(input_width));
63 set_uniform_float(glsl_program_num, prefix, "offset", float(offset) / float(input_width));
65 set_uniform_float(glsl_program_num, prefix, "output_coord_to_slice_num", float(output_height) / float(output_slice_size));
66 set_uniform_float(glsl_program_num, prefix, "slice_num_to_input_coord", float(input_slice_size) / float(input_height));
67 set_uniform_float(glsl_program_num, prefix, "slice_offset_to_input_coord", float(output_slice_size) / float(input_height));
68 set_uniform_float(glsl_program_num, prefix, "offset", float(offset) / float(input_height));
71 // Normalized coordinates could potentially cause blurring of the image.
72 // It isn't critical, but still good practice.
73 Node *self = chain->find_node_for_effect(this);
74 glActiveTexture(chain->get_input_sampler(self, 0));
76 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
78 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);