Make Input an abstract base class, and move the current functionality into FlatInput...
[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, unsigned width, unsigned height);
11
12         // Create the texture itself. We cannot do this in the constructor,
13         // because we don't necessarily know all the settings (sRGB texture,
14         // mipmap generation) at that point.
15         void finalize();
16
17         std::string output_fragment_shader();
18
19         // Uploads the texture if it has changed since last time.
20         void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num);
21
22         ColorSpace get_color_space() { return image_format.color_space; }
23         GammaCurve get_gamma_curve() { return image_format.gamma_curve; }
24
25         // Tells the input where to fetch the actual pixel data. Note that if you change
26         // this data, you must either call set_pixel_data() again (using the same pointer
27         // is fine), or invalidate_pixel_data(). Otherwise, the texture won't be re-uploaded
28         // on subsequent frames.
29         void set_pixel_data(const unsigned char *pixel_data)
30         {
31                 this->pixel_data = pixel_data;
32                 invalidate_pixel_data();
33         }
34
35         void invalidate_pixel_data()
36         {
37                 needs_update = true;
38         }
39
40         const unsigned char *get_pixel_data() const
41         {
42                 return pixel_data;
43         }
44
45         void set_pitch(unsigned pitch) {
46                 assert(!finalized);
47                 this->pitch = pitch;
48         }
49
50         unsigned get_pitch() {
51                 return pitch;
52         }
53
54 private:
55         ImageFormat image_format;
56         GLenum format;
57         GLuint pbo, texture_num;
58         bool needs_update, finalized;
59         int use_srgb_texture_format, needs_mipmaps;
60         unsigned width, height, pitch, bytes_per_pixel;
61         const unsigned char *pixel_data;
62 };
63
64 #endif // !defined(_FLAT_INPUT_H)