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, get_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 *get_last_added_effect() {
75 return last_added_effect;
80 GLint glsl_program_num;
81 bool input_needs_mipmaps;
82 std::vector<Effect *> inputs;
83 std::vector<Effect *> effects; // In order.
86 Effect *normalize_to_linear_gamma(Effect *input);
87 Effect *normalize_to_srgb(Effect *input);
89 void draw_vertex(float x, float y, const std::vector<Effect *> &inputs);
91 // Create a GLSL program computing the given effects in order.
92 Phase compile_glsl_program(const std::vector<Effect *> &inputs, const std::vector<Effect *> &effects);
94 // Create all GLSL programs needed to compute the given effect, and all outputs
95 // that depends on it (whenever possible).
96 void construct_glsl_programs(Effect *start, std::set<Effect *> *completed_effects);
98 unsigned width, height;
99 ImageFormat input_format, output_format;
100 std::vector<Effect *> effects, unexpanded_effects;
101 std::map<Effect *, std::string> effect_ids;
102 std::map<Effect *, GLuint> effect_output_textures;
103 std::map<Effect *, std::vector<Effect *> > outgoing_links;
104 std::map<Effect *, std::vector<Effect *> > incoming_links;
105 Effect *last_added_effect;
107 GLuint source_image_num;
108 bool use_srgb_texture_format;
111 std::vector<Phase> phases;
113 GLenum format, bytes_per_pixel;
116 // Used during the building of the effect chain.
117 std::map<Effect *, ColorSpace> output_color_space;
118 std::map<Effect *, GammaCurve> output_gamma_curve;
122 #endif // !defined(_EFFECT_CHAIN_H)