相关网帖

 

  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
gl the GL interface. Use instanceof to test if the interface supports GL11 or higher interfaces.
config the EGLConfig of the created surface. Can be used to create matching pbuffers.

 

 

更多相关文章

  1. Android(安卓)Inset Drawable
  2. Android保持屏幕常亮的方法
  3. Android完全退出应用程序
  4. android典型代码系列(十)------获取一个应用程序的权限信息(反射
  5. Android监听应用程序安装和卸载
  6. Android(安卓)Application Fundamentals——Android应用程序基础
  7. API 25 (Android(安卓)7.1.1 API) widget.ImageView——属性分析
  8. AndroidManifest.xml文件详解(supports-screens)
  9. android 锁屏

随机推荐

  1. Listview
  2. Android开发平台部署
  3. Android常用的技术点
  4. Android:用定时器刷 timer 新界面
  5. android环境部署(1.1)
  6. JS判断Android、iOS或浏览器的多种方法(
  7. Android(安卓)Studio Check for Update
  8. Android(安卓)各种布局技术-五大布局对象
  9. Android开发者实用代码片段
  10. Android(安卓)入门 和 环境搭建