GLSurfaceView中GL相关资源销毁问题
2016-05-13 11:03
369 查看
http://www.gimoo.net/t/1504/552b806a49022.html
没有context概念,Main函数,Display,mouse,keyboarrd,reshape,这些回调函数中都可以直接调用OpenGL命令。
纹理等gl相关资源需要自己管理,及时释放。从而防止显存不足,gl资源分配失败。。。
gl的context作用域只局限在GLSurfaceView.Renderer的onSurfaceCreated,onSurfaceChanged,onDrawFrame 三个函数中。其他函数都是UI线程中调用,如view的onPause,onResume这类。
在这里调用会报如下错误:
不需要自己释放,android自己管理。Activity的onPause调用了GLSurfaceView::onPause,此时只需要将所有缓存的gl对象句柄清零,而不需要显式调用glDeleteXXX函数释放。例如纹理不需要glDeleteTextures释放,因为此时在UI线程中。下次onResume进入,创建方式两种:
静态创建,在Renderer::onSurfaceCreated函数中,预创建所有需要纹理,各种XXO对象。关于该函数的描述:
延迟到onDrawFrame中,发现纹理不可能用时重新动态创建。
ref : http://stackoverflow.com/questions/4925065/how-to-detect-when-textures-are-destroyed
1. YY下传统的GLUT框架
没有context概念,Main函数,Display,mouse,keyboarrd,reshape,这些回调函数中都可以直接调用OpenGL命令。纹理等gl相关资源需要自己管理,及时释放。从而防止显存不足,gl资源分配失败。。。
2. Android GLSurfaceview
gl的context作用域只局限在GLSurfaceView.Renderer的onSurfaceCreated,onSurfaceChanged,onDrawFrame 三个函数中。其他函数都是UI线程中调用,如view的onPause,onResume这类。在这里调用会报如下错误:
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中,发现纹理不可能用时重新动态创建。
ref : http://stackoverflow.com/questions/4925065/how-to-detect-when-textures-are-destroyed
相关文章推荐
- servlet 实现页面跳转的两种方法
- 查询
- iPhone上提交按钮默认样式问题
- zookeeper启动失败,zkServer.sh status 出错
- java实现冒泡排序,设立标志位,减少遍历趟数
- GCD 深入理解(二)
- android:layout_gravity和android:gravity属性的区别
- springmvc返回json中文乱码及使用jackson自动转换
- .NET通用的数据库操作类(支持多种数据库)
- java中截取字符串第二个小数点之前的字符串
- leetcode记录 104. Maximum Depth of Binary Tree
- spring 下载地址
- Jquery即点即改
- 如何让IIS 8.0支持无后缀图片的访问
- centos Linux 统计某个文件夹占用空间大小
- Leetcode 74 Search a 2D Matrix
- PHP问题 —— undefined function mb_convert_encoding
- 2011版MacBook Air win7安装教程
- MySQL数据库存储引擎比较
- 正则表达式