Switch dll programmatically for MESA Software renderer

171 views Asked by At

I want to add the command-line option --software-rendering to my application which switches to the MESA opengl32.dll found in a subfolder (e.g. mesa\opengl32.dll). How can I switch to this dll programmatically?

So far I know that when I move the opengl32.dll to my main folder, the rendering uses this one, but I want it to be loaded depending on the command-line option

1

There are 1 answers

0
datenwolf On BEST ANSWER

The only clean solution is loading the opengl32.dll using LoadLibrary instead of linking it hard to your program. Then before calling LoadLibrary you can define the search path, where to look for the DLL, or even pass an absolute path. The downside is, that if using LoadLibrary every of the DLLs exported symbols must be retrieved manually using GetProcAddress. The good news is, that the GL loader generated by glLoadGen does exactly that; it uses GetModuleHandle to reference whatever opengl32.dll has been loaded into the process and uses GetProcAddress on the regular OpenGL functions. Furthermore it will also do all the extension loading as well.