Some applications and games require access to OpenGL, Vulkan or GPU(s). Typically, snapped applications require three things to make this possible.
- Including additional user space GPU libraries.
- Initialising those libraries before your application starts.
- Permitting access using the
This document explains how to do this.
Include user space GPU libraries
You need to include the appropriate user space “drivers” in the snap to expose OpenGL/GPU capabilities. All that is typically required is the
libglu1-mesa package. Add this to the
stage-packages of the
part of your application.
parts: mygame: stage-packages: - libglu1-mesa
Graphical applications and GPU libraries require environment configuration to function correctly. The desktop helpers project provides scripts that do additional setup to ensure toolkits, audio stacks and graphics drivers are correctly configured when your application starts. If your application uses GTK, Qt, or another desktop toolkit, then follow the instructions for that toolkit. The
desktop-launch script for that toolkit will also take care of GPU library configuration.
If your application, like most games, does not use a common desktop toolkit, then you can use the
desktop-glib-only helper to do the initialisation of desktop features such as GPU, sound and fonts. The first step is to include a dependency on the
desktop-glib-only part in the part of your application.
parts: mygame: after: - desktop-glib-only
The next step is to copy the
desktop-glib-only part from the desktop helpers
# This part installs the glib dependencies and a `desktop-launch` script to initialise # desktop-specific features such as OpenGL, fonts, themes and the XDG environment. # # It is copied from the snapcraft desktop helpers project and the `source` key is # changed to point to https://github.com/ubuntu/snapcraft-desktop-helpers.git # Please periodically check the desktop helpers repo for updates and copy the changes. # https://github.com/ubuntu/snapcraft-desktop-helpers/blob/master/snapcraft.yaml # desktop-glib-only: source: https://github.com/ubuntu/snapcraft-desktop-helpers.git source-subdir: glib-only ... <copy the rest of this part from the desktop helpers snapcraft.yaml> ...
If none if the prebuilt helpers are suitable for your application, you can create a helper script yourself. See the
sommelier script in the Track Mania Nation Forever snap as an example.
Permit access to GPU hardware
apps: mygame: plugs: - opengl
- Overview of snapcraft support for graphical applications and toolkits
- See the snapcraft.yaml for Xonotic for a more complete example.