0
$\begingroup$

I am looking for an opengl function to get the binding location of a SSBO in a shader.

I found glGetUniformBlockIndex which works for uniform buffers. But there must be some function to get the SSBO binding location.

on The Khronos page they have hard coded the buffer binding (3).

$\endgroup$
2

1 Answer 1

2
$\begingroup$

The call you seek is glGetProgramResourceIndex, and probably glShaderStorageBlockBinding as well.

uint32_t idex=glGetProgramResourceIndex(
  program_loc,
  GL_SHADER_STORAGE_BLOCK,
  name_of_block

);

One thing to note, and this is annoying of blocks in general, is that you must search by block name rather than it's instance name, that would be:

layout(std430) buffer block_name {
  ...
} instance_name;

Because OpenGL refrences the buffer by it's block name, it won't be found if you search by instance name. Pretty, pretty dang inconvenient for me specially; it's complicated so I won't get into why here ;>

Cheers.

$\endgroup$
2
  • 1
    $\begingroup$ The name "some_alias" is its instance name. The instance name refers to the resource and is only used by GLSL. In GLSL the name "first_name" is the "block name" and is how OpenGL references the block. GLSL does not use the block name. The upshot is that the instance name can be different between shader programs but the block names must match for OpenGL to correctly reference the data. At any rate it is usually a best practice to refer to "first_name" as the "block name" and "some_alias" as the "instance name" for clarity. $\endgroup$
    – pmw1234
    Commented Oct 22, 2022 at 12:41
  • $\begingroup$ @pmw1234 Ah, so that makes more sense. I'll go ahead and edit that ;> $\endgroup$
    – Liebranca
    Commented Oct 22, 2022 at 13:15

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.