X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=effect_chain.cpp;h=7b0861f903e9beaf695057e795b165577f35041e;hb=3a918307fb46478ea8080222a58406cfe04a7cbe;hp=10573ef8aba7ac58cf4c037db15552321e494cad;hpb=f0d64ec5bf2e3ccfc20d7cfe8a6843b32d07ffad;p=movit diff --git a/effect_chain.cpp b/effect_chain.cpp index 10573ef..7b0861f 100644 --- a/effect_chain.cpp +++ b/effect_chain.cpp @@ -1733,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; @@ -1800,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); }