32 bit color depth Qt on Raspberry Pi

EDIT: I see this post is still consulted very often. The solution below was the only one I found years ago. Now it seems that setting the env variable QT_QPA_EGLFS_FORCE888 to 1 works perfectly.

Some days ago I was asked to test the performance of 32 bit EGL config color depth with Qt on Raspberry Pi using the eglfs platform plugin. I tried to set the framebuffer to 32 bit color depth using the usual command:

fbset -depth 32

Nothing changed unfortunately. I also tried some other changes I was suggested but no way.
This seems due to some strange parameter passed to the q_configFromGLFormat function in the qeglconvenience.cpp source file. What I did to make Qt render 32 bits per pixel is to simply rewrite the function to always return a 32 bit EGL configuration. This is not a fix of the issue nor a good modification, it is just a hack to make it render true color. I hope I’ll find the time to analyze the situation more accurately.

This is the simple modification I made:

EGLint configCount = 0;
assert(eglGetConfigs(display, 0, 0, &configCount) == EGL_TRUE);
qDebug("%d EGL configurations were found.", configCount);
EGLConfig* configs = new EGLConfig[configCount];
assert(eglGetConfigs(display, configs, configCount, &configCount) == EGL_TRUE);

// List the configurations. 
for (int i = 0; i < configCount; i++) {
   EGLint redSize, blueSize, greenSize, alphaSize;
   //assert(eglGetConfigAttrib(display, *(configs + i), EGL_RED_SIZE, &redSize) == EGL_TRUE);
   //assert(eglGetConfigAttrib(display, *(configs + i), EGL_GREEN_SIZE, &greenSize) == EGL_TRUE);
   //assert(eglGetConfigAttrib(display, *(configs + i), EGL_BLUE_SIZE, &blueSize) == EGL_TRUE);
   //assert(eglGetConfigAttrib(display, *(configs + i), EGL_ALPHA_SIZE, &alphaSize) == EGL_TRUE);
   //qDebug("Config %d: RGBA(%d, %d, %d, %d).", i, redSize, greenSize, blueSize, alphaSize);
} 

// Choose the first 32 bit configuration.
EGLConfig config;
int i = 0;
for (i = 0; i < configCount; i++) {
   EGLint redSize, blueSize, greenSize, alphaSize;
   assert(eglGetConfigAttrib(display, *(configs + i), EGL_RED_SIZE, &redSize) == EGL_TRUE);
   assert(eglGetConfigAttrib(display, *(configs + i), EGL_GREEN_SIZE, &greenSize) == EGL_TRUE);
   assert(eglGetConfigAttrib(display, *(configs + i), EGL_BLUE_SIZE, &blueSize) == EGL_TRUE);
   assert(eglGetConfigAttrib(display, *(configs + i), EGL_ALPHA_SIZE, &alphaSize) == EGL_TRUE);
   qDebug("Config %d: RGBA(%d, %d, %d, %d).", i, redSize, greenSize, blueSize, alphaSize);
   if (redSize == 8 && blueSize == 8 && greenSize == 8 && alphaSize == 8) {
      config = *(configs + i);
      break;
   }
}
delete[] configs;
return config;

Also, you might want to choose according to other values of the EGL configurations. Anyway, this is sufficient to achieve the result for the moment.

After this modification, you’ll have to rebuild the static library this is included into, and then the eglfs plugin. So:

cd your_qt_sources/qtbase/src/platformsupport
make

this should rebuild libQt5PlatformSupport.a, then rebuild the entire eglfs plugin:

cd your_qt_sources/qtbase/src/plugins/platforms/eglfs
make clean
make -jn

then place the newly built libqeglfs.so in your Pi in the platform plugin directory.

NOTE: for updated information read here.

2 thoughts on “32 bit color depth Qt on Raspberry Pi”

  1. Hi, is this still needed on QT 5.4.1? I notice problems with color depth (with piOmxTextures library), is this the only way to make it use 32bit?
    Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *