johnbakers
johnbakers

Reputation: 24771

How does glBufferData know which VBO to work on?

Here is the formal declaration for glBufferData which is used to populate a VBO:

void glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage);

What is confusing, however, is that you can have multiple VBOs, but this function does not require a handle to a particular VBO, so how does it know which VBO you are intending?

The target parameter can be either GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER but my understanding is that you can have more than one of each of these.

The same is true of the similar glBufferSubData method, which is intended to be called subsequent times on a VBO -- how does it know which VBO to handle?

Upvotes: 2

Views: 1304

Answers (3)

phaazon
phaazon

Reputation: 2002

glBindBuffer is a function that exposes the given buffer as bound. Such a glBufferData access it then by side-effect, through the currently bound buffer object.

Upvotes: 0

Kimi
Kimi

Reputation: 14119

This is a common pattern in OpenGL to bind object to a target and perform operations on it by issuing function calls without a handle. The same applies to the textures.

Upvotes: 4

datenwolf
datenwolf

Reputation: 162327

OpenGL operations that use a buffer object, make use of the buffer that has been bound by the most recent call to glBindBuffer on the used target.

Upvotes: 0

Related Questions