Download presentation
Presentation is loading. Please wait.
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 GLuint vao; glGenVertexArrays(1, &vao); // 建立三個 VAO GLuint vao[3]; glGenVertexArrays(3, vao);
6
glDeleteVertexArrays – 刪除VAO
範例 // 一個 VAO GLuint vao; glGenVertexArrays(1, &vao); glDeleteVertexArrays(1, &vao); // 三個 VAO GLuint vao[3]; glGenVertexArrays(3, vao); glDeleteVertexArrays(3, vao);
7
glIsVertexArray – 檢查是否為VAO
範例 GLuint vao, k = 100; Glboolean isVAO; glGenVertexArrays(1, &vao); isVAO = glIsVertexArray(vao); // return true isVAO = glIsVertexArray(k); // return false
8
glBindVertexArray – 連結 VAO
9
範例 GLuint vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); GLuint vao[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 的資料
13
glGenBuffers – 建立BO 範例 GLuint buffer; glGenBuffers(1, &buffer );
14
glDeleteBuffers – 刪除BO
範例 GLuint buffer; glGenBuffers(1, &buffer); glDeleteBuffers(1, &buffer);
15
glIsBuffer – 檢查是否為BO 範例 GLuint buffer, k = 100; Glboolean isBO;
glGenBuffers(1, &buffer ); isBO = glIsBuffer(buffer); // return true isBO = glIsBuffer(k); // return false
16
glBindBuffer – 連結 BO 至特定目標
範例 GLuint buffer; glGenBuffers(1, &buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer);
17
glBufferData – 配置 BO 的資料
19
Values for usage Parameter of glBufferData()
Operations Update Frequency
20
Values for usage Parameter of glBufferData()
21
Values for usage Parameter of glBufferData()
22
範例 // 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);
23
glGetAttribLocation – 取得屬性變數的位址
範例 GLuint loc = glGetAttribLocation(program, "position"); #version 330 in vec4 position; void main() { gl_Position = position; }
24
Enable/Disable Vertex Attribute Array
25
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.
27
範例 #define BUFFER_OFFSET( offset ) ((GLvoid*) (offset))
GLuint loc = 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; }
28
glDrawArrays
30
參考資料 Vertex Array Object (OpenGL Wiki)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.