Search code examples
openglopengl-4

glBindBuffer and direct state access?


According to slide 23 of NVIDIA's OpenGL 4.5 Update presentation the following is true:

Non-DSA: glGenBuffers + glBindBuffer

DSA: glCreateBuffers

I tried writing a DSA only program. While using glDrawArraysIndirect to draw I'm forced to use glBindBuffer along glCreateBuffers


Here's a snippet of the working code:

glCreateBuffers(1, &bufObj);

glBindBuffer(GL_DRAW_INDIRECT_BUFFER, bufObj); //If deleted creates SEGFAULT crash

glNamedBufferData(bufObj, sizeof(mydrawcall), mydrawcall, GL_STATIC_DRAW);
...
glDrawArraysIndirect(GL_TRIANGLES, 0);

  • Is glBindBuffer non-DSA?
  • Am I missing another newer DSA function or is this the only way?

Solution

  • The purpose of direct state access is not to remove object binding from your application completely (that would be the purpose of the various "bindless" extensions). The purpose of direct state access is to allow you to access the state of an object without having to bind it (ie: directly).

    Pre-DSA, you had to bind a buffer just to allocate storage, upload data, etc. With DSA functions, you don't have to. You pass the buffer directly to the function you use to manipulate its state.

    But to actually use buffers in a rendering process, you must still bind it to the context or attach it to some other object which itself will get bound to the context.

    To use a buffer's storage as uniform data, it must be bound to the context with glBindBufferRange(GL_UNIFORM_BUFFER (or equivalent calls). To use a buffer to store vertex data, you must attach it to a VAO through glVertexArrayVertexBuffer, then bind that VAO to the context. To use a buffer for pixel transfer operations, you must bind the buffer to the appropriate location with glBindBuffer. And so forth.

    The same goes for using a buffer as the source for indirect command execution. That's a rendering operation, so the buffer must be bound to the indirect target before issuing the indirect command.

    But it only needs to be bound at the time you issue that command. You don't have to bind it immediately after creation. Just before you actually call glDrawArraysIndirect.