- assert(output_gamma_curve.count(input) != 0);
- if (output_gamma_curve[input] == GAMMA_sRGB) {
- // TODO: check if the extension exists
- use_srgb_texture_format = true;
- output_gamma_curve[input] = GAMMA_LINEAR;
+ // Find out if all the inputs can be set to deliver sRGB inputs.
+ // If so, we can just ask them to do that instead of inserting a
+ // (possibly expensive) conversion operation.
+ //
+ // NOTE: We assume that effects generally don't mess with the gamma
+ // curve (except GammaCompressionEffect, which should never be
+ // inserted into a chain when this is called), so that we can just
+ // update the output gamma as we go.
+ //
+ // TODO: Setting this flag for one source might confuse a different
+ // part of the pipeline using the same source.
+ std::vector<Node *> nonlinear_inputs;
+ std::vector<Node *> intermediates;
+ find_all_nonlinear_inputs(input, &nonlinear_inputs, &intermediates);
+
+ bool all_ok = true;
+ for (unsigned i = 0; i < nonlinear_inputs.size(); ++i) {
+ Input *input = static_cast<Input *>(nonlinear_inputs[i]->effect);
+ all_ok &= input->can_output_linear_gamma();
+ }
+
+ if (all_ok) {
+ for (unsigned i = 0; i < nonlinear_inputs.size(); ++i) {
+ bool ok = nonlinear_inputs[i]->effect->set_int("output_linear_gamma", 1);
+ assert(ok);
+ nonlinear_inputs[i]->output_gamma_curve = GAMMA_LINEAR;
+ }
+ for (unsigned i = 0; i < intermediates.size(); ++i) {
+ intermediates[i]->output_gamma_curve = GAMMA_LINEAR;
+ }