mirror of
https://github.com/microsoft/DirectXTex
synced 2024-11-08 22:10:05 +00:00
Ex versions of DDSTextureLoader & WICTextureLoader for advanced / expert scenarios
This commit is contained in:
parent
7eec38846c
commit
1168867270
@ -138,7 +138,7 @@ inline HANDLE safe_handle( HANDLE h ) { return (h == INVALID_HANDLE_VALUE) ? 0 :
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
template<UINT TNameLength>
|
||||
inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_z_ const char (&name)[TNameLength])
|
||||
inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_ const char (&name)[TNameLength])
|
||||
{
|
||||
#if defined(_DEBUG) || defined(PROFILE)
|
||||
resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name);
|
||||
@ -727,7 +727,7 @@ static HRESULT FillInitData( _In_ size_t width,
|
||||
_Out_ size_t& theight,
|
||||
_Out_ size_t& tdepth,
|
||||
_Out_ size_t& skipMip,
|
||||
_Out_cap_(mipCount*arraySize) D3D11_SUBRESOURCE_DATA* initData )
|
||||
_Out_cap_x_(mipCount*arraySize) D3D11_SUBRESOURCE_DATA* initData )
|
||||
{
|
||||
if ( !bitData || !initData )
|
||||
return E_POINTER;
|
||||
@ -814,8 +814,12 @@ static HRESULT CreateD3DResources( _In_ ID3D11Device* d3dDevice,
|
||||
_In_ size_t mipCount,
|
||||
_In_ size_t arraySize,
|
||||
_In_ DXGI_FORMAT format,
|
||||
_In_ D3D11_USAGE usage,
|
||||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_In_ bool isCubeMap,
|
||||
_In_count_(mipCount*arraySize) D3D11_SUBRESOURCE_DATA* initData,
|
||||
_In_count_x_(mipCount*arraySize) D3D11_SUBRESOURCE_DATA* initData,
|
||||
_Out_opt_ ID3D11Resource** texture,
|
||||
_Out_opt_ ID3D11ShaderResourceView** textureView )
|
||||
{
|
||||
@ -833,10 +837,10 @@ static HRESULT CreateD3DResources( _In_ ID3D11Device* d3dDevice,
|
||||
desc.MipLevels = static_cast<UINT>( mipCount );
|
||||
desc.ArraySize = static_cast<UINT>( arraySize );
|
||||
desc.Format = format;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
desc.Usage = usage;
|
||||
desc.BindFlags = bindFlags;
|
||||
desc.CPUAccessFlags = cpuAccessFlags;
|
||||
desc.MiscFlags = miscFlags & ~D3D11_RESOURCE_MISC_TEXTURECUBE;
|
||||
|
||||
ID3D11Texture1D* tex = nullptr;
|
||||
hr = d3dDevice->CreateTexture1D( &desc,
|
||||
@ -897,10 +901,13 @@ static HRESULT CreateD3DResources( _In_ ID3D11Device* d3dDevice,
|
||||
desc.Format = format;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.SampleDesc.Quality = 0;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = (isCubeMap) ? D3D11_RESOURCE_MISC_TEXTURECUBE : 0;
|
||||
desc.Usage = usage;
|
||||
desc.BindFlags = bindFlags;
|
||||
desc.CPUAccessFlags = cpuAccessFlags;
|
||||
if ( isCubeMap )
|
||||
desc.MiscFlags = miscFlags | D3D11_RESOURCE_MISC_TEXTURECUBE;
|
||||
else
|
||||
desc.MiscFlags = miscFlags & ~D3D11_RESOURCE_MISC_TEXTURECUBE;
|
||||
|
||||
ID3D11Texture2D* tex = nullptr;
|
||||
hr = d3dDevice->CreateTexture2D( &desc,
|
||||
@ -975,10 +982,10 @@ static HRESULT CreateD3DResources( _In_ ID3D11Device* d3dDevice,
|
||||
desc.Depth = static_cast<UINT>( depth );
|
||||
desc.MipLevels = static_cast<UINT>( mipCount );
|
||||
desc.Format = format;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
desc.Usage = usage;
|
||||
desc.BindFlags = bindFlags;
|
||||
desc.CPUAccessFlags = cpuAccessFlags;
|
||||
desc.MiscFlags = miscFlags & ~D3D11_RESOURCE_MISC_TEXTURECUBE;
|
||||
|
||||
ID3D11Texture3D* tex = nullptr;
|
||||
hr = d3dDevice->CreateTexture3D( &desc,
|
||||
@ -1029,9 +1036,13 @@ static HRESULT CreateTextureFromDDS( _In_ ID3D11Device* d3dDevice,
|
||||
_In_ const DDS_HEADER* header,
|
||||
_In_bytecount_(bitSize) const uint8_t* bitData,
|
||||
_In_ size_t bitSize,
|
||||
_In_ size_t maxsize,
|
||||
_In_ D3D11_USAGE usage,
|
||||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_Out_opt_ ID3D11Resource** texture,
|
||||
_Out_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_In_ size_t maxsize )
|
||||
_Out_opt_ ID3D11ShaderResourceView** textureView )
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
@ -1204,7 +1215,9 @@ static HRESULT CreateTextureFromDDS( _In_ ID3D11Device* d3dDevice,
|
||||
|
||||
if ( SUCCEEDED(hr) )
|
||||
{
|
||||
hr = CreateD3DResources( d3dDevice, resDim, twidth, theight, tdepth, mipCount - skipMip, arraySize, format, isCubeMap, initData.get(), texture, textureView );
|
||||
hr = CreateD3DResources( d3dDevice, resDim, twidth, theight, tdepth, mipCount - skipMip, arraySize,
|
||||
format, usage, bindFlags, cpuAccessFlags, miscFlags,
|
||||
isCubeMap, initData.get(), texture, textureView );
|
||||
|
||||
if ( FAILED(hr) && !maxsize && (mipCount > 1) )
|
||||
{
|
||||
@ -1242,7 +1255,9 @@ static HRESULT CreateTextureFromDDS( _In_ ID3D11Device* d3dDevice,
|
||||
twidth, theight, tdepth, skipMip, initData.get() );
|
||||
if ( SUCCEEDED(hr) )
|
||||
{
|
||||
hr = CreateD3DResources( d3dDevice, resDim, twidth, theight, tdepth, mipCount - skipMip, arraySize, format, isCubeMap, initData.get(), texture, textureView );
|
||||
hr = CreateD3DResources( d3dDevice, resDim, twidth, theight, tdepth, mipCount - skipMip, arraySize,
|
||||
format, usage, bindFlags, cpuAccessFlags, miscFlags,
|
||||
isCubeMap, initData.get(), texture, textureView );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1257,6 +1272,22 @@ HRESULT DirectX::CreateDDSTextureFromMemory( _In_ ID3D11Device* d3dDevice,
|
||||
_Out_opt_ ID3D11Resource** texture,
|
||||
_Out_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_In_ size_t maxsize )
|
||||
{
|
||||
return CreateDDSTextureFromMemoryEx( d3dDevice, ddsData, ddsDataSize, maxsize,
|
||||
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0,
|
||||
texture, textureView );
|
||||
}
|
||||
|
||||
HRESULT DirectX::CreateDDSTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice,
|
||||
_In_bytecount_(ddsDataSize) const uint8_t* ddsData,
|
||||
_In_ size_t ddsDataSize,
|
||||
_In_ size_t maxsize,
|
||||
_In_ D3D11_USAGE usage,
|
||||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_Out_opt_ ID3D11Resource** texture,
|
||||
_Out_opt_ ID3D11ShaderResourceView** textureView )
|
||||
{
|
||||
if (!d3dDevice || !ddsData || (!texture && !textureView))
|
||||
{
|
||||
@ -1302,14 +1333,10 @@ HRESULT DirectX::CreateDDSTextureFromMemory( _In_ ID3D11Device* d3dDevice,
|
||||
+ sizeof( DDS_HEADER )
|
||||
+ (bDXT10Header ? sizeof( DDS_HEADER_DXT10 ) : 0);
|
||||
|
||||
HRESULT hr = CreateTextureFromDDS( d3dDevice,
|
||||
header,
|
||||
ddsData + offset,
|
||||
ddsDataSize - offset,
|
||||
texture,
|
||||
textureView,
|
||||
maxsize
|
||||
);
|
||||
HRESULT hr = CreateTextureFromDDS( d3dDevice, header,
|
||||
ddsData + offset, ddsDataSize - offset, maxsize,
|
||||
usage, bindFlags, cpuAccessFlags, miscFlags,
|
||||
texture, textureView );
|
||||
|
||||
if (texture != 0 && *texture != 0)
|
||||
{
|
||||
@ -1330,7 +1357,22 @@ HRESULT DirectX::CreateDDSTextureFromFile( _In_ ID3D11Device* d3dDevice,
|
||||
_Out_opt_ ID3D11Resource** texture,
|
||||
_Out_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_In_ size_t maxsize )
|
||||
{
|
||||
{
|
||||
return CreateDDSTextureFromFileEx( d3dDevice, fileName, maxsize,
|
||||
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0,
|
||||
texture, textureView );
|
||||
}
|
||||
|
||||
HRESULT DirectX::CreateDDSTextureFromFileEx( _In_ ID3D11Device* d3dDevice,
|
||||
_In_z_ const wchar_t* fileName,
|
||||
_In_ size_t maxsize,
|
||||
_In_ D3D11_USAGE usage,
|
||||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_Out_opt_ ID3D11Resource** texture,
|
||||
_Out_opt_ ID3D11ShaderResourceView** textureView )
|
||||
{
|
||||
if (!d3dDevice || !fileName || (!texture && !textureView))
|
||||
{
|
||||
return E_INVALIDARG;
|
||||
@ -1352,14 +1394,10 @@ HRESULT DirectX::CreateDDSTextureFromFile( _In_ ID3D11Device* d3dDevice,
|
||||
return hr;
|
||||
}
|
||||
|
||||
hr = CreateTextureFromDDS( d3dDevice,
|
||||
header,
|
||||
bitData,
|
||||
bitSize,
|
||||
texture,
|
||||
textureView,
|
||||
maxsize
|
||||
);
|
||||
hr = CreateTextureFromDDS( d3dDevice, header,
|
||||
bitData, bitSize, maxsize,
|
||||
usage, bindFlags, cpuAccessFlags, miscFlags,
|
||||
texture, textureView );
|
||||
|
||||
#if defined(_DEBUG) || defined(PROFILE)
|
||||
if (texture != 0 || textureView != 0)
|
||||
|
@ -45,4 +45,27 @@ namespace DirectX
|
||||
_Out_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_In_ size_t maxsize = 0
|
||||
);
|
||||
|
||||
HRESULT CreateDDSTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice,
|
||||
_In_bytecount_(ddsDataSize) const uint8_t* ddsData,
|
||||
_In_ size_t ddsDataSize,
|
||||
_In_ size_t maxsize,
|
||||
_In_ D3D11_USAGE usage,
|
||||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_Out_opt_ ID3D11Resource** texture,
|
||||
_Out_opt_ ID3D11ShaderResourceView** textureView
|
||||
);
|
||||
|
||||
HRESULT CreateDDSTextureFromFileEx( _In_ ID3D11Device* d3dDevice,
|
||||
_In_z_ const wchar_t* szFileName,
|
||||
_In_ size_t maxsize,
|
||||
_In_ D3D11_USAGE usage,
|
||||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_Out_opt_ ID3D11Resource** texture,
|
||||
_Out_opt_ ID3D11ShaderResourceView** textureView
|
||||
);
|
||||
}
|
@ -82,7 +82,7 @@ private:
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
template<UINT TNameLength>
|
||||
inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_z_ const char (&name)[TNameLength])
|
||||
inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_ const char (&name)[TNameLength])
|
||||
{
|
||||
#if defined(_DEBUG) || defined(PROFILE)
|
||||
resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name);
|
||||
@ -319,9 +319,13 @@ static size_t _WICBitsPerPixel( REFGUID targetGuid )
|
||||
static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice,
|
||||
_In_opt_ ID3D11DeviceContext* d3dContext,
|
||||
_In_ IWICBitmapFrameDecode *frame,
|
||||
_In_ size_t maxsize,
|
||||
_In_ D3D11_USAGE usage,
|
||||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_Out_opt_ ID3D11Resource** texture,
|
||||
_Out_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_In_ size_t maxsize )
|
||||
_Out_opt_ ID3D11ShaderResourceView** textureView )
|
||||
{
|
||||
UINT width, height;
|
||||
HRESULT hr = frame->GetSize( &width, &height );
|
||||
@ -568,10 +572,19 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice,
|
||||
desc.Format = format;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.SampleDesc.Quality = 0;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.BindFlags = (autogen) ? (D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET) : (D3D11_BIND_SHADER_RESOURCE);
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = (autogen) ? D3D11_RESOURCE_MISC_GENERATE_MIPS : 0;
|
||||
desc.Usage = usage;
|
||||
desc.CPUAccessFlags = cpuAccessFlags;
|
||||
|
||||
if ( autogen )
|
||||
{
|
||||
desc.BindFlags = bindFlags | D3D11_BIND_RENDER_TARGET;
|
||||
desc.MiscFlags = miscFlags | D3D11_RESOURCE_MISC_GENERATE_MIPS;
|
||||
}
|
||||
else
|
||||
{
|
||||
desc.BindFlags = bindFlags;
|
||||
desc.MiscFlags = miscFlags;
|
||||
}
|
||||
|
||||
D3D11_SUBRESOURCE_DATA initData;
|
||||
initData.pSysMem = temp.get();
|
||||
@ -626,8 +639,24 @@ HRESULT DirectX::CreateWICTextureFromMemory( _In_ ID3D11Device* d3dDevice,
|
||||
_In_ size_t wicDataSize,
|
||||
_Out_opt_ ID3D11Resource** texture,
|
||||
_Out_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_In_ size_t maxsize
|
||||
)
|
||||
_In_ size_t maxsize )
|
||||
{
|
||||
return CreateWICTextureFromMemoryEx( d3dDevice, d3dContext, wicData, wicDataSize, maxsize,
|
||||
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0,
|
||||
texture, textureView );
|
||||
}
|
||||
|
||||
HRESULT DirectX::CreateWICTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice,
|
||||
_In_opt_ ID3D11DeviceContext* d3dContext,
|
||||
_In_bytecount_(wicDataSize) const uint8_t* wicData,
|
||||
_In_ size_t wicDataSize,
|
||||
_In_ size_t maxsize,
|
||||
_In_ D3D11_USAGE usage,
|
||||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_Out_opt_ ID3D11Resource** texture,
|
||||
_Out_opt_ ID3D11ShaderResourceView** textureView )
|
||||
{
|
||||
if (!d3dDevice || !wicData || (!texture && !textureView))
|
||||
{
|
||||
@ -669,7 +698,9 @@ HRESULT DirectX::CreateWICTextureFromMemory( _In_ ID3D11Device* d3dDevice,
|
||||
if ( FAILED(hr) )
|
||||
return hr;
|
||||
|
||||
hr = CreateTextureFromWIC( d3dDevice, d3dContext, frame.Get(), texture, textureView, maxsize );
|
||||
hr = CreateTextureFromWIC( d3dDevice, d3dContext, frame.Get(), maxsize,
|
||||
usage, bindFlags, cpuAccessFlags, miscFlags,
|
||||
texture, textureView );
|
||||
if ( FAILED(hr))
|
||||
return hr;
|
||||
|
||||
@ -693,6 +724,22 @@ HRESULT DirectX::CreateWICTextureFromFile( _In_ ID3D11Device* d3dDevice,
|
||||
_Out_opt_ ID3D11Resource** texture,
|
||||
_Out_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_In_ size_t maxsize )
|
||||
{
|
||||
return CreateWICTextureFromFileEx( d3dDevice, d3dContext, fileName, maxsize,
|
||||
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0,
|
||||
texture, textureView );
|
||||
}
|
||||
|
||||
HRESULT DirectX::CreateWICTextureFromFileEx( _In_ ID3D11Device* d3dDevice,
|
||||
_In_opt_ ID3D11DeviceContext* d3dContext,
|
||||
_In_z_ const wchar_t* fileName,
|
||||
_In_ size_t maxsize,
|
||||
_In_ D3D11_USAGE usage,
|
||||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_Out_opt_ ID3D11Resource** texture,
|
||||
_Out_opt_ ID3D11ShaderResourceView** textureView )
|
||||
{
|
||||
if (!d3dDevice || !fileName || (!texture && !textureView))
|
||||
{
|
||||
@ -714,7 +761,9 @@ HRESULT DirectX::CreateWICTextureFromFile( _In_ ID3D11Device* d3dDevice,
|
||||
if ( FAILED(hr) )
|
||||
return hr;
|
||||
|
||||
hr = CreateTextureFromWIC( d3dDevice, d3dContext, frame.Get(), texture, textureView, maxsize );
|
||||
hr = CreateTextureFromWIC( d3dDevice, d3dContext, frame.Get(), maxsize,
|
||||
usage, bindFlags, cpuAccessFlags, miscFlags,
|
||||
texture, textureView );
|
||||
if ( FAILED(hr))
|
||||
return hr;
|
||||
|
||||
|
@ -58,4 +58,29 @@ namespace DirectX
|
||||
_Out_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_In_ size_t maxsize = 0
|
||||
);
|
||||
|
||||
HRESULT CreateWICTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice,
|
||||
_In_opt_ ID3D11DeviceContext* d3dContext,
|
||||
_In_bytecount_(wicDataSize) const uint8_t* wicData,
|
||||
_In_ size_t wicDataSize,
|
||||
_In_ size_t maxsize,
|
||||
_In_ D3D11_USAGE usage,
|
||||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_Out_opt_ ID3D11Resource** texture,
|
||||
_Out_opt_ ID3D11ShaderResourceView** textureView
|
||||
);
|
||||
|
||||
HRESULT CreateWICTextureFromFileEx( _In_ ID3D11Device* d3dDevice,
|
||||
_In_opt_ ID3D11DeviceContext* d3dContext,
|
||||
_In_z_ const wchar_t* szFileName,
|
||||
_In_ size_t maxsize,
|
||||
_In_ D3D11_USAGE usage,
|
||||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_Out_opt_ ID3D11Resource** texture,
|
||||
_Out_opt_ ID3D11ShaderResourceView** textureView
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user