【问题标题】:Android, Graceful OpenGL shutdown with NDK?Android,使用 NDK 优雅地关闭 OpenGL?
【发布时间】:2012-08-29 05:58:52
【问题描述】:

我的应用由两个 Activity 组成:一个具有典型 Android UI 小部件的普通 Activity,另一个具有基于 JNI 的 OpenGL ES 视图的 Activity。

应用程序切换两个活动,所以我认为我必须在退出活动之前优雅地释放 OpenGL 资源。 (通过调用 glDeleteProgram、glDeleteBuffers、glDeleteTextures ...)

我参考了 hello-gl2 示例,但只有 OpenGL 设置代码,没有 OpenGL 销毁/关闭代码。所以我不知道我应该在哪里调用原生 OpenGL 发布方法。

我尝试了以下两个位置,但收到错误消息:

E/libEGL(7224):在没有当前上下文的情况下调用 OpenGL ES API(每个线程记录一次)

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
    }
}

在哪里可以优雅地释放 OpenGL 资源? 或者在native部分设置当前OpenGL上下文的方法是什么?

【问题讨论】:

标签: opengl-es resources android-ndk java-native-interface release


【解决方案1】:

真的没必要。当 GLSurfaceView 被销毁时,它将释放其 EGL 上下文,这将释放与其关联的所有资源。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-27
    • 2011-04-26
    • 1970-01-01
    • 2014-12-01
    • 2020-06-29
    • 2021-06-03
    • 2014-11-03
    • 2012-08-22
    相关资源
    最近更新 更多