OpenGL core on Raspberry Pi 4

In this post I explain how to get OpenGL 3.3+ with the core profile working on the Raspberry Pi 4. Parts of this might work on older models however I did only test all of this on a Pi 4B with 8GiB of RAM.

Just not at the moment of writing no matter which driver you use, there is no support for depth buffers. So the use for 3D programs may be limited.

Preparations

First off the preparations. All drivers used in this post need the V3D kernel module. So make sure /boot/config.txt contains the following line:

dtoverlay=vc4-fkms-v3d

In addition to that you need recent mesa drivers. I recommend either using manjaro arm or the ubuntu raspberry pi builds with the oibaf ppa. Raspberry Pi OS can be problematic because its driver and kernel versions are a bit outdated.

I did all experiments and testing on a rapsberry pi 4B with 8GiB of RAM running Manjaro KDE arm (raspberry pi version not the general).

OpenGL 3.3

If you only need OpenGL 3.3 support with GLSL 330 you can just use the V3D mesa driver which is the support. However because of the missing depth buffer support, by default the available version is only 2.1. To get have a newer version an environment variable has to be set like below:

export MESA_GL_VERSION_OVERRIDE=3.3 MESA_GLSL_VERSION_OVERRIDE=330

You can specify a higher OpenGL version, however its use is limited without higher GLSL versions. The V3D shader compiler can only handle up to GLSL 330

OpenGL 4.x

To use newer OpenGL versions zink has to be used on top of the V3DV vulkan driver. Since that one is the default driver not much is needed to get zink running. However just as with the default GL driver, the vulkan driver has no support for depth buffers, which is needed in zink for OpenGL 3.2+. So just like before the mesa GL and GLSL versions have to be overridden. This results in the command below to set all environment variables.

export MESA_GL_VERSION_OVERRIDE=4.6 MESA_GLSL_VERSION_OVERRIDE=460 __GLX_VENDOR_LIBRARY_NAME=mesa MESA_LOADER_DRIVER_OVERRIDE=zink GALLIUM_DRIVER=zink

This command sets GLSL version to 460 and the OpenGL version to 4.6. A lot of features are not going to work which should be expected since the driver is forced to run with less hardware support than expected. The code I tested ran just as well as on the native driver. Unlike the native driver zink seems to have no problem creating an OpenGL context using version 4.6 and compiling these shaders seems to work as well. However be aware that there might be problems. If you find a bug just open a new issue on the mesa gitlab and provide an example to reproduce your error, so that other devs can reproduce and fix the problem.

Performance

The performance in both cases with the default clock speeds is the same (just as slow in both cases).

I will do some more testing once that is done this will be added to this paragraph.

Conclusion

Although its annoying that these workarounds are needed, getting the OpenGL core profile working on the raspberry pi is great. This allows for a lot of code to be easily ported to the pi, be it for personal projects, industrial applications or educational programs.

1 comment

Leave a comment