RealSense Cross Platform API
RealSense Cross-platform API
rs_processing_gl.hpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2017 RealSense, Inc. All Rights Reserved.
3 
4 #ifndef LIBREALSENSE_RS2_PROCESSING_GL_HPP
5 #define LIBREALSENSE_RS2_PROCESSING_GL_HPP
6 
7 #include <librealsense2/rs.hpp>
8 #include "rs_processing_gl.h"
9 
10 #include <memory>
11 
12 namespace rs2
13 {
14  namespace gl
15  {
16  class pointcloud;
17  class yuy_to_rgb;
18 
19  inline void shutdown_rendering()
20  {
21  rs2_error* e = nullptr;
23  error::handle(e);
24  }
25 
26 #ifdef _glfw3_h_
27  inline void init_rendering(bool use_glsl = true)
28  {
29  rs2_error* e = nullptr;
30 
31  glfw_binding binding{
32  nullptr,
33  &glfwWindowHint,
34  &glfwCreateWindow,
35  &glfwDestroyWindow,
36  &glfwMakeContextCurrent,
37  &glfwGetCurrentContext,
38  &glfwSwapInterval,
39  &glfwGetProcAddress
40  };
41 
42  rs2_gl_init_rendering_glfw(RS2_API_VERSION, binding, use_glsl ? 1 : 0, &e);
43  error::handle(e);
44  }
45 #else
46  inline void init_rendering(bool use_glsl = true)
47  {
48  rs2_error* e = nullptr;
49  rs2_gl_init_rendering(RS2_API_VERSION, use_glsl ? 1 : 0, &e);
50  error::handle(e);
51  }
52 #endif
53 
54  inline void init_processing(bool use_glsl = true)
55  {
56  rs2_error* e = nullptr;
57  rs2_gl_init_processing(RS2_API_VERSION, use_glsl ? 1 : 0, &e);
58  error::handle(e);
59  }
60 
61  inline void shutdown_processing()
62  {
63  rs2_error* e = nullptr;
65  error::handle(e);
66  }
67 
68 #ifdef _glfw3_h_
69  inline void init_processing(GLFWwindow* share_with, bool use_glsl = true)
70  {
71  rs2_error* e = nullptr;
72 
73  glfw_binding binding{
74  nullptr,
75  &glfwWindowHint,
76  &glfwCreateWindow,
77  &glfwDestroyWindow,
78  &glfwMakeContextCurrent,
79  &glfwGetCurrentContext,
80  &glfwSwapInterval,
81  &glfwGetProcAddress
82  };
83 
84  rs2_gl_init_processing_glfw(RS2_API_VERSION, share_with, binding, use_glsl ? 1 : 0, &e);
85  error::handle(e);
86  }
87 #endif
88 
93  class gpu_frame : public frame
94  {
95  public:
96  gpu_frame(const frame& f)
97  : frame(f)
98  {
99  rs2_error* e = nullptr;
100  if (!f || (rs2_gl_is_frame_extendable_to(f.get(), RS2_GL_EXTENSION_VIDEO_FRAME, &e) == 0 && !e))
101  {
102  reset();
103  }
104  error::handle(e);
105  }
106 
107  uint32_t get_texture_id(unsigned int id = 0) const
108  {
109  rs2_error * e = nullptr;
110  auto r = rs2_gl_frame_get_texture_id(get(), id, &e);
111  error::handle(e);
112  return r;
113  }
114  };
115 
121  {
122  public:
123  yuy_decoder() : rs2::yuy_decoder(init()) { }
124 
125  private:
126  std::shared_ptr<rs2_processing_block> init()
127  {
128  rs2_error* e = nullptr;
129  auto block = std::shared_ptr<rs2_processing_block>(
132  error::handle(e);
133 
134  // Redirect options API to the processing block
135  //options::operator=(pb);
136 
137  return block;
138  }
139  };
140 
146  {
147  public:
148  m420_decoder() : rs2::m420_decoder(init()) { }
149 
150  private:
151  std::shared_ptr<rs2_processing_block> init()
152  {
153  rs2_error* e = nullptr;
154  auto block = std::shared_ptr<rs2_processing_block>(
157  error::handle(e);
158 
159  // Redirect options API to the processing block
160  //options::operator=(pb);
161 
162  return block;
163  }
164  };
165 
170  {
171  public:
172  y411_decoder() : rs2::y411_decoder( init() ) {}
173 
174  private:
175  static std::shared_ptr<rs2_processing_block> init()
176  {
177  rs2_error* e = nullptr;
178  auto block = std::shared_ptr<rs2_processing_block>(
181  error::handle(e);
182 
183  return block;
184  }
185  };
186 
191  class colorizer : public rs2::colorizer
192  {
193  public:
194  colorizer() : rs2::colorizer(init()) { }
195 
196  private:
197  std::shared_ptr<rs2_processing_block> init()
198  {
199  rs2_error* e = nullptr;
200  auto block = std::shared_ptr<rs2_processing_block>(
203  error::handle(e);
204 
205  return block;
206  }
207  };
208 
209  class uploader : public rs2::filter
210  {
211  public:
212  uploader() : rs2::filter(init()) { }
213 
214  private:
215  std::shared_ptr<rs2_processing_block> init()
216  {
217  rs2_error* e = nullptr;
218  auto block = std::shared_ptr<rs2_processing_block>(
221  error::handle(e);
222  return block;
223  }
224  };
225 
231  {
232  public:
233  pointcloud() : rs2::pointcloud(init()) {}
234 
235  pointcloud(rs2_stream stream, int index = 0)
236  : rs2::pointcloud(init())
237  {
238  set_option(RS2_OPTION_STREAM_FILTER, float(stream));
240  }
241 
242  private:
243  friend class context;
244 
245  std::shared_ptr<rs2_processing_block> init()
246  {
247  rs2_error* e = nullptr;
248 
249  auto block = std::shared_ptr<rs2_processing_block>(
252 
253  error::handle(e);
254 
255  return block;
256  }
257  };
258 
265  {
266  public:
267  camera_renderer() : rs2::filter(init()) {}
268 
269  void set_matrix(rs2_gl_matrix_type type, float* m4x4)
270  {
271  rs2_error* e = nullptr;
272  rs2_gl_set_matrix(get(), type, m4x4, &e);
273  error::handle(e);
274  }
275 
276  static const auto OPTION_MOUSE_X = rs2_option(RS2_OPTION_COUNT + 1);
277  static const auto OPTION_MOUSE_Y = rs2_option(RS2_OPTION_COUNT + 2);
280  static const auto OPTION_SELECTED = rs2_option(RS2_OPTION_COUNT + 5);
281  private:
282  friend class context;
283 
284  std::shared_ptr<rs2_processing_block> init()
285  {
286  rs2_error* e = nullptr;
287 
288  auto block = std::shared_ptr<rs2_processing_block>(
291 
292  error::handle(e);
293  return block;
294  }
295  };
296 
304  {
305  public:
307 
308  void set_matrix(rs2_gl_matrix_type type, float* m4x4)
309  {
310  rs2_error* e = nullptr;
311  rs2_gl_set_matrix(get(), type, m4x4, &e);
312  error::handle(e);
313  }
314 
315  static const auto OPTION_FILLED = rs2_option(RS2_OPTION_COUNT + 1);
316  static const auto OPTION_SHADED = rs2_option(RS2_OPTION_COUNT + 2);
317 
318  static const auto OPTION_MOUSE_X = rs2_option(RS2_OPTION_COUNT + 3);
319  static const auto OPTION_MOUSE_Y = rs2_option(RS2_OPTION_COUNT + 4);
321 
322  static const auto OPTION_PICKED_X = rs2_option(RS2_OPTION_COUNT + 6);
323  static const auto OPTION_PICKED_Y = rs2_option(RS2_OPTION_COUNT + 7);
324  static const auto OPTION_PICKED_Z = rs2_option(RS2_OPTION_COUNT + 8);
325 
326  static const auto OPTION_PICKED_ID = rs2_option(RS2_OPTION_COUNT + 9);
327  static const auto OPTION_SELECTED = rs2_option(RS2_OPTION_COUNT + 10);
329 
330  static const auto OPTION_NORMAL_X = rs2_option(RS2_OPTION_COUNT + 12);
331  static const auto OPTION_NORMAL_Y = rs2_option(RS2_OPTION_COUNT + 13);
332  static const auto OPTION_NORMAL_Z = rs2_option(RS2_OPTION_COUNT + 14);
333 
335 
336  private:
337  friend class context;
338 
339  std::shared_ptr<rs2_processing_block> init()
340  {
341  rs2_error* e = nullptr;
342 
343  auto block = std::shared_ptr<rs2_processing_block>(
346 
347  error::handle(e);
348  return block;
349  }
350  };
351 
354  class align : public rs2::align
355  {
356  public:
357  align(rs2_stream to) : rs2::align(init(to)) {}
358 
359  private:
360  friend class context;
361 
362  std::shared_ptr<rs2_processing_block> init(rs2_stream to)
363  {
364  rs2_error* e = nullptr;
365 
366  auto block = std::shared_ptr<rs2_processing_block>(
369 
370  error::handle(e);
371 
372  return block;
373  }
374  };
375  }
376 }
377 #endif // LIBREALSENSE_RS2_PROCESSING_GL_HPP
void init_processing(bool use_glsl=true)
Definition: rs_processing_gl.hpp:54
Definition: rs_option.h:138
rs2_processing_block * rs2_gl_create_colorizer(int api_version, rs2_error **error)
void rs2_gl_shutdown_processing(int api_version, rs2_error **error)
Definition: rs_frame.hpp:354
#define RS2_API_VERSION
Definition: rs.h:44
Definition: rs_processing_gl.hpp:120
static const auto OPTION_PICKED_ID
Definition: rs_processing_gl.hpp:326
static const auto OPTION_ORIGIN_PICKED
Definition: rs_processing_gl.hpp:328
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
Definition: rs_option.h:26
static const auto OPTION_NORMAL_X
Definition: rs_processing_gl.hpp:330
static const auto OPTION_MOUSE_Y
Definition: rs_processing_gl.hpp:319
void rs2_gl_init_rendering_glfw(int api_version, glfw_binding bindings, int use_glsl, rs2_error **error)
Definition: rs_processing.hpp:499
static const auto OPTION_NORMAL_Y
Definition: rs_processing_gl.hpp:331
Definition: rs_processing_gl.hpp:354
rs2_processing_block * rs2_gl_create_pointcloud_renderer(int api_version, rs2_error **error)
static const auto OPTION_MOUSE_Y
Definition: rs_processing_gl.hpp:277
pointcloud(rs2_stream stream, int index=0)
Definition: rs_processing_gl.hpp:235
void rs2_gl_shutdown_rendering(int api_version, rs2_error **error)
static const auto OPTION_NORMAL_Z
Definition: rs_processing_gl.hpp:332
Definition: rs_processing_gl.h:58
Definition: rs_context.hpp:11
static const auto OPTION_PICKED_Y
Definition: rs_processing_gl.hpp:323
Definition: rs_processing.hpp:528
int rs2_gl_is_frame_extendable_to(const rs2_frame *f, rs2_gl_extension extension_type, rs2_error **error)
Definition: rs_processing_gl.hpp:145
gpu_frame(const frame &f)
Definition: rs_processing_gl.hpp:96
rs2_processing_block * rs2_gl_create_yuy_decoder(int api_version, rs2_error **error)
void shutdown_processing()
Definition: rs_processing_gl.hpp:61
Definition: rs_context.hpp:96
Definition: rs_processing_gl.hpp:230
void reset()
Definition: rs_frame.hpp:622
void set_matrix(rs2_gl_matrix_type type, float *m4x4)
Definition: rs_processing_gl.hpp:269
Definition: rs_processing_gl.hpp:191
rs2_processing_block * rs2_gl_create_m420_decoder(int api_version, rs2_error **error)
Definition: rs_processing_gl.hpp:93
static const auto OPTION_PICKED_Z
Definition: rs_processing_gl.hpp:324
y411_decoder()
Definition: rs_processing_gl.hpp:172
Exposes RealSense processing-block functionality for GPU for C compilers.
void rs2_gl_set_matrix(rs2_processing_block *block, rs2_gl_matrix_type type, float *m4x4, rs2_error **error)
void set_matrix(rs2_gl_matrix_type type, float *m4x4)
Definition: rs_processing_gl.hpp:308
Definition: rs_processing_gl.hpp:169
uploader()
Definition: rs_processing_gl.hpp:212
pointcloud()
Definition: rs_processing_gl.hpp:233
void shutdown_rendering()
Definition: rs_processing_gl.hpp:19
align(rs2_stream to)
Definition: rs_processing_gl.hpp:357
Definition: rs_processing_gl.hpp:209
static const auto OPTION_SELECTED
Definition: rs_processing_gl.hpp:280
m420_decoder()
Definition: rs_processing_gl.hpp:148
static const auto OPTION_FILLED
Definition: rs_processing_gl.hpp:315
static const auto OPTION_MOUSE_X
Definition: rs_processing_gl.hpp:276
void rs2_delete_processing_block(rs2_processing_block *block)
Definition: rs_processing.hpp:429
uint32_t get_texture_id(unsigned int id=0) const
Definition: rs_processing_gl.hpp:107
pointcloud_renderer()
Definition: rs_processing_gl.hpp:306
Definition: rs_processing_gl.h:24
void init_rendering(bool use_glsl=true)
Definition: rs_processing_gl.hpp:46
static void handle(rs2_error *e)
Definition: rs_types.hpp:167
static const auto OPTION_PICKED_X
Definition: rs_processing_gl.hpp:322
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:46
static const auto OPTION_SELECTED
Definition: rs_processing_gl.hpp:327
static const auto OPTION_SCALE_FACTOR
Definition: rs_processing_gl.hpp:334
static const auto OPTION_SHADED
Definition: rs_processing_gl.hpp:316
Definition: rs_processing.hpp:360
static const auto OPTION_WAS_PICKED
Definition: rs_processing_gl.hpp:279
void rs2_gl_init_processing_glfw(int api_version, GLFWwindow *share_with, glfw_binding bindings, int use_glsl, rs2_error **error)
Definition: rs_option.h:73
Definition: rs_processing.hpp:783
rs2_processing_block * rs2_gl_create_camera_renderer(int api_version, rs2_error **error)
static const auto OPTION_MOUSE_PICK
Definition: rs_processing_gl.hpp:320
void rs2_gl_init_rendering(int api_version, int use_glsl, rs2_error **error)
Definition: rs_processing.hpp:739
rs2_processing_block * rs2_gl_create_uploader(int api_version, rs2_error **error)
rs2_processing_block * rs2_gl_create_y411_decoder(int api_version, rs2_error **error)
void set_option(rs2_option option, float value) const
Definition: rs_options.hpp:256
yuy_decoder()
Definition: rs_processing_gl.hpp:123
static const auto OPTION_MOUSE_PICK
Definition: rs_processing_gl.hpp:278
rs2_processing_block * rs2_gl_create_align(int api_version, rs2_stream to, rs2_error **error)
rs2_gl_matrix_type
Definition: rs_processing_gl.h:33
colorizer()
Definition: rs_processing_gl.hpp:194
Definition: rs_processing_gl.hpp:264
unsigned int rs2_gl_frame_get_texture_id(const rs2_frame *f, unsigned int id, rs2_error **error)
Definition: rs_processing.hpp:560
struct rs2_error rs2_error
Definition: rs_types.h:276
Definition: rs_processing_gl.hpp:303
rs2_processing_block * rs2_gl_create_pointcloud(int api_version, rs2_error **error)
rs2_frame * get() const
Definition: rs_frame.hpp:601
camera_renderer()
Definition: rs_processing_gl.hpp:267
struct GLFWwindow GLFWwindow
Definition: rs_processing_gl.h:43
static const auto OPTION_MOUSE_X
Definition: rs_processing_gl.hpp:318
void rs2_gl_init_processing(int api_version, int use_glsl, rs2_error **error)
Definition: rs_option.h:71