android - 在 Android 上管理 OpenGL 资源

标签 android opengl-es resources

我有一个基本的 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/

相关文章:

Android - 手机资源使用率高导致一个耳机音量低?

安卓工作室 : Fixing gradle-wrapper and re-importing project is taking too long

c++ - 如何使用 OpenGL 交叉编译 UnixBench?

android - 使用 glColor 将纹理设置为半透明的问题

c# - 查找 C# 内置函数的实现细节

Android:使用文本文件还是XML文件存储静态数据效率更高

java - 如何在Android中使用Volley方法发布数组,这里最后一个索引值发布在数据库中

android - 如何在 ListView 的项目之间添加元素?

android - Paypal 可以使用版本 15 吗?

iphone - 为什么我的 EAGLVIew 在 iOS 4.2 中不再渲染?