]> git.sesse.net Git - nageru/blob - nageru/tweaked_inputs.h
IWYU-fix nageru/*.h.
[nageru] / 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 <string>
7
8 #include <epoxy/gl.h>
9 #include <movit/image_format.h>
10 #include <movit/flat_input.h>
11 #include <movit/ycbcr_input.h>
12
13 namespace movit {
14 struct ImageFormat;
15 struct YCbCrFormat;
16 }  // namespace movit
17
18 class NonBouncingYCbCrInput : public movit::YCbCrInput {
19 public:
20         NonBouncingYCbCrInput(const movit::ImageFormat &image_format,
21                               const movit::YCbCrFormat &ycbcr_format,
22                               unsigned width, unsigned height,
23                               movit::YCbCrInputSplitting ycbcr_input_splitting = movit::YCBCR_INPUT_PLANAR)
24             : movit::YCbCrInput(image_format, ycbcr_format, width, height, ycbcr_input_splitting) {}
25
26         bool override_disable_bounce() const override { return true; }
27 };
28
29 // We use FlatInput with RGBA inputs a few places where we can't tell when
30 // uploading the texture whether it needs to be converted from sRGB to linear
31 // or not. (FlatInput deals with this if you give it pixels, but we give it
32 // already uploaded textures.)
33 //
34 // Since we require GL_EXT_texture_sRGB_decode (very common, as far as I can tell),
35 // we can just always upload with the sRGB flag turned on (upload your texture with
36 // GL_SRGB8_ALPHA8), and then sRGBSwitchingFlatInput will turn it off if not requested.
37
38 class sRGBSwitchingFlatInput : public movit::FlatInput {
39 public:
40         sRGBSwitchingFlatInput(movit::ImageFormat format, movit::MovitPixelFormat pixel_format, GLenum type, unsigned width, unsigned height)
41             : movit::FlatInput(format, pixel_format, type, width, height) {}
42
43         ~sRGBSwitchingFlatInput();
44         void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) override;
45         void clear_gl_state() override;
46
47         bool set_int(const std::string &key, int value) override
48         {
49                 if (key == "output_linear_gamma") {
50                         output_linear_gamma = value;
51                 }
52                 if (key == "needs_mipmaps") {
53                         needs_mipmaps = value;
54                 }
55                 return movit::FlatInput::set_int(key, value);
56         }
57
58 private:
59         bool output_linear_gamma = false;
60         bool needs_mipmaps = false;
61         GLuint sampler_obj = 0;
62         GLuint texture_unit;
63 };
64
65 #endif  // !defined(_TWEAKED_INPUTS_H)