apkenv: OSMesa and QEMU user-space emulation


apkenv has seen only a few small updates since 2016. As part of my end-of-the-year walk through repositories and open pull requests, I made a note that it might be fun to try to make it work on normal Desktop Linux, as all the other platforms to which it was ported in the past are mostly gone or in some state of decay.


The part responsible for decoding image files for certain game support modules has been changed to just use stb_image.h for decoding, which removes the dependency on libpng and libjpeg for the "host" platform.

OSMesa + qemu-user port

OSMesa is the off-screen software rasterizer of the Mesa project. It allows us to bring up an OpenGL context without any driver support (although rendering is obviously slow, especially when run within qemu-user).

Building OSMesa and linking apkenv against it makes it possible to test it out in situations where an OpenGL driver isn't readily available.

Host UI

While the first proof-of-concept could just render the screen contents to a file, the next revision added a hostui process that takes care of getting input events from the host system and displaying the graphics output. In this mode, the hostui process reads commands from standard input, and writes responses to standard output.

Mixer and OpenGL ES 1.1 serialization

In order to have a playable experience, the OSMesa/qemu-user port also added support for the "mixer" API of apkenv and serialization of OpenGL ES 1.1 calls. This actually makes it possible to skip OSMesa for some games supported by apkenv, and relaying all OpenGL calls to the host OpenGL driver -- in this case, naming the port osmesa is actually a bit of a misnomer.

Support modules

The Petals Redux support module has gotten some fixes, and a new Loonies support module has been added. Also, a very experimental (but works-for-one-of-my-experiments) support module for games using ANativeActivity has been added.

Raspberry Pi 3 support

apkenv has worked on the OG Raspberry Pi at some point in the past, but nobody tested it and there were no clear instructions. Also, since it has been released, Raspbian Linux has advanced quite a lot, so it made sense to re-visit it and see how to fix support.

A new platform module for rpi3 has been added, and instructions for building and running apkenv on a Raspberry Pi 3 with Raspbian are now available for people who want to give it a spin.

What's next

One could call the host OpenGL directly when attaching to the qemu process. There's some experimental code I have working for this use case, and it might be nice to eventually integrate into apkenv, so that the OSMesa dependency can be removed completely again, and all games (including OpenGL ES 2.0-based ones) can run within apkenv on modern Desktop Linux (x86_64 and aarch64).

Try it out

The current code with the changes discussed above is available on Github.

See the various README files for build and setup instructions.

Thomas Perl · 2023-02-02