Why can't I use OpenGL ES 3.0 in Qt?

回眸只為那壹抹淺笑 提交于 2020-01-04 02:19:05

问题


I set a QSurfaceFormat on my window, and this surface format has "3.0" set as its GL version number. The code:

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());

    // ...
}

Also, in main() I enable OpenGL ES mode, like this:

QGuiApplication::setAttribute(Qt::AA_UseOpenGLES);

This means I'm requesting a GL ES 3.0 context.

The ANGLE docs say (in a table near the beginning) that GL ES 3.0 -> D3D 11 API translation support is implemented. And my system supports D3D 11 according to dxdiag.exe.

But when I launch my app, which contains this QML code...

Text {
    text: OpenGLInfo.majorVersion + "." + OpenGLInfo.minorVersion
}

... I see "2.0" is displayed. Also, using the method I described here, I've determined that the maximal supported shading language version on my PC is "100" aka 1.0.

At the same time, from this Qt blog post I know that Qt supports GL ES 3.0 apps.

So why can't I use OpenGL ES 3.0 in Qt?


回答1:


You need to set a QSurfaceFormat on a QWindow before the window itself is created (via create()). If you create top level windows via QML you have no control on when create() gets actually called, so a solution is changing the default surface format somwhere before you create your Q(Gui)Application:

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

    QApplication app(argc, argv); 
    // etc.


来源:https://stackoverflow.com/questions/40385482/why-cant-i-use-opengl-es-3-0-in-qt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!