src/gl/rs-gl.cpp
Go to the documentation of this file.
1 // License: Apache 2.0 See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 
4 #include "api.h"
5 #include "synthetic-stream-gl.h"
6 #include "yuy2rgb-gl.h"
7 #include "align-gl.h"
8 #include "pointcloud-gl.h"
9 #include "../include/librealsense2/h/rs_types.h"
10 #include "../include/librealsense2-gl/rs_processing_gl.h"
11 #include "camera-shader.h"
12 #include "upload.h"
13 #include "pc-shader.h"
14 #include "colorizer-gl.h"
16 #include "proc/colorizer.h"
17 #include "proc/align.h"
18 #include "log.h"
19 #include <assert.h>
20 
21 #include <GLFW/glfw3.h>
22 
23 
25 // API implementation //
27 
28 using namespace librealsense;
29 
31 {
32  std::shared_ptr<gl::context> ctx;
33 };
34 
35 namespace librealsense
36 {
37  RS2_ENUM_HELPERS(rs2_gl_extension, GL_EXTENSION)
38 
40  {
41  switch (value)
42  {
43  case RS2_GL_EXTENSION_VIDEO_FRAME: return "GL Video Frame";
44  default: assert(!is_valid(value)); return UNKNOWN_VALUE;
45  }
46  }
47 }
48 
50 
51 namespace librealsense
52 {
54 
56  {
57  switch (value)
58  {
59  case RS2_GL_MATRIX_TRANSFORMATION: return "Transformation Matrix";
60  case RS2_GL_MATRIX_PROJECTION: return "Projection Matrix";
61  case RS2_GL_MATRIX_CAMERA: return "Camera Matrix";
62  default: assert(!is_valid(value)); return UNKNOWN_VALUE;
63  }
64  }
65 }
66 
68 
70 {
71  verify_version_compatibility(api_version);
72 
73  auto block = std::make_shared<librealsense::gl::yuy2rgb>();
74  auto backup = std::make_shared<librealsense::yuy2_converter>(RS2_FORMAT_RGB8);
75  auto dual = std::make_shared<librealsense::gl::dual_processing_block>();
76  dual->add(block);
77  dual->add(backup);
78  return new rs2_processing_block { dual };
79 }
81 
82 unsigned int rs2_gl_frame_get_texture_id(const rs2_frame* frame_ref, unsigned int id, rs2_error** error) BEGIN_API_CALL
83 {
84  VALIDATE_NOT_NULL(frame_ref);
85  VALIDATE_RANGE(id, 0, MAX_TEXTURES - 1);
86 
87  auto gpu = dynamic_cast<gl::gpu_addon_interface*>((frame_interface*)frame_ref);
88  if (!gpu) throw std::runtime_error("Expected GPU frame!");
89 
90  uint32_t res;
91  if (!gpu->get_gpu_section().input_texture(id, &res))
92  throw std::runtime_error("Texture not ready!");
93 
94  return res;
95 }
96 HANDLE_EXCEPTIONS_AND_RETURN(0, frame_ref)
97 
99 {
101  VALIDATE_ENUM(extension_type);
102 
103  bool res = false;
104 
105  switch (extension_type)
106  {
108  {
109  auto gpu = dynamic_cast<gl::gpu_addon_interface*>((frame_interface*)f);
110  if (!gpu) return false;
111  // If nothing was loaded to the GPU frame, abort
112  if (!gpu->get_gpu_section()) return false;
113  // If GPU frame was backed up to main memory, abort
114  if (!gpu->get_gpu_section().on_gpu()) return false;
115  return true;
116  }
117  default: return false;
118  }
119 }
120 HANDLE_EXCEPTIONS_AND_RETURN(0, f, extension_type)
121 
123 {
124  verify_version_compatibility(api_version);
125  auto block = std::make_shared<librealsense::gl::colorizer>();
126  auto backup = std::make_shared<librealsense::colorizer>();
127  auto dual = std::make_shared<librealsense::gl::dual_processing_block>();
128  dual->add(block);
129  dual->add(backup);
130  return new rs2_processing_block { dual };
131 }
133 
135 {
136  verify_version_compatibility(api_version);
137  auto block = std::make_shared<librealsense::gl::align_gl>(to);
138  auto backup = std::make_shared<librealsense::align>(to);
139  auto dual = std::make_shared<librealsense::gl::dual_processing_block>();
140  dual->add(block);
141  dual->add(backup);
142  return new rs2_processing_block { dual };
143 }
145 
147 {
148  verify_version_compatibility(api_version);
149  auto block = std::make_shared<librealsense::gl::pointcloud_gl>();
150  auto backup = pointcloud::create();
151  auto dual = std::make_shared<librealsense::gl::dual_processing_block>();
152  dual->add(block);
153  dual->add(backup);
154  return new rs2_processing_block { dual };
155 }
157 
159 {
160  auto ptr = dynamic_cast<librealsense::gl::matrix_container*>(block->block.get());
161  if (!ptr) throw std::runtime_error("Processing block does not support matrix setting");
162  rs2::matrix4 m;
163  memcpy(&m.mat, m4x4, sizeof(rs2::matrix4));
164  ptr->set_matrix(type, m);
165 }
166 HANDLE_EXCEPTIONS_AND_RETURN(, block, type, m4x4)
167 
168 
169 void rs2_gl_init_rendering(int api_version, int use_glsl, rs2_error** error) BEGIN_API_CALL
170 {
171  verify_version_compatibility(api_version);
172  glfw_binding binding{
173  &glfwInit,
181  };
182  librealsense::gl::rendering_lane::instance().init(binding, use_glsl > 0);
183 }
184 HANDLE_EXCEPTIONS_AND_RETURN(, api_version, use_glsl)
185 
186 void rs2_gl_init_rendering_glfw(int api_version, glfw_binding bindings, int use_glsl, rs2_error** error) BEGIN_API_CALL
187 {
188  verify_version_compatibility(api_version);
189  librealsense::gl::rendering_lane::instance().init(bindings, use_glsl > 0);
190 }
191 HANDLE_EXCEPTIONS_AND_RETURN(, api_version, use_glsl)
192 
193 void rs2_gl_init_processing(int api_version, int use_glsl, rs2_error** error) BEGIN_API_CALL
194 {
195  verify_version_compatibility(api_version);
196  glfw_binding binding{
197  &glfwInit,
205  };
206  librealsense::gl::processing_lane::instance().init(nullptr, binding, use_glsl > 0);
207 }
208 HANDLE_EXCEPTIONS_AND_RETURN(, api_version, use_glsl)
209 
210 void rs2_gl_init_processing_glfw(int api_version, GLFWwindow* share_with,
211  glfw_binding bindings, int use_glsl, rs2_error** error) BEGIN_API_CALL
212 {
213  verify_version_compatibility(api_version);
214  librealsense::gl::processing_lane::instance().init(share_with, bindings, use_glsl > 0);
215 }
216 HANDLE_EXCEPTIONS_AND_RETURN(, api_version, use_glsl)
217 
219 {
220  verify_version_compatibility(api_version);
222 }
223 HANDLE_EXCEPTIONS_AND_RETURN(, api_version)
224 
226 {
227  verify_version_compatibility(api_version);
229 }
230 HANDLE_EXCEPTIONS_AND_RETURN(, api_version)
231 
233 {
234  verify_version_compatibility(api_version);
235  auto block = std::make_shared<librealsense::gl::camera_renderer>();
236  return new rs2_processing_block { block };
237 }
238 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, api_version)
239 
241 {
242  verify_version_compatibility(api_version);
243  auto block = std::make_shared<librealsense::gl::upload>();
244  return new rs2_processing_block{ block };
245 }
246 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, api_version)
247 
249 {
250  verify_version_compatibility(api_version);
251  auto block = std::make_shared<librealsense::gl::pointcloud_renderer>();
252  return new rs2_processing_block { block };
253 }
254 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, api_version)
255 
256 #ifdef BUILD_EASYLOGGINGPP
257 #ifdef SHARED_LIBS
259 #endif
260 char log_gl_name[] = "librealsense";
261 static logger_type<log_gl_name> logger_gl;
262 #endif
263 
void rs2_gl_init_rendering(int api_version, int use_glsl, rs2_error **error) BEGIN_API_CALL
rs2_processing_block * rs2_gl_create_yuy_decoder(int api_version, rs2_error **error) BEGIN_API_CALL
const char * get_string(rs2_rs400_visual_preset value)
void init(GLFWwindow *share_with, glfw_binding binding, bool use_glsl)
typedef void(APIENTRY *GLDEBUGPROC)(GLenum source
The header of the GLFW 3 API.
void rs2_gl_init_processing_glfw(int api_version, GLFWwindow *share_with, glfw_binding bindings, int use_glsl, rs2_error **error) BEGIN_API_CALL
GLFWAPI GLFWglproc glfwGetProcAddress(const char *procname)
Returns the address of the specified function for the current context.
Definition: context.c:741
void rs2_gl_shutdown_processing(int api_version, rs2_error **error) BEGIN_API_CALL
const GLfloat * m
Definition: glext.h:6814
GLfloat value
rs2_processing_block * rs2_gl_create_uploader(int api_version, rs2_error **error) BEGIN_API_CALL
void verify_version_compatibility(int api_version)
Definition: api.h:463
unsigned int rs2_gl_frame_get_texture_id(const rs2_frame *frame_ref, unsigned int id, rs2_error **error) BEGIN_API_CALL
#define MAX_TEXTURES
rs2_processing_block * rs2_gl_create_colorizer(int api_version, rs2_error **error) BEGIN_API_CALL
const char * rs2_gl_matrix_type_to_string(rs2_gl_matrix_type type)
rs2_processing_block * rs2_gl_create_camera_renderer(int api_version, rs2_error **error) BEGIN_API_CALL
rs2_processing_block * rs2_gl_create_align(int api_version, rs2_stream to, rs2_error **error) BEGIN_API_CALL
bool is_valid(const plane_3d &p)
Definition: rendering.h:243
#define RS2_ENUM_HELPERS(TYPE, PREFIX)
Definition: src/types.h:514
GLFWAPI int glfwInit(void)
Initializes the GLFW library.
Definition: init.c:198
GLdouble f
static std::shared_ptr< pointcloud > create()
Definition: pointcloud.cpp:392
#define HANDLE_EXCEPTIONS_AND_RETURN(R,...)
Definition: api.h:399
#define INITIALIZE_EASYLOGGINGPP
GLFWAPI void glfwSwapInterval(int interval)
Sets the swap interval for the current context.
Definition: context.c:658
unsigned int uint32_t
Definition: stdint.h:80
GLFWAPI void glfwMakeContextCurrent(GLFWwindow *window)
Makes the context of the specified window current for the calling thread.
Definition: context.c:611
void rs2_gl_init_processing(int api_version, int use_glsl, rs2_error **error) BEGIN_API_CALL
void rs2_gl_set_matrix(rs2_processing_block *block, rs2_gl_matrix_type type, float *m4x4, rs2_error **error) BEGIN_API_CALL
float mat[4][4]
Definition: rendering.h:274
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:42
void rs2_gl_init_rendering_glfw(int api_version, glfw_binding bindings, int use_glsl, rs2_error **error) BEGIN_API_CALL
#define BEGIN_API_CALL
Definition: api.h:397
GLFWAPI GLFWwindow * glfwCreateWindow(int width, int height, const char *title, GLFWmonitor *monitor, GLFWwindow *share)
Creates a window and its associated context.
Definition: window.c:151
rs2_gl_extension
#define NOARGS_HANDLE_EXCEPTIONS_AND_RETURN(R)
Definition: api.h:400
GLenum type
#define VALIDATE_RANGE(ARG, MIN, MAX)
Definition: api.h:409
GLFWAPI void glfwDestroyWindow(GLFWwindow *window)
Destroys the specified window and its context.
Definition: window.c:444
static rendering_lane & instance()
void init(glfw_binding binding, bool use_glsl)
void rs2_gl_shutdown_rendering(int api_version, rs2_error **error) BEGIN_API_CALL
rs2_processing_block * rs2_gl_create_pointcloud(int api_version, rs2_error **error) BEGIN_API_CALL
static processing_lane & instance()
rs2_gl_matrix_type
rs2_processing_block * rs2_gl_create_pointcloud_renderer(int api_version, rs2_error **error) BEGIN_API_CALL
GLuint res
Definition: glext.h:8856
#define UNKNOWN_VALUE
Definition: src/types.h:74
int rs2_gl_is_frame_extendable_to(const rs2_frame *f, rs2_gl_extension extension_type, rs2_error **error) BEGIN_API_CALL
GLFWAPI GLFWwindow * glfwGetCurrentContext(void)
Returns the window whose context is current on the calling thread.
Definition: context.c:635
struct GLFWwindow GLFWwindow
GLFWAPI void glfwWindowHint(int hint, int value)
Sets the specified window hint to the desired value.
Definition: window.c:291
#define VALIDATE_NOT_NULL(ARG)
Definition: api.h:406
struct rs2_frame rs2_frame
Definition: rs_types.h:261
#define VALIDATE_ENUM(ARG)
Definition: api.h:407
const char * rs2_gl_extension_to_string(rs2_gl_extension ex)
std::shared_ptr< gl::context > ctx


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