问题
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