Uff,
I was affraid I will not be able to create one, but at the end I succeeded and it still has the same behaviour, so here is the example:
package com.example.loadunloatest;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.Iterator;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.Log;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.RGBColor;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;
public class MainActivity extends Activity {
private GLSurfaceView mGLView;
private MyRenderer renderer = null;
private static FrameBuffer fb = null;
private World world = null;
private RGBColor back = new RGBColor(50, 50, 100);
private boolean loadTest = false;
public static TextureManager tm;
public static MainActivity act;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGLView = new GLSurfaceView(getApplication());
mGLView.setEGLContextClientVersion(2);
renderer = new MyRenderer();
mGLView.setRenderer(renderer);
setContentView(mGLView);
tm = TextureManager.getInstance();
act = this;
}
class MyRenderer implements GLSurfaceView.Renderer {
public MyRenderer() {}
public void onSurfaceChanged(GL10 gl, int w, int h) {
Log.i("onChange",">>>>>>>");
world = new World();
if (fb != null) {
fb.dispose();
}
fb = new FrameBuffer(w, h);
try {
MainActivity.safeLoadTexture("tex",act.getAssets().open("pom.png"),false,true);
} catch (IOException e) {
e.printStackTrace();
}
}
public void onSurfaceCreated(GL10 gl, EGLConfig config) {}
public void onDrawFrame(GL10 gl) {
if(!loadTest){
Log.i("onDraw",">>>>>>>");
try {
MainActivity.safeLoadTexture("tex",act.getAssets().open("pom.png"),false,true);
} catch (IOException e) {
e.printStackTrace();
}
loadTest = true;
}
fb.clear(back);
world.renderScene(fb);
world.draw(fb);
fb.display();
}
}
public static void safeLoadTexture(String name, InputStream IS, boolean useAlpha, boolean force){
Log.i("safeLoad","loading:"+name);
if(force){safeUnloadTexture(name);}
if((force)||(!tm.containsTexture(name)))
{tm.addTexture(name, new Texture(IS, useAlpha));}
Log.i("safeLoad", "newID:"+tm.getTextureID(name));
HashSet names = tm.getNames();
Iterator itr = names.iterator();
while(itr.hasNext()) {
Object element = itr.next();
Log.i("safeLoad", "names:"+(String)element);
}
System.out.println();
}
public static boolean safeUnloadTexture(String name){
Log.i("safeUnload","unloading:"+name);
boolean cleared = false;
Log.i("safeUnload", "previousID:"+tm.getTextureID(name));
if(tm.containsTexture(name)==true){
tm.removeAndUnload(name, fb);}
Log.i("safeUnload", "newID:"+tm.getTextureID(name));
return cleared;
}
}
On my PC Win7 + Emulator it shows this CatLog:
07-28 09:01:03.058: I/safeLoad(1365): loading:tex
07-28 09:01:03.058: I/safeUnload(1365): unloading:tex
07-28 09:01:03.058: I/safeUnload(1365): previousID:-1
07-28 09:01:03.058: I/safeUnload(1365): newID:-1
07-28 09:01:03.058: I/jPCT-AE(1365): Loading Texture...
07-28 09:01:03.068: I/jPCT-AE(1365): Texture loaded...16384 bytes/64*64 pixels!
07-28 09:01:03.068: I/safeLoad(1365): newID:1
07-28 09:01:03.068: I/safeLoad(1365): names:tex
07-28 09:01:03.068: I/safeLoad(1365): names:--dummy--
07-28 09:01:03.068: I/onDraw(1365): >>>>>>>
07-28 09:01:03.078: I/safeLoad(1365): loading:tex
07-28 09:01:03.078: I/safeUnload(1365): unloading:tex
07-28 09:01:03.078: I/safeUnload(1365): previousID:1
07-28 09:01:03.078: I/safeUnload(1365): newID:1
07-28 09:01:03.078: I/jPCT-AE(1365): Loading Texture...
07-28 09:01:03.078: I/jPCT-AE(1365): Texture loaded...16384 bytes/64*64 pixels!
07-28 09:01:03.078: I/safeLoad(1365): newID:1
07-28 09:01:03.078: I/safeLoad(1365): names:tex
07-28 09:01:03.078: I/safeLoad(1365): names:--dummy--
So there is still the part: previousID:1, newID:1 (After the call from the onDrawFrame()), which means that it can detect the texture after it was unloaded in the safeUnloadTexture method... If I am right.
Thanks a lot EgonOlsen,
Darai.