Objectives : make an X11/GLX program run natively on Wayland/EGL, with minimal modifications to the code.
The Linux world is rapidly migrating from the legacy X11 display protocol and server, to Wayland. There are a lot of reasons why this change is necessary, but it's best watching this conference to understand why X is now left behind.
However, there are a few challenges, especially when it comes to OpenGL programs.
There a few different OpenGL APIs today (GL1, GL2, GL3, GLES1, GLE2...) ; on the desktop, the most popular has always been GL1/GL2, whereas GLES, by contrast, is mostly used on mobile OSes (Android, iOS...).
We also need more than pure OpenGL to draw to the screen : a glue for the underlying window system. It's called WGL on Windows, CGL on Mac OS X, and traditionally GLX on Linux/X11.
For instance, our good ol' glxgears benchmark runs on X11 using OpenGL1 and GLX :
glxgears running with GL/GLX
And now, here comes the problem : Wayland doesn't support desktop GL nor GLX.
Instead, it only supports GLES with a new binding named EGL.
We'd normally be forced to rewrite all our implementation code. But let's see how to deal with this case with minimum effort.
So for a code including GL headers :
we basically replace them with jwzGLES/GLES1 ones :
#include <GLES/gl.h> #include "jwzgles.h"
And to link replace :
-lGLESv1_CM -DHAVE_JWZGLES -ljwzgles
I recently needed to port a GLX program under native Wayland ; so I wrote the EGLX wrapper, which remaps GLX calls to EGL-Wayland ones (hence the name ;-) ).
So for a code including GLX headers :
we basically replace them with EGLX ones :
and put at the beginning of the main() function :
And to link add :
In the EGLX source tree, once you've compiled the library, have a look at the modified version of "examples/glxgears.c".
Then build it with :
And run it with :
Wrapped glxgears running on Wayland ; note you can move the surface with the pointer
Here we go !
A video a available HERE.