X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=effect_chain.cpp;h=751a6be2d361839c754ab8aeec4bc6c3f049cae3;hp=bf017166a770f5a2d4d52adf0d68cf303aab30bd;hb=6bec5fc3abc5f57c6cddec2148626cca9a94bedf;hpb=5e34f7a8969f4afc169f034d34fb908019b3a389 diff --git a/effect_chain.cpp b/effect_chain.cpp index bf01716..751a6be 100644 --- a/effect_chain.cpp +++ b/effect_chain.cpp @@ -37,8 +37,11 @@ namespace movit { EffectChain::EffectChain(float aspect_nom, float aspect_denom, ResourcePool *resource_pool) : aspect_nom(aspect_nom), aspect_denom(aspect_denom), + output_color_rgba(false), + output_color_ycbcr(false), dither_effect(NULL), num_dither_bits(0), + output_origin(OUTPUT_ORIGIN_BOTTOM_LEFT), finalized(false), resource_pool(resource_pool), do_phase_timing(false) { @@ -76,19 +79,22 @@ Input *EffectChain::add_input(Input *input) void EffectChain::add_output(const ImageFormat &format, OutputAlphaFormat alpha_format) { assert(!finalized); + assert(!output_color_rgba); output_format = format; output_alpha_format = alpha_format; - output_color_type = OUTPUT_COLOR_RGB; + output_color_rgba = true; } void EffectChain::add_ycbcr_output(const ImageFormat &format, OutputAlphaFormat alpha_format, - const YCbCrFormat &ycbcr_format) + const YCbCrFormat &ycbcr_format, YCbCrOutputSplitting output_splitting) { assert(!finalized); + assert(!output_color_ycbcr); output_format = format; output_alpha_format = alpha_format; - output_color_type = OUTPUT_COLOR_YCBCR; + output_color_ycbcr = true; output_ycbcr_format = ycbcr_format; + output_ycbcr_splitting = output_splitting; assert(ycbcr_format.chroma_subsampling_x == 1); assert(ycbcr_format.chroma_subsampling_y == 1); @@ -206,7 +212,7 @@ Effect *EffectChain::add_effect(Effect *effect, const vector &inputs) return effect; } -// GLSL pre-1.30 doesn't support token pasting. Replace PREFIX(x) with _x. +// ESSL doesn't support token pasting. Replace PREFIX(x) with _x. string replace_prefix(const string &text, const string &prefix) { string output; @@ -361,6 +367,30 @@ void EffectChain::compile_glsl_program(Phase *phase) frag_shader += "\n"; } frag_shader += string("#define INPUT ") + phase->effect_ids[phase->effects.back()] + "\n"; + + // If we're the last phase, add the right #defines for Y'CbCr multi-output as needed. + if (phase->output_node->outgoing_links.empty() && output_color_ycbcr) { + switch (output_ycbcr_splitting) { + case YCBCR_OUTPUT_INTERLEAVED: + // No #defines set. + break; + case YCBCR_OUTPUT_SPLIT_Y_AND_CBCR: + frag_shader += "#define YCBCR_OUTPUT_SPLIT_Y_AND_CBCR 1\n"; + break; + case YCBCR_OUTPUT_PLANAR: + frag_shader += "#define YCBCR_OUTPUT_PLANAR 1\n"; + break; + default: + assert(false); + } + + if (output_color_rgba) { + // Note: Needs to come in the header, because not only the + // output needs to see it (YCbCrConversionEffect and DitherEffect + // do, too). + frag_shader_header += "#define YCBCR_ALSO_OUTPUT_RGBA 1\n"; + } + } frag_shader.append(read_version_dependent_file("footer", "frag")); // Collect uniforms from all effects and output them. Note that this needs @@ -389,6 +419,17 @@ void EffectChain::compile_glsl_program(Phase *phase) frag_shader = frag_shader_header + frag_shader_uniforms + frag_shader; string vert_shader = read_version_dependent_file("vs", "vert"); + + // If we're the last phase and need to flip the picture to compensate for + // the origin, tell the vertex shader so. + if (phase->output_node->outgoing_links.empty() && output_origin == OUTPUT_ORIGIN_TOP_LEFT) { + const string needle = "#define FLIP_ORIGIN 0"; + size_t pos = vert_shader.find(needle); + assert(pos != string::npos); + + vert_shader[pos + needle.size() - 1] = '1'; + } + phase->glsl_program_num = resource_pool->compile_glsl_program(vert_shader, frag_shader); // Collect the resulting location numbers for each uniform. @@ -1489,8 +1530,8 @@ void EffectChain::fix_output_gamma() // gamma-encoded data. void EffectChain::add_ycbcr_conversion_if_needed() { - assert(output_color_type == OUTPUT_COLOR_RGB || output_color_type == OUTPUT_COLOR_YCBCR); - if (output_color_type != OUTPUT_COLOR_YCBCR) { + assert(output_color_rgba || output_color_ycbcr); + if (!output_color_ycbcr) { return; } Node *output = find_output_node();