- Forward


Vertex Specification
In "Modern" OpenGL


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Important Concepts
Back SMYC Forward
  • Vertex Stream:
    • The stream of data values that define the vertices
  • Vertex Attributes:
    • A description of the elements in the vertex stream
  • Primitive:
    • The shape that is encapsulated by the vertex stream
The Vertex Stream
Back SMYC Forward
  • Makeup:
    • Everything that is needed to encapsulate a collection of vertices (e.g., positions, colors, normals)
  • Organization:
    • Can be interleaved or not (e.g., the position of the first vertex can be followed by the color of the first vertex or the positions of all vertices can come first, followed by the colors of all vertices)
The Vertex Stream (cont.)
Back SMYC Forward

A Scene Object Consisting of Two Triangles with a Non-Interleaved Stream

openglexamples/modern/multiple.cpp (Fragment: stream)
 
The Vertex Stream (cont.)
Back SMYC Forward

A Scene Object Consisting of Two Triangles with an Interleaved Stream

openglexamples/modern/interleaved.cpp (Fragment: stream)
 
Vertex Specification
Back SMYC Forward
  • Vertex Array Objects:
    • Describe the data associated with each vertex
  • Vertex Buffer Objects:
    • Store the data associated with each vertex
Vertex Buffer Objects
Back SMYC Forward
  • Buffer Objects:
    • Store an array of unformatted memory allocated by the OpenGL context (typically on the GPU)
  • Vertex Buffer Objects (VBOs):
    • A buffer object that is used as a source for vertex data
Vertex Buffer Objects (cont.)
Back SMYC Forward
  • Creation:
    • void glGenBuffers(GLsizei n​, GLuint* buffers​) where n is the inbound number of buffers to create and buffers is the outbound array of names/handles/IDs
  • Deletion:
    • void glDeleteBuffers(GLsizei n​, const GLuint* buffers​) where n is the inbound number of buffers to create and buffers is the inbound array of names/handles/IDs to delete
  • Setting State:
    • void glBindBuffer(enum target, uint bufferName) binds the buffer object to the context so its state can be changed (where target is typically GL_ARRAY_BUFFER)
    • Subsequent calls to glBufferStorage(), glBufferData(), glClearBufferData(), etc... then change the state
Vertex Buffer Objects (cont.)
Back SMYC Forward

The VBOs for the Non-Interleaved Stream

openglexamples/modern/multiple.cpp (Fragment: vbo)
 
Vertex Buffer Objects (cont.)
Back SMYC Forward

The VBO for the Interleaved Stream

openglexamples/modern/interleaved.cpp (Fragment: vbo)
 
Vertex Array Objects (VAOs)
Back SMYC Forward
  • Recall:
    • VBOs are unformatted
  • Purpose of VAOs:
    • Store all of the state needed by vertices (including the format and the VBOs)
Vertex Array Objects (VAOs)
Back SMYC Forward
  • Creation:
    • void glGenVertexArrays(GLsizei n​, GLuint* arrays​); where n is the inbound number of buffers to create and arrays is the outbound array of names/handles/IDs
  • Deletion:
    • void glDeleteVertexArrays(GLsizei n​, const GLuint *arrays​); where n is the inbound number of buffers to create and arrays is the inbound array of names/handles/IDs to delete
  • Setting State:
    • void glBindVertexArray(GLuint array); binds the VAO to the context so it's state can be changed
    • void glEnableVertexAttribArray(GLuint index​); allows the attribute numbered index to be changed
    • glVertexAttribPointer() can then be used to set the format of the VBO and associate the currently bound VBO with the currently bound VBA
    • void glDisableVertexAttribArray( GLuint index​); prevents the attribute numbered index from being changed
Vertex Array Objects (cont.)
Back SMYC Forward

The VAOs for the Non-Interleaved Stream

openglexamples/modern/multiple.cpp (Fragment: vao)
 
Vertex Array Objects (cont.)
Back SMYC Forward

The VAOs for the Interleaved Stream

openglexamples/modern/interleaved.cpp (Fragment: vao)
 
There's Always More to Learn
Back -