3D그래픽2011. 9. 29. 11:41
GLSurfaceView.Renderer interface에는 아래와 같이 세 개의 abstract method가 정의되어 있다.

Public Methods
abstract void onDrawFrame(GL10 gl)
Called to draw the current frame.
abstract void onSurfaceChanged(GL10 gl, int width, int height)
Called when the surface changed size.
abstract void onSurfaceCreated(GL10 gl, EGLConfig config)
Called when the surface is created or recreated.

이름에서 알 수 있듯이, GLSurfaceView.Renderer가 생성될 때 호출되는 순서는 다음과 같고,

onSurfaceCreated() → onSurfaceChanged() → onDrawFrame()


일단 GLSurfaceView.Renderer가 생성되고 나면, surface의 크기가 변경되지 않는 한 onDrawFrame이 반복 호출된다.

그런데, GLSurfaceView에 있는 onPause()가 호출 되면 GLSurfaceView.Renderer interface의 abstract method 들의 호출이 중단되고, onResume()이 호출되면, onSurfaceCreated()부터 다시 호출이 된다. 즉, surface가 다시 생성된다.

Public Methods
void onPause()
Inform the view that the activity is paused.
void onResume()
Inform the view that the activity is resumed.

이렇게 되면, 새로 생성하는 texture나 shader의 index(?)가 모두 0에서부터 다시 시작되는 것으로 보아, 기존에 생성 해 두었던 texture나 shader program 등의 object들이 모두 제거되는 것으로 보인다. 
그러므로, 뭔가 초기화를 하고 싶다면, onPause() / onResume()을 명시적으로 호출하고, onSurfaceCreated()에 필요한 초기화 코드를 추가하면 될 것 같다.

Posted by 세월의돌