What is the Filter at D3DXCreateTextureFromFileEx for?

Started by
6 comments, last by Dethtoll 17 years, 4 months ago
What is the Filter and MipFilter in the D3DXCreateTextureFromFileEx() use for? Plus how is it different from the sampler state filter. The flags used are different hence i thought they should be different? D3DXCreateTextureFromFileEx() uses such flags: D3DX_FILTER_LINEAR SamplerState uses such flags instead: D3DTEXF_LINEAR
Advertisement
The SamplerState specifies how the texture is filtered when it renders. The parameter to D3DXCreateTextureFromFileEx specifies how the texture is filtered after it is created but before it is returned, but this only happens if the texture is resized.
There are multiple filters.

The MIP filter specifies how the filtering is done for creating the mipmaps.

The other filter desperately needs to be documented. It's used for resizing. It is used if you specify a size other than what's on disk, or if you use default size and don't specify that non pow2 is okay, and the texture is not a power of 2 size.

For example, if you load a 48x48 texture, the load function will automatically make it a 64x64 texture, as it's the next pow2 size that's acceptable. If you specify a filter, it will use this filter to resize the image. This causes many people new to DirectX to complain of blurry textures when they load non pow2 textures. The texture is filtered when loaded, and filtered more when rendered, creating quite a blurry image. If you specify a filter of NONE, it will load the image as is into the upper left part of the texture, and fill the remainder of the texture with black (possibly, and most likely, transparent black if alpha is part of the format). You'll need to do more work to get accurate texture coordinates, but image quality will be better. Of course, you could just save the image as a pow2 size to begin with.
It should probably also be mentioned that many graphics cards support non-pow2 textures, and DirectX doesn't always round up to the next pow2 square size. From the SDK for D3DXCreateTextureFromFileEx():

Height
[in] Height, in pixels. If this value is zero or D3DX_DEFAULT, the dimensions are taken from the file and rounded up to a power of two. If the device supports non-power of 2 textures and D3DX_DEFAULT_NONPOW2 is sepcified, the size will not be rounded.
Quote:Original post by Dethtoll
It should probably also be mentioned that many graphics cards support non-pow2 textures, and DirectX doesn't always round up to the next pow2 square size.

I hinted at that ("or if you use default size and don't specify that non pow2 is okay"), but now that it's mentioned we should round out the discussion.

While most cards allow non pow2 textures, most of those only allow non pow2 conditional, which means no mips, no wrapping, no DXT textures, and cannot be looked up via a dependant texture read in pixel shader 1.x. Most cards also incur a speed hit when using these textures. They're good for title screens, backgrounds, and things of that nature, but not for general use.
Thanks alot guys, so that means any loaded texture will first go through the Loader Filter, then the sampler state filter when render.

Thus most textures when loaded will at the very least go through two filter?

Thanks alot
Only if they're scaled on load. Normally you'd make sure they don't need to be scaled, so the loading filter will not matter.
Quote:Original post by Namethatnobodyelsetook
While most cards allow non pow2 textures, most of those only allow non pow2 conditional, which means no mips, no wrapping, no DXT textures, and cannot be looked up via a dependant texture read in pixel shader 1.x. Most cards also incur a speed hit when using these textures. They're good for title screens, backgrounds, and things of that nature, but not for general use.


Thanks for the further clarification. I knew the 'no mips' condition was common, but wasn't aware of the wrapping and PS1.x limitations.

This topic is closed to new replies.

Advertisement