viktorzeid
viktorzeid

Reputation: 1551

What is the proper way to generate mipmaps

In a recent tutorial, I came across this to generate mipmaps for 'textureObject'

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureObject);
glBindSampler(0, samplerObject);
glGenerateMipmap(GL_TEXTURE_2D);

I want to question the usage of

glActiveTexture(GL_TEXTURE0);
glBindSampler(0, samplerObject);

before calling 'glGenerateMipmap'. Because I get the same result as before, if i comment out these 2 lines.

Are these lines present just to make sure that the right texture unit and sampler is bound before generating mipmaps?

or these lines actually tell which texture unit to choose and what kind of sampling to do to generate mipmaps?

what will happen if I skip these 2 lines?

Upvotes: 2

Views: 10626

Answers (1)

fen
fen

Reputation: 10115

from glGenerateMipmap reference

Specifies the texture target of the active texture unit to which the texture object is bound whose mipmaps will be generated

and more

Mipmap generation replaces texel array levels level base + 1 through q with arrays derived from the level base array, regardless of their previous contents. All other mimap arrays, including the level base array, are left unchanged by this computation.

This way, if you use

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureObject);
glActiveTexture(GL_TEXTURE1); // <<
glGenerateMipmap(GL_TEXTURE_2D);

You will get mipmaps for different texture object (if texture unit 1 has other texture object bound)

Regarding samplers: they can override GL_TEXTURE_BASE_LEVEL​ and GL_TEXTURE_MAX_LEVEL​ so it is also important to use a proper sampler object.

See a good post from g-truck about mipmaps

Upvotes: 2

Related Questions