简体   繁体   English

如何在SharpDX Toolkit(2.5)中创建MipMaps

[英]How to create MipMaps in SharpDX Toolkit (2.5)

i am using the SharpDX-Toolkit and can not create mimaps on a Texture2D. 我正在使用SharpDX-Toolkit,无法在Texture2D上创建mimap。 If i load a texture by the content manager and try to call GenerateMipMaps() i receive a NotSupportedException: 如果我由内容管理器加载纹理并尝试调用GenerateMipMaps(),则会收到NotSupportedException:

Cannot generate mipmaps for this texture (Must be RenderTarget and ShaderResource and MipLevels > 1 无法为此纹理生成Mipmap(必须为RenderTarget和ShaderResource,且MipLevels> 1

Code (in LoadContent-Method of the Game-Class): 代码(在GameClass的LoadContent-Method中):

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

I don't know what to do and i hope anyone can help me with this issue. 我不知道该怎么办,希望有人能帮助我解决这个问题。 Thanks. 谢谢。

Using: 使用:

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

Will default texture usage to "Immutable" and will only allow binding as Shader View. 将默认的纹理用法设置为“不可变”,并且仅将绑定作为“着色器视图”使用。

In order to generate MipMaps, usage needs to be Default and Binding as both ShaderView/RenderView. 为了生成MipMap,需要将“用法”设置为“默认”并绑定为ShaderView / RenderView。

Now you have a few options: 现在您有几个选择:

1/Preprocess your textures as dds with mipmaps, loader would take this into account. 1 /使用mipmaps将纹理预处理为dds,加载程序会将此考虑在内。

TexConv can do that for you. TexConv可以为您做到这一点。 (use -m to specify level count). (使用-m指定级别计数)。

2/Load your texture as above, create a second texture using 2 /如上所述加载纹理,使用创建第二个纹理

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

Now you need to copy the first mip, using : 现在,您需要使用复制第一个Mip:

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

You can now use : 您现在可以使用:

t2.GenerateMipMaps(this.GraphicsDevice);

3/Since with method above you kinda lose the content manager (with auto caches for you). 3 /由于使用上述方法,您可能会丢失内容管理器(为您提供自动缓存)。

You can modify the TextureContentReader class to do that for you, by adding more options for texture loading. 您可以通过添加更多纹理加载选项来修改TextureContentReader类来为您做到这一点。

If you need more help feel free. 如果您需要更多帮助,请随时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM