Search code examples
javaopengllwjgl

Binding a buffer to multiple targets


Can I bind a opengl buffer object to multiple targets. For instance, I bind a buffer to the target array buffer and then bind the same buffer to SHADER_STORAGE_BUFFER or some otger target, is the buffer bound to the first second or both targets?


Solution

  • OpenGL specifications:

    void [gl]BindBuffer( enum target, uint buffer ); If the buffer object named buffer has not been previously bound, the GL creates a new state vector, initialized with a zero-sized memory buffer and comprising all the state and with the same initial values listed in table...

    And

    BindBuffer may also be used to bind an existing buffer object. If the bind is successful no change is made to the state of the newly bound buffer object, and any previous binding to target is broken.

    So, yes: you can use the same name (as created with glGenBuffers) and bind this existing bound buffer with a different use (target in OpenGL parlance). But I can't think of a reason to do this.