]> git.sesse.net Git - nageru/blob - nageru/tweaked_inputs.cpp
Fix a dangling reference (found by GCC 14).
[nageru] / nageru / tweaked_inputs.cpp
1 #include <epoxy/gl.h>
2 #include <movit/flat_input.h>
3 #include <movit/util.h>
4 #include <string>
5
6 #include "tweaked_inputs.h"
7
8 sRGBSwitchingFlatInput::~sRGBSwitchingFlatInput()
9 {
10         if (sampler_obj != 0) {
11                 glDeleteSamplers(1, &sampler_obj);
12         }
13 }
14
15 void sRGBSwitchingFlatInput::set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num)
16 {
17         movit::FlatInput::set_gl_state(glsl_program_num, prefix, sampler_num);
18         texture_unit = *sampler_num - 1;
19
20         if (sampler_obj == 0) {
21                 glGenSamplers(1, &sampler_obj);
22                 check_error();
23                 glSamplerParameteri(sampler_obj, GL_TEXTURE_MIN_FILTER, needs_mipmaps ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR);
24                 check_error();
25                 glSamplerParameteri(sampler_obj, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
26                 check_error();
27                 glSamplerParameteri(sampler_obj, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
28                 check_error()
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);
35                 } else {
36                         glSamplerParameteri(sampler_obj, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT);
37                 }
38                 check_error();
39         }
40
41         glBindSampler(texture_unit, sampler_obj);
42         check_error();
43 }
44
45 void sRGBSwitchingFlatInput::clear_gl_state()
46 {
47         glBindSampler(texture_unit, 0);
48         check_error();
49 }