how to make my init method re-entrant when it comes to textures?

I’m trying to think of a good way to structure my code (I wouldn’t call it a framework ::)), and I wonder what the best approach would be for initialising textures.

  • does that have to happen again, too, when the init method is called?
  • if the texture was read from a slow resource like the internet, I’d rather not have to read it again. Can I keep the TextureData object in memory and simply create a new Texture object for it?

thanks!

Yes, unless your GLContext is sharing textures and display lists with another one whose lifetime spans the one which was just created and destroyed. OpenGL server-side objects use a “reference counting” like mechanism at the driver level; if all contexts which can refer to a given texture object are destroyed simultaneously, the driver deletes the texture object completely. If you aren’t sharing textures and display lists with any other contexts then the answer is a simple yes.

Yes, you can.

thank you 2 ;D

I just realized I’m having the same problem with a Texture (http://download.java.net/media/jogl/builds/nightly/javadoc_public/com/sun/opengl/util/texture/Texture.html ) object as well when I resize a panel (call init() again).

I figured since a Texture object (in my case an array of Texture objects) was not being called from a ‘gl’ method then it was like any other object that I created and it would not be destroyed on init() but I guess that’s not the case as Ken mentions below that the texture objects are destroyed - that sucks.

Ken also confirms that you can keep the TextureData object ( http://download.java.net/media/jogl/builds/nightly/javadoc_public/com/sun/opengl/util/texture/TextureData.html ) so that I don’t have to recreate a Texture, but how do I do this exactly? Does anyone have example code of how I can store the Texture in this object (TextureData) and then reuse it after an init() call - or did I understand the answer discussed above?

In TextureIO, there’s a static method that creates a new Texture based on a TextureData. Is that what you’re looking for?

you know, that might be it. Thank you, I’ll try it out.

edit: I tried that and it worked. thanks. Sucks that I have to keep an array of TextureData and then convert those to Texture objects after init() calls because the original Texture objects are somehow destroyed…the weird thing to me is that after an init() the Texture objects themselves are still not null and I can retrieve things like the texture object (getTextureObject()) but the underlying textures are gone because I use the getTextureObject() to bind the texture but nothing gets bounds (or at least nothing shows up). As a result I had to instead keep an array of the TextureData and on init() I create the Textures for use.

Seems kind of goofy - I hope I’m doing this correctly.