9 #include "../include/librealsense2/hpp/rs_frame.hpp" 10 #include "../include/librealsense2/hpp/rs_processing.hpp" 11 #include "../include/librealsense2-gl/rs_processing_gl.hpp" 19 #include <unordered_set> 23 #define RS2_EXTENSION_VIDEO_FRAME_GL (rs2_extension)(RS2_EXTENSION_COUNT) 24 #define RS2_EXTENSION_DEPTH_FRAME_GL (rs2_extension)(RS2_EXTENSION_COUNT + 1) 25 #define MAX_TEXTURES 2 55 template<
class T,
int N = 2>
62 for (
int i = 0;
i < N;
i++)
78 int next_idx = (
index + 1) % N;
98 memcpy(res, (
void*)pData, w * h *
sizeof(
T));
122 class context :
public std::enable_shared_from_this<context>
127 std::shared_ptr<void> begin_session();
134 std::shared_ptr<rs2::visualizer_2d>
_vis;
142 std::unordered_set<gpu_object*>
objs;
144 std::atomic_bool active {
false };
145 bool use_glsl =
false;
149 std::lock_guard<std::mutex>
lock(mutex);
155 std::lock_guard<std::mutex>
lock(mutex);
156 auto it = objs.find(obj);
186 static bool is_rendering_thread();
240 _use_glsl = use_glsl;
241 if (_needs_cleanup.fetch_xor(1))
242 cleanup_gpu_resources();
244 create_gpu_resources();
249 virtual void cleanup_gpu_resources() = 0;
250 virtual void create_gpu_resources() = 0;
261 std::atomic_int _needs_cleanup { 0 };
262 bool _use_glsl =
false;
281 create_gpu_resources();
312 perform_gl_action([
this](){
313 create_gpu_resources();
319 template<
class T,
class S>
322 auto ctx = _ctx.lock();
325 auto session =
ctx->begin_session();
336 if (
auto ctx = _ctx.lock())
337 return ctx->get_texture_visualizer();
338 else throw std::runtime_error(
"No context available");
352 void fetch_frame(
void* to);
354 bool input_texture(
int id,
uint32_t* tex);
359 void cleanup_gpu_resources()
override;
360 void create_gpu_resources()
override;
362 int get_frame_size()
const;
364 bool on_gpu()
const {
return !backup.get(); }
373 bool backup_content =
true;
374 bool preloaded =
false;
375 bool initialized =
false;
394 _section.on_publish();
395 return T::publish(new_owner);
399 _section.on_unpublish();
404 auto res = T::get_frame_data();
405 _section.fetch_frame((
void*)
res);
438 : _parent(parent), _opt(opt) {}
445 for(
size_t i = 0;
i < _parent->_blocks.size();
i++)
447 if (_parent->_blocks[
i]->supports_option(_opt))
449 _parent->_blocks[
i]->get_option(_opt).set(
value);
461 option&
get() {
return _parent->get().get_option(_opt); }
462 const option&
get()
const {
return _parent->get().get_option(_opt); }
472 for(
size_t i = 0;
i < _blocks.size();
i++)
478 if (
val > 0.
f)
break;
484 return *_blocks[
index];
487 void add(std::shared_ptr<processing_block> block)
489 _blocks.push_back(block);
494 if (block->supports_option(opt))
495 register_option(opt, std::make_shared<bypass_option>(
this, opt));
503 for (
auto&& pb : _blocks) pb->set_processing_callback(callback);
507 for (
auto&& pb : _blocks) pb->set_output_callback(callback);
515 return get().get_source();
518 std::vector<std::shared_ptr<processing_block>>
_blocks;
std::weak_ptr< context > _ctx
static const textual_icon lock
void unregister_gpu_object(gpu_object *obj)
static matrix4 identity()
void unregister_gpu_object(gpu_processing_object *obj)
gpu_addon(gpu_addon &&other)
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
virtual gpu_section & get_gpu_section() override
synthetic_source_interface & get_source() override
std::shared_ptr< rs2_frame_callback > frame_callback_ptr
std::unique_ptr< uint8_t[]> backup
void update_gpu_resources(bool use_glsl)
void perform_gl_action(T action)
bool glsl_enabled() const
void unregister_gpu_object(gpu_rendering_object *obj)
texture_mapping & rs_format_to_gl_format(rs2_format type)
void add(std::shared_ptr< processing_block > block)
GLdouble GLdouble GLdouble w
void enable_recording(std::function< void(const option &)> record_action) override
void query(T *res, int x0, int y0, int w, int h, uint32_t format, uint32_t type)
std::unordered_set< gpu_object * > objs
GLfloat GLfloat GLfloat GLfloat h
virtual ~matrix_container()
virtual ~gpu_rendering_object()
gpu_addon & operator=(gpu_addon &&other)
std::shared_ptr< rs2::visualizer_2d > _vis
GLsizei GLenum GLenum * types
static std::thread::id _rendering_thread
option_range get_range() const override
std::shared_ptr< rs2_frame_processor_callback > frame_processor_callback_ptr
const byte * get_frame_data() const override
#define GL_UNPACK_ALIGNMENT
GLint GLsizei GLsizei height
GLint GLint GLsizei GLint GLenum format
void invoke(frame_holder frames) override
rs2::visualizer_2d & get_texture_visualizer()
std::shared_ptr< context > get_context() const
rs2_format
A stream's format identifies how binary data is encoded within a frame.
bool is_read_only() const override
void set_processing_callback(frame_processor_callback_ptr callback) override
std::recursive_mutex _lock
std::vector< std::shared_ptr< processing_block > > _blocks
bypass_option(dual_processing_block *parent, rs2_option opt)
dual_processing_block * _parent
float query() const override
void register_gpu_object(gpu_object *obj)
rs2::visualizer_2d & get_texture_visualizer()
#define GL_PIXEL_PACK_BUFFER
const char * get_value_description(float v) const override
void register_gpu_object(gpu_processing_object *obj)
const char * get_description() const override
static rendering_lane & instance()
void perform_gl_action(T action, S fallback)
GLuint GLfloat GLfloat y0
void set_context(std::weak_ptr< context > ctx)
typename::boost::move_detail::remove_reference< T >::type && move(T &&t) BOOST_NOEXCEPT
bool is_enabled() const override
void register_gpu_object(gpu_rendering_object *obj)
bool glsl_enabled() const
static processing_lane & instance()
#define GL_PACK_ALIGNMENT
void set_matrix(rs2_gl_matrix_type type, const rs2::matrix4 &val)
virtual ~gpu_processing_object()
const rs2::matrix4 & get_matrix(rs2_gl_matrix_type type) const
void unpublish() override
void set_output_callback(frame_callback_ptr callback) override
bool glsl_enabled() const
std::shared_ptr< context > _ctx
struct GLFWwindow GLFWwindow
frame_interface * publish(std::shared_ptr< archive_interface > new_owner) override