0

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?

neo-mashiro
  • 422
  • 4
  • 13
  • 4
    Correct - the point of DSA is to remove the need for glBindBuffer calls. glBindBuffer maintains state - i.e. the buffer that is currently bound - and that causes a lot of problems with threading, since only one thread can safely call glBIndBuffer at any given time. If you are using `glCreateBuffers`, and `glNamedBuffer****()`, glBindBuffer shouldn't be needed. – robthebloke Jan 17 '22 at 00:22
  • @robthebloke Glad the hear that! That makes my life much easier and I will say goodbye to `glBindBuffer` in UBO and SSBOs. – neo-mashiro Jan 17 '22 at 00:56

1 Answers1

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.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982