]> git.sesse.net Git - movit/blob - input.h
b3eb836a26a8f9d4e1754ddc3574e866763dce2a
[movit] / input.h
1 #ifndef _INPUT_H
2 #define _INPUT_H 1
3
4 #include "effect.h"
5 #include "image_format.h"
6
7 // An input is a degenerate case of an effect; it represents the picture data
8 // that comes from the user. As such, it has zero “inputs” itself, and some of
9 // the normal operations don't really make sense for it.
10 class Input : public Effect {
11 public:
12         Input(ImageFormat format, unsigned width, unsigned height);
13
14         unsigned num_inputs() const { return 0; }
15
16         // Create the texture itself. We cannot do this in the constructor,
17         // because we don't necessarily know all the settings (sRGB texture,
18         // mipmap generation) at that point.
19         void finalize();
20
21         std::string output_fragment_shader();
22
23         // Uploads the texture if it has changed since last time.
24         void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num);
25
26         // Tells the input where to fetch the actual pixel data. Note that if you change
27         // this data, you must either call set_pixel_data() again (using the same pointer
28         // is fine), or invalidate_pixel_data(). Otherwise, the texture won't be re-uploaded
29         // on subsequent frames.
30         void set_pixel_data(const unsigned char *pixel_data)
31         {
32                 this->pixel_data = pixel_data;
33                 invalidate_pixel_data();
34         }
35
36         void invalidate_pixel_data()
37         {
38                 needs_update = true;
39         }
40
41         const unsigned char *get_pixel_data() const
42         {
43                 return pixel_data;
44         }
45
46 private:
47         ImageFormat image_format;
48         GLenum format;
49         GLuint pbo, texture_num;
50         bool needs_update;
51         int use_srgb_texture_format, needs_mipmaps;
52         unsigned width, height, bytes_per_pixel;
53         const unsigned char *pixel_data;
54 };
55
56 #endif // !defined(_INPUT_H)