Sign in to follow this  
Followers 0
ThetaRabbit

OpenGL
Texture unloading

10 posts in this topic

Hi all. I use SOIL with OpenGL. This is a sample from of code lonesock.net/soil.html :
[code]


GLuint tex_2d = SOIL_load_OGL_texture
(
"img.png",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
);

[/code]

How can I unload my texture from memory after using this code?

[size=2]sorry for my bad english.[/size]
0

Share this post


Link to post
Share on other sites
When you say unload, you mean delete the texture?


[code]
glDeleteTextures(1, &tex_2d);
[/code]

The above will delete the texture.
1

Share this post


Link to post
Share on other sites
Depends on which memory you want to unload it from. If you want to unload it from video memory then glDeleteTextures is indeed what you want - the texture will be gone (eventually - glDeleteTextures most likely won't remove it immediately and doesn't actually make any promises about the backing memory store (which may e.g. be kept around for potential future reuse) - all it deals with is the texture object name) and you will never be able to use it again in your OpenGL code unless you recreate it.
1

Share this post


Link to post
Share on other sites
looking at the SOIL source, i believe your looking for:

[code]
SOIL_free_image_data
[/code]

look at the header for more information, and i don't claim to be 100% correct, i've never used soil, but i don't see anything else that seems to indicate deleting behavior.
1

Share this post


Link to post
Share on other sites
[quote name='slicer4ever' timestamp='1331225105' post='4920444']
looking at the SOIL source, i believe your looking for:

[code]
SOIL_free_image_data
[/code]

look at the header for more information, and i don't claim to be 100% correct, i've never used soil, but i don't see anything else that seems to indicate deleting behavior.
[/quote]

I think that's only if you've loaded the file with [size=4]SOIL_load_image, because it returns an unsigned char buffer *, not an OpenGL asset ID.[/size]
1

Share this post


Link to post
Share on other sites
Documented sample code for loading a texture: [url="http://lonesock.net/soil.html"]http://lonesock.net/soil.html[/url] and [url="http://libregamewiki.org/Simple_OpenGL_Image_Library"]http://libregamewiki...L_Image_Library[/url]

SOIL.c, SOIL_load_OGL_texture function, lines 154 and 155:[code] /* and nuke the image data */
SOIL_free_image_data( img );[/code]

There is no need to do anything yourself to free the data.
1

Share this post


Link to post
Share on other sites
[quote name='RobinsonUK' timestamp='1331234087' post='4920479']
[quote name='slicer4ever' timestamp='1331225105' post='4920444']
looking at the SOIL source, i believe your looking for:

[code]
SOIL_free_image_data
[/code]

look at the header for more information, and i don't claim to be 100% correct, i've never used soil, but i don't see anything else that seems to indicate deleting behavior.
[/quote]

I think that's only if you've loaded the file with [size=4]SOIL_load_image, because it returns an unsigned char buffer *, not an OpenGL asset ID.[/size]
[/quote]

you are correct sir, i skimmed over the header file, and saw that, and assumed it was what he was looking for in terms of SOIL consistency.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0