Get the amount of mipmaps

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Get the amount of mipmaps

Post by Mel »

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.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Get the amount of mipmaps

Post by hendu »

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.
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Get the amount of mipmaps

Post by Mel »

I do it like this:

Code: Select all

 
texture = material.getTexture(1);
irr::f32 size = max(texture->getSize().Width,texture->getSize().Height);
mipmapsCount = floor(log(size)/log(2));
 
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
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Get the amount of mipmaps

Post by hendu »

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).
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Get the amount of mipmaps

Post by Mel »

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
Post Reply