2 #include <movit/flat_input.h>
3 #include <movit/util.h>
5 #include "tweaked_inputs.h"
7 sRGBSwitchingFlatInput::~sRGBSwitchingFlatInput()
9 if (sampler_obj != 0) {
10 glDeleteSamplers(1, &sampler_obj);
14 void sRGBSwitchingFlatInput::set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num)
16 movit::FlatInput::set_gl_state(glsl_program_num, prefix, sampler_num);
17 texture_unit = *sampler_num - 1;
19 if (sampler_obj == 0) {
20 glGenSamplers(1, &sampler_obj);
22 glSamplerParameteri(sampler_obj, GL_TEXTURE_MIN_FILTER, needs_mipmaps ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR);
24 glSamplerParameteri(sampler_obj, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
26 glSamplerParameteri(sampler_obj, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
28 // This needs to be done on a sampler and not a texture parameter,
29 // because the texture could be used from multiple different
30 // contexts at the same time. This flag is ignored for non-sRGB-uploaded
31 // textures, so we can set it without checking can_output_linear_gamma().
32 if (output_linear_gamma) {
33 glSamplerParameteri(sampler_obj, GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT);
35 glSamplerParameteri(sampler_obj, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT);
40 glBindSampler(texture_unit, sampler_obj);
44 void sRGBSwitchingFlatInput::clear_gl_state()
46 glBindSampler(texture_unit, 0);