Jump to content
  • Advertisement
Sign in to follow this  
stenny

Textures and their multiple of 2 rule (Widths and Heights)

This topic is 4322 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I'll cut straight to the chase. I always thought a texture's with and height had to be a multiple of two, because that'd increase the speed drasticly. But now I played a bit with the IDirect3DTexture9 and I'm beginning to think DirectX automaticly sets Texture's width and height to the nearest multiple of two. Is this true? -Stenny (So: e.g. If I load an image of 129 x 127 DirectX automaticly sets it's width and height to 128x128)

Share this post


Link to post
Share on other sites
Advertisement
I'd say loading an image of 129x127 would automatically set its size to 256x128, wasting a lot of texture memory.
It's true that most graphics cards can currently handle non power-of-two textures. However, this often comes with either loss of performance, waste of memory, or both.
Although the graphics API accept it, I think you're still better off when using power-of-two sized textures. You have all the control, and not the pain.

Share this post


Link to post
Share on other sites
Hmm...Well it's for a tilesystem. Is there a way around (like, another COM object or something)?
Otherwise it isn't thát of a problem, but it'd take up less space when I don't have to make sure all tilesets have a multiple-of-2-width-and-height.

-Stenny

Share this post


Link to post
Share on other sites
1) DirectX does handle non-power-of-2 textures, but there are a number of problems with it. I don't want to get into all the specific problems, but some of them could become serious issues, such as blurrning, not being able to use MIRROR or WRAP addressing modes, and problems with color-keying and alphatesting.

2) You mention tilesets, which pretty much frees you of these problems. You'd most likely want to use a tilesheet (one texture with several different tiles on it one next to eachother). Other than the performance benifits this gives you, you also won't be limited in the size of each tile on the tile-sheet, and only by it's total size. This would reduce any wasted memory, if any, to a minimum.

Hope this helps.

Share this post


Link to post
Share on other sites
Quote:
2) You mention tilesets, which pretty much frees you of these problems. You'd most likely want to use a tilesheet (one texture with several different tiles on it one next to eachother). Other than the performance benifits this gives you, you also won't be limited in the size of each tile on the tile-sheet, and only by it's total size. This would reduce any wasted memory, if any, to a minimum.


Yes, I'm using tilesheets yes. So I just have to make sure the total width and height of my tilesheet (all the widths and heights together) are a multiple of 2.

Share this post


Link to post
Share on other sites
Quote:
Original post by stenny
So I just have to make sure the total width and height of my tilesheet (all the widths and heights together) are a multiple of 2.

No, not multiple of two, power of two (ie. 2^n, or 2, 4, 8, 16, 32, 64, 128, 256, 512, etc. etc.).

Share this post


Link to post
Share on other sites
If you use D3DX_DEFAULT_NONPOW2 in D3DXCreateTextureFromFileEx, the texture won't be scaled.

As for non-power-of-2 textures, D3D doesn't have any limitation there -- it's a matter of the graphics cards. Some cards don't limit this at all, and some allow it with limitations (described on the D3DCAPS9 page under D3DPTEXTURECAPS_NONPOW2CONDITIONAL). You can check the caps for what support cards have for this. All cards today support textures which aren't power or 2 (most in the conditional form).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!