Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can I free the memory allocated to Image after glTexImage2D call?

Tags:

c++

opengl

3d

glTexImage2D function takes a pointer to the Image data. Now after I have called glGenTextures, glBindTexture, and then glTexImage2D

to use texture in OpenGl. Can I free the memory allocated to the Image data ptr? or does opengl Copies the data from the pointer keeps it inside GPU after call to glTexImage2D or it uses my Image data for texture?

like image 413
Ujjwal Avatar asked Jan 25 '13 08:01

Ujjwal


2 Answers

Yes, you're safe to delete your information pointer once you provide it to glTexImage2D, it will just copy it to somewhere closer to the card (such as graphics card memory) and use it from there.

int *p = getImagePixels();

glTexImage2D(GL_TEXTURE..., p);

delete [] p;
like image 103
h4lc0n Avatar answered Oct 21 '22 23:10

h4lc0n


Check out this similar question for a discussion on freeing glTexImage2D. It would seem that you can, though.

like image 30
Ian D'Aprix Avatar answered Oct 21 '22 23:10

Ian D'Aprix