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