Dennis
Dennis

Reputation: 47

the offsets in one UBO used in multiple shaders

I use one uniform block like this:

uniform matrices
{
    mat4 pv_matrix;
    mat4 screen_matrix;
};

in different shaders with the same binding point defined explicitly by UniformBlockBinding.

To work with a Uniform Buffer Object need to query the offsets this way:

int offsets = new int[Length];
GL.GetActiveUniforms(id_program, Length, indices,
ActiveUniformParameter.UniformOffset, offsets);

And I call this code for every shader program with the same result.

If I understood correct, the offsets are representing the structure of the uniform buffer object which is one for all called programs.

Does it make sense to call many times or it should be enough to call it ones?

Upvotes: 0

Views: 326

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 473352

By default, uniform blocks are laid out in the shared ordering. As such, you only need to query the layout in one program; any block declaration that is also shared and exactly matches that one will have the same layout.

Or you could just use std140 layout and not query anything.

Upvotes: 3

Related Questions