]> git.sesse.net Git - movit/blob - flat_input.h
Fix the name of the .dot file for the newly created colorspace input pass.
[movit] / flat_input.h
1 #ifndef _FLAT_INPUT_H
2 #define _FLAT_INPUT_H 1
3
4 #include "input.h"
5 #include "init.h"
6
7 // A FlatInput is the normal, “classic” case of an input, where everything
8 // comes from a single 2D array with chunky pixels.
9 class FlatInput : public Input {
10 public:
11         FlatInput(ImageFormat format, MovitPixelFormat pixel_format, GLenum type, unsigned width, unsigned height);
12         ~FlatInput();
13
14         virtual std::string effect_type_id() const { return "FlatInput"; }
15
16         // Create the texture itself. We cannot do this in the constructor,
17         // because we don't necessarily know all the settings (sRGB texture,
18         // mipmap generation) at that point.
19         void finalize();
20
21         virtual bool can_output_linear_gamma() const {
22                 return (movit_srgb_textures_supported &&
23                         type == GL_UNSIGNED_BYTE &&
24                         (image_format.gamma_curve == GAMMA_LINEAR ||
25                          image_format.gamma_curve == GAMMA_sRGB));
26         }
27
28         std::string output_fragment_shader();
29
30         // Uploads the texture if it has changed since last time.
31         void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num);
32
33         unsigned get_width() const { return width; }
34         unsigned get_height() const { return height; }
35         Colorspace get_color_space() const { return image_format.color_space; }
36         GammaCurve get_gamma_curve() const { return image_format.gamma_curve; }
37
38         // Tells the input where to fetch the actual pixel data. Note that if you change
39         // this data, you must either call set_pixel_data() again (using the same pointer
40         // is fine), or invalidate_pixel_data(). Otherwise, the texture won't be re-uploaded
41         // on subsequent frames.
42         void set_pixel_data(const unsigned char *pixel_data)
43         {
44                 assert(this->type == GL_UNSIGNED_BYTE);
45                 this->pixel_data = pixel_data;
46                 invalidate_pixel_data();
47         }
48
49         void set_pixel_data(const float *pixel_data)
50         {
51                 assert(this->type == GL_FLOAT);
52                 this->pixel_data = pixel_data;
53                 invalidate_pixel_data();
54         }
55
56         void invalidate_pixel_data()
57         {
58                 needs_update = true;
59         }
60
61         void set_pitch(unsigned pitch) {
62                 assert(!finalized);
63                 this->pitch = pitch;
64         }
65
66 private:
67         ImageFormat image_format;
68         MovitPixelFormat pixel_format;
69         GLenum format, type;
70         GLuint pbo, texture_num;
71         bool needs_update, finalized;
72         int output_linear_gamma, needs_mipmaps;
73         unsigned width, height, pitch, bytes_per_pixel;
74         const void *pixel_data;
75 };
76
77 #endif // !defined(_FLAT_INPUT_H)