16

There are several ways that Qt can use OpenGL: desktop (native), ANGLE, ES... and now there's 'dynamic' which can choose at runtime. Within an app, is there a way that you can detect which one is in use? Either within C++ or within QML?

e.g. something equivalent to the global declarations that let you detect OS

9
  • 4
    glGetString(GL_VERSION)?
    – genpfault
    Dec 7, 2016 at 15:54
  • 1
    Generally speaking, you would use "dynamic" when you explicitly do not care. That is, you're writing to the lowest common denominator between ANGLE and desktop GL. So why exactly would you need to ask this question? Dec 7, 2016 at 16:06
  • 2
    Intel usually means "upgrade the drivers". You can figure out which context version you've got in many ways: the aforementioned GL_VERSION; using OpenGLInfo in Qt Quick itself; using QOpenGLContext::openGLModuleType().
    – peppe
    Dec 7, 2016 at 21:39
  • 1
    See also here for an explanation and how to use a blacklist for ANGLE/OpenGL depending on the GPU: doc.qt.io/qt-5/…
    – peppe
    Dec 7, 2016 at 21:41
  • 2
    Is there a global way to force use of ANGLE on all Windows devices? You could just rebuild Qt with only ANGLE support, or if you want to use dynamic builds, set Qt::AA_UseOpenGLES before creating a Q(Gui)Application.
    – peppe
    Dec 7, 2016 at 22:42

1 Answer 1

16

To detect the OpenGL version

If you want to enforce a particular OpenGL version

  • set the option in software (see code example below)
    • for desktop/native, either set the environment variable QT_OPENGL to desktop or set the application attribute to Qt::AA_UseDesktopOpenGL
    • for ANGLE, either set the environment variable QT_OPENGL to angle or set the application attribute to Qt::AA_UseOpenGLES
    • for software rendering, either set the environment variable QT_OPENGL to software or set the application attribute to Qt::AA_UseSoftwareOpenGL
  • create a static build of Qt using the configure options to set the implementation of OpenGL you want (but be mindful of the Qt licensing rules)
    • for desktop/native, include -opengl desktop
    • for ANGLE, don't include an -opengl option; that's because it is the default
    • there is also -opengl dynamic which lets Qt choose the best option. This was introduced in Qt 5.4. If you want this option but don't need a static build for any other reason, there's no need to create a static build, as the prebuilt binaries use this option since Qt 5.5.
    • there are also other variants that you can explore at Qt for Windows - Requirements. Although this is a Windows-specific page, much of the information about configuring OpenGL for Qt is contained here. (Probably because most of the OpenGL rendering issues are on the Windows platform!)

Code example

#include <QGuiApplication>
//...

int main(int argc, char *argv[])
{
    // Set the OpenGL type before instantiating the application
    // In this example, we're forcing use of ANGLE.

    // Do either one of the following (not both). They are equivalent.
    qputenv("QT_OPENGL", "angle");
    QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);

    // Now instantiate the app
    QGuiApplication app(argc, argv);
    //...

    return app.exec();
}

(thanks to peppe for the initial answers in the comments above and thanks to user12345 for the Blog link)

3
  • glGetString(GL_VERSION) returns 0 on one of my machines (with Intel HD 3000) and OpenGL fails to show although another graphics card OpenGL test app displays a rendered scene. What can I do?
    – falkb
    May 9, 2018 at 7:13
  • I also have the Intel HD 3000 with win10 (driver 9.17.10.3347 10-31-2013) and the only way to make my QML app work without a crash was to download the opengl32.dll of the mesa software renderer from here: fdossena.com/?p=mesa/index.frag I just copied the opengl32.dll next to my qml_app.exe and finally it ran without crashing. Nov 24, 2020 at 21:40
  • I've also tried the newer driver 9.17.10.4229 5-26-2015 which crashes as well. Nov 24, 2020 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.