我如何检测我的纹理何时在 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/