upload.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2017 Intel Corporation. All Rights Reserved.
3 
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"
7 
9 #include "proc/colorizer.h"
10 #include "colorizer-gl.h"
11 #include "upload.h"
12 #include "option.h"
13 #include "context.h"
14 
15 #ifndef NOMINMAX
16 #define NOMINMAX
17 #endif // NOMINMAX
18 
19 #include <glad/glad.h>
20 
21 #include <iostream>
22 
23 #include <chrono>
24 #include <strstream>
25 
26 #include "synthetic-stream-gl.h"
27 
28 namespace librealsense
29 {
30  namespace gl
31  {
33  : stream_filter_processing_block("Upload Block (GLSL)")
34  {
35  _hist = std::vector<int>(librealsense::colorizer::MAX_DEPTH, 0);
36  _fhist = std::vector<float>(librealsense::colorizer::MAX_DEPTH, 0.f);
37  _hist_data = _hist.data();
38  _fhist_data = _fhist.data();
39 
42 
43  initialize();
44  }
45 
47  {
48  perform_gl_action([&]()
49  {
51  }, [] {});
52  }
53 
55  {
56  _enabled = false;
57  }
59  {
60  _enabled = true;
61  }
62 
64  {
65  auto res = f;
66 
67  if (_enabled)
68  {
69  if (f.get_profile().format() == RS2_FORMAT_YUYV)
70  {
71  auto vf = f.as<rs2::video_frame>();
72  auto width = vf.get_width();
73  auto height = vf.get_height();
74  auto new_f = source.allocate_video_frame(f.get_profile(), f,
75  vf.get_bytes_per_pixel(), width, height, vf.get_stride_in_bytes(), RS2_EXTENSION_VIDEO_FRAME_GL);
76 
77  if (new_f) perform_gl_action([&]()
78  {
79  auto gf = dynamic_cast<gpu_addon_interface*>((frame_interface*)new_f.get());
80 
81  uint32_t output_yuv;
82  gf->get_gpu_section().output_texture(0, &output_yuv, TEXTYPE_UINT16);
83  glBindTexture(GL_TEXTURE_2D, output_yuv);
84  glTexImage2D(GL_TEXTURE_2D, 0, GL_RG8, width, height, 0, GL_RG, GL_UNSIGNED_BYTE, f.get_data());
87 
88  gf->get_gpu_section().set_size(width, height);
89 
90  res = new_f;
91  }, [&]() {
92  _enabled = false;
93  });
94  }
95 
96  if (f.is<rs2::depth_frame>() && (RS2_FORMAT_Z16 == f.get_profile().format()))
97  {
98  auto vf = f.as<rs2::depth_frame>();
99  auto width = vf.get_width();
100  auto height = vf.get_height();
101  auto new_f = source.allocate_video_frame(f.get_profile(), f,
102  vf.get_bytes_per_pixel(), width, height, vf.get_stride_in_bytes(), RS2_EXTENSION_DEPTH_FRAME_GL);
103 
104  if (new_f)
105  {
106  auto ptr = dynamic_cast<librealsense::depth_frame*>((librealsense::frame_interface*)new_f.get());
107 
109  auto depth_data = (uint16_t*)orig->get_frame_data();
110 
111  memcpy(ptr->data.data(), depth_data, ptr->data.size());
112 
113  ptr->set_sensor(orig->get_sensor());
114  orig->acquire();
115  frame_holder h{ orig };
116  ptr->set_original(std::move(h));
117 
118  {
120  depth_data, width, height);
123  }
124 
125  perform_gl_action([&]()
126  {
127  //scoped_timer t("upload.depth");
128 
129  auto gf = dynamic_cast<gpu_addon_interface*>((frame_interface*)new_f.get());
130 
131  uint32_t depth_texture;
132  gf->get_gpu_section().output_texture(0, &depth_texture, TEXTYPE_UINT16);
133  glBindTexture(GL_TEXTURE_2D, depth_texture);
134  glTexImage2D(GL_TEXTURE_2D, 0, GL_RG8, width, height, 0, GL_RG, GL_UNSIGNED_BYTE, f.get_data());
137 
138  uint32_t hist_texture;
139  gf->get_gpu_section().output_texture(1, &hist_texture, TEXTYPE_FLOAT_ASSIST);
140  glBindTexture(GL_TEXTURE_2D, hist_texture);
142  0xFF, 0xFF, 0, GL_RED, GL_FLOAT, _fhist_data);
145 
146  gf->get_gpu_section().set_size(width, height, true);
147 
148  res = new_f;
149  }, [&]() {
150  _enabled = false;
151  });
152  }
153  }
154  }
155 
156  return res;
157  }
158  }
159 }
160 
orig
Definition: rmse.py:46
#define GL_TEXTURE_MAG_FILTER
#define GL_RG8
rs2_frame * get() const
Definition: rs_frame.hpp:590
static const int MAX_DEPTH
Definition: colorizer.h:117
void add_extension(rs2_extension ex)
Definition: source.h:45
#define GL_TEXTURE_2D
#define GL_UNSIGNED_BYTE
void output_texture(int id, uint32_t *tex, texture_type type)
stream_profile get_profile() const
Definition: rs_frame.hpp:557
const void * get_data() const
Definition: rs_frame.hpp:545
unsigned short uint16_t
Definition: stdint.h:79
rs2::frame process_frame(const rs2::frame_source &source, const rs2::frame &f) override
Definition: upload.cpp:63
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:1960
#define glTexImage2D
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
GLdouble f
bool is() const
Definition: rs_frame.hpp:570
#define GL_FLOAT
#define glTexParameteri
unsigned int uint32_t
Definition: stdint.h:80
GLint GLsizei GLsizei height
#define GL_R16F
#define GL_TEXTURE_MIN_FILTER
void create_gpu_resources() override
Definition: upload.cpp:58
#define GL_RG
std::vector< float > _fhist
Definition: upload.h:39
rs2_format format() const
Definition: rs_frame.hpp:44
#define GL_RED
#define RS2_EXTENSION_VIDEO_FRAME_GL
#define glBindTexture
void perform_gl_action(T action, S fallback)
virtual gpu_section & get_gpu_section()=0
typename::boost::move_detail::remove_reference< T >::type && move(T &&t) BOOST_NOEXCEPT
GLsizei GLsizei GLchar * source
#define RS2_EXTENSION_DEPTH_FRAME_GL
GLuint res
Definition: glext.h:8856
static void update_histogram(int *hist, const T *depth_data, int w, int h)
Definition: colorizer.h:104
std::vector< int > _hist
Definition: upload.h:38
#define GL_NEAREST
void cleanup_gpu_resources() override
Definition: upload.cpp:54
static void populate_floating_histogram(float *f, int *hist)
int get_width() const
Definition: rs_frame.hpp:659
GLint GLsizei width
T as() const
Definition: rs_frame.hpp:580


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:50:13