ColorSpace -> Colorspace. I kept typing it wrong, so even though I usually say color...
[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, GLenum type, unsigned width, unsigned height);
11         ~FlatInput();
12
13         virtual std::string effect_type_id() const { return "FlatInput"; }
14
15         // Create the texture itself. We cannot do this in the constructor,
16         // because we don't necessarily know all the settings (sRGB texture,
17         // mipmap generation) at that point.
18         void finalize();
19
20         // TODO: Check that we actually have the required extension.
21         virtual bool can_output_linear_gamma() const {
22                 return (type == GL_UNSIGNED_BYTE &&
23                         (image_format.gamma_curve == GAMMA_LINEAR ||
24                          image_format.gamma_curve == GAMMA_sRGB));
25         }
26
27         std::string output_fragment_shader();
28
29         // Uploads the texture if it has changed since last time.
30         void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num);
31
32         unsigned get_width() const { return width; }
33         unsigned get_height() const { return height; }
34         Colorspace get_color_space() const { return image_format.color_space; }
35         GammaCurve get_gamma_curve() const { return image_format.gamma_curve; }
36
37         // Tells the input where to fetch the actual pixel data. Note that if you change
38         // this data, you must either call set_pixel_data() again (using the same pointer
39         // is fine), or invalidate_pixel_data(). Otherwise, the texture won't be re-uploaded
40         // on subsequent frames.
41         void set_pixel_data(const unsigned char *pixel_data)
42         {
43                 assert(this->type == GL_UNSIGNED_BYTE);
44                 this->pixel_data = pixel_data;
45                 invalidate_pixel_data();
46         }
47
48         void set_pixel_data(const float *pixel_data)
49         {
50                 assert(this->type == GL_FLOAT);
51                 this->pixel_data = pixel_data;
52                 invalidate_pixel_data();
53         }
54
55         void invalidate_pixel_data()
56         {
57                 needs_update = true;
58         }
59
60         void set_pitch(unsigned pitch) {
61                 assert(!finalized);
62                 this->pitch = pitch;
63         }
64
65 private:
66         ImageFormat image_format;
67         MovitPixelFormat pixel_format;
68         GLenum format, type;
69         GLuint pbo, texture_num;
70         bool needs_update, finalized;
71         int output_linear_gamma, needs_mipmaps;
72         unsigned width, height, pitch, bytes_per_pixel;
73         const void *pixel_data;
74 };
75
76 #endif // !defined(_FLAT_INPUT_H)