How to free loaded textures properly?

Started by Eistoeter, December 30, 2008, 10:17:55

Previous topic - Next topic

Eistoeter

Hi

My game can load and display textures now which is very nice. However I'm a little bit unsure how to properly unload these again to free memory?

The following seems not to be enough because I can still bind the texture and display it so I suppose it has not really been freed:

public void deleteTexture(String path) {
                // textures is a TreeMap with Strings as keys
                // and texture objects as values.
                // a texture object saves its id generated by OpenGL
                // which I request here trough getter
		int id = textures.get(path).getId();

		IntBuffer intBuffer = IntBuffer.wrap(new int[] { id });
		GL11.glDeleteTextures(intBuffer);
		textures.remove(path);
	}

Evil-Devil

If you cleared the NIO Buffer you've used to load and upload the texture your done with it.
With glDeleteTextures the texture is removed from the graphiccards RAM and need to be loaded again.

If iam wrong, please correct me :)

Eistoeter

But why can I still bind and render the texture then?  ???

Evil-Devil

It may that you have bind the texture while attempting to delete it. Then the delete process will fail i think.

I found this within the OGL Documentation.
QuoteIf a   texture that is
     currently bound is deleted, the binding reverts to 0 (the
     default texture).

Try to unbound the texture first and delete it then. Should work.

Eistoeter

Thanks everything works fine right now.