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 return (movit_srgb_textures_supported &&
30 type == GL_UNSIGNED_BYTE &&
31 (image_format.gamma_curve == GAMMA_LINEAR ||
32 image_format.gamma_curve == GAMMA_sRGB));
34 virtual AlphaHandling alpha_handling() const {
35 switch (pixel_format) {
36 case FORMAT_RGBA_PREMULTIPLIED_ALPHA:
37 case FORMAT_BGRA_PREMULTIPLIED_ALPHA:
38 return INPUT_AND_OUTPUT_PREMULTIPLIED_ALPHA;
39 case FORMAT_RGBA_POSTMULTIPLIED_ALPHA:
40 case FORMAT_BGRA_POSTMULTIPLIED_ALPHA:
41 return OUTPUT_POSTMULTIPLIED_ALPHA;
45 case FORMAT_GRAYSCALE:
46 return OUTPUT_BLANK_ALPHA;
52 std::string output_fragment_shader();
54 // Uploads the texture if it has changed since last time.
55 void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num);
57 unsigned get_width() const { return width; }
58 unsigned get_height() const { return height; }
59 Colorspace get_color_space() const { return image_format.color_space; }
60 GammaCurve get_gamma_curve() const { return image_format.gamma_curve; }
62 // Tells the input where to fetch the actual pixel data. Note that if you change
63 // this data, you must either call set_pixel_data() again (using the same pointer
64 // is fine), or invalidate_pixel_data(). Otherwise, the texture won't be re-uploaded
65 // on subsequent frames.
67 // The data can either be a regular pointer (if pbo==0), or a byte offset
68 // into a PBO. The latter will allow you to start uploading the texture data
69 // asynchronously to the GPU, if you have any CPU-intensive work between the
70 // call to set_pixel_data() and the actual rendering. In either case,
71 // the pointer (and PBO, if set) has to be valid at the time of the render call.
72 void set_pixel_data(const unsigned char *pixel_data, GLuint pbo = 0)
74 assert(this->type == GL_UNSIGNED_BYTE);
75 this->pixel_data = pixel_data;
77 invalidate_pixel_data();
80 void set_pixel_data(const fp16_int_t *pixel_data, GLuint pbo = 0)
82 assert(this->type == GL_HALF_FLOAT);
83 this->pixel_data = pixel_data;
85 invalidate_pixel_data();
88 void set_pixel_data(const float *pixel_data, GLuint pbo = 0)
90 assert(this->type == GL_FLOAT);
91 this->pixel_data = pixel_data;
93 invalidate_pixel_data();
96 void invalidate_pixel_data();
98 void set_pitch(unsigned pitch) {
100 invalidate_pixel_data();
103 virtual void inform_added(EffectChain *chain)
105 resource_pool = chain->get_resource_pool();
109 ImageFormat image_format;
110 MovitPixelFormat pixel_format;
112 GLuint pbo, texture_num;
113 int output_linear_gamma, needs_mipmaps;
114 unsigned width, height, pitch;
115 const void *pixel_data;
116 ResourcePool *resource_pool;
121 #endif // !defined(_MOVIT_FLAT_INPUT_H)