Fullstack_Developer
Fullstack_Developer

Reputation: 115

Is it bad practice to reuse GL_TEXTURE0 over again when binding different textures?

In many examples, some are reusing GL_TEXTURE0 over and over for different textures, and in other examples they increment the texture slot like so:

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, woodTexture);
...
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, metalTexture);
...
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, plasticTexture);

as opposed to

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, woodTexture);
...
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, metalTexture);
...
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, plasticTexture);

Is one or the other bad practice, or even worse for efficiency, or does it not matter at all?

Upvotes: 1

Views: 202

Answers (1)

sirian_ye
sirian_ye

Reputation: 660

Multiple texture units are for one geometry who has multiple textures. For instance, some lighting shader requires two lighting maps for diffuse and specular. Then you need to provide two textures for two samplers. In this case, you have to active two textures. See the following structure:

struct Material {
    sampler2D diffuse;
    sampler2D specular;    
    float shininess;
}; 

If geometries only have 1 texture, it is ok to just use the GL_TEXTURE0. You don't need to active it multiple times, it will be automatically actived as the default texture

Upvotes: 2

Related Questions