2 #include <movit/flat_input.h>
3 #include <movit/util.h>
6 #include "tweaked_inputs.h"
8 sRGBSwitchingFlatInput::~sRGBSwitchingFlatInput()
10 if (sampler_obj != 0) {
11 glDeleteSamplers(1, &sampler_obj);
15 void sRGBSwitchingFlatInput::set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num)
17 movit::FlatInput::set_gl_state(glsl_program_num, prefix, sampler_num);
18 texture_unit = *sampler_num - 1;
20 if (sampler_obj == 0) {
21 glGenSamplers(1, &sampler_obj);
23 glSamplerParameteri(sampler_obj, GL_TEXTURE_MIN_FILTER, needs_mipmaps ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR);
25 glSamplerParameteri(sampler_obj, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
27 glSamplerParameteri(sampler_obj, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
29 // This needs to be done on a sampler and not a texture parameter,
30 // because the texture could be used from multiple different
31 // contexts at the same time. This flag is ignored for non-sRGB-uploaded
32 // textures, so we can set it without checking can_output_linear_gamma().
33 if (output_linear_gamma) {
34 glSamplerParameteri(sampler_obj, GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT);
36 glSamplerParameteri(sampler_obj, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT);
41 glBindSampler(texture_unit, sampler_obj);
45 void sRGBSwitchingFlatInput::clear_gl_state()
47 glBindSampler(texture_unit, 0);