X-Git-Url: https://git.sesse.net/?p=nageru;a=blobdiff_plain;f=tweaked_inputs.cpp;fp=tweaked_inputs.cpp;h=304c3b43fdad8251197fd9fb0d07a9d948b223dc;hp=0000000000000000000000000000000000000000;hb=142184354968cd1b1918f35772bb6f9f0b1351d6;hpb=72afc695d201f9d2a0dcb316ec62f1610db5fa74 diff --git a/tweaked_inputs.cpp b/tweaked_inputs.cpp new file mode 100644 index 0000000..304c3b4 --- /dev/null +++ b/tweaked_inputs.cpp @@ -0,0 +1,48 @@ +#include +#include +#include + +#include "tweaked_inputs.h" + +sRGBSwitchingFlatInput::~sRGBSwitchingFlatInput() +{ + if (sampler_obj != 0) { + glDeleteSamplers(1, &sampler_obj); + } +} + +void sRGBSwitchingFlatInput::set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) +{ + movit::FlatInput::set_gl_state(glsl_program_num, prefix, sampler_num); + texture_unit = *sampler_num - 1; + + if (sampler_obj == 0) { + glGenSamplers(1, &sampler_obj); + check_error(); + glSamplerParameteri(sampler_obj, GL_TEXTURE_MIN_FILTER, needs_mipmaps ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR); + check_error(); + glSamplerParameteri(sampler_obj, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + check_error(); + glSamplerParameteri(sampler_obj, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + check_error() + // This needs to be done on a sampler and not a texture parameter, + // because the texture could be used from multiple different + // contexts at the same time. This flag is ignored for non-sRGB-uploaded + // textures, so we can set it without checking can_output_linear_gamma(). + if (output_linear_gamma) { + glSamplerParameteri(sampler_obj, GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT); + } else { + glSamplerParameteri(sampler_obj, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT); + } + check_error(); + } + + glBindSampler(texture_unit, sampler_obj); + check_error(); +} + +void sRGBSwitchingFlatInput::clear_gl_state() +{ + glBindSampler(texture_unit, 0); + check_error(); +}