3

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?

Community
  • 1
  • 1
Stefan Monov
  • 11,332
  • 10
  • 63
  • 120
  • *I set a QSurfaceFormat on my window, and this surface format has "3.0" set as its GL version number* how do you do that exactly? What window class are you talking about? – peppe Nov 02 '16 at 21:21
  • @peppe: I edited the question to include that information. – Stefan Monov Nov 03 '16 at 13:47
  • 1
    The way pasted in the code looks wrong, as it's setting the format *after* the creation of the window (and that's too late, you must set it before). Try caling `QSurfaceFormat::setDefaultFormat` before you create your `Q(Gui)Application` object in main. – peppe Nov 03 '16 at 14:26
  • @peppe: Thanks, this worked. Would you please post it as an answer, so I can mark it accepted? – Stefan Monov Nov 03 '16 at 14:58

1 Answers1

5

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.
peppe
  • 21,934
  • 4
  • 55
  • 70