]> git.sesse.net Git - movit/blobdiff - effect_chain.cpp
Loosen up the accuracy bounds a tiny bit in some tests for NVIDIA cards, which have...
[movit] / effect_chain.cpp
index 4d13d3f8d30c6f24c0520f4c4633e864b9d12904..7b0861f903e9beaf695057e795b165577f35041e 100644 (file)
@@ -38,6 +38,7 @@ EffectChain::EffectChain(float aspect_nom, float aspect_denom, ResourcePool *res
          output_color_rgba(false),
          output_color_ycbcr(false),
          dither_effect(NULL),
+         ycbcr_conversion_effect_node(NULL),
          intermediate_format(GL_RGBA16F),
          intermediate_transformation(NO_FRAMEBUFFER_TRANSFORMATION),
          num_dither_bits(0),
@@ -122,14 +123,8 @@ void EffectChain::change_ycbcr_output_format(const YCbCrFormat &ycbcr_format)
 
        output_ycbcr_format = ycbcr_format;
        if (finalized) {
-               // Find the YCbCrConversionEffect node. We don't store it to avoid
-               // an unneeded ABI break (this can be fixed on next break).
-               for (Node *node : nodes) {
-                       if (node->effect->effect_type_id() == "YCbCrConversionEffect") {
-                               YCbCrConversionEffect *effect = (YCbCrConversionEffect *)(node->effect);
-                               effect->change_output_format(ycbcr_format);
-                       }
-               }
+               YCbCrConversionEffect *effect = (YCbCrConversionEffect *)(ycbcr_conversion_effect_node->effect);
+               effect->change_output_format(ycbcr_format);
        }
 }
 
@@ -1622,8 +1617,8 @@ void EffectChain::add_ycbcr_conversion_if_needed()
                return;
        }
        Node *output = find_output_node();
-       Node *ycbcr = add_node(new YCbCrConversionEffect(output_ycbcr_format));
-       connect_nodes(output, ycbcr);
+       ycbcr_conversion_effect_node = add_node(new YCbCrConversionEffect(output_ycbcr_format));
+       connect_nodes(output, ycbcr_conversion_effect_node);
 }
        
 // If the user has requested dither, add a DitherEffect right at the end
@@ -1738,8 +1733,10 @@ void EffectChain::render_to_fbo(GLuint dest_fbo, unsigned width, unsigned height
        check_error();
        glDisable(GL_DITHER);
        check_error();
-       glEnable(GL_FRAMEBUFFER_SRGB);
+
+       const bool final_srgb = glIsEnabled(GL_FRAMEBUFFER_SRGB);
        check_error();
+       bool current_srgb = final_srgb;
 
        // Save original viewport.
        GLuint x = 0, y = 0;
@@ -1805,7 +1802,22 @@ void EffectChain::render_to_fbo(GLuint dest_fbo, unsigned width, unsigned height
                                CHECK(dither_effect->set_int("output_height", height));
                        }
                }
-               execute_phase(phase, phase_num == phases.size() - 1, &bound_attribute_indices, &output_textures, &generated_mipmaps);
+               bool last_phase = (phase_num == phases.size() - 1);
+
+               // Enable sRGB rendering for intermediates in case we are
+               // rendering to an sRGB format.
+               bool needs_srgb = last_phase ? final_srgb : true;
+               if (needs_srgb && !current_srgb) {
+                       glEnable(GL_FRAMEBUFFER_SRGB);
+                       check_error();
+                       current_srgb = true;
+               } else if (!needs_srgb && current_srgb) {
+                       glDisable(GL_FRAMEBUFFER_SRGB);
+                       check_error();
+                       current_srgb = true;
+               }
+
+               execute_phase(phase, last_phase, &bound_attribute_indices, &output_textures, &generated_mipmaps);
                if (do_phase_timing) {
                        glEndQuery(GL_TIME_ELAPSED);
                }