PDA

View Full Version : Texture Memory Limit... what happens?



Dark
10-29-2002, 03:03 PM
I was wondering... what happens when you have more textures in memory than your videocard memory permits... ok I know that OpenGL then loads the texture whenever it is used from system mem... but where does that data then come from... what I really want to know is this: you have the function call

void glTexImage2D(
GLenum target,
GLint level,
GLint components,
GLsizei width,
GLsizei height,
GLint border,
GLenum format,
GLenum type,
const GLvoid *pixels
);


once you loaded the data with the "pixels" pointer... is it safe to discard the data in that pointer? Does OpenGL need that pointer (because it internally stored it) when it needs to reload the texture to texture memory on the video card... because for now I just discarded that memory.. but I really do not know if that is entirely safe... I could test it... but I really do not know wheter it also uses AGP sharable system memory.. since I have 640MB main mem and 64MB on my videocard.. I really wouldn't want to test it by creating something like 704+ MB for textures to test it... and I might even be wrong then...

So if you can give me an answer the the question: "is it safe to discard the pointer to the pixel memory you fed to the glTexImage2D function" I would be very gratefull...

(ps: I think it is safe because there is a gluBuild2DMipmaps function and you don't have to call another function before releasing the OpenGL context stuff etc... and if you had to leave to pointer intact for OpenGL you surely would have to free the memory of that pointer before program termination... But what concerns me then... WHY DOES ALMOST EVERY PROGRAMMER OF WHOM I HAVE SEEN THE CODE LEAVE THAT POINTER INTACT TILL THE END OF THE PROGRAM????)

Thank you in advance

Asgard
10-29-2002, 03:23 PM
It is safe to discard the memory the pixels pointer points to. OpenGL stores textures internally.

Rob Fletcher
10-30-2002, 12:59 AM
Hi,

On your last comment. All the programmers I know de-allocate the memory into which the texture was loaded (either from file, or generate programmatically), and then free the pointer as well, once the texture has been loaded into texture memory with glTexImage2D.

I would expect that the various manufacturers use different schemes in their drivers to effect the most efficient use of the available texture memory. You can of course always release a texture when done before loading in the next, if you are paranoid about this. (My O2 just uses standard memory as texture memory and when this runs out of course unix swap comes into play etc etc)

I suspect the truth lies in the driver details. You maybe able to find out from the manufacturer. Also, a google search may help as I bet this has been "wondered about" before!

R.

Dark
10-30-2002, 01:19 AM
Thank you for your help

mattc
10-30-2002, 05:30 PM
you may wish to think of it as a variable you've declared within opengl: with glGenTextures you declare them, with glBind you assign them (make them active), with glDeleteTextures you release them - it's just that they're "inside" gl subsystem, so you have to use those functions to manage them.