I am not clear when will the OpenGL context lose and what the system do when the context lose. Please give me some advice.
What i want to do is that:
When window size changed, the world will auto-scale to the right size but without unloading the textures from gpu because i don't want to the delay.
If i change code to an empty implement:
// in class which implements Renderer
public void onSurfaceChanged(GL10 gl, int width, int height) {
Log.d("jPCT-AE", "3d Renderer Surface Changed: " + width + ", " + height);
Log.d("jPCT-AE", "3d Renderer Surface Changed: update frameBuffer");
}
When the window size changed(64*64 to 128*128), the world didn't scale to 128*128, but all are rendering fine.
WindowSize: 64*64 -> 128*128
1, Before change code: the world will scale to larger after a delay
2, After change code: the world won't scale, but rendering fine, and there is almost little delay.
I am not clear if the OpenGL context will lose when the window(surface) size changed? Or only when the surface destroyed, the context lost.
I tried this: GLSurfaceView.setVisiable(GONE);
Then the view will gone and the surface will destroy(GLSurfaceView.onDestroyed()), the OpenGL context seems to be destroyed, but when i "GLSurfaceView.setVisiable(VISABLE)", things happened like this:
GLSurfaceView.surfaceCreate() -> GLSurfaceView.surfaceChanged() -> Renderer.onSurfaceCreate()(the method has an empty implement) -> Renderer.onSurfaceChanged()(the method has an empty implement) -> onDrawFrame()
And this situation looks like the one of "window size changed": the world didn't scale, but render fine.
Full codes:
// in class which implements Renderer
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
Log.d("jPCT-AE", "3d Renderer Surface Created");
}
public void onSurfaceChanged(GL10 gl, int width, int height)
{
Log.d("jPCT-AE", "3d Renderer Surface Changed: " + width + ", " + height);
if(mFirstEntry) // mFirstEntry wiil change to false in onDrawFrame
{
initFrameBuffer(gl, width, height);
getGameContext().setFrameBuffer(mFrameBuffer);
initFpsShown(); // rely on initFramebuffer
mGameLogic.onCreate();
}
// else if(getGameContext().getGameConfig().canWindowScale())
// {
// Log.d("jPCT-AE", "3d Renderer Surface Changed: update frameBuffer");
// mFrameBuffer.dispose();
// initFrameBuffer(gl, width, height);
// getGameContext().setFrameBuffer(mFrameBuffer);
// initFpsShown();
// }
mGameLogic.onResize(mFrameBuffer.getWidth(), mFrameBuffer.getHeight());
}