为什么我不能在 Qt 中使用 OpenGL ES 3.0?

Ste*_*nov 3 qt opengl-es opengl-es-3.0

我QSurfaceFormat在窗口上设置了一个,并且该表面格式将“3.0”设置为其 GL 版本号。代码:

static QSurfaceFormat createSurfaceFormat() {
    QSurfaceFormat format;
    format.setSamples(4);
    format.setDepthBufferSize(24);
    format.setStencilBufferSize(8);
    format.setVersion(3, 0);
    return format;
}

int main(int argc, char *argv[]) {
    // ...

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    QWindow* window = (QWindow*) engine.rootObjects().first();
    window->setFormat(::createSurfaceFormat());

    // ...
}
Run Code Online (Sandbox Code Playgroud)

另外,main()我启用 OpenGL ES 模式,如下所示:

QGuiApplication::setAttribute(Qt::AA_UseOpenGLES);
Run Code Online (Sandbox Code Playgroud)

这意味着我正在请求 GL ES 3.0 上下文。

ANGLE 文档(在开头附近的表格中)表示GL ES 3.0 -> D3D 11已实现 API 翻译支持。我的系统支持 D3D 11 根据dxdiag.exe.

但是当我启动包含此 QML 代码的应用程序时......

Text {
    text: OpenGLInfo.majorVersion + "." + OpenGLInfo.minorVersion
}
Run Code Online (Sandbox Code Playgroud)

...我看到显示“2.0”。另外,使用我在此处描述的方法,我确定我的 PC 上支持的最大着色语言版本是“100”,即 1.0。

同时,从这篇Qt博客文章中我知道Qt支持GL ES 3.0应用程序。

那么为什么我不能在 Qt 中使用 OpenGL ES 3.0 呢?

pep*_*ppe 5

在创建窗口本身之前,您需要在 QWindow 上设置 QSurfaceFormat(通过create())。如果您通过 QML 创建顶级窗口,则无法控制create()实际调用的时间,因此解决方案是在创建 Q(Gui)Application 之前更改默认表面格式:

int main(int argc, char **argv) {
    // createSurfaceFormat() is the function you pasted above
    QSurfaceFormat::setDefaultFormat(createSurfaceFormat());

    QApplication app(argc, argv); 
    // etc.
Run Code Online (Sandbox Code Playgroud)