GLSurfaceView中GL相关资源销毁问题

1. YY下传统的GLUT框架

没有context概念,Main函数,Display,mouse,keyboarrd,reshape,这些回调函数中都可以直接调用OpenGL命令。

纹理等gl相关资源需要自己管理,及时释放。从而防止显存不足,gl资源分配失败。。。

glut框架下所有gl函数指令只局限在主线程中,不支持多线程调用


2. Android GLSurfaceview

gl的context作用域只局限在GLSurfaceView.Renderer的onSurfaceCreated,onSurfaceChanged,onDrawFrame 三个函数中。其他函数都是UI线程中调用,如view的onPause,onResume这类。

在UI线程函数中调用gl的函数时,会报如下错误:
02-06 10:00:51.318: E/libEGL(4458): call to OpenGL ES API with no current context (logged once per thread)

3. 纹理等GL资源释放情况

不需要自己释放,android自己管理。 Activity的onPause调用了GLSurfaceView::onPause,此时只需要将所有缓存的gl对象句柄清零,而不需要显式调用glDeleteXXX函数释放。例如纹理不需要glDeleteTextures释放,因为此时在UI线程中。下次onResume进入,创建方式两种:

  • 静态创建,在Renderer::onSurfaceCreated函数中,预创建所有需要纹理,各种XXO对象。关于该函数的描述:
    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.

  • 延迟到onDrawFrame中,发现纹理等资源的句柄为0,不可用时重新动态创建。

ref : http://stackoverflow.com/questions/4925065/how-to-detect-when-textures-are-destroyed

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值