5

I am creating an OpenGL video player using Ffmpeg and all my videos aren't power of 2 (as they are normal video resolutions). It runs at fine fps with my nvidia card but I've found that it won't run on older ATI cards because they don't support non-power-of-two textures.

I will only be using this on an Nvidia card so I don't really care about the ATI problem too much but I was wondering how much of a performance boost I'd get if the textuers were power-of-2? Is it worth padding them out?

Also, if it is worth it, how do I go about padding them out to the nearest larger power-of-two?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Infiniti Fizz
  • 1,726
  • 4
  • 24
  • 40

1 Answers1

3

Writing a video player you should update your texture content using glTexSubImage2D(). This function allows you to supply arbitarily sized images, that will be placed somewhere in the target texture. So you can initialize the texture first with a call of glTexImage() with the data pointer being NULL, then fill in the data.

The performance gain of pure power of 2 textures strongly depends on the hardware used, but in extreme cases it may be up to 300%.

genpfault
  • 51,148
  • 11
  • 85
  • 139
datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • Okay, I am already using glTexSubImage2D() like you say but when I init the texture with glTexImage2D() should I create it as a power of two and then sort out the glTexCoord2f() calls to only show the video "part" of the texture for maximum efficiency? – Infiniti Fizz Sep 01 '11 at 09:12
  • It largely depends on your OpenGL implementation (read GPU). All the recent GPUs have a only very small performance hit for NPO2 – datenwolf Sep 01 '11 at 09:39
  • Efficiency does not have to do do with rendering performance, but memory usage. So if I do not use power of two textures, will the driver round it up to nearest power of two, thus wasting memory? – user877329 Jul 08 '19 at 18:15
  • @user877329: No, it won't upscale. Yes, you're right that these days memory bandwidth is the major concern. However when the pow2 constraint was set (early 1990-ies), the circuitry/codepaths to support mipmapping and downscaling from arbitrary resolutions were prohibitively expensive. However if you compare the corner case of (2\*\*x) vs. (2\*\*x)-1 the slowdown still is noticeable, albeit 8 years later nowhere near as bad as a decade ago. – datenwolf Jul 08 '19 at 18:33
  • @datenwolf Another choice than upscaling (which is a bad idea, being computational intensive) is zero-padding and modifying recalculating UV-coordinates. – user877329 Jul 08 '19 at 18:43
  • 1
    @user877329: Doesn't work for wrap repeating texture application though (even if you jump over the gap by adjusting the texture coordinates in the shader, there'll still be a filtering discontinuity). – datenwolf Jul 08 '19 at 20:05