【Android开发学习16】Android OpenGL ES 关于glDrawArrays和glDrawElements
2013-02-22 16:21
387 查看
引用一段网上的话:
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
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
相关文章推荐
- 【Android开发学习17】Android OpenGL ES 光照与混合glDrawElements
- 【Android开发学习14】Android OpenGL ES 纹理映射之glDrawElements
- 【Android开发学习18】Android OpenGL ES 光照glDrawArrays
- 【Android开发学习13】Android OpenGL ES 3D空间与glDrawArrays
- 【Android开发学习15】Android OpenGL ES 纹理映射之glDrawArrays
- Android OpenGL ES 开发教程(5):关于EGL
- Android开发学习之路-关于Exception
- Android OpenGL(二) 学习《Android 3D 游戏开发技术宝典 -openGL ES 2.0》
- 【Android开发学习12】Android OpenGL ES 旋转glRotatef
- Android OpenGL ES 开发教程(2):关于OpenGL ES
- Android OpenGL ES 开发教程(16):Viewing和Modeling(MODELVIEW) 变换
- Android开发学习笔记-关于Android的消息推送以及前后台切换
- 【Android开发学习37】android opengl es 2.0里surfaceview背景透明
- Android OpenGL ES 开发教程(16):Viewing和Modeling(MODELVIEW) 变换
- 关于进行java学习和Android开发,本人认为的一些基础的入门必需知识,全程手敲
- Android OpenGL ES 开发教程(16):Viewing和Modeling(MODELVIEW) 变换
- 【Android开发学习09】Android OpenGL ES 基础
- Android OpenGL ES 开发教程(16):Viewing和Modeling(MODELVIEW) 变换
- Android开发学习笔记(三):关于fragment_main.xml、activity_main.xml与主函数之间的关系
- 【Android开发学习19】关于GL_NEAREST和GL_LINEAR的选择