Free texture memory

I realize that it is generally not relevant to know exactly how much texture memory is free since openGL should handle the swapping, but…

I display video files as textures and do so in several ways, one of which is to copy all the videos frames to texture memory and let it run from the device without any copying to the device while rendering. This obviously only works for somewhat small videos, even with texture compression, but I need to display a warning to the user if I fail to copy the entire video to texture memory, and then possibly abort the loading.

For this reason I need to either detect if a new texture causes an old one to swap out or I need to see how much free memory I have before creating each new texture, or even better, see how much memory I have available before starting to load the video to texture memory.

Are there any functions that can give me some of that information?

There used to be a glAreTexturesResident() function, and/or glGetTexParameter(GL_TEXTURE_RESIDENT), which would do more or less what you’re looking for. Unfortunately, they seem to have been deprecated as of OpenGL 3.1; I’m not really clear what the officially-blessed alternative is these days (anyone?)

On the other hand, I gather that most deprecated functionality is likely to continue to be supported by GPUs for the foreseeable future. If 100% compliance isn’t an issue for you then these functions might suit your purposes.

Taicoon: Are you creating a new texture for each video frame?

How are you loading texture image data to the opengl texture object? You can call glTexImage2D as many as you want to update texture object data. It is not nessary to create a new texture for that.

The best and fastest way, if your hardware supports it, is IMO to use Pixel Buffer Objects (PBO) to upload each frame directly to video memory through DMA.
More information here:

At first the function seemed usable, but it turns out that at least with the opengl implementation in win7 64 bit, a texture is not made resident before it is actually used for rendering.

I could do some fake rendering with every texture after creating it, but it seems like a nasty hack.

With directx there was an option to force a preload of a texture so you could make sure a certain texture was moved to the device if you for some reason knew that that would be a good idea ahead of time. Is the something similar in opengl?

>Are you creating a new texture for each video frame

In one mode, yes. Generally no.
If I have several movies (HD format) being streamed then there comes a time when it cannot move enough texels any more. In that case I may place one of the videos, perhaps a short loop, in texture memory so it does not have to be copied frame by frame when rendering.
Where a three frame movie (as an example) could easily be stores in texture memory and just be used, the streaming version would constantly have to move all the texels for the frames.

To close this thread in an informative way, I will add this information I found.

Both nvidia and ati have released extensions which give the total memory, total video memory and free video memory as well as eviction information.
The nvidia specks are here

Yes, we’re using NVX_gpu_memory_info – extremely useful extension. Hadn’t used the ATI one yet.