Get mipmap levels of a texture?

Is it possible to get the amount of mipmaps a texture currently has?

Perhaps glGetTexParameter(****, GL_TEXTURE_BASE_LEVEL, )

The spec says that for any non-rectangular texture(i.e. GL_TEXTURE_RECTANGLE etc.), the number of levels is equal to

num_levels = log_2(maxsize) + 1

where (for 2D tex, array, cube and cube array)

maxsize = max(width, height)

Oddly enough, NVidia doesn’t seem to honor the constraints of the spec when it comes to the actual computation of th ei-th level of a mipmap for NPOTs. It appears they take a NPOT texture and convert the 0-th level to a the POT where the dimensions are equal

level_1 = 2 ^ floor(log_2(min(width,height)))

From there, they proceed as usual for POT textures.

Unfortunately max level seems to just return default or what you’ve previously set it to. I’m not sure what max level even affects.

It would still be great if I can get an absolute value back from opengl, for example after using glGenerateMipmaps, but I think I can solve my specific problem another way for now. Thanks.