最近研究EGL的off-screen rendering,特别是使用GBM这块,网上资料很少。综合搜集到的资料,整合了一个小demo。很多注意事项都写在代码注释里面了。
EGL Spec的介绍,没有提及如何使用GBM进行off-screen rendering。因为这属于native platform的实现。
EGLSurfaces:
1. windows: used for onscreen rendering
2. pbuffers: used for offscreen rendering
3. pixmaps: used for offscreen rendering into buffers that may be accessed through native APIs.
EGL windows and pixmaps are tied to platform windows and pixmaps.
EGL supports off-screen rendering surfaces in pbuffers. Pbuffers differ from windows in the followings ways:
1. Pbuffers are typically allocated in offscreen(non-visible) graphics memory and are intended only for accelerated
offscreen rendering.
2. Pbuffers are EGL resources and have no associated native window or native window type. It may not by possible to
render to pbuffers using native rendering APIs.
更多参考资料:
https://www.khronos.org/registry/EGL/extensions/MESA/EGL_MESA_platform_gbm.txt
This extension defines how to create EGL resources from native GBM resources using the functions defined by EGL_EXT_platform_base.
(GBM is a Generic Buffer Manager for Linux).
https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_platform_gbm.txt (EGL 1.5 is required.)
This extension defines how to create EGL resources from native GBM resources using the EGL 1.5 platform functionality
(GBM is a Generic Buffer Manager for Linux).
EGL/GBM does not support Pbuffers. It doesn't support Pixmaps either.
To create an offscreen surface with EGL/GBM, you must pass a gbm_surface to eglCreateWindowSurface. "Window" is a misnomer.
No real "window" gets created. The resultant buffer will remain offscreen unless you use the kernel's KMS APIs to post it to the display.
// eglGetDisplay((EGLNativeDisplayType)my_gbm_device);
// eglCreateWindowSurface(egl_dpy, egl_config, (EGLNativeWindowTy