Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

QQuick3D Class

Helper class for selecting correct surface format. More...

Header: #include <QQuick3D>
Since: Qt 5.15

Static Public Members

QSurfaceFormat idealSurfaceFormat(int samples = -1)

Detailed Description

When using Qt Quick 3D with OpenGL it is necessary to take extra steps to define what kind of surface format is used when initializing Qt Quick. This is because by the time Qt Quick is aware that 3D content is being used, the OpenGL context and window surface has already been initialized. So this helper class is provided to request the ideal surface format from Qt Quick 3D so that it can be set as the default surface for Qt Quick before initialization.

If this helper is run when using any other rendering backends than OpenGL then it just returns a copy of the current default QSurfaceFormat with the requested samples.

If this helper is run when using the OpenGL rendering backend, then it will test for sufficiently modern versions of OpenGL and support for multisampling if requested. Normally Qt Quick will request an OpenGL 2.0 or OpenGL ES 2.0 context, which would limit the features available when using Qt Quick 3D, so an extra step is needed to request a more capable context.

The correct usage pattern is to call QSurfaceFormat::setDefaultFormat to set the QSurfaceFormat returned by QQuick3D::idealSurfaceFormat. It is important that this method is called after QGuiApplication is constructed, but before the Qt Quick application content is loaded. This code snippet shows the correct usage pattern:

#include <QGuiApplication>
#include <QQmlApplicationEngine>

#include <QtGui>
#include <QtQuick3D/qquick3d.h>

int main(int argc, char *argv[])
    QGuiApplication app(argc, argv);


    QQmlApplicationEngine engine;
    if (engine.rootObjects().isEmpty())
        return -1;

    return app.exec();

Member Function Documentation

[static] QSurfaceFormat QQuick3D::idealSurfaceFormat(int samples = -1)

Returns an ideal surface format for the platform. Optionally, samples can be specified to select the number of multisamples for antialiasing.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded