安卓:当OpenGL上下文破坏? [英] Android: When is OpenGL context destroyed?

查看:586
本文介绍了安卓:当OpenGL上下文破坏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android上,GLSurfaceView文件说,这样的:

On android, the GLSurfaceView documentation says this:

当活动暂停的GLSurfaceView必须得到通知,并   恢复。 GLSurfaceView客户端需要调用的onPause()时   活动暂停,onResume()的活动恢复的时候。这些电话   让GLSurfaceView暂停和恢复渲染线程,并且还   让GLSurfaceView释放并重新创建了OpenGL显示。

A GLSurfaceView must be notified when the activity is paused and resumed. GLSurfaceView clients are required to call onPause() when the activity pauses and onResume() when the activity resumes. These calls allow GLSurfaceView to pause and resume the rendering thread, and also allow GLSurfaceView to release and recreate the OpenGL display.

所以,我应该做这样的事情在我的活动:

So I'm supposed to do something like this in my activity:

public void onPause() {
    myGlSurfaceView.onPause();
}

public void onResume() {
    myGlSurfaceView.onResume();
}

我观察我的code,如果我不叫的onPause()和onResume(),那么上下文是不是当我preSS home键丢失,所以我可以在应用程序之间切换然后回到我的比赛,一切正常。我看到的是,如果我使用后退按钮,然后关闭游戏屏幕是黑的,当我再次打开它,但我可以改变后退按钮行为完全关闭游戏,避免了这个问题。

I'm observing in my code that if I don't call onPause() and onResume() then the context is not lost when I press the home button, so I can switch between applications and then go back to my game and everything is working. What I see is that if I close the game using the back button then the screen is black when I open it again, but I can change the back button behaviour to totally close the game and avoid this problem.

我的问题是:当OpenGL上下文破坏?如果我不叫的onPause()和onResume()我可以假设它永远不会被破坏?

So my question is: when is the openGL context destroyed? If I don't call onPause() and onResume() can I assume that it will never be destroyed?

编辑:

我针对Android 2.2系统,所以设置preserveEGLContextOnPause()是不是一种选择我。

I'm targeting Android 2.2, so setPreserveEGLContextOnPause() is not an option to me.

推荐答案

OpenGL的可能只有Actvity后失去::在onPause()被调用,也只有在这种情况下。请参阅<一href="http://developer.android.com/reference/android/opengl/GLSurfaceView.html#set$p$pserveEGLContextOnPause%28boolean%29">set$p$pserveEGLContextOnPause文档:

The OpenGL might be lost only after Actvity::onPause() is called, and only in this case. See the setPreserveEGLContextOnPause documentation :

无论EGL上下文实际上是preserved与否取决于该程序上运行的Andr​​oid设备是否支持EGL上下文或没有任意数量。只能支持的EGL上下文有限数量的设备必须释放的EGL上下文,以便允许多个应用程序共享的GPU。   [...] 东瀛背景[可]释放的时候GLSurfaceView暂停和GLSurfaceView恢复时重新创建。

Whether the EGL context is actually preserved or not depends upon whether the Android device that the program is running on can support an arbitrary number of EGL contexts or not. Devices that can only support a limited number of EGL contexts must release the EGL context in order to allow multiple applications to share the GPU. [...] the EGL context [can be] released when the GLSurfaceView is paused, and recreated when the GLSurfaceView is resumed.

编辑:文档中描述的情况是所有Android版本有效。不管你有机会获得设置preserveEGLContextOnPause

在我看来,这是一个主要的缺点是安卓OGLES实现。你不能肯定

In my opinion, this is one major drawback is Android OGLES implementation : you can't be certain.

的<一个href="http://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer.html">documentation本身是模糊的(EGL上下文丢失注):

The documentation itself is vague (EGL Context Lost note) :

有那里的EGL渲染背景将会丢失的情况。这通常发生在设备醒来去睡觉后

There are situations where the EGL rendering context will be lost. This typically happens when device wakes up after going to sleep

我注意到了有关家庭和后退按钮相同的行为你。电话是不完全萨姆斯(但不记得他们precisely)。

I noticed the same behavior as you about the Home and Back button. Calls are not exactly the sames (but can't remember them precisely).

要肯定的是,OpenGL上下文是唯一可用的方法是创建在<一个所有的OpenGL资源href="http://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer.html#onSurfaceCreated%28javax.microedition.khronos.opengles.GL10,%20javax.microedition.khronos.egl.EGLConfig%29">onSurfaceCreated

The only way to be sure that the OpenGL context is available is to create all OpenGL resources in onSurfaceCreated

请注意关于设置preserveEGLContextOnPause 。再次,这<一href="http://developer.android.com/reference/android/opengl/GLSurfaceView.html#set$p$pserveEGLContextOnPause%28boolean%29">documentation评论演示环境破坏的随机的行为:

Note about setPreserveEGLContextOnPause. Once again, this documentation comment demonstrates the "random" behavior of context destruction :

如果设置为true,那么EGL背景下的可能是preserved 当GLSurfaceView暂停。 [...]

If set to true, then the EGL context may be preserved when the GLSurfaceView is paused. [...]

这篇关于安卓:当OpenGL上下文破坏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