]> git.sesse.net Git - nageru/blob - tweaked_inputs.h
Enable the video grid display for simple video mode, too.
[nageru] / tweaked_inputs.h
1 #ifndef _TWEAKED_INPUTS_H
2 #define _TWEAKED_INPUTS_H 1
3
4 // Some tweaked variations of Movit inputs.
5
6 #include <movit/ycbcr_input.h>
7
8 namespace movit {
9 struct ImageFormat;
10 struct YCbCrFormat;
11 }  // namespace movit
12
13 class NonBouncingYCbCrInput : public movit::YCbCrInput {
14 public:
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) {}
20
21         bool override_disable_bounce() const override { return true; }
22 };
23
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.)
28 //
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.
33 //
34 // If you're using NonsRGBCapableFlatInput, upload with GL_RGBA8.
35 // If using sRGBSwitchingFlatInput, upload with GL_SRGB8_ALPHA8.
36
37 class NonsRGBCapableFlatInput : public movit::FlatInput {
38 public:
39         NonsRGBCapableFlatInput(movit::ImageFormat format, movit::MovitPixelFormat pixel_format, GLenum type, unsigned width, unsigned height)
40             : movit::FlatInput(format, pixel_format, type, width, height) {}
41
42         bool can_output_linear_gamma() const override { return false; }
43 };
44
45 class sRGBSwitchingFlatInput : public movit::FlatInput {
46 public:
47         sRGBSwitchingFlatInput(movit::ImageFormat format, movit::MovitPixelFormat pixel_format, GLenum type, unsigned width, unsigned height)
48             : movit::FlatInput(format, pixel_format, type, width, height) {}
49
50         ~sRGBSwitchingFlatInput();
51         void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) override;
52         void clear_gl_state() override;
53
54         bool set_int(const std::string &key, int value) override
55         {
56                 if (key == "output_linear_gamma") {
57                         output_linear_gamma = value;
58                 }
59                 if (key == "needs_mipmaps") {
60                         needs_mipmaps = value;
61                 }
62                 return movit::FlatInput::set_int(key, value);
63         }
64
65 private:
66         bool output_linear_gamma = false;
67         bool needs_mipmaps = false;
68         GLuint sampler_obj = 0;
69         GLuint texture_unit;
70 };
71
72
73 #endif  // !defined(_TWEAKED_INPUTS_H)