Vertex Buffer Objects
- Transfer data (points and attributes) to the GPU once.
- Generate Buffer names
- glGenBuffers(GLsizeI n, GLuint * buffers)
- Returns the "name" or ID of n different buffers in the buffer array positions.
- I am reasonably sure that this is an index into a buffer table.
- But you don't know that you will have sequential numbers
- One buffer
- Bind the buffer to a use
- glBindBuffer(GLenum target, GLuint buffer)
- Target: described here is how the buffer will be used.
- GL_ARRAY_BUFFER is a buffer for data, what we will use.
- This mechanism can be used to transfer data back and forth from the CPU/CPU hence the many different options.
- buffer is one of the buffers from the previous command.
- This essentially tells OpenGL how you will be using the buffer.
- I think of this as allocating a structure of the correct type on the remote machine.
- If nothing is bound to the name, it is bound.
- If something is bound, the binding is broken and rebound
-
- Associate data with the buffer
- glBufferData(GLenum target, GLsizepter, size, const GLvoid * data, GLEnum usage)
- target is a buffer id which has been allocated and bound
- The same list as above. (GL_ARRAY_BUFFER)
- size is the size, in bytes of the data to be transferred
- data is a pointer to the data to be copied, or NULL
- If NULL no data is copied
- But space is allocated
- usage is a hint on how the data will be used.
- STREAM - written once, used a few times.
- STATIC - written once, used many times.
- DYNAMIC - modified frequently
- DRAW - used for drawing
- READ
- WRITE
- GL_STATIC_DRAW , GL_STREAM_READ
- We probably want GL_STATIC_DRAW, or GL_STREAM_DRAW
- Note that the incorrect setting will cause poor performance
- If the buffer was pointing to an object, the object memory is deallocated.