Textures: To the Power of 2 or Not to the ...

To the Power of 2 or Not to the power of two, that is the question.

Are there any GL functions that will let me make textures out of images with dimensions that are not to the power of 2 or do I need to scale them myself? If so, howso? (hehehe)

Look into the GL_NV_texture_rectangle extension.

From my experience, if you care for performance, use power-of-two textures.

Unless you use extensions, the hardware must create textures that are power of two in size. You can sub-image a smaller portion of that, but then you have to re-scale your texture coordinates (and tiling won’t work right).

The glu texture functions can accept images of arbitrary dimensions, but they don’t know about extensions (most notably ARB_texture_compression_s3tc and EXT_packed_pixels).

as in gluBuild2DMipmaps? I’ve heard the opposite from others…

The GLU functions “accept” images of arbitrary size. They then re-sample to a power of two, as described in the specification. The filter they use isn’t even all that good (it’s a box filter, implemented in a really slow way).

There’s gluScale() I think that gluBuildMipmaps() uses to scale to power of two before making the mip chain.

Texture rectangle is for NV I think + it’s slower, why bother, use good paint programs and rescale your image (professionaly ) and then use them, they are faster and runs everywhere! Even DX documentation says USE power of 2 textures for performance!

As a engine programmer i won’t suggest neither gluScaleImage nor gluBuild2DMipmaps.Usually the result from this two functions is unpredictable and it’s about 100 times faster and better if you add your own routines for mipmap building and image scaling.

Quick question. I saw some discussion on a mailing list recently about gamma correct mip-mapping.

I probably already know the answer to this, but I assume gluBuildMipMaps, and the SGIS_Auto_mipmap_thingymajig dont do gamma correct mip-mapping. Am I right?


I’d guess gluBuild2DMimaps() probably doesn’t. However, looking at the spec, SGIS_generate_mipmaps doesn’t actually say what algorithm is used to do the mipmapping (although it suggests a basic 2x2 box), also you can set hints (fastest, nicest) that might change the operation.


2 ideas:

  1. scale your image to the closest/larger power of 2 size (you can use gluScaleImage for this)
  2. create a texture with the closest/larger power of 2 and keep your image as part of this texture, and adjust the texture coordinates appropriately (ie. the right/bottom coords will not be (1, 1) anymore)

There are some other things to consider:

  • if you need to repeat your texture you’ll have to go with 1).
  • if you can use the second idea, you can combine multiple images inside a single, bigger texture (nice perf gain!)

Hope this helps,