<p>Fixed. I feel pretty silly. When I set <code>glActiveTexture</code> it primes the OpenGL context to set the active texture for <strong>all</strong> subsequence texture binds. Thus the bind at line 66 overwrites it. I solved this by setting <code>GL_TEXTURE0</code> as my 'reset' texture and setting <code>glActivateTexture(GL_TEXTURE0)</code> when I am done binding a texture unit.</p>

CC BY-SA 4.0
2023-08-25T00:47:08.340Z
2023-08-25T00:47:08.340Z
William Allen
<p>I am using NVIDIA Nsight to debug my OpenGL state. In the screenshots below:</p>
<ul>
<li>I generate a single texture with the ID <code>10</code>.</li>
<li>I activate <code>GL_TEXTURE0</code> and bind texture <code>10</code> to that texture unit.</li>
<li>I generate a single texture with the ID <code>11</code>.</li>
<li>I activate <code>GL_TEXTURE1</code> and bind texture <code>11</code> to that texture unit.</li>
</ul>
<p>When I view the API inspector, I see that texture <code>11</code> is bound to both <code>unit 0</code> and <code>unit 1</code>, which I presume is <code>GL_TEXTURE0</code> and <code>GL_TEXTURE1</code>.</p>
<p>Am I misunderstanding something about how texture units work in OpenGL? This is not the behavior I would expect.</p>
<p><a href="https://i.sstatic.net/Y6lUC.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Y6lUC.png" alt="Events tab" /></a></p>
<p><a href="https://i.sstatic.net/YTTcY.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/YTTcY.png" alt="API Inspector, Textures" /></a></p>

<opengl><texture>
OpenGL texture unit bindings - Why is a single texture mapped to both texture units when each are individually assigned?
William Allen
# OpenGL texture unit bindings - Why is a single texture mapped to both texture units when each are individually assigned?

(Asked by: username_0 on 2023-08-25)

I am using NVIDIA Nsight to debug my OpenGL state. In the screenshots below:

* I generate a single texture with the ID `10`.
* I activate `GL_TEXTURE0` and bind texture `10` to that texture unit.
* I generate a single texture with the ID `11`.
* I activate `GL_TEXTURE1` and bind texture `11` to that texture unit.

When I view the API inspector, I see that texture `11` is bound to both `unit 0` and `unit 1`, which I presume is `GL_TEXTURE0` and `GL_TEXTURE1`.

Am I misunderstanding something about how texture units work in OpenGL? This is not the behavior I would expect.

[![Events tab](https://i.sstatic.net/Y6lUC.png)](https://i.sstatic.net/Y6lUC.png)

[![API Inspector, Textures](https://i.sstatic.net/YTTcY.png)](https://i.sstatic.net/YTTcY.png)

**Tags:** opengl, texture


---

## 1 answers

### Answer by username_0 on 2023-08-25. Score: 1 | Accepted answer

Fixed. I feel pretty silly. When I set `glActiveTexture` it primes the OpenGL context to set the active texture for **all** subsequence texture binds. Thus the bind at line 66 overwrites it. I solved this by setting `GL_TEXTURE0` as my 'reset' texture and setting `glActivateTexture(GL_TEXTURE0)` when I am done binding a texture unit.


---

