问题
Can you please help me in finding the equivalent DX12 API/sample code by which I could load a bitmap and create a texture ?
For DX11 it is D3DX11CreateShaderResourceViewFromFile
and for DX9 it is D3DXCreateTextureFromFileEx
回答1:
You can use the following functions from DirectXTK, as well as many other.
// Standard version
HRESULT __cdecl LoadWICTextureFromMemory(
_In_ ID3D12Device* d3dDevice,
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
size_t wicDataSize,
_Outptr_ ID3D12Resource** texture,
std::unique_ptr<uint8_t[]>& decodedData,
D3D12_SUBRESOURCE_DATA& subresource,
size_t maxsize = 0);
HRESULT __cdecl LoadWICTextureFromFile(
_In_ ID3D12Device* d3dDevice,
_In_z_ const wchar_t* szFileName,
_Outptr_ ID3D12Resource** texture,
std::unique_ptr<uint8_t[]>& decodedData,
D3D12_SUBRESOURCE_DATA& subresource,
size_t maxsize = 0);
Alternatively you can use Windows Imaging Component to write your own implementation, especially if you would like to have more control.
来源:https://stackoverflow.com/questions/34492720/how-to-create-a-texture-from-a-bitmap-file