Does uniform binding point shared between different stages at the same program?

Viewed 374

I look at this link https://learnopengl.com/Advanced-OpenGL/Advanced-GLSL It says different program can share same binding point's uniform value, but it doesn't mention whether the vertex shader and fragment shader could share them same uniform buffer ?
If they could share, did I need to define the same uniform twice with the same name and the same binding

1 Answers

glBindBufferRange doesn't take a shader stage when you bind a buffer. As such, UBO binding points are not stage specific. Binding point 0, for example, is the same binding point whether you use it in a VS, FS, or both. Both names represent the same bound buffer object.

did I need to define the same uniform twice with the same name and the same binding

Yes, in exactly the same way that if you want to share some class in two different cpp files, both files have to have the same class definition. In C++, this is typically done via a header. In GLSL, it happens however you want it to happen.

Related