Jump to content
  • Advertisement
Sign in to follow this  
eagerone

OpenGL how much vram can I use?

This topic is 3000 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So, I'm loading my textures and suddenly openGL says no thanks, I'm full.

Is there a way I can determine graphical card properties with opengl so I could optimise the textures based on that?

thanks

Share this post


Link to post
Share on other sites
Advertisement
You can ask what the largest texture available would be.


unsigned int CGL::pollMaxTexture(void)
{
unsigned int sz = 8192;
GLint width;

while(sz)
{
glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGBA, sz,sz, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);

if (width!=0)
{
return sz*sz;
}
sz /= 2;
}
return 0;
}




This will return you roughly the number of RGBA texture pixels you have available that can be allocated in a single texture. Since that requires them to be available in vram, it tells you how much vram space is left for textures by applications (all apps, not just yours).

Share this post


Link to post
Share on other sites
Quote:
Original post by Katie
You can ask what the largest texture available would be.

*** Source Snippet Removed ***

This will return you roughly the number of RGBA texture pixels you have available that can be allocated in a single texture. Since that requires them to be available in vram, it tells you how much vram space is left for textures by applications (all apps, not just yours).


This is the most reasonable way to do it.

However if the memory is virtual you wont be getting back gpu space specifically. Opengl has virtual memory so the texture may not be on the card, and will be swapped in when needed. This will be slow and so its best to get GPU texture memory size via a proprietary driver call.

On systems that are not ati or nvidia its likely that the Intel GMA is used and will be stealing system ram anyway so the above method is valid.

Share this post


Link to post
Share on other sites
If you're on Windows you can create a Direct3D object, query it for available video RAM, then destory it, before creating your OpenGL context. Then just keep a rough but reasonable count of how much you're using as you create and destory OpenGL objects.

Share this post


Link to post
Share on other sites
thanks for the replies

So how do you suggest I manage my resources? Should I even bother? The extensions seem to be what I was looking for, but I am really not sure I need to manage my textures. I was thinking of using different sizes and mipmaps based on memory available.

I don't like the idea of using two APIs, so I dont think I'll implement the function if dx turns out to be the best way to do this. Need to read about NVX_gpu_memory_info and ATI_meminfo and their support.

Share this post


Link to post
Share on other sites
The nice thing about the ATI/NV extensions is that they use glGetIntegerv, which means they either succeed and write a value or fail and do nothing. Which means, no function pointer loading, etc. You just set your variable to a "conservative" default (say, 128M), call the fuction twice with the respective constant, and clear error state.
Either one of them worked, or none did -- in any case it won't crash or do something undefined. Be sure to be a bit judicious with the numbers you get, they can only give you a rough orientation, not exact allocation sizes. You can never be sure what may happen that unexpectedly uses up a few megabytes (other program, window manager, fragmentation). I'm subtracting 4 times the size of the screen buffer from the "currently free" number to account for anything that might come unexpected. That appears to work fine, but it surely isn't a very scientific thing. :-)

Unluckily, due to this (and some other reasons) there is no canonical way of querying video memory. The general consensus has been for years that you don't need to know and you don't want to know. And if you do want to know, you just don't know yet that you really don't want to know. And if you did know, the information would be pointless.

Of course "you don't need to know" doesn't help you one bit if you're trying to figure whether to load a ~5 MB or a ~100 MB texture set.

Share this post


Link to post
Share on other sites
I'm doing this for learning anyway, so I would like to know what I wouldnt like to know, and in order to know that I will have to know about the very thing you were talking about.

Also, my head hurts.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!