Skip to main content
gamedev.net
🔒 Locked

OpenGL Texture Memory

Started by dynamicman 6 replies 850+ views
Original Post
dynamicman
dynamicman
What does OpenGL do with the texture data that we give it using glTexImage2D (1D/2D/3D)? I guess there are only two places, either it will store it in RAM or in video memory. What does OpenGL do? Is there any way we can control where our texture data resides? I''m trying to build a memory manager, and I was wondering how textures should be handled. From what I see thus far, I load the texture into ram, give it to OpenGL and *poof* I can release the initial memory allocations.
silvermace
silvermace
OpenGL makes a local copy of the data so that it con control its internal data structure.

GL controls where the texture is (RAM or Video MEM).
But i think you can give GL hints by using glPrioritizeTextures (opens a new window)

as to your memory manager, OpenGL cleans up its own allocations so
all you have to do is

*pImage = new byte(images_size)
LoadImageFile( pImage )
BindToOpenGL( pImage )
delete [] pImage;

hope that helps
::Irix


[edited by - silvermace on January 10, 2004 6:45:16 PM]
dynamicman
dynamicman
Hmm. So what I''m guessing is that OpenGL will have a "working set" of textures loaded in its driver''s memory space, and when we "bind" the texture, it will move the texture into video RAM (if it isn''t there already) and continue the process. glPriortizeTextures will allow OpenGL to know what textures to swap out of Video RAM (to be replaced with something needed).

In the Red book, it says something about OpenGL using the LRU (least recently used) strategy in some drivers, and its possible for the programmer to give OpenGL better feedback by updating the priority list ever so often (eg. increase priority when texture bound, decrease overall priority of all textures at a constant rate).

Does this all sound right to you guys?

And maybe I''m an idiot for asking this question, does the texture need to be in Video RAM before we use it to render something? I mean, whenever we bind a texture, are we explicitly saying "load it into Video RAM"?
Monder
Monder
That's pretty much spot on, when binding a texture OpenGL will see if it's in video ram, if it's not it will transfer it from the local RAM to VRAM, possibly moving another texture out of VRAM to make space for it (using a least recently used cache, so basically the texture that was used least recently will be moved out). You can use glPrioritizeTextures( ) to tell OpenGL that some textures are more important than others, so they're more likely to stay in the VRam cache.

You can find more information in this gamasutra article (you need to register (for free), but gamasutra is a good site with lots of useful info so it's work it). You can skip straight to the texture mangement part if you want as that's where the info on how OpenGL manages textures is.

[edited by - Monder on January 10, 2004 7:02:53 PM]
dynamicman
dynamicman
I feel a warm tingly feeling...

Thanks guys/gals!

[edited by - dynamicman on January 10, 2004 7:09:43 PM]
Phil Price
Phil Price
Actually a bit of threadjacking here, is there anyway to poll the Graphics Card to tell you have much graphics memory it has and how much is free at the time of asking?

On another note Im using PNGs for textures loaded via C#''s "Bitmap" object, is there anyway to calculate how much texture memory it will use up because obviously PNGs have compression - does texture memeory?
Phil Price™: Better than cool - uber cool.
vNistelrooy
vNistelrooy
quote:
Original post by Phil Price
Actually a bit of threadjacking here, is there anyway to poll the Graphics Card to tell you have much graphics memory it has and how much is free at the time of asking?



No.



"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"
_the_phantom_
_the_phantom_
quote:
Original post by Phil Price
On another note Im using PNGs for textures loaded via C#''s "Bitmap" object, is there anyway to calculate how much texture memory it will use up because obviously PNGs have compression - does texture memeory?


Yes, you can upload the gfx to the graphics card with compression, although it is lossy-jpg like compression iirc.

GL_ARB_texture_compression is the extension you want to look up (core feature from OGL1.3)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.