glTexStorage2D​ automatic mipmap level calculation

ARB_texture_storage added glTexStorage2D, but unfortunately the function requires you to specify the number of mipmap levels.

This means you have to write your own function to calculate this if you want a full mipmap stack. This is of course prone to error, and extra effort for the common case where you just want to load a texture.

In D3D you can specify 0 mipmap levels and a full mipmap stack is created.

Thus I suggest this function be modified to accept a 0 level that automatically creates a full mipmap stack.

You can use glGenerateMipmap to do this.

Its ‘floor(log2(max(width,height)))+1’.
Arent you exagerating a bit?

You can use glGenerateMipmap to do this.

No, you can’t. glTexStorage creates [i]immutable[/i] storage. You can use glGenerateMipmap to create the mipmap texel data, but it cannot create more mipmaps than exist in the immutable storage.

Or fls(width|height) if you want to work with ints only (fls is ‘find last set bit’)

Or just calc it by hand:
int levels = 1;
while ((width|height) >> levels) levels += 1;