Saturday, December 15, 2018

opengl - Should I use textures not sized to a power of 2?


In the early days of OpenGL and DirectX, texture sizes were required to be powers of two. This meant interpolation of float values could be done very quickly, using shifting and such.


Since OpenGL 2.0 (and preceding that, via an extension) non-power-of-two texture dimensions have been supported.


Do power-of-two textures have performance advantages on modern integrated and discrete GPUs? What advantages do non-power-of-two textures have?


Does a significant desktop population have cards supporting non-power-of-two textures?



Answer



Are there performance advantages to sticking to power-of-two textures on modern integrated and discrete GPUs?



Most of modern GPUs support non-power of two (NPOT) textures and handle them well. Performance drop is quite little. But there are few problems to consider:




  • When using NPOT texture it takes more space in RAM, just like next-sized POT texture. Technically you just waste the space that could be used to put something in there;




  • NPOT textures may be handled noticeably slower (in OpenGL 2.1 I had up to 30% performance drop) compared to POT of next size;




  • Older GPUs and on-board/on-chip GPUs are not so advanced, they often support NPOT textures, but support is quite slow and clumsy;





  • Even older GPUs may refuse to accept/display NPOT textures at all;




  • There could be edging artifacts caused by mip-map interpolation, your 25x25 texture might have a black fringe where pixels were added to stuff it to 32x32 size.




P.S. I don't know for sure about mobile devices, there might be even more restrictions regarding POT textures.


What advantages do non-power-of-two textures have, if any?



As far as I know there are only 2 advantages:



  • They take less space on HDD if they are not packed (when packed empty areas give very little add)

  • You can save time on writing NPOT -> POT converter. You will need one for release version, but using NPOT textures for designing and prototyping interface / models is just fine


Are there large populations of desktop users who don't have cards that support non-power-of-two textures?


As far as I know and tested on PC - Yes. That includes major percentage of speed-drop / minor bugs GPUs and minor percentage of cards that won't handle NPOT at all.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...