PDA

View Full Version : glBindTexture and memory



fortikur
07-02-2003, 03:53 AM
Under C++Builder I wrote the following code:


FILE *ff;
textureim = new unsigned char [512*512*4];

ff=fopen("d:\\000.bma","rb");
fread(textureim,128*128*4,1,ff);
fclose(ff);


glGenTextures(1, &backgr[0]);
glBindTexture(GL_TEXTURE_2D, backgr[0]);

I use GeneralMemoryStatus to watch how much memory I have left, like that:

GlobalMemoryStatus(&ms);
Edit1->Text=ms.dwAvailPhys;

When I reach the "glBindTexture" line, I see, that something eats up my memory. I tested all lines, but the memory 'runs away' only, if I use glBingTexture. If I make an 'X-thousand-times' loop, my prog will surely crash.
Is there a possibility to free the memory, allocated by glBindTexture, or is GlobalMemoryStatus wrong, or did I missed out something?

errno
07-02-2003, 03:59 AM
do you mean that if you do:
while(1) glBindTexture(GL_TEXTURE_2D, texid);
the memory run away ???

or the textureim = new unsigned char [512*512*4]; is included in the loop ???????????????????????????

Relic
07-02-2003, 04:16 AM
glGenTextures(); will allocate memory to store the texture object's informations (not the teximage, yet).
glBindTexture() only switches between those texture objects and shouldn't increase the memory, well, except for the first usage in case the necessary few control informations like filter, priority etc. are allocated lazily in the driver or when you're downloading the teximages for the first time.
Of course your memory will run out if you generate too many texture objects. Virtual address space is only 2 GB on Win32, so the possible ids itself would exceed that.
Use glDeleteTextures to cleanup unused texture objects. (Was that your question?)

[This message has been edited by Relic (edited 07-02-2003).]

fortikur
07-03-2003, 12:31 PM
So, You mean, if I use glDeleteTextures each time I have a glGenTextures, I will have the same quantity of memory? (if yes: right, that was my question!)
Thanx!