-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR #2956 from Arun-Prasad-V: Extending LibRS's GL support to RS ROS2
- Loading branch information
Showing
9 changed files
with
209 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright 2023 Intel Corporation. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <librealsense2/rs.hpp> // Include RealSense Cross Platform API | ||
|
||
#if defined (ACCELERATE_WITH_GPU) | ||
|
||
#define GL_SILENCE_DEPRECATION | ||
#define GLFW_INCLUDE_GLU | ||
#include <GLFW/glfw3.h> | ||
#include <GL/gl.h> | ||
#include <iostream> | ||
|
||
#include <librealsense2-gl/rs_processing_gl.hpp> // Include GPU-Processing API | ||
|
||
|
||
#ifndef PI | ||
#define PI 3.14159265358979323846 | ||
#define PI_FL 3.141592f | ||
#endif | ||
|
||
|
||
class GLwindow | ||
{ | ||
public: | ||
|
||
GLwindow(int width, int height, const char* title) | ||
: _width(width), _height(height) | ||
{ | ||
glfwInit(); | ||
glfwWindowHint(GLFW_VISIBLE, 0); | ||
win = glfwCreateWindow(width, height, title, nullptr, nullptr); | ||
if (!win) | ||
throw std::runtime_error("Could not open OpenGL window, please check your graphic drivers or use the textual SDK tools"); | ||
glfwMakeContextCurrent(win); | ||
|
||
glfwSetWindowUserPointer(win, this); | ||
|
||
} | ||
|
||
~GLwindow() | ||
{ | ||
glfwDestroyWindow(win); | ||
glfwTerminate(); | ||
} | ||
|
||
void close() | ||
{ | ||
glfwSetWindowShouldClose(win, 1); | ||
} | ||
|
||
float width() const { return float(_width); } | ||
float height() const { return float(_height); } | ||
|
||
operator bool() | ||
{ | ||
auto res = !glfwWindowShouldClose(win); | ||
|
||
glfwPollEvents(); | ||
|
||
return res; | ||
} | ||
|
||
operator GLFWwindow* () { return win; } | ||
|
||
private: | ||
GLFWwindow* win; | ||
int _width, _height; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2023 Intel Corporation. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "../include/base_realsense_node.h" | ||
#include <chrono> | ||
|
||
using namespace realsense2_camera; | ||
using namespace std::chrono_literals; | ||
|
||
#if defined (ACCELERATE_WITH_GPU) | ||
|
||
void BaseRealSenseNode::initOpenGLProcessing(bool use_gpu_processing) | ||
{ | ||
// Once we have a window, initialize GL module | ||
// Pass our window to enable sharing of textures between processed frames and the window | ||
// The "use_gpu_processing" is going to control if we will use CPU or GPU for data processing | ||
rs2::gl::init_processing(_app, use_gpu_processing); | ||
if (use_gpu_processing) | ||
rs2::gl::init_rendering(); | ||
|
||
_timer = _node.create_wall_timer(1000ms, std::bind(&BaseRealSenseNode::glfwPollEventCallback, this)); | ||
} | ||
|
||
void BaseRealSenseNode::glfwPollEventCallback() | ||
{ | ||
// Must poll the GLFW events perodically, else window will hang or crash | ||
glfwPollEvents(); | ||
} | ||
|
||
void BaseRealSenseNode::shutdownOpenGLProcessing() | ||
{ | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters