Docsity

Transformations and Matrices in Interactive Computer Graphics - Prof. David E. Breen, Study notes of Computer Graphics

Partial preview of the text

Download Transformations and Matrices in Interactive Computer Graphics - Prof. David E. Breen and more Study notes Computer Graphics in PDF only on Docsity!

Vertex Buffer Objects and

Transformations

Week 4

David Breen

Department of Computer Science

Drexel University

Based on material from Ed Angel, University of New Mexico and Manolya Eyiyurekli, Drexel University

CS 432/

INTERACTIVE COMPUTER GRAPHICS

Vertex Buffer Objects

(VBOs)

  • enhance the performance of OpenGL by providing the benefits of vertex arrays and display lists, while avoiding downsides of their implementations
  • allow vertex array data to be stored in high- performance graphics memory on the server side and promotes efficient data transfer
  • GL_ARB_vertex_buffer_object extension should be supported by your graphics card.
  • Advantage - Display list is a server side

function, so it does not suffer from

overhead of data transfer

  • Disadvantage – Once a display list is

compiled, the data in the display list

cannot be modified

Why not use display lists?

Why use VBOs?

Only Advantages

  • Data in vertex buffer object can be read and updated by mapping the buffer into client's memory space
  • Shares the buffer objects with many clients, like display lists and textures. Since VBO is on the server's side, multiple clients will be able to access the same buffer with the corresponding identifier

Creating VBOs

  • Generate a new buffer object with

glGenBuffersARB().

  • Bind the buffer object with

glBindBufferARB().

  • Copy vertex data to the buffer object

with glBufferDataARB().

  • glGenBuffersARB()
    • creates buffer objects and returns the identifiers of the buffer objects void glGenBuffersARB(GLsizei n, GLuint* ids)
      • n: number of buffer objects to create
      • ids: the address of a GLuint variable or array to store a single ID or multiple IDs
  • glBufferDataARB()
    • You can copy the data into the buffer object with glBufferDataARB() when the buffer has been initialized. void glBufferDataARB(GLenum target, GLsizei size, const void* data, GLenum usage) - target is either GL_ARRAY_BUFFER_ARB or GL_ELEMENT_ARRAY_BUFFER_ARB. - size is the number of bytes of data to transfer. - The third parameter is the pointer to the array of source data. - "usage" flag is a performance hint for VBO to provide how the buffer object is going to be used: static, dynamic or stream, and read, copy or draw.
  • 9 enumerated values for usage flags
    • GL_STATIC_DRAW_ARB
    • GL_STATIC_READ_ARB
    • GL_STATIC_COPY_ARB
    • GL_DYNAMIC_DRAW_ARB
    • GL_DYNAMIC_READ_ARB
    • GL_DYNAMIC_COPY_ARB
    • GL_STREAM_DRAW_ARB
    • GL_STREAM_READ_ARB
    • GL_STREAM_COPY_ARB
      • Static: data in VBO will not be changed
      • Dynamic: the data will be changed frequently
      • Stream: the data will be changed every frame
      • Draw: the data will be sent to GPU in order to draw
      • Read: the data will be read by the client's application
      • Copy: the data will be used both drawing and reading
  • glDeleteBuffersARB() void glDeleteBuffersARB(GLsizei n, const GLuint* ids)
    • You can delete a single VBO or multiple VBOs with glDeleteBuffersARB() if they are not used anymore. After a buffer object is deleted, its contents will be lost.

Drawing VBO

  • VBO sits on top of the existing vertex array implementation
  • Rendering VBO is almost same as using vertex array.
  • The pointer to the vertex array is now an offset into a currently bound buffer object.
  • No additional APIs are required to draw a VBO except glBindBufferARB().
  • Binding the buffer object with 0 switches off VBO operation. - It is a good idea to turn VBO off after use, so normal vertex array operations with absolute pointers will be re-activated.

Updating VBO

  • Two ways to update
    • Copy new data into the bound VBO with glBufferDataARB() or glBufferSubDataARB(). - 2 copies of vertex data: one in your application and the other in VBO.
    • Map the buffer object into client's memory, and the client can update data with the pointer to the mapped buffer.
  • glMapBufferARB()
    • map the buffer object into client's memory
    • returns pointer to buffer void* glMapBufferARB(GLenum target, GLenum access) - target is either GL_ARRAY_BUFFER_ARB or GL_ELEMENT_ARRAY_BUFFER_ARB. - The second parameter, access flag specifies what to do with the mapped data: read, write or both. - GL_READ_ONLY_ARB - GL_WRITE_ONLY_ARB - GL_READ_WRITE_ARB - Causes a synchronizing issue. - If GPU is still working with the buffer object, glMapBufferARB() will not return until GPU finishes its job with the corresponding buffer object. - To avoid waiting (idle), you can call first glBufferDataARB() with NULL pointer, then call glMapBufferARB(). - Valid only if you want to update entire data set

Transformations

Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 20

Objectives

  • Introduce standard transformations
    • Rotations
    • Translation
    • Scaling
    • Shear
  • Derive homogeneous coordinate

transformation matrices

  • Learn to build arbitrary transformation

matrices from simple transformations