Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: glTexStorage2D​ automatic mipmap level calculation

Hybrid View

  1. #1
    Intern Contributor
    Join Date
    Jul 2010
    Posts
    74

    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.

  2. #2
    Junior Member Regular Contributor
    Join Date
    Mar 2009
    Posts
    153
    You can use glGenerateMipmap to do this.

  3. #3
    Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    268
    Quote Originally Posted by Leith Bade View Post
    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?

  4. #4
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    You can use glGenerateMipmap to do this.
    No, you can't. glTexStorage creates immutable storage. You can use glGenerateMipmap to create the mipmap texel data, but it cannot create more mipmaps than exist in the immutable storage.

  5. #5
    Member Regular Contributor
    Join Date
    Apr 2004
    Posts
    250
    Quote Originally Posted by kyle_ View Post
    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;
    Last edited by l_belev; 12-03-2012 at 08:50 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •