从 DX12 中的图像创建纹理 VC++

Creating a texture from a image in DX 12 VC++

我只想知道 Directx 12 API 从图像创建纹理。

DX11 是 D3DX11CreateShaderResourceViewFromFile,DX9 是 D3DXCreateTextureFromFileEx,DX12 是?​​

没有。

Direct3D 12 是低级 API。一个非常低级API。它没有仅通过文件名从整块布料创建纹理的便捷功能。如果你想创建一个纹理,你必须为它工作。您必须加载文件,找出您想要的格式,通过询问系统需要多少内存来为其分配内存,然后通过一系列复杂的步骤将加载的图像传输到内存中。

现在情况好多了。微软为 DX12 重写了他们的 DDSTextureLoader,并在 GitHub 上作为他们的 MiniEngine 的一部分发布了它 https://github.com/Microsoft/DirectX-Graphics-Samples/blob/master/MiniEngine/Core/DDSTextureLoader.cpp

您可能还想看看我的衍生作品,它旨在让 DDSTextureLoader 在 MiniEngine 之外更容易使用。 https://github.com/ClemensX/ShadedPath12/blob/master/ShadedPath12/ShadedPath12/DDSTextureLoader.cpp

我将这个加载器用于我所有的纹理文件。它能很好地解析 DDS (DirectDrawSurface) 文件格式,包括 mipmap。

Direct3D 12 的官方 'utility header' 是 d3dx12.h. It's an inline header and has no DLL or static library, so the functionality provided is limited to true helpers. It has no equivalent to D3DX11CreateShaderResourceViewFromFile. It is not included as part of the Windows SDK, but instead is provided under the MIT license and you are expected to just copy it into your project--it's included in the various DirectX 12 Visual Studio templates including my Direct3D Game templates

您可以使用 DirectX Tool Kit for DirectX 12 for some ready-to-use texture loader for Direct3D 12. See this tutorial lesson 中提供的 DDSTextureLoaderWICTextureLoader 模块。

It's worth noting that D3DX9, D3DX10, and D3DX11 are all deprecated and only available as part of the legacy DirectX SDK per MSDN. In other words, you shouldn't be using D3DX11CreateShaderResourceViewFromFile for your Direct3D 11 code. See this blog post for a full list of D3DX9/10/11 replacements. TL;DR: use DDSTextureLoader and WICTextureLoader in DirectX Tool Kit for DirectX 11.

Google 关于 DX-12 和纹理的问题一直参考这个主题,所以让我们更新。

1.托管

如果您坚持“托管”,请使用最新版本的 SharpDX (2019) 查看示例

https://github.com/discosultan/dx12-game-programming

它为 DX-12 本机提供了一个 C# 接口并且可以正常工作,有很多非常好的示例,包括纹理,

  • 09-Crate 加载单个 DDS 纹理并将其显示在立方体上
  • 09-TexColumns 显示各种形状的基本 UV 坐标操作

.. 但恕我直言,继续依赖 good old SharpDX 库并不明智,因为该库是 not maintained anymore。我无法为 C# atm 推荐好的替代方案,我不是 Unity 和 Vulkan 方面的专家。

2。非托管

正如本主题前面提到的,DX-12 的改进。他们仍然这样做。在此处查看 Chuck Walbourn 的当前样本,

https://github.com/microsoft/Xbox-ATG-Samples

对于直线PC/x64,你会发现这个,

https://github.com/microsoft/Xbox-ATG-Samples/tree/master/PCSamples

对于PC/UWP,你会发现这个,

https://github.com/microsoft/Xbox-ATG-Samples/tree/master/UWPSamples

这些是非常好的 x64 非托管 C++ 14.0 示例,使用 DirectXtk for DirectX-12。 Master 的最后一次更新是 3 个月前。涉及纹理的例子,还有直接位图纹理是

  • SimpleTexturePC12 加载单个 .jpg 纹理并在前视图中显示它
  • DirectXTKSimpleSample12 加载多个纹理
  • Graphics\VideoTexturePC12 显示从 .mp4 视频中读取的动态纹理

这些项目是为 VS2017 配置的,但是当在 VS2019 中加载它们时它们会立即转换并编译并且 运行 ok。

其他来源

DX-12 上的一个已知总机是 vinjn on github,他的页面是

http://www.vinjn.com/awesome-d3d12/

从那里导航以研究文章并查找各种其他示例。

有一个3dgep.com关于DX12纹理的教程,那就是

https://www.3dgep.com/learning-directx-12-4/

..伴随着

https://github.com/jpvanoosten/LearningDirectX12