java - 如何检测纹理何时被破坏

标签 java android opengl-es-2.0

我如何检测我的纹理何时在 Android 上被破坏? 我的 GLSurfaceView 的渲染器类目前看起来像这样:

public void onDrawFrame(GL10 gl)
{
    nativeLibrary.drawFrame();
}
public void onSurfaceChanged(GL10 gl, int width, int height) 
{
    if (reload)
    {
        library.glRecreate(); //this method reloads destroyed textures
    }
    else
    {
        nativeLibrary.init(width, height)); //this method initializes my game
        reload = true;
    }
}
public void onSurfaceCreated(GL10 gl, EGLConfig config) 
{
}

问题是这并不总是有效。当我从我的游戏中按下主页按钮然后再次启动它时,它就像一个魅力。但是当我锁定设备,然后再次解锁时,所有纹理都是黑色的。当我也锁定它时,一切似乎都重置了(我的游戏总是回到主菜单)。当我使用主页按钮退出游戏,然后进行锁定/解锁时,游戏不会重置。

最佳答案

在 Android 上执行 OpenGL 时,我强烈建议您观看 these two编写开源游戏的 Android 拥护者 Chris Pruett 的 Google I/O 演讲 Replica Island .

Here他谈到了你所看到的确切问题。长话短说:您不会检测到您的纹理(和缓冲区)何时被破坏,但您可以检测到它们何时需要重新创建。而这正是 onSurfaceCreated 的内容回调用于:

Since this method is called at the beginning of rendering, as well as every time the EGL context is lost, this method is a convenient place to put code to create resources that need to be created when the rendering starts, and that need to be recreated when the EGL context is lost. Textures are an example of a resource that you might want to create here.

关于java - 如何检测纹理何时被破坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4925065/

相关文章:

java - 使用 H2 数据库了解 JdbcConnectionPool

java - 尝试使用方法创建驾驶执照考试程序

android - OpenGL 二维 : glColor4 has no effect - what have I missed?

java - Camel -redis : why does this not print to the console?

java - 在循环中从 map 中删除值

java - 在 Android 上下载 - FileNotFoundException 但文件存在

java - 存在 UI 线程问题的竞争条件。

android - 在没有文件观察器的情况下监听android文件系统中的文件更改

android - 使用 glMultMatrixf 进行翻译,以及何时规范化

ios - UIImageView 是怎么做到动画这么流畅的? (或 : how to get OpenGL to efficiently animate frame by frame textures)