Adding OpenGL/GPU support to a snap


#1

Some applications and games require access to OpenGL or GPU(s) which can be facilitated with a few additions to the snapcraft.yaml.

stage-packages:

You need to include the appropriate “drivers” in the snap to expose OpenGL/GPU capabilities. All that is typically required is libglu1-mesa should be added to the stage-packages: in the parts: section of the snapcraft.yaml. For example:

parts:
  mygame:
    stage-packages:
      - libglu1-mesa

See the snapcraft.yaml for Xonotic for a more complete example.

Desktop helpers

Desktop helpers are scripts that provide some additional setup to ensure toolkits, audio stacks and graphics drivers are correctly exposed to the snap. You will need to define a suitable desktop helper via the after: keyword in the parts: section of the snapcraft.yaml. For example

parts:
  mygame:
    after:
      - desktop-glib-only

If the application/game uses GTK or Qt then either the desktop-gtk2, desktop-gtk3, desktop-q4 or desktop-qt5 helper should be used. If the application/game doesn’t require the GTK or Qt toolkits then the desktop-glib-only helper should be suitable.

If none if the prebuilt helpers are suitable a bespoke helper script can be bundled in the snap. See the sommelier script in the Track Mania Nation Forever snap as an example.

Interfaces

If the snap is strictly confined then the opengl interface needs adding to the plugs: in the apps: section of the snapcraft.yaml. For example:

apps:
  mygame:
    plugs:
      - opengl

See the snapcraft.yaml for Xonotic for a more complete example. Learn more about interfaces and the available plugs.


Snap build fails to find required plugin