Brain Dump

Vertex Buffer Objects

Tags
opengl

Data (vertices) allocated on the GPU.

We send data from our program to the GPU so that it can be processed without slow transfers between the GPU and the CPU. This is generally the first stage in the drawing something.

Once in the GPU the vertex shader has near instant access to data.

Creating a VBO

We create a buffer and access it through an id.

unsigned int VBO;
glGenBuffers(1, &VBO);

OpenGL also needs to know the kind of buffer this object points to.

glBindBuffer(GL_ARRAY_BUFFER, VBO);

We can then assign data to a VBO.

float vertices[] = {
    -0.5f, -0.5f, 0.0f,
     0.5f, -0.5f, 0.0f,
     0.0f,  0.5f, 0.0f
};

glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

Data Management

The final parameter in the call to glBufferData specifies how the data should be managed. Possible values include:

ValueMeaning
GL_STREAM_DRAWData is set only once and used by the GPU at most a few times.
GL_STATIC_DRAWData is set only once and used many times.
GL_DYNAMIC_DRAWData is changed a lot and used many times.