therecipe / qt

Qt binding for Go (Golang) with support for Windows / macOS / Linux / FreeBSD / Android / iOS / Sailfish OS / Raspberry Pi / AsteroidOS / Ubuntu Touch / JavaScript / WebAssembly
GNU Lesser General Public License v3.0
10.38k stars 736 forks source link

Is it possible to force Qt to use ANGLE when cross compiling from Linux to Windows? #720

Open quantonganh opened 5 years ago

quantonganh commented 5 years ago

http://doc.qt.io/qt-5/windows-requirements.html

For Qt Quick 2 to work, a graphics driver that provides OpenGL 2.1 or higher is required. The default driver from Windows is OpenGL 1.1.

qt.scenegraph.general: Using sg animation driver
qt.scenegraph.general: Animation Driver: using vsync: 15.63 ms
qt.scenegraph.general: texture atlas dimensions: 512x1024
qt.scenegraph.general: R/G/B/A Buffers:    8 8 8 8
qt.scenegraph.general: Depth Buffer:       32
qt.scenegraph.general: Stencil Buffer:     8
qt.scenegraph.general: Samples:            -1
qt.scenegraph.general: GL_VENDOR:          Microsoft Corporation
qt.scenegraph.general: GL_RENDERER:        GDI Generic
qt.scenegraph.general: GL_VERSION:         1.1.0
qt.scenegraph.general: GL_EXTENSIONS:      GL_WIN_swap_hint GL_EXT_bgra GL_EXT_paletted_texture
qt.scenegraph.general: Max Texture Size:  1024
qt.scenegraph.general: Debug context:     false

Due to this problem, my app is crashing on Windows. My co-worker tried to build it on Windows and it works because it fall back to ANGLE:

qt.scenegraph.general: windows render loop
qt.scenegraph.general: Using sg animation driver
qt.scenegraph.general: Animation Driver: using vsync: 15.63 ms
qt.scenegraph.general: texture atlas dimensions: 512x1024
qt.scenegraph.general: R/G/B/A Buffers:    8 8 8 8
qt.scenegraph.general: Depth Buffer:       24
qt.scenegraph.general: Stencil Buffer:     8
qt.scenegraph.general: Samples:            0
qt.scenegraph.general: GL_VENDOR:          Google Inc.
qt.scenegraph.general: GL_RENDERER:        ANGLE (Microsoft Basic Render Driver Direct3D11 vs_5_0 ps_5_0)
qt.scenegraph.general: GL_VERSION:         OpenGL ES 2.0 (ANGLE 2.1.0.8613f4946861)

The thing is we are building from Linux using threcipe/qt:windows_64_shared image. I tried something like this:

but the app hangs when starting. There is no logs in console even with QT_DEBUG_CONSOLE=true.

I don't see ANGLE here: https://github.com/therecipe/qt/blob/master/quick/quick.go#L15089

Is it possible to force Qt to use ANGLE when building on Linux?

therecipe commented 5 years ago

Hey

Sorry, it's not possible to force the angle backend if you cross compile with docker atm. (But it will be possible soon.) This is because the mxe builds still have the angle (and also the dynamic) backend disabled: https://github.com/mxe/mxe/blob/master/src/qtbase.mk#L44 You can find more info about this here: https://github.com/mxe/mxe/issues/947 https://github.com/mxe/mxe/pull/2012 https://github.com/mxe/mxe/issues/1685 https://github.com/therecipe/qt/issues/222

The very same issue is also present for msys2 builds from windows hosts: https://github.com/Alexpux/MINGW-packages/blob/master/mingw-w64-qt5/PKGBUILD#L93 https://github.com/Alexpux/MINGW-packages/issues/924 https://github.com/Alexpux/MINGW-packages/issues/1649 https://github.com/Alexpux/MINGW-packages/issues/3002

What you can do at the moment, is to use the software backend to get it working: https://doc.qt.io/qt-5/qtquick-visualcanvas-adaptations.html To do so you just need to export QT_QUICK_BACKEND=software or use https://doc.qt.io/qt-5/qquickwindow.html#setSceneGraphBackend-1

but the app hangs when starting. There is no logs in console even with QT_DEBUG_CONSOLE=true.

This is probably because the application is crashing while loading the plugins, so there is no Go code executed yet. But you should be able to get some infos by setting QT_DEBUG_PLUGINS=1 as well.

