We all know windows provide a generic OpenGL driver. But some display card vendors provider specific openGL driver. I am wondering how OS to choose which driver to use?
-
2The same way any other driver works: by hooking into the OS and telling it "whenever you need to access this piece of hardware, call me". The vendors provide these OpenGL drivers as part of the general GPU drivers – jalf Aug 17 '13 at 12:39
-
@jalf: I'm not sure the term *hooking* is appropriate here. I would rather say that it registers with the OS. – Ben Voigt Aug 17 '13 at 12:46
-
Yeah, I guess you're right. Let's pretend I said that instead :) – jalf Aug 17 '13 at 12:59
2 Answers
There are WGL functions for getting pointers to appropriate functions of newer OpenGL. Windows chooses the GPU arbitrarily when creating the context.
So, when you, for example, request a 4.3 core context it looks at the list of drivers, says that the one will handle this particular context, and then all wgl
calls are made so that they load appropriate functions from the particular driver's dll.

- 38,596
- 7
- 91
- 135
The easiest platform to explain how this works is Microsoft Windows. They have an "Installable Client Driver" (ICD) model, where the Windows SDK provides the bare minimum OpenGL functionality (OpenGL 1.1) and an extensible window system interface (WGL).
When you create your context using the WGL API in Microsoft Windows, you can enumerate all of the pixel formats for a specific device. Some pixel formats will be hardware accelerated and some will use the fallback software OpenGL 1.1 reference implementation. If you get a hardware accelerated format, all of your OpenGL commands will be handled by the graphics card driver and you will have a set of extensions to both GL and WGL that are not available in the reference (1.1) implementation.
This is why so much of modern OpenGL has to be handled through extension loading on Microsoft Windows, at the lowest level you only get OpenGL 1.1 and for anything newer than that, you have to ask the driver for the address of the function you want to use.
Many platforms have a similar system with respect to hardware/software co-existence. Mac OS X is even trickier, because you can start out with a hardware accelerated OpenGL implementation but call the wrong function (one that cannot be implemented in hardware on the installed GPU) and it will throw you off the "fast path" and fallback to software.
The nice thing about Mac OS X, however, is that this fallback only applies to individual stages of the pipeline. It will go back to hardware acceleration for the next stage as long as everything can be implemented in hardware. The beauty is that in OS X, the software implementation of OpenGL is complete (e.g. a 3.2 context will support the entire OpenGL 3.2 feature set even if doing so requires partial/full software implementation). You do not lose functionality if the GPU does not support something, just a LOT of performance. This is in huge contrast to Windows, where none of modern OpenGL has a software fallback.

- 42,359
- 2
- 81
- 106