Skip to content

Latest commit

 

History

History

gles2_drm

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

gles2_drm

Example how to do GLES2 rendering with open-source vc4 OpenGL driver by using libdrm and mesa.

This is only way how to do hardware accelerated OpenGL rendering on 64-bit Arch Linux ARM.

Preparations

We will build our own mesa library, to have the latest version and to not depend on X11 libraries. Raspbian mesa package does not even have vc4 backend.

First install necessary development files for libdrm and mesa in sysroot - they require zlib and expat libraries.

For Raspbian do:

../sysroot.py --distro raspbian --sysroot "${SYSROOT}" zlib1g-dev libexpat1-dev

For Ubuntu do:

../sysroot.py --distro ubuntu --sysroot "${SYSROOT}" zlib1g-dev libexpat1-dev

For Arch Linux ARM:

../sysroot.py --distro alarm --sysroot "${SYSROOT}" --target "${TARGET}" zlib expat gcc

For Alpine Linux:

../sysroot.py --distro alpine --sysroot "${SYSROOT}" --target "${TARGET}" zlib-dev expat-dev linux-headers

Remember to install zlib1g and libexpat1 for Raspbian & Ubuntu or zlib and expat packages for Arch Linux ARM or zlib, expat and libstdc++ for Alpine Linux on your device.

Now execute ./build.sh script. This will download and build libdrm and mesa libraries in ${SYSROOT}/usr/local. Extra build dependencies for host machine are: meson, ninja, python-mako, and patchelf.

When it finishes, upload them to your Raspberry Pi, in this example we will put them in home folder:

scp "${SYSROOT}"/usr/local/lib/{libdrm.so.2,libgbm.so.1,libglapi.so.0,libEGL.so.1,libGLESv2.so.2,dri/vc4_dri.so,dri/v3d_dri.so} [email protected]:

The libraries need to be placed in same folder as main executable. Then there will be no need to set LD_LIBRARY_PATH.

Make sure you load open-source vc4 OpenGL driver on your Raspberry Pi. On Raspbian or Arch Linux ARM check /boot/config.txt file, on Ubuntu check /boot/firmware/config.txt, it should have dtoverlay=vc4-fkms-v3d line. This is not needed for 64-bit Arch Linux ARM, it loads vc4 driver automatically. For Raspberry Pi 4 add dtoverlay=vc4-kms-v3d-pi4 instead.

For Ubuntu you'll need skip u-boot bootloader because it does not load extra overlay for vc4. Edit /boot/firmware/config.txt and change kernel line to kernel=vmlinuz. Then comment out device_tree_address line - add # comment in front of it. Now copy overlay folder to boot partition:

sudo cp -r /lib/firmware/`uname -r`/device-tree/overlays /boot/firmware/

More information here.

Building & running

Execute make to build.

You can execute make run to build & upload & run executable on Raspberry Pi. By default it will try to connect to [email protected] host. You can override it by setting PI variable: make run [email protected]

You should see colorful triangle spinning. By default vsync is enabled, but you can disable it by changing ENABLE_VSYNC variable in source code.

Error handling is done using assert, feel free to change it when porting to your code.