130 likes | 254 Views
Outline. Display Lists Vertex Arrays Vertex Buffer Objects. Display List. Group of OpenGL commands that have been compiled for later execution Vertex and pixel data are evaluated and copied into the display list memory
E N D
Outline • Display Lists • Vertex Arrays • Vertex Buffer Objects
Display List • Group of OpenGL 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 re-transmitting 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 ?
Vertex Array • Drawing a cube consists of: • Drawing 6 Quads – Faces • Each face needs 4glVertex*() calls • 24glVertex*() calss in total • What about glColor* (24) and glNormals*(24) ? • We can notice that vertices are shared among faces
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
Vertex Array - Initialization • OpenGL provides functions to activate and deactivate 6 different types of arrays glEnableClientState() , glDisableClientState() • There are 6 functions to specify the exact positions of arrays • glVertexPointer(): specify pointer to vertex coords array • glNormalPointer(): specify pointer to normal array • glColorPointer(): specify pointer to RGB color array • glTexCoordPointer(): specify pointer to texture cords array
Vertex Array - Initialization glVertexPointer(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.
Vertex Buffer Object (VBO) • Enhances the performance of OpenGL • 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
Creating VBO • Creating a VBO requires 3 steps: • Generate a new buffer object with glGenBuffersARB(). • Bind the buffer object withglBindBufferARB(). • Copy vertex data to the buffer object with glBufferDataARB().
glGenBuffersARB() • 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 glGenBuffersARB(GLsizei n, GLuint* ids)
glBindBufferARB() • Hooks the buffer object with the corresponding ID glBindBufferARB(GLenumtarget, 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)
glBufferDataARB() glBufferDataARB(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
Drawing VBO Switch VBO off