8

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?

  • Have your QT application load your own `OpenGL32.dll` using `LoadLibrary` at the very beginning. Knowing that an application can only load one module of a specified name, it won't be able to load the one in system32 since it already loaded yours. If the application is statically linking `OpenGL32`, you're going to have a hard time and might have to resort to hooking. – Brandon Mar 02 '14 at 22:53
  • Isn't there an option to use a Qt5 package without OpenGL? I'm not sure, but I remember seeing versions labeled something like Qt 5.2 OpenGL and one without OpenGL. – Skalli Mar 03 '14 at 12:35
  • @Skali Using the non-openGL version of Qt is not an option because I am relying on a `OpenGLSurface` to draw on a `QWindow` and I am using all the nice helpers like `QOpenGLShaderProgram` and friends. @CantChooseUsernames Unfortunately `LoadLibrary` doesn't work either as `Qt5Gui.dll` seems to cause the system `opengl32.dll` to be linked at load-time so all the harm is already done when `main()` is invoked. Any ideas which hooks could help? – Matthias Zilk Mar 03 '14 at 21:18
  • 1
    I have no idea how much effort this would be, but could you change the linking of opengl32.dll in the Qt sources? I haven't worked with OpenGL and Qt in one project (only seperately). – Skalli Mar 04 '14 at 09:42
  • 1
    Why don't You use software rendering to render textures, and then pass that to the built in OpenGL library? (Rendering textures on quad is basically guaranteed functionality in any OpenGL) – przemo_li Mar 21 '14 at 11:05

1 Answers1

1

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

Garrappachc
  • 719
  • 5
  • 19