EffectChain::EffectChain(float aspect_nom, float aspect_denom)
: aspect_nom(aspect_nom),
aspect_denom(aspect_denom),
+ fbo(0),
finalized(false) {}
+EffectChain::~EffectChain()
+{
+ for (unsigned i = 0; i < nodes.size(); ++i) {
+ if (nodes[i]->output_texture != 0) {
+ glDeleteTextures(1, &nodes[i]->output_texture);
+ }
+ delete nodes[i]->effect;
+ delete nodes[i];
+ }
+ for (unsigned i = 0; i < phases.size(); ++i) {
+ glDeleteProgram(phases[i]->glsl_program_num);
+ glDeleteShader(phases[i]->vertex_shader);
+ glDeleteShader(phases[i]->fragment_shader);
+ delete phases[i];
+ }
+ if (fbo != 0) {
+ glDeleteFramebuffers(1, &fbo);
+ }
+}
+
Input *EffectChain::add_input(Input *input)
{
inputs.push_back(input);
node->effect_id = effect_id;
node->output_color_space = COLORSPACE_INVALID;
node->output_gamma_curve = GAMMA_INVALID;
+ node->output_texture = 0;
nodes.push_back(node);
node_map[effect] = node;
Phase *phase = new Phase;
phase->glsl_program_num = glsl_program_num;
+ phase->vertex_shader = vs_obj;
+ phase->fragment_shader = fs_obj;
phase->input_needs_mipmaps = input_needs_mipmaps;
phase->inputs = true_inputs;
phase->effects = effects;
start_new_phase = true;
}
- if (deps[i]->outgoing_links.size() > 1 && deps[i]->effect->num_inputs() > 0) {
- // More than one effect uses this as the input,
- // and it is not a texture itself.
- // The easiest thing to do (and probably also the safest
- // performance-wise in most cases) is to bounce it to a texture
- // and then let the next passes read from that.
- start_new_phase = true;
+ if (deps[i]->outgoing_links.size() > 1) {
+ if (deps[i]->effect->num_inputs() > 0) {
+ // More than one effect uses this as the input,
+ // and it is not a texture itself.
+ // The easiest thing to do (and probably also the safest
+ // performance-wise in most cases) is to bounce it to a texture
+ // and then let the next passes read from that.
+ start_new_phase = true;
+ } else {
+ // For textures, we try to be slightly more clever;
+ // if none of our outputs need a bounce, we don't bounce
+ // but instead simply use the effect many times.
+ //
+ // Strictly speaking, we could bounce it for some outputs
+ // and use it directly for others, but the processing becomes
+ // somewhat simpler if the effect is only used in one such way.
+ for (unsigned j = 0; j < deps[i]->outgoing_links.size(); ++j) {
+ Node *rdep = deps[i]->outgoing_links[j];
+ start_new_phase |= rdep->effect->needs_texture_bounce();
+ }
+ }
}
if (deps[i]->effect->changes_output_size()) {
continue;
}
- ColorSpace color_space = node->incoming_links[0]->output_color_space;
+ Colorspace color_space = node->incoming_links[0]->output_color_space;
GammaCurve gamma_curve = node->incoming_links[0]->output_gamma_curve;
for (unsigned j = 1; j < node->incoming_links.size(); ++j) {
if (node->incoming_links[j]->output_color_space != color_space) {
// The conversion effects already have their outputs set correctly,
// so leave them alone.
- if (node->effect->effect_type_id() != "ColorSpaceConversionEffect") {
+ if (node->effect->effect_type_id() != "ColorspaceConversionEffect") {
node->output_color_space = color_space;
}
if (node->effect->effect_type_id() != "GammaCompressionEffect" &&
if (input->output_color_space == COLORSPACE_sRGB) {
continue;
}
- Node *conversion = add_node(new ColorSpaceConversionEffect());
+ Node *conversion = add_node(new ColorspaceConversionEffect());
conversion->effect->set_int("source_space", input->output_color_space);
conversion->effect->set_int("destination_space", COLORSPACE_sRGB);
conversion->output_color_space = COLORSPACE_sRGB;
{
Node *output = find_output_node();
if (output->output_color_space != output_format.color_space) {
- Node *conversion = add_node(new ColorSpaceConversionEffect());
+ Node *conversion = add_node(new ColorspaceConversionEffect());
conversion->effect->set_int("source_space", output->output_color_space);
conversion->effect->set_int("destination_space", output_format.color_space);
conversion->output_color_space = output_format.color_space;
connect_nodes(output, conversion);
+ propagate_gamma_and_color_space();
}
}