2012-08-16 78 views
1

我想在我的Android游戏中释放纹理,缓冲区和着色器,如果用户点击返回按钮,则调用完成()活动方法,导入onDestroy ),我重写了清理游戏数据,关闭服务器连接等。
我在我的清单中设置了android:launchMode =“singleTask”,因此调用finish()活动总是会导致立即销毁。但是要使用glDeleteBuffers(...),例如,它必须从具有EGL上下文(Renderer线程)的线程调用,但即使设置并从Renderer类调用此类方法,我也会得到 - 无OpenGL ES上下文错误。Android OpenGL ES 2.0 - 在onDestroy中使用glDelete *()

我使用NDK,所以NativeLib。*调用C/C++的功能,如

JNIEXPORT void JNICALL /*class path*/_NativeLib_onDrawFrame(JNIEnv* env, jclass _class) 
{ 
glClear(GL_COLOR_BUFFER_BIT); 
... 
} 

查看

public class OGLES2View extends GLSurfaceView 
{ 

    private static class OGLES2Renderer implements GLSurfaceView.Renderer 
    { 
    public void onDrawFrame(GL10 unused) 
    { 
     NativeLib.onDrawFrame(); 
    } 

    public void onSurfaceChanged(GL10 unused, int width, int height) 
    { 
     NativeLib.onSurfaceChanged(width, height); 
    } 

    public void onSurfaceCreated(GL10 unused, EGLConfig unusedConfig) 
    { 
     NativeLib.onSurfaceCreated(); 
    } 

    public void onSurfaceDestroy() 
    { 
     Log.i(LOG_TAG, "Destroying Opengl objects"); 
     NativeLib.onGLDestroy();//Don't work - call to OpenGL API with current context 
    } 

} 

public OGLES2Renderer renderer = null; 
public OGLES2View(Context context) 
{ 
    super(context); 
    setRenderer(renderer = new OGLES2Renderer()); 
} 

在活动

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    ogles2View = new OGLES2View(this); 
    setContentView(ogles2View); 
} 

@Override 
protected void onDestroy() 
{ 
    Log.i(LOG_TAG, "Got finish request for game"); 
    super.onDestroy(); 
    ogles2View.render.onSurfaceDestroy(); // Don't not work 
} 

回答

1

一旦EGL上下文得到销毁所有的GL缓冲区等会被破坏,所以这是不成功的cessary。