Do I understand it right? VBO

Hi, I’m learning OpenGL 3.3.0 right now, and I’d like to know if the way I understand VBOs so far is correct. I haven’t read anything about VAOs yet, so this is just me trying to comprehend what VBOs do when I use certain functions in the code.

After declaring 3 vertices that form a triangle primitive using a float array, that vertex data sits there in code, OpenGL isn’t ‘aware’ of it. In order to make OpenGL ‘aware’ of it, I need to send that vertex data to the Vertex Shader. How do I send this information? Through a VBO. So, basically, a VBO is a memory on the GPU that stores my vertex data (my triangle). So, if I were to break it down, it would be something like this:

    GLuint VBO; // I declare my VBO
    glGenBuffers(1, &VBO); // I create an ID for my VBO, that ID will be GL_ARRAY_BUFFER
    glBindBuffer(GL_ARRAY_BUFFER, VBO); // I bind the ID to the VBO
    glBufferData(GL_ARRAY_BUFFER, sizeof(triangle), triangle, GL_STATIC_DRAW);
    // let's ignore GL_STATIC_DRAW here, I know what that does. So basically, here I'm saying:
    // that vertex data (triangle vertices) that I've declared, I'm going to store it in the VBOs ID, then I'll 
    // specify the size of that vertex data, and then I'll specify the vertex data itself. 

So basically, a VBO collects all the vertex data information, stores it within, and sends it to the Vertex Shader (which is a bunch of code), which is the 1st step in the Pipeline Rendering process.

VBO > send info to > Vertex Shader or Vertex Shader collects info from VBO which is located in the GPU memory (either way).

This is how I understand things so far. I want to know if the way I understand it, function by function, is correct. Otherwise, I find myself writing functions that I learn by memory but have no idea what they mean.

Do I understand how this works? Or am I confused?

A buffer object is just a block of memory which may be GPU memory. Unlike memory allocated with e.g. malloc, it doesn’t have a fixed address in the CPU’s address space. Data can be written with glBufferData or glBufferSubData, or read with glGetBufferSubData. A buffer can also be mapped to the CPU’s address space with glMapBuffer or glMapBufferRange (unless the buffer is created and mapped with GL_MAP_PERSISTENT_BIT, it must be unmapped before issuing draw calls which use it).

A vertex buffer object (VBO) is a buffer object which is used to store vertex attribute data. glVertexAttribPointer stores the name (handle, ID) of the buffer which is bound to the GL_ARRAY_BUFFER target as part of the state for the attribute array. So when you subsequently issue a draw call, the data for that vertex attribute is sourced from that buffer.

The terms “vertex buffer object” and “VBO” are colloquial; the specification doesn’t use them. The terminology is a legacy of the various extensions which pre-date their introduction into the core standard.

What GClements said.

But to your comment above specifically, first:

  • Yes, a buffer object collects the vertex data that’s ultimately sent through a vertex shader. But…
  • No, it has no active roll in sending it anywhere. It’s just a dumb block of data. When you setup for a draw call, you tell OpenGL to “pull” the data from that buffer object; the buffer object doesn’t “push” it somewhere.

Second, a buffer object (e.g. one used to store vertex data – a VBO) only contains the raw data itself. It doesn’t maintain any knowledge of the actual “format” of the data contained in the block. You provide that format to OpenGL when you tell it to read from that buffer object at a specific offset in the buffer object. In fact, you can store any number of different blocks of data with different underlying data formats in a single buffer object if you want.