Udostępnij za pośrednictwem


Notes on porting to DirectX 11.1: Textures

Screenshot of the Crate demo app from Frank Luna's 'Introduction to 3D Game Programming with DirectX'.

Previously: Notes on porting to DirectX 11.1 from earlier versions

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:

    • DirectXTK library (runtime), CreateXXXTextureFromFile (where XXX is DDS or WIC)
    • DirectXTex library (tools), LoadFromXXXFile (where XXX is WIC, DDS, or TGA; WIC doesn't support DDS and TGA; D3DX 9 supported TGA as a common art source format for games) then CreateTexture

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.

Technorati Tags: DirectX,Windows,Windows 8,Windows programming,Windows SDK