1 #ifndef _MOVIT_FLAT_INPUT_H
2 #define _MOVIT_FLAT_INPUT_H 1
9 #include "effect_chain.h"
11 #include "image_format.h"
19 // A FlatInput is the normal, “classic” case of an input, where everything
20 // comes from a single 2D array with chunky pixels.
21 class FlatInput : public Input {
23 FlatInput(ImageFormat format, MovitPixelFormat pixel_format, GLenum type, unsigned width, unsigned height);
26 virtual std::string effect_type_id() const { return "FlatInput"; }
28 virtual bool can_output_linear_gamma() const {
29 // On desktop OpenGL, there's also GL_SLUMINANCE8 which could give us
30 // support for single-channel sRGB decoding, but it's not supported
31 // on GLES, and we're already actively rewriting single-channel inputs
32 // to GL_RED (even on desktop), so we stick to 3- and 4-channel inputs.
33 return (movit_srgb_textures_supported &&
34 type == GL_UNSIGNED_BYTE &&
35 (pixel_format == FORMAT_RGB ||
36 pixel_format == FORMAT_RGBA_POSTMULTIPLIED_ALPHA) &&
37 (image_format.gamma_curve == GAMMA_LINEAR ||
38 image_format.gamma_curve == GAMMA_sRGB));
40 virtual AlphaHandling alpha_handling() const {
41 switch (pixel_format) {
42 case FORMAT_RGBA_PREMULTIPLIED_ALPHA:
43 return INPUT_AND_OUTPUT_PREMULTIPLIED_ALPHA;
44 case FORMAT_RGBA_POSTMULTIPLIED_ALPHA:
45 return OUTPUT_POSTMULTIPLIED_ALPHA;
49 return OUTPUT_BLANK_ALPHA;
55 std::string output_fragment_shader();
57 // Uploads the texture if it has changed since last time.
58 void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num);
60 unsigned get_width() const { return width; }
61 unsigned get_height() const { return height; }
62 Colorspace get_color_space() const { return image_format.color_space; }
63 GammaCurve get_gamma_curve() const { return image_format.gamma_curve; }
64 virtual bool is_single_texture() const { return true; }
66 // Tells the input where to fetch the actual pixel data. Note that if you change
67 // this data, you must either call set_pixel_data() again (using the same pointer
68 // is fine), or invalidate_pixel_data(). Otherwise, the texture won't be re-uploaded
69 // on subsequent frames.
71 // The data can either be a regular pointer (if pbo==0), or a byte offset
72 // into a PBO. The latter will allow you to start uploading the texture data
73 // asynchronously to the GPU, if you have any CPU-intensive work between the
74 // call to set_pixel_data() and the actual rendering. In either case,
75 // the pointer (and PBO, if set) has to be valid at the time of the render call.
76 void set_pixel_data(const unsigned char *pixel_data, GLuint pbo = 0)
78 assert(this->type == GL_UNSIGNED_BYTE);
79 this->pixel_data = pixel_data;
81 invalidate_pixel_data();
84 void set_pixel_data(const unsigned short *pixel_data, GLuint pbo = 0)
86 assert(this->type == GL_UNSIGNED_SHORT);
87 this->pixel_data = pixel_data;
89 invalidate_pixel_data();
92 void set_pixel_data_fp16(const fp16_int_t *pixel_data, GLuint pbo = 0)
94 assert(this->type == GL_HALF_FLOAT);
95 this->pixel_data = pixel_data;
97 invalidate_pixel_data();
100 void set_pixel_data(const float *pixel_data, GLuint pbo = 0)
102 assert(this->type == GL_FLOAT);
103 this->pixel_data = pixel_data;
105 invalidate_pixel_data();
108 void invalidate_pixel_data();
110 void set_pitch(unsigned pitch) {
112 invalidate_pixel_data();
115 virtual void inform_added(EffectChain *chain)
117 resource_pool = chain->get_resource_pool();
121 ImageFormat image_format;
122 MovitPixelFormat pixel_format;
124 GLuint pbo, texture_num;
125 int output_linear_gamma, needs_mipmaps;
126 unsigned width, height, pitch;
127 const void *pixel_data;
128 ResourcePool *resource_pool;
129 bool fixup_swap_rb, fixup_red_to_grayscale;
134 #endif // !defined(_MOVIT_FLAT_INPUT_H)