<p>By using the <a href="https://www.khronos.org/opengl/wiki/Sampler_(GLSL)#Version_4.20_binding" rel="nofollow noreferrer">exact same syntax</a> as you did for SSBOs:</p>

<pre><code>layout(binding = 0) uniform sampler2D texture_name;
</code></pre>

<p>This is a GL 4.2 feature, so if you can use SSBOs, you can use this.</p>

CC BY-SA 4.0
2018-07-17T15:14:59.503Z
2018-07-17T15:14:59.503Z
Nicol Bolas
<p>The way I learnt to send a texture to a shader is more or less</p>

<pre><code>//Use program
//Bind texture to the texture unit to its appropriate target
glActiveTexture(GL_TEXTURE0 + texture_unit);
glBindTexture(target, textureID);
//Get the uniform location in the program and attach the texture unit
GLuint location = /*get the location somewhow*/;
glUniform1i(location,texture_unit);
</code></pre>

<p>However when dealing with buffers and SSBOS rather than trying to find a location through a string name, the object is declared as:</p>

<pre><code>layout(std430, binding = 2) buffer texture_meta_data
</code></pre>

<p>For example. This means that the SSBO is to be bound at binding point 2</p>

<p>And then on the C++ side one does something like</p>

<pre><code>glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, SSBOID);
</code></pre>

<p>To bind the object to the binding point.</p>

<p>How can you do the same with textures?</p>

<opengl><texture><shader><c++>
Can you avoid querying for a texture location in OpenGL?
Makogan
# Can you avoid querying for a texture location in OpenGL?

(Asked by: username_0 on 2018-07-16)

The way I learnt to send a texture to a shader is more or less

```
//Use program
//Bind texture to the texture unit to its appropriate target
glActiveTexture(GL_TEXTURE0 + texture_unit);
glBindTexture(target, textureID);
//Get the uniform location in the program and attach the texture unit
GLuint location = /*get the location somewhow*/;
glUniform1i(location,texture_unit);

```

However when dealing with buffers and SSBOS rather than trying to find a location through a string name, the object is declared as:

```
layout(std430, binding = 2) buffer texture_meta_data

```

For example. This means that the SSBO is to be bound at binding point 2

And then on the C++ side one does something like

```
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, SSBOID);

```

To bind the object to the binding point.

How can you do the same with textures?

**Tags:** opengl, texture, shader, c++


---

## 1 answers

### Answer by username_1 on 2018-07-17. Score: 2 | Accepted answer

By using the [exact same syntax](https://www.khronos.org/opengl/wiki/Sampler_(GLSL)#Version_4.20_binding) as you did for SSBOs:

```
layout(binding = 0) uniform sampler2D texture_name;

```

This is a GL 4.2 feature, so if you can use SSBOs, you can use this.


---

