4 #include "../include/librealsense2/hpp/rs_sensor.hpp" 5 #include "../include/librealsense2/hpp/rs_processing.hpp" 6 #include "../include/librealsense2-gl/rs_processing_gl.hpp" 16 #include <glad/glad.h> 27 "varying vec2 textCoords;\n" 28 "uniform sampler2D textureSampler;\n" 29 "uniform float opacity;\n" 30 "uniform float width;\n" 31 "uniform float height;\n" 33 " float pixel_width = 1.0 / width;\n" 34 " float pixel_height = 1.0 / height;\n" 38 " float tex_y = 1.0 - textCoords.y;\n" 39 " if (mod(floor(gl_FragCoord.x), 2.0) == 0.0){\n" 40 " vec2 tx1 = vec2(textCoords.x, tex_y);\n" 41 " vec4 px1 = texture2D(textureSampler, tx1);\n" 42 " vec2 tx2 = vec2(textCoords.x + pixel_width, tex_y);\n" 43 " vec4 px2 = texture2D(textureSampler, tx2);\n" 44 " y = px1.x; u = px1.y; v = px2.y;\n" 48 " vec2 tx1 = vec2(textCoords.x - pixel_width, tex_y);\n" 49 " vec4 px1 = texture2D(textureSampler, tx1);\n" 50 " vec2 tx2 = vec2(textCoords.x, tex_y);\n" 51 " vec4 px2 = texture2D(textureSampler, tx2);\n" 52 " y = px2.x; u = px1.y; v = px2.y;\n" 54 " //y *= 256.0; u *= 256.0; v *= 256.0;\n" 55 " float c = y - (16.0 / 256.0);\n" 56 " float d = u - 0.5;\n" 57 " float e = v - 0.5;\n" 58 " vec3 color = vec3(0.0);\n" 59 " //color.x = clamp(((298.0 / 256.0) * c + (409.0 / 256.0) * e + 0.5), 0.0, 1.0);\n" 60 " //color.y = clamp(((298.0 / 256.0) * c - (100.0 / 256.0) * d - (208.0/256.0) * e + 0.5), 0.0, 1.0);\n" 61 " //color.z = clamp(((298.0 / 256.0) * c + (516.0 / 256.0) * d + 0.5), 0.0, 1.0);\n" 62 " color.x = clamp((y + 1.40200 * (v - 0.5)), 0.0, 1.0);\n" 63 " color.y = clamp((y - 0.34414 * (u - 0.5) - 0.71414 * (v - 0.5)), 0.0, 1.0);\n" 64 " color.z = clamp((y + 1.77200 * (u - 0.5)), 0.0, 1.0);\n" 65 " gl_FragColor = vec4(color.xyz, opacity);\n" 79 _width_location = _shader->get_uniform_location(
"width");
80 _height_location = _shader->get_uniform_location(
"height");
85 _shader->load_uniform(_width_location, (
float)w);
86 _shader->load_uniform(_height_location, (
float)h);
94 void yuy2rgb::cleanup_gpu_resources()
101 void yuy2rgb::create_gpu_resources()
103 _viz = std::make_shared<visualizer_2d>(std::make_shared<yuy2rgb_shader>());
104 _fbo = std::make_shared<fbo>(_width, _height);
105 _enabled = glsl_enabled() ? 1 : 0;
113 auto opt = std::make_shared<librealsense::ptr_option<int>>(
114 0, 1, 0, 1, &
_enabled,
"GLSL enabled");
164 yuy_texture = input_frame.get_texture_id(0);
176 gf->get_gpu_section().output_texture(0, &output_rgb,
TEXTYPE_RGB);
188 _fbo->createTextureAttachment(output_rgb);
199 _viz->draw_texture(yuy_texture);
#define GL_TEXTURE_MAG_FILTER
void add_extension(rs2_extension ex)
stream_profile get_profile() const
const void * get_data() const
GLdouble GLdouble GLdouble w
GLfloat GLfloat GLfloat GLfloat h
void register_option(rs2_option id, std::shared_ptr< option > option)
void set_size(int w, int h)
frame allocate_video_frame(const stream_profile &profile, const frame &original, int new_bpp=0, int new_width=0, int new_height=0, int new_stride=0, rs2_extension frame_type=RS2_EXTENSION_VIDEO_FRAME) const
#define GL_COLOR_BUFFER_BIT
#define glBindFramebuffer
rs2::frame process_frame(const rs2::frame_source &source, const rs2::frame &f) override
void cleanup_gpu_resources() override
#define GL_TEXTURE_MIN_FILTER
uint32_t _height_location
#define RS2_EXTENSION_VIDEO_FRAME_GL
rs2::stream_profile _output_profile
const rs2_stream_profile * get() const
void perform_gl_action(T action, S fallback)
std::shared_ptr< rs2::fbo > _fbo
#define GL_COLOR_ATTACHMENT0
rs2_stream stream_type() const
stream_profile clone(rs2_stream type, int index, rs2_format format) const
static const char * fragment_shader_text
rs2::stream_profile _input_profile
std::shared_ptr< rs2::visualizer_2d > _viz