When developing an OpenGL program, is there a way to poll from the system to find out just how many megabytes are available to store textures, etc?
Or is the standard approach these days just allocate memory and forget about everything?
Here's where to look. On the Windows search bar, type dxdiag. Wait for it to open then click either Display 1 or Display 2 to view your other GPU. Under Display Memory, you'll be able to see how much dedicated VRAM the GPU has.
Our recommendation is to go with a GPU with at least 6GB of graphics memory if you plan on playing games at 1080p, high quality and reasonable framerates. Most graphics cards with this VRAM capacity will run most modern games, even demanding ones above 60 fps at high quality.
Although the official stance remains "you don't need to know, you don't want to know, and it would not help you anyway", luckily at least two IHVs have shown a little more insight lately and offer extensions to query that information:
One nice thing about these extensions is that they have a least common denominator which is just what most people need, and you don't need to query extension support or do anything special, as they both work via glGetIntegerv
.
In the easiest case, you can just initialize an array of 4 integers to zero (or some minimum default value that you'll assume in case the extensions don't work), then you call glGetIntegerv
twice (with GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX
and TEXTURE_FREE_MEMORY_ATI
, respectively), and finally call glGetError
to clear the error state. glGetIntegerv
does not modify the pointed-to memory if it fails, nor does it crash or any other bad thing -- it merely sets the error state to GL_INVALID_ENUM
.
Both extensions return a value in the first array position, the ATI one returns some values in the other 3 too.
n.b.: glAreTexturesResident
has not been supported for almost a decade on mainstream hardware, in the same manner as texture priorities. The common mantra is that the driver writer knows much better than you anyway.
OpenGL doesn't give you this information. And frankly: There's only little benefit, simply because today we have multitasking operating systems. The OpenGL driver is responsible for swapping in texture data to/from system memory, if there's demand for it.
What OpenGL can do for you, is tell, if the textures you've uploaded are still resident in fast memory. The function is called "glAreTexturesResident". You can use this to gradually upload stuff to the GPU until you've filled up the GPU's memory. But keep in mind that you're not the only user of the GPU.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With