Notes on porting to DirectX 11.1: Textures
A lot changed between DX11 and DX11.1, and texture processing is a big part of the delta. As you may know, the D3DX utility library is gone, replaced by external shared source libraries.
The docs for handy texture utilities like D3DX11CreateShaderResourceViewFromFile say this:
Instead of using this function, we recommend that you use these:
I’ve opted for DirectXTex, just because it’s owned by Chuck Walbourn, so it’s a companion to his Effects11 library. For best runtime performance, Chuck suggests using the DirectXTK library.
To port the sample code in chapter 8 of Frank Luna’s book to DX11.1, I compiled the DirectXTex library and dropped the DirectXTex.h, DirectXTex.inl, and DirectXTex.lib files into the Common directory.
In Frank’s Crate demo, the CrateApp::Init() method loads a texture by using the now-unavailable D3DX11CreateShaderResourceViewFromFile function:
HR(D3DX11CreateShaderResourceViewFromFile(md3dDevice, L"Textures/WoodCrate01.dds", 0, 0, &mDiffuseMapSRV, 0 ));
This call gets replaced by:
TexMetadata imageMetadata; ScratchImage* pScratchImage = new ScratchImage(); HR( LoadFromDDSFile( L"Textures/WoodCrate01.dds", DDS_FLAGS_NONE, &imageMetadata, *pScratchImage ) ); HR( CreateShaderResourceView( md3dDevice, pScratchImage->GetImages(), pScratchImage->GetImageCount(), imageMetadata, &mDiffuseMapSRV ) );
Everything else works as expected.