11

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?

Ujjwal
  • 426
  • 1
  • 5
  • 16

2 Answers2

15

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;
h4lc0n
  • 2,730
  • 5
  • 29
  • 41
1

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

Community
  • 1
  • 1