Repository: opencv
Issue: OpenCV EGL support for none X Server environment offscreen render
Labels: category: gpu/cuda (contrib),RFC

<!--
If you have a question rather than reporting a bug please go to http://answers.opencv.org where you get much faster responses.
If you need further assistance please read [How To Contribute](https://github.com/opencv/opencv/wiki/How_to_contribute).

This is a template helping you to create an issue which can be processed as quickly as possible. This is the bug reporting section for the OpenCV library.
-->

##### System information (version)
<!-- Example
- OpenCV => 3.1
- Operating System / Platform => Windows 64 Bit
- Compiler => Visual Studio 2015
-->

- OpenCV => :3.4.1
- Operating System / Platform => :Linux version 4.13.0-43-generic (buildd@lcy01-amd64-029) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9))
- Compiler => :gcc 5.4.0

##### Detailed description

With the help of https://devblogs.nvidia.com/egl-eye-opengl-visualization-without-x-server/ , 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.

Now I want to use OpenCV's `cv::ogl` and `cv::cuda` to simplify some module develop. The `map`,`download` interface are very friendly to use. 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-opengl-server-side-rendering/ , 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?

##### Steps to reproduce

<!-- to add code example fence it with triple backticks and optional file extension
    ```.cpp
    // C++ code example
    ```
 or attach as .txt or .zip file
-->