opengl-es - Android,使用 NDK 优雅地关闭 OpenGL?

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

我的应用程序包含两个事件:一个是带有典型 Android UI 小部件的正常事件,另一个是具有基于 JNI 的 OpenGL ES View 的事件。

该应用会切换两个事件,因此我认为我必须在退出事件之前优雅地释放 OpenGL 资源。 (通过调用 glDeleteProgram、glDeleteBuffers、glDeleteTextures ...)

我引用了 hello-gl2 示例,但只有 OpenGL 设置代码,没有 OpenGL 销毁/关闭代码。所以我不知道应该在哪里调用 native 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 上下文的方法是什么?

最佳答案

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

关于opengl-es - Android,使用 NDK 优雅地关闭 OpenGL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12171714/

相关文章:

java - 如何在 Libgdx 中支持 OpenGL ES GL10、GL11 和 GL20?

ios - 将 4x4 矩阵传递给 glUniformMatrix4fv

objective-c - 如何在 iPhone OpenGL ES 粒子系统中绘制 1000 多个粒子(具有独特的旋转、缩放和 Alpha)而不减慢游戏速度?

Android 和 Kotlin 可变参数 : formatted strings returns garbage

android - 系统/fcntl.h : no such file while cross compiling pcsclite for Android?

android - 无法理解有助于异步显示的 BufferQueue 同步逻辑

python - 导入错误 : No module named 'resource'

visual-studio - Windows .rc 文件的免费资源编辑器?

android - 如何将 JNI 与 AAR 库一起使用?

android - 无法为 Android 构建 ffmpeg