Wednesday, July 3, 2013

Selecting your graphics card with NVIDIA Optimus

Introduction to Win32 and OpenGL 4.3 - Part2

1. Summary

This is part 2 of the "Introduction to Win32 and OpenGL 4.3" series. In this post, we'll have a look at NVIDIA Optimus and selecting your Graphics card: we'll want to make sure we have a graphics card that supports OpenGL 4.3 in the first place!

2. OpenGL 4.3

2.1. Laptop

When I wanted to get OpenGL 4.3 running, I was immediately confronted with the presence of an integrated and a discrete graphics card on my laptop: my application kept returning an OpenGL 4.0 context! It turns out that the answer was provided by glewinfo.exe, a program provided with GLEW.
When we look at the "NVIDIA Control Panel", we see that the preferred graphics processor has been set to "Auto-select", this basically means that the the integrated graphics card will be selected.

Preferred Graphics Processor is set to Auto-select

We can confirm the selected graphics card, by running glewinfo.exe, a program provided together with Glew. A part of the glewinfo.exe output can be found below:

    GLEW Extension Info

GLEW version 1.9.0
Reporting capabilities of pixelformat 3
Running on a Intel(R) HD Graphics 4000 from Intel
OpenGL version 4.0.0 - Build is supported

Our assumption has been confirmed, the integrated graphics processor, in this case an "Intel HD Graphics 4000" GPU was selected. However, we see that the supported OpenGL version is limited to 4.0! To this date (25/06/2013), I didn't find a driver that enables OpenGL 4.3 for this GPU. When we set the preferred graphics processor to High-Performance NVIDIA processor, as can be seen in the following picture, we will select the NVIDIA graphics card:

Selecting the high-performance NVIDIA processor
Indeed, glewinfo returns the following:

    GLEW Extension Info

GLEW version 1.9.0
Reporting capabilities of pixelformat 1
Running on a GeForce GT 630M/PCIe/SSE2 from NVIDIA Corporation
OpenGL version 4.3.0 is supported

We can see that the NVIDIA graphics card was selected, moreover, OpenGL 4.3 is supported on this card! (Please see the NVIDIA website for the graphics cards and minimum driver version required for OpenGL 4.3).
Now, in order to save precious battery power of your PC, you most likely don't want to enable the NVIDIA graphics card by default, nor do you want to ask the user of your application to select the graphics card manually. So there must be a way to do this programmatically. Indeed, NVIDIA provides the answer by its NVIDIA Optimus technology.
It turns out that it doesn't need to be more complex then exporting the following variable in order to select the NVIDIA card from within your application:

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

Some other possibilities are explained more indepth here.

2.2. Desktop 

OpenGL 4.3 was relatively straightforward to get up and running on my desktop. I just needed the latest driver for my NVIDIA GT 640, which unlocked OpenGL 4.3.

3. Future post

Now that we have a graphics card and we are certain that it supports OpenGL 4.3, we'll set up our OpenGL 4.3 context in our Win32 application in the next post.

No comments:

Post a Comment