Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an OpenGL context with a specific graphics driver?

Some computers have more than one graphics card/chipset installed, even when (for example for laptops) they don't have more than one monitor.

I'm having trouble with a laptop system that's got both Intel and Nvidia graphics hardware. Intel's drivers are notoriously awful in their OpenGL support, and my code is running up against an inexplicable rendering bug, because it seems to default to the Intel system, not the Nvidia one, when creating the rendering context.

Is there any way to avert this at startup? To say something like "poll for all available graphics drivers, avoid Intel drivers if possible, and build me a OpenGL rendering context with the driver that will work"?

like image 689
Mason Wheeler Avatar asked Apr 22 '13 19:04

Mason Wheeler


Video Answer


1 Answers

There's no portable way to do what you're asking, but this document describes how to force "High Performance Graphics Render" on systems with NVIDIA Optimus technology:

http://developer.download.nvidia.com/devzone/devcenter/gamegraphics/files/OptimusRenderingPolicies.pdf

Specifically, refer to the section "Global Variable NvOptimusEnablement (new in Driver Release 302)", which says:

Starting with the Release 302 drivers, application developers can direct the Optimus driver at runtime to use the High Performance Graphics to render any application–even those applications for which there is no existing application profile. They can do this by exporting a global variable named NvOptimusEnablement . The Optimus driver looks for the existence and value of the export. Only th e LSB of the DWORD matters at this time. A value of 0x00000001 indicates that rendering should be performed using High Performance Graphics. A value of 0x00000000 indicates that this method should be ignored.

Example Usage:

extern "C" {
    _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
}

Another possibility is the WGL_nv_gpu_affinity extension, but your WGL context needs to support it and I'm not sure if it works on mixed Intel/NVIDIA systems:

http://developer.download.nvidia.com/opengl/specs/WGL_nv_gpu_affinity.txt
like image 96
Greg Prisament Avatar answered Sep 22 '22 16:09

Greg Prisament