Support EGL for creating GL contexts on X11
Submitted by Emmanuele Bassi
The X11 platform has two GL native API:
- EGL with support for X11 surfaces
GDK supports the former, but not the latter.
There are various use cases for supporting EGL-X11:
- various embedded hardware platforms support OpenGL ES and EGL, and have native X11 drivers, but as they don't support OpenGL, they don't usually come with GLX drivers
- newer Linux features, like passing around zero-copy dmabuf objects can be handled using EGL and platform-specific extensions, but they cannot be implemented using GLX
We can definitely add a configure-time option for building GTK+ with a specific API; we should also add an option to specify whether GTK+ should default to OpenGL or OpenGL ES. These options are useful for system integrators that know and control which platform they are building GTK+ for.
There are some issues with selecting whether to use GLX or EGL-X11, and then selecting OpenGL or OpenGL ES at run time.
On the embedded hardware side, there's the added complexity that the platform may have Mesa installed, which means that selecting GLX first will result in a perfectly working GL software rasterizer, instead of the hardware accelerated option.
We cannot really drop GLX, mostly because not every desktop system supports EGL out of the box on X11.
A plausible attempt at a solution is:
- add a
--with-x11-opengl-api=auto|glx|eglconfigure-time option, to allow selecting which GL native API should be used;
autodetects support for GLX and EGL, and does a run-time check
- add a
--with-default-opengl-api=auto|gl|glesconfigure-time option, to allow selecting the default GL API between OpenGL and OpenGL ES; this determines the default value of GdkGLContext.use_es when use_es is set to "-1" (platform default); if
autois selected, we keep the current behaviour of checking via epoxy if the currently bound API is "desktop GL"
- when using the X11 backend, we check whether EGL is supported, and default to it; if it's not available, we fall back to GLX
This changes the default platform API from GLX to EGL-X11; we need to check with various stakeholders in the X.org community whether or not it's a good plan.
An initial implementation of the EGL-X11 support can be found in the wip/ebassi/gdk-egl-x11 branch: https://git.gnome.org/browse/gtk+/log/?h=wip/ebassi/gdk-egl-x11
What's missing from that branch:
- configure time option for selecting between GL and GLES default
- build both GLX and EGL-X11 GdkGLContext
- default to EGL-X11 and fall back to GLX