1 / 29

Vertex Array Objects & Buffer Objects

Vertex Array Objects & Buffer Objects. 靜宜大學資工系 蔡奇偉副教授. 大綱. Vertex Attributes Vertex Array Object (端點陣列物件 ) Buffer Objects (暫存區物件). Vertex Attributes (端點屬性). 每一個端點可以具下列的屬性: 位置( position ) 顏色 ( color ) 法 向量 ( normal ) 紋理貼圖座 檔 ( texture coordinates ) 雲霧特效 座標 ( fog coordinates )

wilda
Télécharger la présentation

Vertex Array Objects & Buffer Objects

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Vertex Array Objects & Buffer Objects 靜宜大學資工系 蔡奇偉副教授

  2. 大綱 • Vertex Attributes • Vertex Array Object(端點陣列物件) • Buffer Objects(暫存區物件)

  3. Vertex Attributes(端點屬性) • 每一個端點可以具下列的屬性: • 位置(position) • 顏色(color) • 法向量(normal) • 紋理貼圖座檔(texture coordinates) • 雲霧特效座標(fog coordinates) • 應用程式資料(application data)

  4. Vertex Array Objects(端點陣列物件) • Vertex Array Objects (VAO) are OpenGL Objects that store the set of bindings between Vertex Attributes and the user's source vertex data. • glGenVertexArrays– 建立VAO • glDeleteVertexArrays– 刪除VAO • glIsVertexArray– 檢查是否為VAO • glBindVertexArray – 連結 VAO

  5. glGenVertexArrays–建立VAO 範例 // 建立一個 VAO GLuintvao; glGenVertexArrays(1, &vao); // 建立三個 VAO GLuintvao[3]; glGenVertexArrays(3, vao);

  6. glDeleteVertexArrays – 刪除VAO 範例 // 一個 VAO GLuintvao; glGenVertexArrays(1, &vao); glDeleteVertexArrays(1, &vao); // 三個 VAO GLuintvao[3]; glGenVertexArrays(3, vao); glDeleteVertexArrays(3, vao);

  7. glIsVertexArray– 檢查是否為VAO 範例 GLuintvao, k = 100; GlbooleanisVAO; glGenVertexArrays(1, &vao); isVAO= glIsVertexArray(vao); // return true isVAO = glIsVertexArray(k); // return false

  8. glBindVertexArray–連結 VAO

  9. 範例 GLuintvao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); GLuintvao[3]; glGenVertexArrays(3, vao); glBindVertexArray(vao[1]);

  10. VAO 的內部 參見:Vertex Array Object (OpenGL Wiki)

  11. Buffer Objects(暫存區物件) • Buffer Objects is the general term for unformatted linear memory allocated by the OpenGL context. These can be used to store vertex data, pixel data retrieved from images or the framebuffer, and a variety of other things. • glGenBuffers– 建立BO • glDeleteBuffers – 刪除BO • glIsBuffer – 檢查是否為BO • glBindBuffer – 連結 BO 至特定目標 • glBufferData – 配置 BO 的資料

  12. glGenBuffers – 建立BO 範例 GLuint buffer; glGenBuffers(1, &buffer );

  13. glDeleteBuffers – 刪除BO 範例 GLuint buffer; glGenBuffers(1, &buffer); glDeleteBuffers(1, &buffer);

  14. glIsBuffer – 檢查是否為BO 範例 GLuintbuffer, k = 100; GlbooleanisBO; glGenBuffers(1, &buffer ); isBO= glIsBuffer(buffer); // return true isBO= glIsBuffer(k); // return false

  15. glBindBuffer – 連結 BO 至特定目標 範例 GLuint buffer; glGenBuffers(1, &buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer);

  16. glBufferData– 配置 BO 的資料

  17. Values for usage Parameter of glBufferData() Operations Update Frequency

  18. Values for usage Parameter of glBufferData()

  19. Values for usage Parameter of glBufferData()

  20. 範例 // Create and initialize a buffer object GLuint buffer; glGenBuffers(1, &buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer); glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW);

  21. glGetAttribLocation – 取得屬性變數的位址 範例 GLuint loc = glGetAttribLocation(program, "position"); #version 330 in vec4 position; void main() { gl_Position = position; }

  22. Enable/Disable Vertex Attribute Array

  23. glVertexAttribPointer When rendering, OpenGL pulls vertex data from arrays stored in buffer objects. What we need to tell OpenGL is what format our vertex array data in the buffer object is stored in. That is, we need to tell OpenGL how to interpret the array of data stored in the buffer. The glVertexAttribPointer() function tells OpenGL all of this. glVertexAttribPointer() always refers to whatever buffer is bound to GL_ARRAY_BUFFER at the time that this function is called.

  24. 範例 #define BUFFER_OFFSET( offset ) ((GLvoid*) (offset)) GLuintloc = glGetAttribLocation( program, "position" ); glEnableVertexAttribArray( loc ); glVertexAttribPointer( loc, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) ); #version 330 in vec4 position; void main() { gl_Position = position; }

  25. glDrawArrays

  26. 參考資料 Vertex Array Object (OpenGL Wiki)

More Related