How does glBufferData know which VBO to work on?

2019-02-26 06:02发布

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?

3条回答
贪生不怕死
2楼-- · 2019-02-26 06:41

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.

查看更多
Rolldiameter
3楼-- · 2019-02-26 06:50

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.

查看更多
劳资没心,怎么记你
4楼-- · 2019-02-26 06:55

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.

查看更多
登录 后发表回答