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 2 of 2

Thread: Manually generate mipmaps for textures loaded using glCompressedTexImage2D

  1. #1
    Intern Newbie
    Join Date
    Dec 2012
    Posts
    40

    Question Manually generate mipmaps for textures loaded using glCompressedTexImage2D

    I need to generate the mipmaps for my textures on the fly, but I can't use glGenerateMipmap. The initialization of the texture data is supposed to be done on a separate thread in the background, independent of any OpenGL-calls.

    Generating the mipmaps for uncompressed textures on the CPU is fairly straight forward (Following the information from this document), however that somewhat fails when working with compressed textures. Apparantly OpenGL doesn't like it if you try to use both glCompressedTexImage2D and glTexImage2D on the same texture object, no errors are generated, but the texture ends up entirely black.
    I'm guessing that the mipmap data needs to be in a compressed format as well. So, my question is, how do I generate the data I need to create the mipmaps of a compressed texture, and how do I then get that data into a format I can use with glCompressedTexImage2D?

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,155
    Quote Originally Posted by Silverlan View Post
    Generating the mipmaps for uncompressed textures on the CPU is fairly straight forward ... however that somewhat fails when working with compressed textures. Apparantly OpenGL doesn't like it if you try to use both glCompressedTexImage2D and glTexImage2D on the same texture object, no errors are generated, but the texture ends up entirely black.
    You wouldn't call both of these methods on the same texture -- they both allocate texels (and optionally provide texel data). The second call on the same MIP would free the previous texels and allocate a fresh new MIP level.

    Use glTexImage2D to allocate each texture MIP (NULL ptr to allocate only and not provide pixel data), and then use glCompressedTexSubImage2D to upload the texels to each MIP level.

    (I don't know if it's still true, but in ancient times it used to be that some drivers seg faulted if you provided a NULL pointer to glCompressedTexImage2D. Probably fixed by now. If so, then can use glCompressedTexImage2D to allocate, and optionally glCompressedTexSubImage2D to provide texels after allocation.)

    I'm guessing that the mipmap data needs to be in a compressed format as well. So, my question is, how do I generate the data I need to create the mipmaps of a compressed texture, and how do I then get that data into a format I can use with glCompressedTexImage2D?
    Yes. As to how to generate, depends on which compressed texture format you're talking about (which ones?). if you just want a solution for the common DXT compressed texture formats, websearch "squish simon brown". Read the links, download the library, and use it. There are other options out there as well.

Tags for this Thread

Posting Permissions

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