1 #ifndef _TWEAKED_INPUTS_H
2 #define _TWEAKED_INPUTS_H 1
4 // Some tweaked variations of Movit inputs.
6 #include <movit/ycbcr_input.h>
13 class NonBouncingYCbCrInput : public movit::YCbCrInput {
15 NonBouncingYCbCrInput(const movit::ImageFormat &image_format,
16 const movit::YCbCrFormat &ycbcr_format,
17 unsigned width, unsigned height,
18 movit::YCbCrInputSplitting ycbcr_input_splitting = movit::YCBCR_INPUT_PLANAR)
19 : movit::YCbCrInput(image_format, ycbcr_format, width, height, ycbcr_input_splitting) {}
21 bool override_disable_bounce() const override { return true; }
24 // We use FlatInput with RGBA inputs a few places where we can't tell when
25 // uploading the texture whether it needs to be converted from sRGB to linear
26 // or not. (FlatInput deals with this if you give it pixels, but we give it
27 // already uploaded textures.)
29 // If we have GL_EXT_texture_sRGB_decode (very common, as far as I can tell),
30 // we can just always upload with the sRGB flag turned on, and then turn it off
31 // if not requested; that's sRGBSwitchingFlatInput. If not, we just need to
32 // turn off the functionality altogether, which is NonsRGBCapableFlatInput.
34 // If you're using NonsRGBCapableFlatInput, upload with GL_RGBA8.
35 // If using sRGBSwitchingFlatInput, upload with GL_SRGB8_ALPHA8.
37 class NonsRGBCapableFlatInput : public movit::FlatInput {
39 NonsRGBCapableFlatInput(movit::ImageFormat format, movit::MovitPixelFormat pixel_format, GLenum type, unsigned width, unsigned height)
40 : movit::FlatInput(format, pixel_format, type, width, height) {}
42 bool can_output_linear_gamma() const override { return false; }
45 class sRGBSwitchingFlatInput : public movit::FlatInput {
47 sRGBSwitchingFlatInput(movit::ImageFormat format, movit::MovitPixelFormat pixel_format, GLenum type, unsigned width, unsigned height)
48 : movit::FlatInput(format, pixel_format, type, width, height) {}
50 void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) override
52 movit::FlatInput::set_gl_state(glsl_program_num, prefix, sampler_num);
54 // This flag is ignored for non-sRGB-uploaded textures, so we can set it
55 // without checking can_output_linear_gamma().
56 glActiveTexture(GL_TEXTURE0 + *sampler_num - 1);
57 if (output_linear_gamma) {
58 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT);
60 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT);
64 bool set_int(const std::string &key, int value) override
66 if (key == "output_linear_gamma") {
67 output_linear_gamma = value;
69 return movit::FlatInput::set_int(key, value);
73 int output_linear_gamma = false;
77 #endif // !defined(_TWEAKED_INPUTS_H)