OpenCV EGL support for none X Server environment offscreen render

asked 2018-06-08 01:58:34 -0600

joshuafc gravatar image

With the help of https://devblogs.nvidia.com/egl-eye-o... , I have write a program do such things:

  1. Choose One GPUID(one of 0~3) On My 4 GPU System.
  2. Create OpenGL Context Without X Window at specified GPU Device.
  3. Create OpenGL Buffer, map it to cuda device ptr.
  4. Decode rtsp video stream with nvcodec hardware acceleration, storage decoded frame at maped cuda device memory at step 3.
  5. Use decoded frame cuda memory do caffe deep learning inference, get the algorithm result.
  6. Unmap cuda device ptr. so now the openGL buffer has the frame data.
  7. Use OpenGL FBO to render frame and algorithm result off screen. copy rendered data to PBO.
  8. Encode rendered frame data and save to mp4 file with nvcodec hardware acceleration.

I want to use OpenCV's cv::ogl and cv::cuda to simplify some module develop. But I can't create a cv::ocl::Buffer object, gl::GenBuffers() get a bufid == 0 assert failed , then I find OpenCV call glXGetProcAddressARB to get API.

In page https://devblogs.nvidia.com/linking-o... , I found some Information, ref below:

Linking an OpenGL application was simple: you only needed to link against libGL.so. functions for both OpenGL and glX were bundled into the same library, libGL.so.

But People want to have X11-based display managers on the same system with Wayland, or to use hardware-accelerated OpenGL on the same system with software-emulated OpenGL. This requires a cleaner separation between the OpenGL library and OpenGL context-management libraries.

GLVND, the OpenGL Vendor Neutral Dispatch for Linux, was born to meet this requirement. To use glX and OpenGL today, you should link against libOpenGL.so as well as libGLX.so. The first contains the OpenGL symbols, the latter the GLX symbols. If you want to use EGL context management instead, link against libOpenGL.so and libEGL.so.

If your application uses OpenGL extension functions, it is your responsibility to use the correct extension function loader mechanism for the initialized context. A GLX-based context should use glXGetProcAddress, whereas an EGL-based context should use eglGetProcAddress. Note that the use of a particular loader may be implicit: GLEW, for example, uses the GLEW_EGL C preprocessor macro to choose the loader.

My program depend on libOpenGL.so and libEGL.so. libopencv_core.so link to libGL.so, it seems like there have no official support to choose which type OpenGL context (glx or egl) ogl::Buffer,ogl::Texture,ogl::Array object should use.

How can I use ogl::Buffer,ogl::Texture,ogl::Array in my EGL OpenGL Context thread. Is there some official plan about this issue? If I should do it my self, where should I modify in opencv source code? how many work should I do to achieve the goal?

edit retag flag offensive close merge delete