Do I really need glBindBuffer for uniform buffer objects?

I'm reading about the section on binding indexed targets in the OpenGL wiki. That's a bit confusing to me, so I tried to search the difference between glBindBuffer and glBindBufferBase on the site, where I found this answer.

I think I'm able to fully understand that answer in the link (hopefully), but still want some clarification on how this would work in the context of direct state access. Specifically, the answer mentions that "glBindBuffer is used to bind a buffer to a specific target so that all operations which modify that target are mapped to that buffer afterwards." According to this logic, if I can use DSA calls like glNamedBufferSubData to modify the buffer directly, then there's no need to use glBindBuffer at all, correct me if I'm wrong.

So for example, if I do something like this:

layout(std140, binding = 7) uniform Foo {
    ivec2 bar1;
    float bar2;
    float baz1;
    vec4 baz2[10];
} foo;
glCreateBuffers(1, &id);
glNamedBufferStorage(id, size, NULL, GL_DYNAMIC_STORAGE_BIT);
glBindBufferBase(target, 7, id);

... // on init, for each block member, query aligned offset, calculate size

while (every frame) {
    ... // prepare new buffer data
    glNamedBufferSubData(id, offset, size, data);  // update data store
}

then I would never need to bind/unbind the buffer at all, is this correct for both UBO and SSBO? mostly importantly, is it safe?


Solution 1:

While you still need to bind objects if you want to render with them (though sometimes indirectly), DSA makes every use of glBindBuffer specifically unnecessary. There are alternative ways to do the useful parts of that bind call (glVertexArrayElementBuffer replacing glBindBuffer(GL_ELEMENT_ARRAY_BUFFER), etc), so the function is entirely unnecessary.