<p>The <code>binding</code> value for uniforms of opaque types is, from the perspective of the OpenGL API, the uniform's <em>value</em>. You set it by using <code>glProgramUniform1i</code>.</p>
<p>As such, you query it by querying the value of the uniform with <code>glGetUniformiv</code>.</p>

CC BY-SA 4.0
2020-07-30T00:51:09.710Z
2020-07-30T00:51:09.710Z
Nicol Bolas
<p>I have an image and a sampler declared in a shader as follow</p>
<pre><code>layout(binding = 5) uniform isampler2D heightmap;
layout(binding = 3) uniform writeonly uimage2D info;
</code></pre>
<p>Which are correctly bound using the following code</p>
<pre><code>glBindTextureUnit(5, heightmapId);
glBindImageTextures(3, 1, &amp;infoId);
</code></pre>
<p>For introspection purposes, I am trying to retrieve the binding points of these objets, 5 and 3, but I didn't find any way to do this for uniforms. Is it possible using the API?</p>
<p>I first tried to use glGetProgramResourceIndex, since it worked with storage buffers, but it doesn't the results are get are incorrect, as if the explicit binding was ignored.</p>
<p>I then looked at glGetProgramResourceiv, but the binding related enums are only available for storage buffers and atomic counters.</p>

<opengl>
Get binding point of sampler/image in shader
Aulaulz
# Get binding point of sampler/image in shader

(Asked by: username_0 on 2020-07-29)

I have an image and a sampler declared in a shader as follow

```
layout(binding = 5) uniform isampler2D heightmap;
layout(binding = 3) uniform writeonly uimage2D info;

```

Which are correctly bound using the following code

```
glBindTextureUnit(5, heightmapId);
glBindImageTextures(3, 1, &infoId);

```

For introspection purposes, I am trying to retrieve the binding points of these objets, 5 and 3, but I didn't find any way to do this for uniforms. Is it possible using the API?

I first tried to use glGetProgramResourceIndex, since it worked with storage buffers, but it doesn't the results are get are incorrect, as if the explicit binding was ignored.

I then looked at glGetProgramResourceiv, but the binding related enums are only available for storage buffers and atomic counters.

**Tags:** opengl


---

## 1 answers

### Answer by username_1 on 2020-07-30. Score: 2 | Accepted answer

The `binding` value for uniforms of opaque types is, from the perspective of the OpenGL API, the uniform's *value*. You set it by using `glProgramUniform1i`.

As such, you query it by querying the value of the uniform with `glGetUniformiv`.


---

