[Android開發學習16]Android OpenGL ES 關於glDrawArrays和glDrawElemen

來源:互聯網
上載者:User

 引用一段網上的話:

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函數。
(點擊上面的名稱,即可進入官方對此函數的說明)

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.