Jump to content

  • Log In with Google      Sign In   
  • Create Account


Free texture image memory after binding it


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Bakuto   Members   -  Reputation: 131

Like
0Likes
Like

Posted 01 April 2013 - 08:02 PM

Greetings,

 

After binding a texture, is it possible to free the image memory and still be able to use the texture?  For example:

 

int LoadGLTextures()	// Load Bitmaps And Convert To Textures
{
	int Status=FALSE;	// Status Indicator

	// Load The Bitmap, Check For Errors.
	if (LoadTGA(&texture[0], "Data/Uncompressed.tga") &&
	    LoadTGA(&texture[1], "Data/Compressed.tga"))
	{
		Status=TRUE;	// Set The Status To TRUE

		for (int loop=0; loop<2; loop++)// Loop Through Both Textures
		{
			// Typical Texture Generation Using Data From The TGA 
			glGenTextures(1, &texture[loop].texID);	// Create The Texture
			glBindTexture(GL_TEXTURE_2D, texture[loop].texID);
			glTexImage2D(GL_TEXTURE_2D, 0, texture[loop].bpp / 8, texture[loop].width, texture[loop].height, 0, texture[loop].type, GL_UNSIGNED_BYTE, texture[loop].imageData);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

			if (texture[loop].imageData)	// If Texture Image Exists 
			{
				free(texture[loop].imageData);	// Free The Texture Image Memory 
			}
		}
	}
	return Status;	// Return The Status
}

 

 



Sponsor:

#2 Hodgman   Moderators   -  Reputation: 27051

Like
1Likes
Like

Posted 01 April 2013 - 08:13 PM

Yes, glTexImage2D is copying your image data.



#3 TheKreature   Crossbones+   -  Reputation: 373

Like
3Likes
Like

Posted 01 April 2013 - 09:42 PM

Yes, glTexImage2D is copying your image data.

 

Probably worth mentioning GL synchronization notes:

This stuff used to be a little different, and has improved immensely:

 

From: http://www.opengl.org/wiki/Synchronization


Legacy Note: The only OpenGL functions that behave differently are functions that end in Pointer​. When these use client-side memory (which is no longer permitted in core OpenGL), the pointers are stored for a period of time. During that period, they must remain valid.

These are usually used for rendering calls; in which case, once the rendering call has returned, the memory to be read from client data has been read. Modifications to client memory after the rendering call will only affect future rendering calls, not those that have already passed.
This is generally why Buffer Objects are better than using client memory for rendering. A rendering call with buffers does not have to handle the possibility of the user changing the memory later, so it can simply write a few tokens into the command stream. With client memory, it must copy all of the vertices out of the client-side arrays.


Edited by TheKreature, 01 April 2013 - 09:42 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS