How can i find out the amount of mipmaps a texture has during run time? I figure I can lock and unlock the levels until it fails, but i am worried that could cause a memory leak and be quite slow specially if i am trying to use a shader that needs the amount of mipmaps a texture has as a parameter.
Would it be possible to add such a method to the ITexture* interface? like a "irr::s32 getMipMapsCount() const" or something. After all, it is almost a constant parameter for a texture.
Get the amount of mipmaps
Get the amount of mipmaps
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Re: Get the amount of mipmaps
Unless you've specifically ordered it not to, all levels exist. Check the spec for the calculation, I forget if the smallest level is 1 or 2 pixels.
Re: Get the amount of mipmaps
I do it like this:
Precisely that is is the problem, that maybe not all the mipmap levels are generated, so i asked for a safe way to know this detail. Still, this is a good measurement, but honestly, i would rather know the exact amount beforehand
Code: Select all
texture = material.getTexture(1);
irr::f32 size = max(texture->getSize().Width,texture->getSize().Height);
mipmapsCount = floor(log(size)/log(2));
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Re: Get the amount of mipmaps
Levels may only be missing if you told them to, and in that case, only you will know they are missing. The driver sees them as black, it doesn't know which ones are valid (unless you specified that too, in that case it can be queried back).
Re: Get the amount of mipmaps
Hmm.. Also it may come in handy when you don't want some specific mip levels to be reached (texture atlases...)
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt