我有一个基本的 Activity 类,它创建一个 GLSurfaceView 并在其 SetRenderer 方法中传递一个从 Renderer 派生的类。现在我知道当手机或平板电脑进入休眠状态时(到目前为止,DirectX 9 也是如此)OpenGL 资源可能会丢失,并且当手机从 sleep 状态返回时必须重新创建这些资源。
我认为我的所有其他类(class)、 Activity 等都完全恢复到唤醒时的状态,这是否正确?即我只需要在 onSurfaceCreated 方法中重新绑定(bind)纹理、着色器、GL 状态等。我不需要重新创建 View 或渲染器对象。
onSurfaceCreated 方法是在手机唤醒时调用,还是仅在启动时调用一次?我在 onSurfaceCreated 中收到的 GL 对象是否已销毁(即存储它并通过 sleep /唤醒周期使用它是否安全)?
最佳答案
Am I right in thinking that all of my other classes, the activity and so on, are restored exactly as they were when it wakes?
这取决于 Activity 是否在这些“唤醒”之间被终止。如果在这些暂停之间 Activity 没有被终止,你的类的所有内容都会恢复到你离开 Activity 时的状态。
I would only have to re-bind things like textures, shaders, GL state and so on in the onSurfaceCreated method. I don't need to recreate the view, or the renderer object.
正确。
Does the onSurfaceCreated method get called when the phone wakes, or just once at startup?
每次创建新表面时都会调用它,这意味着每次您的应用程序从后台进入前台时。
关于android - 在 Android 上管理 OpenGL 资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6705297/