2

I am writing a particle simulation which uses OpenGL>= 4.3 and came upon a "problem" (or rather the lack of one), which confuses me.
For the compute shader part, I use various GL_SHADER_STORAGE_BUFFERs which are bound to binding points via glBindBufferBase().
One of these GL_SHADER_STORAGE_BUFFERs is also used in the vertex shader to supply normals needed for rendering. The binding in both the compute and vertex shader GLSL (these are called shaders 1 below) looks like this:

OpenGL part:

glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, normals_ssbo);

GLSL part:

...
layout(std430, binding = 1) buffer normals_ssbo
{
 vec4 normals[];
};
...

The interesting part is that in a seperate shader program with a different vertex shader (below called shader 2), the binding point 1 is (re-)used like this:
GLSL:

layout(location = 1) in vec4 Normal;

but in this case, the normals come from a different buffer object and the binding is done using a VAO, like this:
OpenGL:

glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, 0);

As you can see, the binding point and the layout of the data (both are vec4) are the same, but the actual buffer objects differ.

Now to my questions:
Why does the VAO of shader 2, which is created and used after setting up shaders 1 (which use glBindBufferBase for binding), seamingly overwrite (?) the binding point, but shaders 1 still remember the SSBO binding and work fine without calling glBindBufferBase again before using them?
How does OpenGL know which of those two buffer objects the binding point (which in both cases is 1) should use? Are binding points created via VAO and glBindBufferBase simply completely seperate things? If that's the case, why does something like this NOT work:

layout(std430, binding = 1) buffer normals_ssbo
{
 vec4 normals[];
};
layout(location = 1) in vec4 Normal;
asked Jun 12, 2018 at 0:13
1
  • In the last example you could write to a buffer mapped to an attribute. I'm not sure if this will get you into troubles. Commented Jun 12, 2018 at 7:05

1 Answer 1

2

Are binding points created via VAO and glBindBufferBase simply completely seperate things?

Yes, they are. That's why they're set by two different functions.

If that's the case, why does something like this NOT work:

Two possibilities present themselves. You implemented it incorrectly on the rendering side, or your driver has a bug. Which is which cannot be determined without seeing your actual code.

answered Jun 12, 2018 at 0:25
Sign up to request clarification or add additional context in comments.

1 Comment

After trying the last example again, it works just fine, which does make sense, considering the location is just the index of a particular attribute in the vertex attribute array. Could you point out to me if there is a method for saving the other bindings (glBindBufferBase)? I would like to be able to switch all of those kinda similar to binding a different VAO, is there such a mechanism or do I have to rebind them all manually?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.