PDA

View Full Version : glTexStorage2D​ automatic mipmap level calculation



Leith Bade
11-16-2012, 01:57 AM
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.

randall
11-16-2012, 04:17 AM
You can use glGenerateMipmap to do this.

kyle_
11-16-2012, 09:23 AM
This means you have to write your own function to calculate this if you want a full mipmap stack.

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

Alfonse Reinheart
11-16-2012, 09:32 AM
You can use glGenerateMipmap to do this.

No, you can't. glTexStorage creates immutable storage (http://www.opengl.org/wiki/Texture_Storage#Immutable_storage). You can use glGenerateMipmap to create the mipmap texel data (http://www.opengl.org/wiki/Texture_Storage#Automatic_mipmap_generation), but it cannot create more mipmaps than exist in the immutable storage.

l_belev
12-03-2012, 04:34 AM
Its 'floor(log2(max(width,height)))+1'.

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;