Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QQuick3D Class Reference

\inmodule QtQuick3D More...

#include <qquick3d.h>

+ Collaboration diagram for QQuick3D:

Static Public Member Functions

static Q_QUICK3D_EXPORT QSurfaceFormat idealSurfaceFormat (int samples=-1)
 Returns an ideal surface format for the platform.
 

Detailed Description

\inmodule QtQuick3D

Since
5.15

Helper class for selecting correct surface format.

When using Qt Quick 3D with OpenGL it is necessary to take extra steps to define what kind of \l {QSurfaceFormat}{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 \l QSurfaceFormat::setDefaultFormat to set the \l QSurfaceFormat returned by \l QQuick3D::idealSurfaceFormat. It is important that this method is called after \l 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);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
static int exec()
Enters the main event loop and waits until exit() is called, then returns the value that was set to e...
\macro qGuiApp
QQmlApplicationEngine provides a convenient way to load an application from a single QML file.
static Q_QUICK3D_EXPORT QSurfaceFormat idealSurfaceFormat(int samples=-1)
Returns an ideal surface format for the platform.
Definition qquick3d.cpp:212
static void setDefaultFormat(const QSurfaceFormat &format)
Sets the global default surface format.
\inmodule QtCore
Definition qurl.h:94
int main()
[0]
#define QStringLiteral(str)
QApplication app(argc, argv)
[0]
QJSEngine engine
[0]

Definition at line 12 of file qquick3d.h.

Member Function Documentation

◆ idealSurfaceFormat()

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

Returns an ideal surface format for the platform.

Optionally, samples can be specified to select the number of multisamples for antialiasing.

Definition at line 212 of file qquick3d.cpp.

References QSurfaceFormat::defaultFormat(), fmt, QOpenGLContext::LibGL, QOpenGLContext::openGLModuleType(), and QSGRendererInterface::OpenGLRhi.

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: