2 #define _FLAT_INPUT_H 1
9 // A FlatInput is the normal, “classic” case of an input, where everything
10 // comes from a single 2D array with chunky pixels.
11 class FlatInput : public Input {
13 FlatInput(ImageFormat format, MovitPixelFormat pixel_format, GLenum type, unsigned width, unsigned height);
16 virtual std::string effect_type_id() const { return "FlatInput"; }
18 // Create the texture itself. We cannot do this in the constructor,
19 // because we don't necessarily know all the settings (sRGB texture,
20 // mipmap generation) at that point.
23 virtual bool can_output_linear_gamma() const {
24 return (movit_srgb_textures_supported &&
25 type == GL_UNSIGNED_BYTE &&
26 (image_format.gamma_curve == GAMMA_LINEAR ||
27 image_format.gamma_curve == GAMMA_sRGB));
29 virtual AlphaHandling alpha_handling() const {
30 switch (pixel_format) {
31 case FORMAT_RGBA_PREMULTIPLIED_ALPHA:
32 case FORMAT_BGRA_PREMULTIPLIED_ALPHA:
33 return INPUT_AND_OUTPUT_PREMULTIPLIED_ALPHA;
34 case FORMAT_RGBA_POSTMULTIPLIED_ALPHA:
35 case FORMAT_BGRA_POSTMULTIPLIED_ALPHA:
36 return OUTPUT_POSTMULTIPLIED_ALPHA;
39 case FORMAT_GRAYSCALE:
40 return OUTPUT_BLANK_ALPHA;
46 std::string output_fragment_shader();
48 // Uploads the texture if it has changed since last time.
49 void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num);
51 unsigned get_width() const { return width; }
52 unsigned get_height() const { return height; }
53 Colorspace get_color_space() const { return image_format.color_space; }
54 GammaCurve get_gamma_curve() const { return image_format.gamma_curve; }
56 // Tells the input where to fetch the actual pixel data. Note that if you change
57 // this data, you must either call set_pixel_data() again (using the same pointer
58 // is fine), or invalidate_pixel_data(). Otherwise, the texture won't be re-uploaded
59 // on subsequent frames.
60 void set_pixel_data(const unsigned char *pixel_data)
62 assert(this->type == GL_UNSIGNED_BYTE);
63 this->pixel_data = pixel_data;
64 invalidate_pixel_data();
67 void set_pixel_data(const float *pixel_data)
69 assert(this->type == GL_FLOAT);
70 this->pixel_data = pixel_data;
71 invalidate_pixel_data();
74 void invalidate_pixel_data()
79 void set_pitch(unsigned pitch) {
85 ImageFormat image_format;
86 MovitPixelFormat pixel_format;
88 GLuint pbo, texture_num;
89 bool needs_update, finalized;
90 int output_linear_gamma, needs_mipmaps;
91 unsigned width, height, pitch, bytes_per_pixel;
92 const void *pixel_data;
95 #endif // !defined(_FLAT_INPUT_H)