15 #include <glad/glad.h> 40 throw std::runtime_error(
"Selected RealSense format cannot be converted to GL format!");
47 throw std::runtime_error(
"Selected RealSense format cannot be converted to GL format!");
68 _data.register_gpu_object(obj);
73 _data.unregister_gpu_object(obj);
78 std::lock_guard<std::mutex>
lock(_data.mutex);
81 LOG_INFO(
"Initializing rendering, GLSL=" << use_glsl);
83 for (
auto&&
obj : _data.objs)
85 obj->update_gpu_resources(use_glsl);
90 LOG_INFO(
" " << _data.objs.size() <<
" GPU objects initialized");
97 std::lock_guard<std::mutex>
lock(_data.mutex);
99 for (
auto&&
obj : _data.objs)
101 obj->update_gpu_resources(
false);
103 _data.active =
false;
104 LOG_INFO(
" " << _data.objs.size() <<
" GPU objects cleaned-up");
121 _data.register_gpu_object(obj);
126 _data.unregister_gpu_object(obj);
131 std::lock_guard<std::mutex>
lock(_data.mutex);
133 LOG_INFO(
"Initializing processing, GLSL=" << use_glsl);
138 _ctx = std::make_shared<context>(share_with, binding);
139 auto session =
_ctx->begin_session();
141 for (
auto&&
obj : _data.objs)
144 obj->update_gpu_resources(use_glsl);
147 LOG_INFO(
" " << _data.objs.size() <<
" GPU objects initialized");
152 std::lock_guard<std::mutex>
lock(_data.mutex);
154 LOG_INFO(
"Shutting down processing");
156 _data.active =
false;
157 auto session =
_ctx->begin_session();
159 for (
auto&&
obj : _data.objs)
162 obj->update_gpu_resources(
false);
165 LOG_INFO(
" " << _data.objs.size() <<
" GPU objects cleaned-up");
200 gpu_section::operator bool()
283 bool need_to_fetch =
false;
285 if (
loaded[
i]) need_to_fetch =
true;
305 width,
height, 0, textype.gl_format, textype.data_type,
nullptr);
342 throw std::runtime_error(
"Could not initialize offscreen context!");
355 _vis = std::make_shared<rs2::visualizer_2d>();
363 if (curr ==
_ctx)
return nullptr;
368 auto me = shared_from_this();
369 return std::shared_ptr<void>(
nullptr, [curr, me](
void*){
370 me->_binding.glfwMakeContextCurrent(curr);
std::weak_ptr< context > _ctx
static const textual_icon lock
glfwCreateWindowFun glfwCreateWindow
void init(GLFWwindow *share_with, glfw_binding binding, bool use_glsl)
void unregister_gpu_object(gpu_processing_object *obj)
glfwMakeContextCurrentFun glfwMakeContextCurrent
#define glFramebufferTexture2D
The header of the GLFW 3 API.
glfwDestroyWindowFun glfwDestroyWindow
glfwGetProcAddressFun glfwGetProcAddress
void *(* GLADloadproc)(const char *name)
std::unique_ptr< uint8_t[]> backup
void output_texture(int id, uint32_t *tex, texture_type type)
void unregister_gpu_object(gpu_rendering_object *obj)
texture_mapping & rs_format_to_gl_format(rs2_format type)
void create_gpu_resources() override
std::shared_ptr< rs2::visualizer_2d > _vis
void fetch_frame(void *to)
GLsizei GLenum GLenum * types
#define GL_COLOR_BUFFER_BIT
static std::thread::id _rendering_thread
GLint GLsizei GLsizei height
GLint GLint GLsizei GLint GLenum format
void set_size(uint32_t width, uint32_t height, bool preloaded=false)
void cleanup_gpu_resources() override
rs2_format
A stream's format identifies how binary data is encoded within a frame.
bool loaded[MAX_TEXTURES]
std::recursive_mutex _lock
std::shared_ptr< void > begin_session()
GLAPI int gladLoadGLLoader(GLADloadproc)
glfwSwapIntervalFun glfwSwapInterval
texture_mapping & gl_format_mapping(texture_type type)
int get_frame_size() const
rs2::visualizer_2d & get_texture_visualizer()
LOG_INFO("Log message using LOG_INFO()")
void register_gpu_object(gpu_processing_object *obj)
static rendering_lane & instance()
void perform_gl_action(T action, S fallback)
void init(glfw_binding binding, bool use_glsl)
#define GLFW_VISIBLE
Window visibility window hint and attribute.
glfwGetCurrentContextFun glfwGetCurrentContext
void register_gpu_object(gpu_rendering_object *obj)
static processing_lane & instance()
#define GL_COLOR_ATTACHMENT0
glfwWindowHintFun glfwWindowHint
bool input_texture(int id, uint32_t *tex)
static bool is_rendering_thread()
context(GLFWwindow *share_with, glfw_binding binding)
struct GLFWwindow GLFWwindow
texture_mapping texture_formats[TEXTYPE_COUNT]