8
$\begingroup$

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 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?

$\endgroup$
10
$\begingroup$

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 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, 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

$\endgroup$
  • $\begingroup$ 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! $\endgroup$ – glampert Aug 25 '15 at 1:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.