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