diff --git a/src/common/subsystems.hpp b/src/common/subsystems.hpp index f32f0f5f2..68da0ee1e 100644 --- a/src/common/subsystems.hpp +++ b/src/common/subsystems.hpp @@ -31,23 +31,6 @@ using std::cerr; using std::endl; namespace kb { -void print_fps() { - static uint64_t cnt = 0; - static int64 start = cv::getTickCount(); - static double tickFreq = cv::getTickFrequency(); - static double fps = 1; - - if (cnt > 0 && cnt % uint64(ceil(fps)) == 0) { - int64 tick = cv::getTickCount(); - fps = tickFreq / ((tick - start + 1) / cnt); - cerr << "FPS : " << fps << '\r'; - start = tick; - cnt = 1; - } - - ++cnt; -} - void gl_check_error(const std::filesystem::path &file, unsigned int line, const char *expression) { GLint errorCode = glGetError(); @@ -615,10 +598,6 @@ void init() { gl::context = cv::ocl::OpenCLExecutionContext::getCurrent(); } -void swap_buffers() { - kb::egl::swap_buffers(); -} - std::string get_info() { return reinterpret_cast(glGetString(GL_VERSION)); } @@ -638,6 +617,22 @@ void blit_frame_buffer_to_screen() { glBlitFramebuffer(0, 0, WIDTH, HEIGHT, 0, 0, WIDTH, HEIGHT, GL_COLOR_BUFFER_BIT, GL_NEAREST); } + +bool display() { + if(x11::is_initialized()) { + //Blit the framebuffer we have been working on to the screen + gl::blit_frame_buffer_to_screen(); + + //Check if the x11 window was closed + if(x11::window_closed()) + return false; + + //Transfer the back buffer (which we have been using as frame buffer) to the native window + egl::swap_buffers(); + } + + return true; +} } // namespace gl namespace cl { @@ -735,6 +730,23 @@ void init(bool debug = false) { pop(); } } //namespace nvg + +void print_fps() { + static uint64_t cnt = 0; + static int64 start = cv::getTickCount(); + static double tickFreq = cv::getTickFrequency(); + static double fps = 1; + + if (cnt > 0 && cnt % uint64(ceil(fps)) == 0) { + int64 tick = cv::getTickCount(); + fps = tickFreq / ((tick - start + 1) / cnt); + cerr << "FPS : " << fps << '\r'; + start = tick; + cnt = 1; + } + + ++cnt; +} } #endif /* SRC_SUBSYSTEMS_HPP_ */ diff --git a/src/nanovg/nanovg-demo.cpp b/src/nanovg/nanovg-demo.cpp index d163f32de..5fd53b92d 100644 --- a/src/nanovg/nanovg-demo.cpp +++ b/src/nanovg/nanovg-demo.cpp @@ -217,17 +217,9 @@ int main(int argc, char **argv) { //Transfer buffer ownership back to OpenGL gl::release_to_gl(frameBuffer); - if (x11::is_initialized()) { - //Blit the framebuffer we have been working on to the screen - gl::blit_frame_buffer_to_screen(); - - //Check if the x11 window was closed - if (x11::window_closed()) { - break; - } - //Transfer the back buffer (which we have been using as frame buffer) to the native window - gl::swap_buffers(); - } + //if x11 is enabled it displays the framebuffer in the native window. returns false if the window was closed. + if(!gl::display()) + break; //Activate the OpenCL context for VAAPI va::bind(); diff --git a/src/optflow/optflow-demo.cpp b/src/optflow/optflow-demo.cpp index 5d698576d..6bf66c2ff 100644 --- a/src/optflow/optflow-demo.cpp +++ b/src/optflow/optflow-demo.cpp @@ -189,15 +189,9 @@ int main(int argc, char **argv) { cv::flip(frameBuffer, frameBuffer, 0); gl::release_to_gl(frameBuffer); - if (x11::is_initialized()) { - gl::blit_frame_buffer_to_screen(); - - if (x11::window_closed()) { - break; - } - - gl::swap_buffers(); - } + //if x11 is enabled it displays the framebuffer in the native window. returns false if the window was closed. + if(!gl::display()) + break; va::bind(); writer << videoFrame; diff --git a/src/tetra/tetra-demo.cpp b/src/tetra/tetra-demo.cpp index a5fd38215..e0830eec3 100644 --- a/src/tetra/tetra-demo.cpp +++ b/src/tetra/tetra-demo.cpp @@ -122,17 +122,9 @@ int main(int argc, char **argv) { //Release the frame buffer for use by OpenGL gl::release_to_gl(frameBuffer); - if(x11::is_initialized()) { - //Blit the framebuffer we have been working on to the screen - gl::blit_frame_buffer_to_screen(); - - //Check if the x11 window was closed - if(x11::window_closed()) - break; - - //Transfer the back buffer (which we have been using as frame buffer) to the native window - gl::swap_buffers(); - } + //if x11 is enabled it displays the framebuffer in the native window. returns false if the window was closed. + if(!gl::display()) + break; //Activate the OpenCL context for VAAPI va::bind(); diff --git a/src/video/video-demo.cpp b/src/video/video-demo.cpp index 42adfffb0..1c8af7b8b 100644 --- a/src/video/video-demo.cpp +++ b/src/video/video-demo.cpp @@ -165,17 +165,9 @@ int main(int argc, char **argv) { //Release the frame buffer for use by OpenGL gl::release_to_gl(frameBuffer); - if(x11::is_initialized()) { - //Blit the framebuffer we have been working on to the screen - gl::blit_frame_buffer_to_screen(); - - //Check if the x11 window was closed - if(x11::window_closed()) - break; - - //Transfer the back buffer (which we have been using as frame buffer) to the native window - gl::swap_buffers(); - } + //if x11 is enabled it displays the framebuffer in the native window. returns false if the window was closed. + if(!gl::display()) + break; //Activate the OpenCL context for VAAPI va::bind();