QQuick3D Class

帮助类,用于选择正确的曲面格式。更多

Header: #include <QQuick3D>

静态公共成员

QSurfaceFormat idealSurfaceFormat(int samples = -1)

详细说明

在使用Qt Quick 3D 与 OpenGL 时,有必要采取额外步骤,在初始化Qt Quick 时定义使用哪种surface format 。这是因为当Qt Quick 意识到正在使用 3D 内容时,OpenGL 上下文和窗口表面已经初始化。因此,提供此辅助类是为了向Qt Quick 3D 请求理想的曲面格式,以便在初始化之前将其设置为Qt Quick 的默认曲面。

如果在使用 OpenGL 以外的任何其他渲染后端时运行该辅助程序,那么它只会返回当前默认QSurfaceFormat 的副本,并包含所请求的样本。

如果在使用 OpenGL 渲染后端时运行此辅助程序,它将测试是否有足够新的 OpenGL 版本,并根据请求支持多重采样。通常情况下,Qt Quick 会请求 OpenGL 2.0 或 OpenGL ES 2.0 上下文,这会限制使用Qt Quick 3D 时可用的功能,因此需要额外的步骤来请求功能更强的上下文。

正确的使用模式是调用QSurfaceFormat::setDefaultFormat 来设置QQuick3D::idealSurfaceFormat 返回的QSurfaceFormat 。重要的是,该方法应在QGuiApplication 构建之后、Qt Quick 应用程序内容加载之前调用。本代码片段展示了正确的使用模式:

#include <QGuiApplication>
#include <QQmlApplicationEngine>

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

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

    QSurfaceFormat::setDefaultFormat(QQuick3D::idealSurfaceFormat(4));

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;

    return app.exec();
}

另请参阅 OpenGL 具体说明

成员函数文档

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

返回平台的理想曲面格式。可选择指定samples ,以选择抗锯齿的多采样点数。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.