Uniform Buffer Object layout binding

I have two Uniform Blocks in my vertex shader :

layout(std140, binding=1) uniform Transforms
uniform mat4		mvp;
uniform mat4		proj;
uniform mat4		mv;
uniform mat4		nrmn;
layout(std140, binding=3) uniform Shadows
uniform mat4 shadowMtx[2];

I can get the correct binding for Transforms using glGetActiveUniformBlockiv with GL_UNIFORM_BLOCK_BINDING but it gives me 0 for Shadows.

If I change Shadow to

layout(std140, binding=3) uniform Shadows
uniform mat4 dummy;
uniform mat4 shadowMtx[2];

querying GL_UNIFORM_BLOCK_BINDING now gives the correct location. Have I misunderstood something or is this a bug?

I’m using openGL 4.2 with Nvidia 460 w/ 296.10 drivers



I have not used arrays in my structures; but I don’t see anything wrong with your original structure. Do you still need the padding if you just use 2 matrices not as an array?

Sounds like a driver bug.

That being said, in general, the reason for you to assign block bindings in the shader is if you have some convention, so that your source code automatically knows where these bindings are. Say, your projection matrix is always in binding point 0, your array of matrices for skinning is always in binding 1, etc.

I didn’t try two arrays, but It also happens if I put a dummy array at the top of Transforms.

That’s pretty much what I am doing, it’s for a bunch of tests with some shared UBOs and it’s easier than setting the binding point each time, though that isn’t a big undertaking in itself.

I should try and see if I can still manually bind the uniform block to the right location.

What I was saying is that you shouldn’t be getting the active uniform block binding at all. You should simply know that it’s binding X.

Is the problem that the value you’re getting from OpenGL is wrong, or is it that you’re getting incorrect rendering if you ignore what OpenGL says?

The rendering was incorrect, so I just added a few checks to see what was not as I expected.

File a bug report on it then. There’s not much more you can do than that.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.