1 #ifndef _EFFECT_CHAIN_H
2 #define _EFFECT_CHAIN_H 1
10 enum PixelFormat { FORMAT_RGB, FORMAT_RGBA, FORMAT_BGR, FORMAT_BGRA };
14 COLORSPACE_REC_709 = 0, // Same as sRGB.
15 COLORSPACE_REC_601_525 = 1,
16 COLORSPACE_REC_601_625 = 2,
23 GAMMA_REC_709 = 2, // Same as Rec. 601.
27 PixelFormat pixel_format;
28 ColorSpace color_space;
29 GammaCurve gamma_curve;
34 EffectChain(unsigned width, unsigned height);
37 // input, effects, output, finalize need to come in that specific order.
39 void add_input(const ImageFormat &format);
41 // The returned pointer is owned by EffectChain.
42 Effect *add_effect(EffectId effect) {
43 return add_effect(effect, last_added_effect());
45 Effect *add_effect(EffectId effect, Effect *input) {
46 std::vector<Effect *> inputs;
47 inputs.push_back(input);
48 return add_effect(effect, inputs);
50 Effect *add_effect(EffectId effect, Effect *input1, Effect *input2) {
51 std::vector<Effect *> inputs;
52 inputs.push_back(input1);
53 inputs.push_back(input2);
54 return add_effect(effect, inputs);
56 Effect *add_effect(EffectId effect, const std::vector<Effect *> &inputs);
58 // Similar to add_effect, but:
60 // * Does not insert any normalizing effects.
61 // * Does not ask the effect to insert itself, so it won't work
64 // We should really separate out these two “sides” of Effect in the
66 void add_effect_raw(Effect *effect, const std::vector<Effect *> &inputs);
68 void add_output(const ImageFormat &format);
71 //void render(unsigned char *src, unsigned char *dst);
72 void render_to_screen(unsigned char *src);
74 Effect *last_added_effect() {
75 if (effects.empty()) {
78 return effects.back();
84 GLint glsl_program_num;
85 bool input_needs_mipmaps;
86 std::vector<Effect *> inputs;
87 std::vector<Effect *> effects; // In order.
90 Effect *normalize_to_linear_gamma(Effect *input);
91 Effect *normalize_to_srgb(Effect *input);
93 void draw_vertex(float x, float y, const std::vector<Effect *> &inputs);
95 // Create a GLSL program computing the given effects in order.
96 Phase compile_glsl_program(const std::vector<Effect *> &inputs, const std::vector<Effect *> &effects);
98 // Create all GLSL programs needed to compute the given effect, and all outputs
99 // that depends on it (whenever possible).
100 void construct_glsl_programs(Effect *start, std::set<Effect *> *completed_effects);
102 unsigned width, height;
103 ImageFormat input_format, output_format;
104 std::vector<Effect *> effects, unexpanded_effects;
105 std::map<Effect *, std::string> effect_ids;
106 std::map<Effect *, GLuint> effect_output_textures;
107 std::map<Effect *, std::vector<Effect *> > outgoing_links;
108 std::map<Effect *, std::vector<Effect *> > incoming_links;
110 GLuint source_image_num;
111 bool use_srgb_texture_format;
114 std::vector<Phase> phases;
116 GLenum format, bytes_per_pixel;
119 // Used during the building of the effect chain.
120 std::map<Effect *, ColorSpace> output_color_space;
121 std::map<Effect *, GammaCurve> output_gamma_curve;
125 #endif // !defined(_EFFECT_CHAIN_H)