<p>The call you seek is <code>glGetProgramResourceIndex</code>, and probably <code>glShaderStorageBlockBinding</code> as well.</p>
<pre><code>uint32_t idex=glGetProgramResourceIndex(
  program_loc,
  GL_SHADER_STORAGE_BLOCK,
  name_of_block

);
</code></pre>
<p>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:</p>
<pre><code>layout(std430) buffer block_name {
  ...
} instance_name;
</code></pre>
<p>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; <a href="https://github.com/Liebranca/sin/blob/main/bin/singl" rel="nofollow noreferrer">it's complicated</a> so I won't get into why here ;&gt;</p>
<p>Cheers.</p>

CC BY-SA 4.0
2022-10-22T12:41:10.107Z
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.
pmw1234
CC BY-SA 4.0
2022-10-22T13:15:38.883Z
@pmw1234 Ah, so that makes more sense. I'll go ahead and edit that ;>
Liebranca
CC BY-SA 4.0
2022-10-22T01:12:45.223Z
2022-10-22T13:21:31.387Z
2022-10-22T13:21:31.387Z
Liebranca
<p>I am looking for an opengl function to get the binding location of a SSBO in a shader.</p>
<p>I found <code>glGetUniformBlockIndex</code> which works for uniform buffers. But there must be some function to get the SSBO binding location.</p>
<p>on The <a href="https://www.khronos.org/opengl/wiki/Shader_Storage_Buffer_Object" rel="nofollow noreferrer">Khronos page</a> they have hard coded the buffer binding (3).</p>

CC BY-SA 4.0
2022-10-17T13:54:24.303Z
@NicolBolas you are right, I meen `glGetUniformBlockIndex`
Thomas
CC BY-SA 4.0
2022-10-17T14:07:37.673Z
That's not what `glGetUniformBlockIndex` does. It gets the UBO index for a particular block. That index is [*not* the index you use for bindings.](https://www.khronos.org/opengl/wiki/Interface_Block_(GLSL)#Block_buffer_binding) That index merely [refers to a specific UBO, allowing you to query properties about that UBO.](https://www.khronos.org/opengl/wiki/Program_Introspection#Uniform_blocks)
Nicol Bolas
<opengl>
get binding location of Shader Storage Buffer Object [OpenGL]
Thomas
# get binding location of Shader Storage Buffer Object [OpenGL]

(Asked by: username_0 on 2022-10-17)

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](https://www.khronos.org/opengl/wiki/Shader_Storage_Buffer_Object) they have hard coded the buffer binding (3).

**Tags:** opengl

> **Comments:**
> **username_0**: @username_1 you are right, I meen `glGetUniformBlockIndex`  
> **username_1**: That's not what `glGetUniformBlockIndex` does. It gets the UBO index for a particular block. That index is [*not* the index you use for bindings.](https://www.khronos.org/opengl/wiki/Interface_Block_(GLSL)#Block_buffer_binding) That index merely [refers to a specific UBO, allowing you to query properties about that UBO.](https://www.khronos.org/opengl/wiki/Program_Introspection#Uniform_blocks)  

---

## 1 answers

### Answer by username_2 on 2022-10-22. Score: 2 | Accepted answer

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](https://github.com/username_2/sin/blob/main/bin/singl) so I won't get into why here ;>

Cheers.

> **Comments:**
> **username_3**: 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.  
> **username_2**: @username_3 Ah, so that makes more sense. I'll go ahead and edit that ;>  

---

