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

给你一囗甜甜゛ 提交于 2019-12-13 08:52:44

问题


I just want know Directx 12 API to create texture from image.

For DX11 it is D3DX11CreateShaderResourceViewFromFile and for DX9 it is D3DXCreateTextureFromFileEx and for DX12 ?


回答1:


Things are a little bit better by now. Microsoft rewrote their DDSTextureLoader for DX12 and released it as part of their MiniEngine on GitHub https://github.com/Microsoft/DirectX-Graphics-Samples/blob/master/MiniEngine/Core/DDSTextureLoader.cpp

You also may want to take a look at my derivative work that is intended to make use of the DDSTextureLoader a bit easier outside of MiniEngine. https://github.com/ClemensX/ShadedPath12/blob/master/ShadedPath12/ShadedPath12/DDSTextureLoader.cpp

I use this loader for all my texture files. It parses DDS (DirectDrawSurface) file format pretty well, including mipmaps.




回答2:


There isn't one.

Direct3D 12 is a low-level API. A very low-level API. It doesn't have convenience functions that create textures out of whole cloth from just a filename. If you want to create a texture, you have to work for it. You have to load the file, figure out what format you want it in, allocate memory for it by asking the system how much memory it would take, then go through a complex series of steps to transfer your loaded image into that memory.




回答3:


The official 'utility header' for Direct3D 12 is 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.

You can use the DDSTextureLoader and WICTextureLoader modules provided in the DirectX Tool Kit for DirectX 12 for some ready-to-use texture loader for Direct3D 12. See this tutorial lesson.

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.



来源:https://stackoverflow.com/questions/34494559/creating-a-texture-from-a-image-in-dx-12-vc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!