Is ordering between glUniformBlockBinding and glBindBufferBase important?
Asked Answered
E

1

9

When using UBOs, we bind a uniform block to a binding point. Then we also bind the UBO to the same binding point: something like:

glUseProgram(ProgramName);
glUniformBlockBinding(ProgramName, uniformLocation, bindingPoint);
glBindBufferBase(GL_UNIFORM_BUFFER, bindingPoint, bufId);

I have 2 questions on this:

  1. should I specify glUniformBlockBinding first or glBindBufferBase or the order doesn't matter?
  2. If my understanding is correct, then glBindBufferBase must be called only after we have updated the UBO with data. If this is correct then this answers my first question.
Empyreal answered 24/7, 2013 at 7:23 Comment(2)
uniformLocation That's not a uniform location. That is a uniform block index. It's not the same thing.Cachexia
"If this is correct then this answers my first question." - No, it doesn't (referring to the "answer" not the "is correct"). Why should it?Uncanny
C
11

glUniformBlockBinding sets state in the program (which is why you shouldn't be calling it every frame). glBindBufferRange sets state in the OpenGL context. Neither affects the other until you render, so no, it doesn't matter which.

And yes, you cannot call glBindBufferRange (or Base, which is defined in terms of Range) unless you have allocated storage for the buffer object.

Cachexia answered 24/7, 2013 at 7:48 Comment(3)
Thanks Nicol. That answers my question.Empyreal
btw, could you please explain the difference between setting state in program vs setting state in GL context?Empyreal
@kvikram: Perhaps you should take some time to learn a bit more about OpenGL.Cachexia

© 2022 - 2024 — McMap. All rights reserved.