【Android开发学习16】Android OpenGL ES 关于glDrawArrays和glDrawElements

来源:互联网 发布:林贤治 知乎 编辑:程序博客网 时间:2024/05/11 20:07

 引用一段网上的话:

For both, you pass OpenGL some buffers containing vertex data.

glDrawArrays is basically "draw this contiguous range of vertices, using the data I gave you earlier". Good:

You don't need to build an index buffer
Bad:

If you organise your data into GL_TRIANGLES, you will have duplicate vertex data for adjacent triangles. This is obviously wasteful.
If you use GL_TRIANGLE_STRIP and GL_TRIANGLE_FAN to try and avoid duplicating data: it isn't terribly effective and you'd have to make a rendering call for each strip and fan. OpenGL calls are expensive and should be avoided where possible
With glDrawElements, you pass in buffer containing the indices of the vertices you want to draw.

Good

No duplicate vertex data - you just index the same data for different triangles
You can just use GL_TRIANGLES and rely on the vertex cache to avoid processing the same data twice - no need to re-organise your geometry data or split rendering over multiple calls
Bad

Memory overhead of index buffer
My recommendation is to use glDrawElements

个人理解为:
glDrawArrays主要讲数据空间损耗在顶点的定义处;
glDrawElements主要讲数据空间损耗在顶点索引的定义处;
如果在你的工程中,画的图形较少或者,图形虽多但很多相同的,则可采用glDrawArrays更节省数据占用的空间;
相反,如果图形多,而且形状大不相同的时候,可以优先考虑采用glDrawElements函数。
(点击上面的名称,即可进入官方对此函数的说明)

 

 

 

 本文博客源地址:http://blog.csdn.net/ypist

 

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 托班幼儿不刷牙怎么办 两岁的宝宝蛀牙怎么办 小孩在学校被打怎么办 油画棒画在墙上怎么办 宝宝把蜡笔吃了怎么办 吃鸡更新了怎么办开始 数字画涂料干了怎么办 广告画颜料干了怎么办 宝宝断奶后瘦了怎么办 腿一个粗一个细怎么办 两条小腿不一样粗怎么办 两岁宝宝坐不了怎么办 q糖孩子吃多了怎么办 q糖孩子吃的太多怎么办 ps图层不能覆盖怎么办 孩子的字写的不好怎么办 孩子爱打人怎么办 6招 一岁宝宝爱打人怎么办 2岁小朋友爱打人怎么办 小朋友爱动手怎么办4岁 5,6岁爱动手打人怎么办 七个月宝宝大便干燥怎么办 两岁宝宝吐奶怎么办 2岁宝宝轻微蛀牙怎么办 2岁宝宝喝水都吐怎么办 2岁宝宝吐的厉害怎么办 两岁宝宝个子矮怎么办 宝宝吐了一天了怎么办 3岁宝宝吃饭呕吐怎么办 3岁宝宝突然呕吐怎么办 11个月婴儿呕吐怎么办 2岁宝宝呕吐是怎么办 2岁宝宝呕吐腹泻怎么办 七个月的宝宝拉肚子怎么办 两岁宝宝玩手机怎么办 5岁宝宝突然口吃怎么办 3岁宝宝突然口吃怎么办 2岁半宝宝结巴怎么办 卤门2岁未闭合怎么办 宝宝2岁说话结巴怎么办 4岁半的宝宝口臭怎么办