<p>Modern hardware doesn't really have the concept of texture binding points as exposed by OpenGL. Rather, the shader unit uses a descriptor (which is just some kind of fat pointer) which can potentially address any texture as long as it's resident in video memory. This is what makes things like <a href="https://www.opengl.org/registry/specs/ARB/bindless_texture.txt">bindless textures</a> possible. So the large amount of "texture units" available in current implementations is simply trying to handwave this now-irrelevant part of the API.</p>

<p>That said, the recommended way of implementing what you're trying to do (avoiding re-binding of textures) is to use <a href="https://www.opengl.org/wiki/Array_Texture">texture arrays</a>, which allow you to dynamically index into a set of textures in the shader, as long as they all have the same format and size. This presentation contains more details about these and other techniques for reducing driver overhead when rendering with modern OpenGL: <a href="http://www.slideshare.net/CassEveritt/approaching-zero-driver-overhead">Approaching Zero Driver Overhead</a></p>

CC BY-SA 3.0
2015-08-25T01:39:07.027Z
I've watched that presentation before, it is very good. I did not know about what you mention in the first paragraph though, so thanks for that info!
glampert
CC BY-SA 3.0
2015-08-25T00:33:25.640Z
2015-08-25T04:34:12.847Z
2015-08-25T04:34:12.847Z
yuriks
<p>When applying multiple textures to a mesh, like for bump-mapping, I usually bind the textures to the first few fixed texture units, e.g.: diffuse = unit 0, bump = unit 1, specular = unit 2, then keep reusing those to each different mesh with different textures. But I've always wondered why <a href="https://www.opengl.org/sdk/docs/man/html/glActiveTexture.xhtml"><code>glActiveTexture</code></a> supports so many texture units (in the previous link, it says at least 80).</p>

<p>So it occurred to me that one possible way of managing textures is to bind distinct textures to each available unit and leave them enabled, just updating the uniform sampler index. That should improve rendering perf by reducing the number of textures switches. If you have less textures than the max texture units, you never have to unbind a texture.</p>

<p>Is this standard practice on real-time OpenGL applications (I believe this also applies to D3D)? And are there any non obvious performance implications of taking this approach? Memory overhead perhaps?</p>

<opengl><texture>
Is it good practice to use all the available texture units?
glampert
# Is it good practice to use all the available texture units?

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

When applying multiple textures to a mesh, like for bump-mapping, I usually bind the textures to the first few fixed texture units, e.g.: diffuse = unit 0, bump = unit 1, specular = unit 2, then keep reusing those to each different mesh with different textures. But I've always wondered why [`glActiveTexture`](https://www.opengl.org/sdk/docs/man/html/glActiveTexture.xhtml) supports so many texture units (in the previous link, it says at least 80).

So it occurred to me that one possible way of managing textures is to bind distinct textures to each available unit and leave them enabled, just updating the uniform sampler index. That should improve rendering perf by reducing the number of textures switches. If you have less textures than the max texture units, you never have to unbind a texture.

Is this standard practice on real-time OpenGL applications (I believe this also applies to D3D)? And are there any non obvious performance implications of taking this approach? Memory overhead perhaps?

**Tags:** opengl, texture


---

## 1 answers

### Answer by username_1 on 2015-08-25. Score: 12 | Accepted answer

Modern hardware doesn't really have the concept of texture binding points as exposed by OpenGL. Rather, the shader unit uses a descriptor (which is just some kind of fat pointer) which can potentially address any texture as long as it's resident in video memory. This is what makes things like [bindless textures](https://www.opengl.org/registry/specs/ARB/bindless_texture.txt) possible. So the large amount of "texture units" available in current implementations is simply trying to handwave this now-irrelevant part of the API.

That said, the recommended way of implementing what you're trying to do (avoiding re-binding of textures) is to use [texture arrays](https://www.opengl.org/wiki/Array_Texture), which allow you to dynamically index into a set of textures in the shader, as long as they all have the same format and size. This presentation contains more details about these and other techniques for reducing driver overhead when rendering with modern OpenGL: [Approaching Zero Driver Overhead](http://www.slideshare.net/CassEveritt/approaching-zero-driver-overhead)

> **Comments:**
> **username_0**: I've watched that presentation before, it is very good. I did not know about what you mention in the first paragraph though, so thanks for that info!  

---

