【发布时间】: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上下文的方法是什么?
【问题讨论】:
-
我在这里stackoverflow.com/questions/8932732/…问了一个类似的问题,不幸的是没有找到解决方案。
标签: opengl-es resources android-ndk java-native-interface release