Android下基于OpenGL的程序会发生纹理丢失的原因

 相关网帖

 

  1。Workaround to losing the OpenGL context when Android pauses?

 

   http://gamedev.stackexchange.com/questions/12629/workaround-to-losing-the-opengl-context-when-android-pauses

 

 2。Problems with EGL_CONTEXT_LOST

 

http://code.google.com/p/android/issues/detail?id=5064

 

 

3。EGL Context Preservation on Android

 

http://cjix.info/blog/g3d/egl-context-preservation-on-android/

 

 

 

  一般基于GDI的Android应用程序在进入OnPause( )后,如果应用程序不被系统回收机制回收的话,这个APK用到的图片资源之类的还是存在于内存中的,所以这个APK返回前台进入OnReStart( )后图片资源不需要重新去加载并可以马上切回前台显示。

 

    最近为了加快自己基于OpenGL的应用程序与导航软件前后台来回切换的速度,也考虑用基于GDI的Android应用程序对资源的处理方式来处理,也就是图片资源(纹理)不是每次都去加载,想当然地认为基于OpenGL的应用程序跟基于GDI的应用程序一样,从后台切到前台,图片资源(纹理)还存在内存(应用程序还没有被系统的回收机制所杀掉),就把过去的那些图片资源(纹理)直接拿过来用,结果显示出来的应用程序却是白茫茫的一片,基于OpenGL的应用程序并没有像基于GDI的应用程序一样在内存里面保留原来的那些图片资源(纹理),也就有了Android下基于OpenGL的程序会发生纹理丢失的现象。

 

    后来看到Android下的SDK对所提供OpenGL接口的一些描述,才有点明白,觉得可能就是SDK中提到的原因,但不是十分肯定!

 

public static interface

GLSurfaceView.Renderer

 

public abstract void onSurfaceCreated(GL10 gl,EGLConfig config)
Since: API Level 3

Called when the surface is created or recreated.

Called when the rendering thread starts and whenever the EGL context is lost. The EGL context will typically be lost when the Android device awakes after going to sleep.

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.

Note that when the EGL context is lost, all OpenGL resources associated with that context will be automatically deleted. You do not need to call the corresponding "glDelete" methods such as glDeleteTextures to manually delete these lost resources.

 

Parameters
glthe GL interface. Use instanceof to test if the interface supports GL11 or higher interfaces.
configthe EGLConfig of the created surface. Can be used to create matching pbuffers.

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值