]> git.sesse.net Git - movit/blob - flat_input.h
Output the graph in dot form at finalize time.
[movit] / flat_input.h
1 #ifndef _FLAT_INPUT_H
2 #define _FLAT_INPUT_H 1
3
4 #include "input.h"
5
6 // A FlatInput is the normal, “classic” case of an input, where everything
7 // comes from a single 2D array with chunky pixels.
8 class FlatInput : public Input {
9 public:
10         FlatInput(ImageFormat format, MovitPixelFormat pixel_format, unsigned width, unsigned height);
11
12         virtual std::string effect_type_id() const { return "FlatInput"; }
13
14         // Create the texture itself. We cannot do this in the constructor,
15         // because we don't necessarily know all the settings (sRGB texture,
16         // mipmap generation) at that point.
17         void finalize();
18
19         // TODO: Check that we actually have the required extension.
20         virtual bool can_output_linear_gamma() const { return true; }
21
22         std::string output_fragment_shader();
23
24         // Uploads the texture if it has changed since last time.
25         void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num);
26
27         ColorSpace get_color_space() const { return image_format.color_space; }
28         GammaCurve get_gamma_curve() const { return image_format.gamma_curve; }
29
30         // Tells the input where to fetch the actual pixel data. Note that if you change
31         // this data, you must either call set_pixel_data() again (using the same pointer
32         // is fine), or invalidate_pixel_data(). Otherwise, the texture won't be re-uploaded
33         // on subsequent frames.
34         void set_pixel_data(const unsigned char *pixel_data)
35         {
36                 this->pixel_data = pixel_data;
37                 invalidate_pixel_data();
38         }
39
40         void invalidate_pixel_data()
41         {
42                 needs_update = true;
43         }
44
45         const unsigned char *get_pixel_data() const
46         {
47                 return pixel_data;
48         }
49
50         void set_pitch(unsigned pitch) {
51                 assert(!finalized);
52                 this->pitch = pitch;
53         }
54
55         unsigned get_pitch() {
56                 return pitch;
57         }
58
59 private:
60         ImageFormat image_format;
61         MovitPixelFormat pixel_format;
62         GLenum format;
63         GLuint pbo, texture_num;
64         bool needs_update, finalized;
65         int output_linear_gamma, needs_mipmaps;
66         unsigned width, height, pitch, bytes_per_pixel;
67         const unsigned char *pixel_data;
68 };
69
70 #endif // !defined(_FLAT_INPUT_H)