However you are lucky, I'm working on some new docker images atm that will provide a workaround for this issue (and some other issues such as windows xp support and proper styling for widget applications on linux). The images will use wine to compile your code against the official windows version of Qt which are build with -opengl dynamic and I think they also have the angle backend enabled as well, but the compilation with them will take you longer (like twice as long).

I will try to push the changes today, so the new images should be available in 12-24 hours.

Also btw, the windows_64_shared image still only contains Qt 5.8, so maybe test your code against one of the other 3 windows images because those are already on 5.11.1. And I will update the windows_64_shared image to Qt 5.11.1 tommorrow as well.

quantonganh commented 5 years ago

This is because the mxe builds still have the angle (and also the dynamic) backend disabled: https://github.com/mxe/mxe/blob/master/src/qtbase.mk#L44

Ah, OK.

What you can do at the moment, is to use the software backend to get it working: https://doc.qt.io/qt-5/qtquick-visualcanvas-adaptations.html

I tried it already:

quick.QQuickWindow_SetSceneGraphBackend(quick.QSGRendererInterface__Software)

The app is not crash but images are not rendered. Do you know why? How can I debug this problem?

This is probably because the application is crashing while loading the plugins, so there is no Go code executed yet. But you should be able to get some infos by setting QT_DEBUG_PLUGINS=1 as well.

I didn't know about that, thanks.

and I think they also have the angle backend enabled as well

Sure, as I show above when enabling QSG_INFO.

but the compilation with them will take you longer (like twice as long).

It's ok instead of switching to build on Windows :D.

I will try to push the changes today, so the new images should be available in 12-24 hours.

Please ping me when it's available, thanks.

quantonganh commented 5 years ago

This is probably because the application is crashing while loading the plugins, so there is no Go code executed yet. But you should be able to get some infos by setting QT_DEBUG_PLUGINS=1 as well.

You're right:

Got keys from plugin meta data ("windows")
loaded library "C:/Program Files/x VPN/x VPN Client/platforms/qwindows.dll"
QFactoryLoader::QFactoryLoader() checking directory path "C:/Program Files/x VPN/x VPN Client/platformthemes" ...
QFactoryLoader::QFactoryLoader() checking directory path "C:/Program Files/x VPN/x VPN Client/styles" ...
QFactoryLoader::QFactoryLoader() checking directory path "C:/Program Files/x VPN/x VPN Client/accessiblebridge" ...
therecipe commented 5 years ago

The app is not crash but images are not rendered. Do you know why? How can I debug this problem?

Yeah, that's probably because the software backend doesn't fully support all QML stuff like animations and such.

However, I pushed the changes for the new image, just wait for https://hub.docker.com/r/therecipe/qt/builds/bvpud5n7vysg4tcvsvytw9y/ to finish and pull windows_32_shared_wine

Then use qtdeploy -docker build windows_32_shared_wine as usual ...

quantonganh commented 5 years ago

@therecipe https://hub.docker.com/r/therecipe/qt/builds/bvpud5n7vysg4tcvsvytw9y/

Step 2/36 : RUN QT=qt-unified-windows-x86-online.exe && curl -sL --retry 10 --retry-delay 10 -O https://download.qt.io/official_releases/online_installers/$QT && QT_QPA_PLATFORM=minimal xvfb-run wine Z:\$QT --script=C:\gopath\src\github.com\therecipe\qt\internal\ci\iscript.qs WINDOWS=true

---> Running in 3764ca8eb9e3

[32810] Warning: No QtAccount credentials found. Please login via the maintenance tool of the SDK.

therecipe commented 5 years ago

Shit, seems like the Qt online installer is not working at the moment. But the build should work with the offline installer now: https://github.com/therecipe/qt/commit/2bcefc48ec6c4ec7de1b4ccb9e6ea7a8a893d82b

Hope it goes through this time: https://hub.docker.com/r/therecipe/qt/builds/bdybbk3agomgjvlp4yajxty/

If not then maybe try to build the image yourself.

curl -sLO https://raw.githubusercontent.com/therecipe/qt/master/internal/docker/wine/Dockerfile && docker build -t therecipe/qt:windows_32_shared_wine .

edit: image is build successfully, but you might need to remove all old "rcc" and "moc" files from your project to make it work