1 #ifndef _EFFECT_CHAIN_H
2 #define _EFFECT_CHAIN_H 1
8 #include "image_format.h"
13 EffectChain(unsigned width, unsigned height);
16 // input, effects, output, finalize need to come in that specific order.
18 // EffectChain takes ownership of the given input.
19 // input is returned back for convenience.
20 Input *add_input(Input *input);
22 // EffectChain takes ownership of the given effect.
23 // effect is returned back for convenience.
24 Effect *add_effect(Effect *effect) {
25 return add_effect(effect, last_added_effect());
27 Effect *add_effect(Effect *effect, Effect *input) {
28 std::vector<Effect *> inputs;
29 inputs.push_back(input);
30 return add_effect(effect, inputs);
32 Effect *add_effect(Effect *effect, Effect *input1, Effect *input2) {
33 std::vector<Effect *> inputs;
34 inputs.push_back(input1);
35 inputs.push_back(input2);
36 return add_effect(effect, inputs);
38 Effect *add_effect(Effect *effect, const std::vector<Effect *> &inputs);
40 // Similar to add_effect, but:
42 // * Does not insert any normalizing effects.
43 // * Does not ask the effect to insert itself, so it won't work
46 // We should really separate out these two “sides” of Effect in the
48 void add_effect_raw(Effect *effect, const std::vector<Effect *> &inputs);
50 void add_output(const ImageFormat &format);
53 //void render(unsigned char *src, unsigned char *dst);
54 void render_to_screen();
56 Effect *last_added_effect() {
57 if (effects.empty()) {
60 return effects.back();
66 GLint glsl_program_num;
67 bool input_needs_mipmaps;
68 std::vector<Effect *> inputs; // Only from other phases; input textures are not counted here.
69 std::vector<Effect *> effects; // In order.
70 unsigned output_width, output_height;
73 // Determine the preferred output size of a given phase.
74 // Requires that all input phases (if any) already have output sizes set.
75 void find_output_size(Phase *phase);
77 void find_all_nonlinear_inputs(Effect *effect,
78 std::vector<Input *> *nonlinear_inputs,
79 std::vector<Effect *> *intermediates);
80 Effect *normalize_to_linear_gamma(Effect *input);
81 Effect *normalize_to_srgb(Effect *input);
83 void draw_vertex(float x, float y, const std::vector<Effect *> &inputs);
85 // Create a GLSL program computing the given effects in order.
86 Phase *compile_glsl_program(const std::vector<Effect *> &inputs, const std::vector<Effect *> &effects);
88 // Create all GLSL programs needed to compute the given effect, and all outputs
89 // that depends on it (whenever possible).
90 void construct_glsl_programs(Effect *output);
92 unsigned width, height;
93 ImageFormat output_format;
94 std::vector<Effect *> effects;
95 std::vector<Input *> inputs; // Also contained in effects.
96 std::map<Effect *, std::string> effect_ids;
97 std::map<Effect *, GLuint> effect_output_textures;
98 std::map<Effect *, std::pair<GLuint, GLuint> > effect_output_texture_sizes;
99 std::map<Effect *, std::vector<Effect *> > outgoing_links;
100 std::map<Effect *, std::vector<Effect *> > incoming_links;
103 std::vector<Phase *> phases;
105 // This is a bit ugly; we should probably fix so that Phase takes other phases
106 // as inputs, instead of Effect.
107 std::map<Effect *, Phase *> output_effects_to_phase;
109 GLenum format, bytes_per_pixel;
112 // Used during the building of the effect chain.
113 std::map<Effect *, ColorSpace> output_color_space;
114 std::map<Effect *, GammaCurve> output_gamma_curve;
118 #endif // !defined(_EFFECT_CHAIN_H)