refactoring

pull/3471/head
kallaballa 3 years ago
parent 5f182636ef
commit 58f664aa3e
  1. 54
      src/common/subsystems.hpp
  2. 14
      src/nanovg/nanovg-demo.cpp
  3. 12
      src/optflow/optflow-demo.cpp
  4. 14
      src/tetra/tetra-demo.cpp
  5. 14
      src/video/video-demo.cpp

@ -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<const char*>(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_ */

@ -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();

@ -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;

@ -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();

@ -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();

Loading…
Cancel
Save