Home > 计算机与 Internet > XNA:Load Texture from file with mipmaps

XNA:Load Texture from file with mipmaps

解决XNA加载纹理的Mipmap问题

原链接:http://social.msdn.microsoft.com/Forums/en-US/xnaframework/thread/ba28d14e-365b-4c00-b481-0fc65f31437c

Xengor wrote:

I have tried doing as Derek suggested:

TextureCreationParameters parameters = new TextureCreationParameters(0, 0, 0, 1, SurfaceFormat.Unknown, ResourceUsage.AutoGenerateMipMap, ResourcePool.Managed, Color.White, FilterOptions.None, FilterOptions.None);
newTex = Texture.FromFile(GraphicsManager.Default.Device, Settings.Default.TexturePath + lowerCaseFileName, parameters);

————————————A-N-T-I—G-F-W————————————————–

You do realise you’re setting the number of mipmaps to 1 with those parameters?

I’ve found the simplest way to deal with mipmaps is to use the .dds file format for  textures and generate the mipmaps as a pre-process using the DX SDK tools. That way you have full control over which textures have mipmaps, the formats of the textures, etc. This leaves the game code simpler and moves any conversion, mipmap generation, etc out of the run-time.

If you do want to create mipmaps when you load a texture use parameters like this:

TextureCreationParameters tcp = new TextureCreationParameters(
                0,
                0,
                0,
                0, // setting this to 0 causes mipmaps to be created
                SurfaceFormat.Unknown,
                ResourceUsage.None,
                ResourcePool.Managed,
                Color.White,
                FilterOptions.Triangle | FilterOptions.Dither,
                FilterOptions.Box);

Note, ResourceUsage.AutoGenerateMipMap is not used. AutoGenerateMipMap creates a texture that only has one mipmap level you can access and the others are auto generated – you might use this to auto generate mip maps for a render target or other dynamically generated texture.

Cheers,
Leaf.

Advertisements
Categories: 计算机与 Internet
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: