X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=dither_effect.cpp;h=4643d07180993fdd286e460eba758b08d949d9d3;hp=87e729a3c9feca0a7253e7617eeb41d287d9f68b;hb=1514db1d0f3963dbc18177d2fd7eaae16a069c3b;hpb=f1a81dca72da9aa5103527b8c9494381204e70c5 diff --git a/dither_effect.cpp b/dither_effect.cpp index 87e729a..4643d07 100644 --- a/dither_effect.cpp +++ b/dither_effect.cpp @@ -1,9 +1,11 @@ -#include +#include #include +#include #include "dither_effect.h" +#include "effect_util.h" +#include "init.h" #include "util.h" -#include "opengl.h" namespace { @@ -39,7 +41,9 @@ DitherEffect::~DitherEffect() std::string DitherEffect::output_fragment_shader() { - return read_file("dither_effect.frag"); + char buf[256]; + sprintf(buf, "#define NEED_EXPLICIT_ROUND %d\n", (movit_num_wrongly_rounded > 0)); + return buf + read_file("dither_effect.frag"); } void DitherEffect::update_texture(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) @@ -85,6 +89,10 @@ void DitherEffect::set_gl_state(GLuint glsl_program_num, const std::string &pref { Effect::set_gl_state(glsl_program_num, prefix, sampler_num); + assert(width > 0); + assert(height > 0); + assert(num_bits > 0); + if (width != last_width || height != last_height || num_bits != last_num_bits) { update_texture(glsl_program_num, prefix, sampler_num); last_width = width; @@ -105,4 +113,9 @@ void DitherEffect::set_gl_state(GLuint glsl_program_num, const std::string &pref // we don't have to worry about it. float tc_scale[] = { float(width) / float(texture_width), float(height) / float(texture_height) }; set_uniform_vec2(glsl_program_num, prefix, "tc_scale", tc_scale); + + // Used if the shader needs to do explicit rounding. + int round_fac = (1 << num_bits) - 1; + set_uniform_float(glsl_program_num, prefix, "round_fac", round_fac); + set_uniform_float(glsl_program_num, prefix, "inv_round_fac", 1.0f / round_fac); }