[Android development and learning 16] Android OpenGL ES about glDrawArrays and glDrawElemen

Source: Internet
Author: User

If you reference an online record:

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 obviusly wasteful.
If you use GL_TRIANGLE_STRIP and GL_TRIANGLE_FAN to try and avoid duplicating data: it isn't terribly valid tive and you 'd have to make a rendering call for each strip and fan. openGL callare expensive and shocould 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 cballs
Bad

Memory overhead of index buffer
My recommendation is to use glDrawElements


My personal understanding is:
GlDrawArrays focuses on the definition of the Data Space Loss in the vertex;
GlDrawElements focuses on the definition of the vertex index for data space loss;
In your project, you can use glDrawArrays to save data space if there are few or many identical images;
On the contrary, if there are many images with different shapes, you can use the glDrawElements function first.
(Click the name above to go to the official description of this function)

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.