Reputation: 1047
unsigned int vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
We bind the buffer in OpenGL in 3rd line, we set the mode to GL_ARRAY_BUFFER
or anything else.
Why should we set the mode again in glBufferData
which just use the last bounded buffer?
Upvotes: 1
Views: 300
Reputation: 22175
Note, that the first parameter of glBindBuffer
is not a mode, but a buffer binding point to which the buffer will be bound. There are several of these binding points and a buffer can also be bound to more than one binding point at a time.
The reason why one needs to repeat this is that multiple buffers can be bound to different buffer binding points at the same time. When, for example, rendering with indexed geometry, there will be one buffer bound to GL_ARRAY_BUFFER
and another buffer bound to GL_ELEMENT_ARRAY_BUFFER
. The first parameter of glBufferData
now identifies which of the bound buffers you want to upload data to.
In the Direct State Access extension, the need to specify the binding point has been replaced by passing the buffer handle directly to the methods:
glNamedBufferData(GLuint buffer, GLsizei size, const void *data, GLenum usage)
Upvotes: 3