shkim
shkim

Reputation: 1183

Android, Graceful OpenGL shutdown with NDK?

My app consists of two activities: one normal activity with typical Android UI widgets, and other activity which has JNI-based OpenGL ES View.

The app switches both activities so I think I must gracefully release the OpenGL resources before exiting the activity. (by calling glDeleteProgram, glDeleteBuffers, glDeleteTextures ...)

I refered hello-gl2 sample, but there is only OpenGL setup code, and no OpenGL destroy/shutdown code. so I don't know where should I call the native OpenGL release methods.

I tried the following two locations, but I got an error message:

E/libEGL(7224): call to OpenGL ES API with no current context (logged once per thread)

class MyGLView extends GLSurfaceView
{
    ...
    private static class ContextFactory implements GLSurfaceView.EGLContextFactory {
        public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) { ... }

        public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context) {
            // call native shutdown method, location #1
        }
    }

    public void surfaceDestroyed(SurfaceHolder holder)
    {
        // call native shutdown method, location #2
    }
    ...

    public class Renderer implements GLSurfaceView.Renderer
    {
        public void onSurfaceCreated(GL10 gl, EGLConfig config)
        {
            // call native initialization method here: Works fine!
        }

        // no surface destroy callback method in GLSurfaceView.Renderer
    }
}

Where can I gracefully release the OpenGL resources? or What is the method to set the current OpenGL context in native part?

Upvotes: 3

Views: 1223

Answers (1)

kelnos
kelnos

Reputation: 878

There's really no need. When the GLSurfaceView gets destroyed, it will free its EGL context, which will release all resources associated with it.

Upvotes: 1

Related Questions