Add support for `MUJOCO_GL=osmesa` on Windows and macOS
The feature, motivation and pitch
I am working on packaging and running the testsuite of gymnasium 1.0.0 on conda-forge (in https://github.com/conda-forge/gymnasium-feedstock/pull/41). The tests are supposed to run on headless CI machines. While all the mujoco tests related to rendering work fine on Linux by setting MUJOCO_GL=osmesa, the rendering test fail on Windows and macOS.
I looked into supporting MUJOCO_GL=osmesa also on Windows and macOS, and the part of the code to modify seem:
- https://github.com/google-deepmind/mujoco/blob/3.2.4/python/mujoco/gl_context.py#L22
- https://github.com/google-deepmind/mujoco/blob/3.2.4/src/render/glad/glad.c#L226-L244
- https://github.com/google-deepmind/mujoco/blob/3.2.4/src/render/glad/glad.c#L88-L97
The python modifications are trivial, while the one on the glad's C files are a bit more complex.
In particular, on the Linux side to decide if osmesa should be used, Linux-specific strategies like checking if osmesa-symbols are present in the global process symbol table or check libraries already loaded in the process with dl_iterate_phdr. Replicating the same strategy on macOS or Windows may not be trivial given how different the loading of shared libraries works on these operating systems.
However, I wonder if it could make sense on Windows and macOS to just check for the value of the MUJOCO_GL env variable from the C code, and try to load OSMesa only if MUJOCO_GL=osmesa? Or there could be downside there? I would probably avoid to modify the Linux logic if it is working fine at the moment.
Note that this modification would not address the problem on how the user installs the osmesa library in the first place, but that is also the situation on Linux, where osmesa should be installed by some package manager that is also able to install C++ libraries (such as the system apt or yum package manager, or conda).
Alternatives
Do not support MUJOCO_GL=osmesa on Windows and macOS
Additional context
.
xref to related issue: https://github.com/google-deepmind/mujoco/issues/959
osmesa was removed from mesa upstream, see https://github.com/conda-forge/mesalib-feedstock/issues/109, so we should deprecate/drop all its use, not allow for more. I guess most users will not realize this as long as commonly used stable distribution will continue to ship a mesa version with osmesa, but if Ubuntu 26.04 actually ships without osmesa, I guess most users may start realizing the problem.
The topic "how to do software rendering on Windows or macOS" is still a topic, and there are some actions that it could make sense to do (for example, EGL is supported also on Windows, even if not out of the box, see https://github.com/pal1000/mesa-dist-win, so it could make sense to allow EGL also on Windows), but this is not related to this issue, that can be closed as osmesa was removed from mesa upstream.