]> git.sesse.net Git - movit/blob - flat_input.h
9266659596ad8026f7993380c3cf1053a655714f
[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         // 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         // TODO: Check that we actually have the required extension.
18         virtual bool can_output_linear_gamma() const { return true; }
19
20         std::string output_fragment_shader();
21
22         // Uploads the texture if it has changed since last time.
23         void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num);
24
25         ColorSpace get_color_space() const { return image_format.color_space; }
26         GammaCurve get_gamma_curve() const { return image_format.gamma_curve; }
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         MovitPixelFormat pixel_format;
60         GLenum format;
61         GLuint pbo, texture_num;
62         bool needs_update, finalized;
63         int output_linear_gamma, needs_mipmaps;
64         unsigned width, height, pitch, bytes_per_pixel;
65         const unsigned char *pixel_data;
66 };
67
68 #endif // !defined(_FLAT_INPUT_H)