1 #ifndef _MOVIT_FLAT_INPUT_H
2 #define _MOVIT_FLAT_INPUT_H 1
9 #include "effect_chain.h"
10 #include "image_format.h"
16 // A FlatInput is the normal, “classic” case of an input, where everything
17 // comes from a single 2D array with chunky pixels.
18 class FlatInput : public Input {
20 FlatInput(ImageFormat format, MovitPixelFormat pixel_format, GLenum type, unsigned width, unsigned height);
23 virtual std::string effect_type_id() const { return "FlatInput"; }
25 virtual bool can_output_linear_gamma() const {
26 return (movit_srgb_textures_supported &&
27 type == GL_UNSIGNED_BYTE &&
28 (image_format.gamma_curve == GAMMA_LINEAR ||
29 image_format.gamma_curve == GAMMA_sRGB));
31 virtual AlphaHandling alpha_handling() const {
32 switch (pixel_format) {
33 case FORMAT_RGBA_PREMULTIPLIED_ALPHA:
34 case FORMAT_BGRA_PREMULTIPLIED_ALPHA:
35 return INPUT_AND_OUTPUT_PREMULTIPLIED_ALPHA;
36 case FORMAT_RGBA_POSTMULTIPLIED_ALPHA:
37 case FORMAT_BGRA_POSTMULTIPLIED_ALPHA:
38 return OUTPUT_POSTMULTIPLIED_ALPHA;
41 case FORMAT_GRAYSCALE:
42 return OUTPUT_BLANK_ALPHA;
48 std::string output_fragment_shader();
50 // Uploads the texture if it has changed since last time.
51 void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num);
53 unsigned get_width() const { return width; }
54 unsigned get_height() const { return height; }
55 Colorspace get_color_space() const { return image_format.color_space; }
56 GammaCurve get_gamma_curve() const { return image_format.gamma_curve; }
58 // Tells the input where to fetch the actual pixel data. Note that if you change
59 // this data, you must either call set_pixel_data() again (using the same pointer
60 // is fine), or invalidate_pixel_data(). Otherwise, the texture won't be re-uploaded
61 // on subsequent frames.
63 // The data can either be a regular pointer (if pbo==0), or a byte offset
64 // into a PBO. The latter will allow you to start uploading the texture data
65 // asynchronously to the GPU, if you have any CPU-intensive work between the
66 // call to set_pixel_data() and the actual rendering. In either case,
67 // the pointer (and PBO, if set) has to be valid at the time of the render call.
68 void set_pixel_data(const unsigned char *pixel_data, GLuint pbo = 0)
70 assert(this->type == GL_UNSIGNED_BYTE);
71 this->pixel_data = pixel_data;
73 invalidate_pixel_data();
76 void set_pixel_data(const float *pixel_data, GLuint pbo = 0)
78 assert(this->type == GL_FLOAT);
79 this->pixel_data = pixel_data;
81 invalidate_pixel_data();
84 void invalidate_pixel_data();
86 void set_pitch(unsigned pitch) {
88 invalidate_pixel_data();
91 virtual void inform_added(EffectChain *chain)
93 resource_pool = chain->get_resource_pool();
97 ImageFormat image_format;
98 MovitPixelFormat pixel_format;
100 GLuint pbo, texture_num;
101 int output_linear_gamma, needs_mipmaps;
102 unsigned width, height, pitch;
103 const void *pixel_data;
104 ResourcePool *resource_pool;
107 #endif // !defined(_MOVIT_FLAT_INPUT_H)