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