Outline Display Lists Vertex Arrays Vertex Buffer Objects

Outline �Display Lists �Vertex Arrays �Vertex Buffer Objects 2

Display List � Group of Open. GL commands that have been compiled for later execution � Vertex and pixel data are evaluated and copied into the display list memory � You can reuse it repeatedly without re-evaluating and retransmitting data � It reduces CPU cycles to perform the actual data transfer � Expensive computations (transformation, lighting …) are processed only once while display list is created Static or Dynammic ? 3

Vertex Array � Drawing a cube consists of: Drawing 6 Quads – Faces � Each face needs 4 gl. Vertex*() calls � 24 gl. Vertex*() calss in total � What about gl. Color* (24) and gl. Normals*(24) ? � � We can notice that vertices are shared among faces 4

Vertex Array � Using vertex array reduces the number of function calls � It also reduces the redundant usage of shared vertices arrays are transferred to the video adapter every frame drawing 5

Vertex Array - Initialization � Open. GL provides functions to activate and deactivate 6 different types of arrays gl. Enable. Client. State() , gl. Disable. Client. State() � There are 6 functions to specify the exact positions of arrays � gl. Vertex. Pointer(): specify pointer to vertex coords array � gl. Normal. Pointer(): specify pointer to normal array � gl. Color. Pointer(): specify pointer to RGB color array � gl. Tex. Coord. Pointer(): specify pointer to texture cords array 6

Vertex Array - Initialization gl. Vertex. Pointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) � size: specifies the number of coordinates per vertex. Default is 4. � type: GL_SHORT, GL_INT, GL_FLOAT, or GL_DOUBLE are accepted � stride: specifies the byte offset between consecutive vertices � pointer: specifies a pointer to the first coordinate of the first vertex in the array. 7

Vertex Buffer Object (VBO) � Enhances the performance of Open. GL � providing the benefits of vertex array and display list while avoiding their downsides � Allows vertex array data to be stored in graphics memory � Vertex buffer objects can be modified after its creation 8

Creating VBO � Creating a VBO requires 3 steps: � Generate a new buffer object with gl. Gen. Buffers. ARB(). � Bind the buffer object with gl. Bind. Buffer. ARB(). � Copy vertex data to the buffer object with gl. Buffer. Data. ARB(). 9

gl. Gen. Buffers. ARB() � Requires 2 parameters: � the first one is the number of buffer objects to create � the second parameter is the address of a GLuint variable or array to store a single ID or multiple IDs gl. Gen. Buffers. ARB(GLsizei n, GLuint* ids) 10

gl. Bind. Buffer. ARB() � Hooks the buffer object with the corresponding ID gl. Bind. Buffer. ARB(GLenum target, GLuint id) � Target is a hint to tell VBO whether this buffer object will store vertex array data or index array data � GL_ARRAY_BUFFER_ARB (vertex array) Vertex coordinates � Texture coordinates � Normals � and more � � GL_ELEMENT_ARRAY_BUFFER_ARB (index array) 11

gl. Buffer. Data. ARB() gl. Buffer. Data. ARB(GLenum target, GLsizei size, const void* data, GLenum usage) � target: GL_ARRAY_BUFFER_ARB/ GL_ELEMENT_ARRAY_BUFFER_ARB � size: number of bytes of data to transfer � data: pointer to the source data � Usage: provide how the buffer object is going to be used � GL_STATIC_DRAW_ARB � GL_DYNAMIC_DRAW_ARB 12

Creating a single VBO 13

Drawing VBO Switch VBO off 14
- Slides: 13