Power-of-two textures

Started by
6 comments, last by Matias Goldberg 17 years, 1 month ago
Is this limitation still in effect? I have a sprite sheet that is 300x300. Do I have to load it onto a texture that is 512x512? Or do I have to worry about this stuff anymore?
Advertisement
GL_ARB_texture_non_power_of_two allows you to use arbitrary dimensions as normal textures.
Quote:Original post by OrangyTang
GL_ARB_texture_non_power_of_two allows you to use arbitrary dimensions as normal textures.

Not that I have any useful information, but does this apply to a DirectX forum post? [wink]
There are ways around it, as mentioned, but generally yes you should use powers of 2 textures. Use the extra space in a 512x512 sprite sheet for extra stuff when you need it.
If your sprite sheet is 300x300, can't you move it around and make it e.g. 512x200, and then just expand that to 512x256?
Quote:Original post by jouley
Quote:Original post by OrangyTang
GL_ARB_texture_non_power_of_two allows you to use arbitrary dimensions as normal textures.

Not that I have any useful information, but does this apply to a DirectX forum post? [wink]

Haha, thats what I get for browsing Active Topics and the OpenGL forum at the same time.
Quote:Original post by Daniel Miller
Is this limitation still in effect? I have a sprite sheet that is 300x300. Do I have to load it onto a texture that is 512x512? Or do I have to worry about this stuff anymore?


It's entirely hardware dependent. Look at D3DCAPS9.TextureCaps at runtime to query the restrictions of the card in the machine your app is running on.

Look for D3DPTEXTURECAPS_POW2. If the card does not have that flag set, then the card supports textures with dimensions that are not powers of two.

If D3DPTEXTURECAPS_POW2 is set, the next thing to look for is D3DPTEXTURECAPS_NONPOW2CONDITIONAL. If both are set, then the card can handle textures with dimensions that aren't powers of two BUT there will be some conditions/restrictions on what you can do with those textures (such as only being able to use the clamp address mode - the docs for that cap explains them in full).

To see how widely supported features like those are, take a look at the Graphics Card Capabilities spreadsheet in the Sample Browser in the DirectX SDK.


Personally I'd save the hassle and ensure artwork was power-of-2 sized like Steve suggested (BTW: textures haven't needed to be square since the 3Dfx Voodoo2 days - so you can find memory efficient layouts with power-of-2).

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

To what S1CA said I have to add:

1) On some cards, using 300x300 (non-power-of-2) textures may result in slower performance, even than using 512x512 (power-of-2) textures.
2) It exists the posibility, that a poor card/driver informs incorrectly about it's power-of-2 capability, or implements it badly.

If you copy your 300x300 tex into a 512x512 tex, and adjust your tex coordinates to u=0.5859375f v=0.5859375f (300/512)
You will achieve higher speed than stretching your 300x300 to 512x512 and using u=1.0f v=1.0f
The only thing you will waste then would (by using u = 0.5859...) will be video memory, which will be, in the worst case, (512x512-300x300)*(32/8)= 688576 bytes = 672 KB (per texture)
That assumes you're using 32-bit textures (alpha included) but I don't think that more than 24 bits will be needed, which will make only 504 KB.
Anyway, like DrEvil said, "Use the extra space in a 512x512 sprite sheet for extra stuff when you need it."

Hope it helps
Dark Sylinc

This topic is closed to new replies.

Advertisement