Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delay-loading of opengl32.dll fails with Qt5

I need to use OpenGL version 2 features within an Qt5 poject on Windows 7 (Qt is built with desktop OpenGL not ANGLE). To support running the application via remote desktop I would like to fall back to software rendering via Mesa if necessary. My plan is to check the OpenGl version upon startup. If it is to low, I set a flag in the application settings, print a message and terminate the programm. When the program is started again I can read the flag and decide if I need to load the opengl32.dll from Mesa instead of Windows' builtin version.

To get this working I tried delay-loading opengl32.dll by setting the /DELAYLOAD:opengl32.dll linker flag and then using SetDllDierectoryW([path to dir with Mesa's opengl32.dll]) to redirect the dll lookup. Unfortunaly this does not work as the builtin version of opengl32.dll is already in memory right after entering main() and thus SetDllDirectory has no effect.

Dependency Walker shows me that Qt5Gui.dll itself is linked against opengl32.dll and I suspect that this undermines the delay-loading. But when I try to also delay-load Qt5Gui.dll the linker fails due to an imported symbol "__declspec(dllimport) public: static struct QMetaObject const QWindow::staticMetaObject" (__imp_?staticMetaObject@QWindow@@2UQMetaObject@@B). I have how no idea how to get rid of this.

I really need OpenGL 2 so there seems no way around using Mesa for software rendering. But I couldn't come up with an alternative to delay-loading either. Changing the PATH settings whenever I want to switch between hardware and software rendering doesn't seem to work and switching by moving Mesa's opengl32.dll into or out of the application dir is not an option as a normal user shouldn't have the required write permissions.

Is there any way to get delay-loading of opengl32.dll working with Qt5?

like image 825
Matthias Zilk Avatar asked Mar 02 '14 21:03

Matthias Zilk


1 Answers

Qt5Gui itself is linked to OpenGL. If your application is able to lazy-load this library, you can try calling QCoreApplication::setLibraryPaths() without system paths, using paths for your libraries instead.

Apart from that, your can tweak your qt.conf file. Read about it here: http://qt-project.org/doc/qt-5/qt-conf.html

like image 59
Garrappachc Avatar answered Oct 04 '22 01:10

Garrappachc