1

我正在使用 SharpDX-Toolkit,无法在 Texture2D 上创建 mimap。如果我通过内容管理器加载纹理并尝试调用 GenerateMipMaps() 我收到 NotSupportedException:

无法为此纹理生成 mipmap(必须是 RenderTarget 和 ShaderResource 以及 MipLevels > 1

代码(在游戏类的 LoadContent-Method 中):

Texture2D texture = this.Content.Load<Texture2D>("MyTexture");
texture.GenerateMipMaps(this.GraphicsDevice); <- Exception thrown in this line

我不知道该怎么办,我希望任何人都可以帮助我解决这个问题。谢谢。

4

1 回答 1

3

使用:

 Texture2D texture = this.Content.Load<Texture2D>("MyTexture");

将默认纹理使用为“不可变”,并且只允许绑定为着色器视图。

为了生成 MipMaps,需要使用 Default 和 Binding 作为 ShaderView/RenderView。

现在你有几个选择:

1/使用 mipmap 将纹理预处理为 dds,加载程序会考虑到这一点。

TexConv可以为您做到这一点。(使用 -m 指定级别计数)。

2/如上加载你的纹理,使用创建第二个纹理

 Texture2D texturewithmips = Texture2D.New(device, texture.Width, texture.Height, MipMapCount.Auto, texture.Format,
 TextureFlags.ShaderResource | TextureFlags.RenderTarget,
 1,Direct3D11.ResourceUsage.Default);

现在你需要复制第一个 mip,使用:

device.Copy(texture, 0, null, t2, 0);

您现在可以使用:

t2.GenerateMipMaps(this.GraphicsDevice);

3/由于使用上述方法,您有点失去了内容管理器(为您提供自动缓存)。

您可以通过添加更多纹理加载选项来修改 TextureContentReader 类来为您执行此操作。

如果您需要更多帮助,请随意。

于 2013-11-07T18:27:29.483 回答