Mukesh Bharsakle
Mukesh Bharsakle

Reputation: 443

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

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 ?

Upvotes: 0

Views: 5862

Answers (4)

Goodies
Goodies

Reputation: 2069

Google keeps referring to this topic for questions around DX-12 and textures, so let's update.

1. Managed

If you insist on "managed" check out the samples with the last version of SharpDX (2019)

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

It provides a C# interface to DX-12 native and it works, there are a lot of very nice samples, including texturing,

  • 09-Crate loads a single DDS texture and shows it on a cube
  • 09-TexColumns shows basic UV-coordinate actions on various shapes

.. but IMHO it's not really advisable, to keep depending on the good old SharpDX library, because that library is not maintained anymore. I can't advise good alternatives for C# atm, I'm not an expert on Unity and Vulkan.

2. Unmanaged

As mentioned earlier in this topic, DX-12 things improve. They still do. Check out Chuck Walbourn's current samples here,

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

For straight PC/x64, you'll find this,

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

For PC/UWP, you'll find this,

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

These are very nice x64 unmanaged C++ 14.0 examples, using DirectXtk for DirectX-12. Last update in the Master was 3 months ago. Examples involving textures, also straight bitmap textures are

  • SimpleTexturePC12 loads a single .jpg texture and shows it in front view
  • DirectXTKSimpleSample12 loads several textures
  • Graphics\VideoTexturePC12 shows a dynamic texture read from an .mp4 video

These projects are configured for VS2017, but they convert out of the box when loading them in VS2019 and they compile and run ok.

Other sources

A known switchboard on DX-12 is vinjn on github, his page is

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

Navigate from there to study articles and find various other samples.

There is a 3dgep.com tutorial on the subject of DX12 textures, that is

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

.. accompanied by

https://github.com/jpvanoosten/LearningDirectX12

Upvotes: 0

Chuck Walbourn
Chuck Walbourn

Reputation: 41127

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.

Upvotes: 1

Clemens Fehr
Clemens Fehr

Reputation: 146

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.

Upvotes: 3

Nicol Bolas
Nicol Bolas

Reputation: 474436

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.

Upvotes: 1

Related Questions