mirror of
https://github.com/microsoft/DirectXTex.git
synced 2025-07-14 06:00:14 +02:00
Added DDSTextureLoader for DX12
This commit is contained in:
parent
0f75b5d268
commit
5278803345
@ -121,34 +121,31 @@ struct DDS_HEADER_DXT10
|
|||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
struct handle_closer { void operator()(HANDLE h) { if (h) CloseHandle(h); } };
|
||||||
|
|
||||||
struct handle_closer { void operator()(HANDLE h) { if (h) CloseHandle(h); } };
|
typedef public std::unique_ptr<void, handle_closer> ScopedHandle;
|
||||||
|
|
||||||
typedef public std::unique_ptr<void, handle_closer> ScopedHandle;
|
inline HANDLE safe_handle( HANDLE h ) { return (h == INVALID_HANDLE_VALUE) ? 0 : h; }
|
||||||
|
|
||||||
inline HANDLE safe_handle( HANDLE h ) { return (h == INVALID_HANDLE_VALUE) ? 0 : h; }
|
template<UINT TNameLength>
|
||||||
|
inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_ const char (&name)[TNameLength])
|
||||||
template<UINT TNameLength>
|
{
|
||||||
inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_ const char (&name)[TNameLength])
|
#if defined(_DEBUG) || defined(PROFILE)
|
||||||
{
|
|
||||||
#if defined(_DEBUG) || defined(PROFILE)
|
|
||||||
resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name);
|
resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name);
|
||||||
#else
|
#else
|
||||||
UNREFERENCED_PARAMETER(resource);
|
UNREFERENCED_PARAMETER(resource);
|
||||||
UNREFERENCED_PARAMETER(name);
|
UNREFERENCED_PARAMETER(name);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
//--------------------------------------------------------------------------------------
|
||||||
|
HRESULT LoadTextureDataFromFile(
|
||||||
//--------------------------------------------------------------------------------------
|
_In_z_ const wchar_t* fileName,
|
||||||
static HRESULT LoadTextureDataFromFile( _In_z_ const wchar_t* fileName,
|
|
||||||
std::unique_ptr<uint8_t[]>& ddsData,
|
std::unique_ptr<uint8_t[]>& ddsData,
|
||||||
DDS_HEADER** header,
|
DDS_HEADER** header,
|
||||||
uint8_t** bitData,
|
uint8_t** bitData,
|
||||||
size_t* bitSize
|
size_t* bitSize)
|
||||||
)
|
{
|
||||||
{
|
|
||||||
if (!header || !bitData || !bitSize)
|
if (!header || !bitData || !bitSize)
|
||||||
{
|
{
|
||||||
return E_POINTER;
|
return E_POINTER;
|
||||||
@ -177,33 +174,26 @@ static HRESULT LoadTextureDataFromFile( _In_z_ const wchar_t* fileName,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the file size
|
// Get the file size
|
||||||
LARGE_INTEGER FileSize = { 0 };
|
|
||||||
|
|
||||||
#if (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
|
|
||||||
FILE_STANDARD_INFO fileInfo;
|
FILE_STANDARD_INFO fileInfo;
|
||||||
if ( !GetFileInformationByHandleEx( hFile.get(), FileStandardInfo, &fileInfo, sizeof(fileInfo) ) )
|
if ( !GetFileInformationByHandleEx( hFile.get(), FileStandardInfo, &fileInfo, sizeof(fileInfo) ) )
|
||||||
{
|
{
|
||||||
return HRESULT_FROM_WIN32( GetLastError() );
|
return HRESULT_FROM_WIN32( GetLastError() );
|
||||||
}
|
}
|
||||||
FileSize = fileInfo.EndOfFile;
|
|
||||||
#else
|
|
||||||
GetFileSizeEx( hFile.get(), &FileSize );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// File is too big for 32-bit allocation, so reject read
|
// File is too big for 32-bit allocation, so reject read
|
||||||
if (FileSize.HighPart > 0)
|
if (fileInfo.EndOfFile.HighPart > 0)
|
||||||
{
|
{
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need at least enough data to fill the header and magic number to be a valid DDS
|
// Need at least enough data to fill the header and magic number to be a valid DDS
|
||||||
if (FileSize.LowPart < ( sizeof(DDS_HEADER) + sizeof(uint32_t) ) )
|
if (fileInfo.EndOfFile.LowPart < ( sizeof(DDS_HEADER) + sizeof(uint32_t) ) )
|
||||||
{
|
{
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create enough space for the file data
|
// create enough space for the file data
|
||||||
ddsData.reset( new (std::nothrow) uint8_t[ FileSize.LowPart ] );
|
ddsData.reset( new (std::nothrow) uint8_t[fileInfo.EndOfFile.LowPart ] );
|
||||||
if (!ddsData)
|
if (!ddsData)
|
||||||
{
|
{
|
||||||
return E_OUTOFMEMORY;
|
return E_OUTOFMEMORY;
|
||||||
@ -213,7 +203,7 @@ static HRESULT LoadTextureDataFromFile( _In_z_ const wchar_t* fileName,
|
|||||||
DWORD BytesRead = 0;
|
DWORD BytesRead = 0;
|
||||||
if (!ReadFile( hFile.get(),
|
if (!ReadFile( hFile.get(),
|
||||||
ddsData.get(),
|
ddsData.get(),
|
||||||
FileSize.LowPart,
|
fileInfo.EndOfFile.LowPart,
|
||||||
&BytesRead,
|
&BytesRead,
|
||||||
nullptr
|
nullptr
|
||||||
))
|
))
|
||||||
@ -221,7 +211,7 @@ static HRESULT LoadTextureDataFromFile( _In_z_ const wchar_t* fileName,
|
|||||||
return HRESULT_FROM_WIN32( GetLastError() );
|
return HRESULT_FROM_WIN32( GetLastError() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BytesRead < FileSize.LowPart)
|
if (BytesRead < fileInfo.EndOfFile.LowPart)
|
||||||
{
|
{
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
@ -248,7 +238,7 @@ static HRESULT LoadTextureDataFromFile( _In_z_ const wchar_t* fileName,
|
|||||||
(MAKEFOURCC( 'D', 'X', '1', '0' ) == hdr->ddspf.fourCC))
|
(MAKEFOURCC( 'D', 'X', '1', '0' ) == hdr->ddspf.fourCC))
|
||||||
{
|
{
|
||||||
// Must be long enough for both headers and magic value
|
// Must be long enough for both headers and magic value
|
||||||
if (FileSize.LowPart < ( sizeof(DDS_HEADER) + sizeof(uint32_t) + sizeof(DDS_HEADER_DXT10) ) )
|
if (fileInfo.EndOfFile.LowPart < ( sizeof(DDS_HEADER) + sizeof(uint32_t) + sizeof(DDS_HEADER_DXT10) ) )
|
||||||
{
|
{
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
@ -261,17 +251,17 @@ static HRESULT LoadTextureDataFromFile( _In_z_ const wchar_t* fileName,
|
|||||||
ptrdiff_t offset = sizeof( uint32_t ) + sizeof( DDS_HEADER )
|
ptrdiff_t offset = sizeof( uint32_t ) + sizeof( DDS_HEADER )
|
||||||
+ (bDXT10Header ? sizeof( DDS_HEADER_DXT10 ) : 0);
|
+ (bDXT10Header ? sizeof( DDS_HEADER_DXT10 ) : 0);
|
||||||
*bitData = ddsData.get() + offset;
|
*bitData = ddsData.get() + offset;
|
||||||
*bitSize = FileSize.LowPart - offset;
|
*bitSize = fileInfo.EndOfFile.LowPart - offset;
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
// Return the BPP for a particular format
|
// Return the BPP for a particular format
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
static size_t BitsPerPixel( _In_ DXGI_FORMAT fmt )
|
size_t BitsPerPixel( _In_ DXGI_FORMAT fmt )
|
||||||
{
|
{
|
||||||
switch( fmt )
|
switch( fmt )
|
||||||
{
|
{
|
||||||
case DXGI_FORMAT_R32G32B32A32_TYPELESS:
|
case DXGI_FORMAT_R32G32B32A32_TYPELESS:
|
||||||
@ -414,19 +404,20 @@ static size_t BitsPerPixel( _In_ DXGI_FORMAT fmt )
|
|||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
// Get surface information for a particular format
|
// Get surface information for a particular format
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
static void GetSurfaceInfo( _In_ size_t width,
|
void GetSurfaceInfo(
|
||||||
|
_In_ size_t width,
|
||||||
_In_ size_t height,
|
_In_ size_t height,
|
||||||
_In_ DXGI_FORMAT fmt,
|
_In_ DXGI_FORMAT fmt,
|
||||||
_Out_opt_ size_t* outNumBytes,
|
size_t* outNumBytes,
|
||||||
_Out_opt_ size_t* outRowBytes,
|
_Out_opt_ size_t* outRowBytes,
|
||||||
_Out_opt_ size_t* outNumRows )
|
_Out_opt_ size_t* outNumRows )
|
||||||
{
|
{
|
||||||
size_t numBytes = 0;
|
size_t numBytes = 0;
|
||||||
size_t rowBytes = 0;
|
size_t rowBytes = 0;
|
||||||
size_t numRows = 0;
|
size_t numRows = 0;
|
||||||
@ -546,14 +537,14 @@ static void GetSurfaceInfo( _In_ size_t width,
|
|||||||
{
|
{
|
||||||
*outNumRows = numRows;
|
*outNumRows = numRows;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
#define ISBITMASK( r,g,b,a ) ( ddpf.RBitMask == r && ddpf.GBitMask == g && ddpf.BBitMask == b && ddpf.ABitMask == a )
|
#define ISBITMASK( r,g,b,a ) ( ddpf.RBitMask == r && ddpf.GBitMask == g && ddpf.BBitMask == b && ddpf.ABitMask == a )
|
||||||
|
|
||||||
static DXGI_FORMAT GetDXGIFormat( const DDS_PIXELFORMAT& ddpf )
|
DXGI_FORMAT GetDXGIFormat( const DDS_PIXELFORMAT& ddpf )
|
||||||
{
|
{
|
||||||
if (ddpf.flags & DDS_RGB)
|
if (ddpf.flags & DDS_RGB)
|
||||||
{
|
{
|
||||||
// Note that sRGB formats are written using the "DX10" extended header
|
// Note that sRGB formats are written using the "DX10" extended header
|
||||||
@ -784,12 +775,12 @@ static DXGI_FORMAT GetDXGIFormat( const DDS_PIXELFORMAT& ddpf )
|
|||||||
}
|
}
|
||||||
|
|
||||||
return DXGI_FORMAT_UNKNOWN;
|
return DXGI_FORMAT_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
static DXGI_FORMAT MakeSRGB( _In_ DXGI_FORMAT format )
|
DXGI_FORMAT MakeSRGB( _In_ DXGI_FORMAT format )
|
||||||
{
|
{
|
||||||
switch( format )
|
switch( format )
|
||||||
{
|
{
|
||||||
case DXGI_FORMAT_R8G8B8A8_UNORM:
|
case DXGI_FORMAT_R8G8B8A8_UNORM:
|
||||||
@ -816,11 +807,12 @@ static DXGI_FORMAT MakeSRGB( _In_ DXGI_FORMAT format )
|
|||||||
default:
|
default:
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
static HRESULT FillInitData( _In_ size_t width,
|
HRESULT FillInitData(
|
||||||
|
_In_ size_t width,
|
||||||
_In_ size_t height,
|
_In_ size_t height,
|
||||||
_In_ size_t depth,
|
_In_ size_t depth,
|
||||||
_In_ size_t mipCount,
|
_In_ size_t mipCount,
|
||||||
@ -834,7 +826,7 @@ static HRESULT FillInitData( _In_ size_t width,
|
|||||||
_Out_ size_t& tdepth,
|
_Out_ size_t& tdepth,
|
||||||
_Out_ size_t& skipMip,
|
_Out_ size_t& skipMip,
|
||||||
_Out_writes_(mipCount*arraySize) D3D11_SUBRESOURCE_DATA* initData )
|
_Out_writes_(mipCount*arraySize) D3D11_SUBRESOURCE_DATA* initData )
|
||||||
{
|
{
|
||||||
if ( !bitData || !initData )
|
if ( !bitData || !initData )
|
||||||
{
|
{
|
||||||
return E_POINTER;
|
return E_POINTER;
|
||||||
@ -914,11 +906,12 @@ static HRESULT FillInitData( _In_ size_t width,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (index > 0) ? S_OK : E_FAIL;
|
return (index > 0) ? S_OK : E_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
static HRESULT CreateD3DResources( _In_ ID3D11Device* d3dDevice,
|
HRESULT CreateD3DResources(
|
||||||
|
_In_ ID3D11Device* d3dDevice,
|
||||||
_In_ uint32_t resDim,
|
_In_ uint32_t resDim,
|
||||||
_In_ size_t width,
|
_In_ size_t width,
|
||||||
_In_ size_t height,
|
_In_ size_t height,
|
||||||
@ -935,7 +928,7 @@ static HRESULT CreateD3DResources( _In_ ID3D11Device* d3dDevice,
|
|||||||
_In_reads_opt_(mipCount*arraySize) D3D11_SUBRESOURCE_DATA* initData,
|
_In_reads_opt_(mipCount*arraySize) D3D11_SUBRESOURCE_DATA* initData,
|
||||||
_Outptr_opt_ ID3D11Resource** texture,
|
_Outptr_opt_ ID3D11Resource** texture,
|
||||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView )
|
_Outptr_opt_ ID3D11ShaderResourceView** textureView )
|
||||||
{
|
{
|
||||||
if ( !d3dDevice )
|
if ( !d3dDevice )
|
||||||
return E_POINTER;
|
return E_POINTER;
|
||||||
|
|
||||||
@ -1148,11 +1141,12 @@ static HRESULT CreateD3DResources( _In_ ID3D11Device* d3dDevice,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
static HRESULT CreateTextureFromDDS( _In_ ID3D11Device* d3dDevice,
|
HRESULT CreateTextureFromDDS(
|
||||||
|
_In_ ID3D11Device* d3dDevice,
|
||||||
_In_opt_ ID3D11DeviceContext* d3dContext,
|
_In_opt_ ID3D11DeviceContext* d3dContext,
|
||||||
_In_ const DDS_HEADER* header,
|
_In_ const DDS_HEADER* header,
|
||||||
_In_reads_bytes_(bitSize) const uint8_t* bitData,
|
_In_reads_bytes_(bitSize) const uint8_t* bitData,
|
||||||
@ -1165,7 +1159,7 @@ static HRESULT CreateTextureFromDDS( _In_ ID3D11Device* d3dDevice,
|
|||||||
_In_ bool forceSRGB,
|
_In_ bool forceSRGB,
|
||||||
_Outptr_opt_ ID3D11Resource** texture,
|
_Outptr_opt_ ID3D11Resource** texture,
|
||||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView )
|
_Outptr_opt_ ID3D11ShaderResourceView** textureView )
|
||||||
{
|
{
|
||||||
HRESULT hr = S_OK;
|
HRESULT hr = S_OK;
|
||||||
|
|
||||||
UINT width = header->width;
|
UINT width = header->width;
|
||||||
@ -1499,12 +1493,12 @@ static HRESULT CreateTextureFromDDS( _In_ ID3D11Device* d3dDevice,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
static DDS_ALPHA_MODE GetAlphaMode( _In_ const DDS_HEADER* header )
|
DDS_ALPHA_MODE GetAlphaMode( _In_ const DDS_HEADER* header )
|
||||||
{
|
{
|
||||||
if ( header->ddspf.flags & DDS_FOURCC )
|
if ( header->ddspf.flags & DDS_FOURCC )
|
||||||
{
|
{
|
||||||
if ( MAKEFOURCC( 'D', 'X', '1', '0' ) == header->ddspf.fourCC )
|
if ( MAKEFOURCC( 'D', 'X', '1', '0' ) == header->ddspf.fourCC )
|
||||||
@ -1528,8 +1522,8 @@ static DDS_ALPHA_MODE GetAlphaMode( _In_ const DDS_HEADER* header )
|
|||||||
}
|
}
|
||||||
|
|
||||||
return DDS_ALPHA_MODE_UNKNOWN;
|
return DDS_ALPHA_MODE_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
_Use_decl_annotations_
|
_Use_decl_annotations_
|
||||||
|
@ -36,45 +36,46 @@ namespace DirectX
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Standard version
|
// Standard version
|
||||||
HRESULT CreateDDSTextureFromMemory( _In_ ID3D11Device* d3dDevice,
|
HRESULT CreateDDSTextureFromMemory(
|
||||||
|
_In_ ID3D11Device* d3dDevice,
|
||||||
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
||||||
_In_ size_t ddsDataSize,
|
_In_ size_t ddsDataSize,
|
||||||
_Outptr_opt_ ID3D11Resource** texture,
|
_Outptr_opt_ ID3D11Resource** texture,
|
||||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||||
_In_ size_t maxsize = 0,
|
_In_ size_t maxsize = 0,
|
||||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
|
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
|
||||||
);
|
|
||||||
|
|
||||||
HRESULT CreateDDSTextureFromFile( _In_ ID3D11Device* d3dDevice,
|
HRESULT CreateDDSTextureFromFile(
|
||||||
|
_In_ ID3D11Device* d3dDevice,
|
||||||
_In_z_ const wchar_t* szFileName,
|
_In_z_ const wchar_t* szFileName,
|
||||||
_Outptr_opt_ ID3D11Resource** texture,
|
_Outptr_opt_ ID3D11Resource** texture,
|
||||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||||
_In_ size_t maxsize = 0,
|
_In_ size_t maxsize = 0,
|
||||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
|
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
|
||||||
);
|
|
||||||
|
|
||||||
// Standard version with optional auto-gen mipmap support
|
// Standard version with optional auto-gen mipmap support
|
||||||
HRESULT CreateDDSTextureFromMemory( _In_ ID3D11Device* d3dDevice,
|
HRESULT CreateDDSTextureFromMemory(
|
||||||
|
_In_ ID3D11Device* d3dDevice,
|
||||||
_In_opt_ ID3D11DeviceContext* d3dContext,
|
_In_opt_ ID3D11DeviceContext* d3dContext,
|
||||||
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
||||||
_In_ size_t ddsDataSize,
|
_In_ size_t ddsDataSize,
|
||||||
_Outptr_opt_ ID3D11Resource** texture,
|
_Outptr_opt_ ID3D11Resource** texture,
|
||||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||||
_In_ size_t maxsize = 0,
|
_In_ size_t maxsize = 0,
|
||||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
|
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
|
||||||
);
|
|
||||||
|
|
||||||
HRESULT CreateDDSTextureFromFile( _In_ ID3D11Device* d3dDevice,
|
HRESULT CreateDDSTextureFromFile(
|
||||||
|
_In_ ID3D11Device* d3dDevice,
|
||||||
_In_opt_ ID3D11DeviceContext* d3dContext,
|
_In_opt_ ID3D11DeviceContext* d3dContext,
|
||||||
_In_z_ const wchar_t* szFileName,
|
_In_z_ const wchar_t* szFileName,
|
||||||
_Outptr_opt_ ID3D11Resource** texture,
|
_Outptr_opt_ ID3D11Resource** texture,
|
||||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||||
_In_ size_t maxsize = 0,
|
_In_ size_t maxsize = 0,
|
||||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
|
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
|
||||||
);
|
|
||||||
|
|
||||||
// Extended version
|
// Extended version
|
||||||
HRESULT CreateDDSTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice,
|
HRESULT CreateDDSTextureFromMemoryEx(
|
||||||
|
_In_ ID3D11Device* d3dDevice,
|
||||||
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
||||||
_In_ size_t ddsDataSize,
|
_In_ size_t ddsDataSize,
|
||||||
_In_ size_t maxsize,
|
_In_ size_t maxsize,
|
||||||
@ -85,10 +86,10 @@ namespace DirectX
|
|||||||
_In_ bool forceSRGB,
|
_In_ bool forceSRGB,
|
||||||
_Outptr_opt_ ID3D11Resource** texture,
|
_Outptr_opt_ ID3D11Resource** texture,
|
||||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
|
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
|
||||||
);
|
|
||||||
|
|
||||||
HRESULT CreateDDSTextureFromFileEx( _In_ ID3D11Device* d3dDevice,
|
HRESULT CreateDDSTextureFromFileEx(
|
||||||
|
_In_ ID3D11Device* d3dDevice,
|
||||||
_In_z_ const wchar_t* szFileName,
|
_In_z_ const wchar_t* szFileName,
|
||||||
_In_ size_t maxsize,
|
_In_ size_t maxsize,
|
||||||
_In_ D3D11_USAGE usage,
|
_In_ D3D11_USAGE usage,
|
||||||
@ -98,11 +99,11 @@ namespace DirectX
|
|||||||
_In_ bool forceSRGB,
|
_In_ bool forceSRGB,
|
||||||
_Outptr_opt_ ID3D11Resource** texture,
|
_Outptr_opt_ ID3D11Resource** texture,
|
||||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
|
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
|
||||||
);
|
|
||||||
|
|
||||||
// Extended version with optional auto-gen mipmap support
|
// Extended version with optional auto-gen mipmap support
|
||||||
HRESULT CreateDDSTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice,
|
HRESULT CreateDDSTextureFromMemoryEx(
|
||||||
|
_In_ ID3D11Device* d3dDevice,
|
||||||
_In_opt_ ID3D11DeviceContext* d3dContext,
|
_In_opt_ ID3D11DeviceContext* d3dContext,
|
||||||
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
||||||
_In_ size_t ddsDataSize,
|
_In_ size_t ddsDataSize,
|
||||||
@ -114,10 +115,10 @@ namespace DirectX
|
|||||||
_In_ bool forceSRGB,
|
_In_ bool forceSRGB,
|
||||||
_Outptr_opt_ ID3D11Resource** texture,
|
_Outptr_opt_ ID3D11Resource** texture,
|
||||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
|
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
|
||||||
);
|
|
||||||
|
|
||||||
HRESULT CreateDDSTextureFromFileEx( _In_ ID3D11Device* d3dDevice,
|
HRESULT CreateDDSTextureFromFileEx(
|
||||||
|
_In_ ID3D11Device* d3dDevice,
|
||||||
_In_opt_ ID3D11DeviceContext* d3dContext,
|
_In_opt_ ID3D11DeviceContext* d3dContext,
|
||||||
_In_z_ const wchar_t* szFileName,
|
_In_z_ const wchar_t* szFileName,
|
||||||
_In_ size_t maxsize,
|
_In_ size_t maxsize,
|
||||||
@ -128,6 +129,5 @@ namespace DirectX
|
|||||||
_In_ bool forceSRGB,
|
_In_ bool forceSRGB,
|
||||||
_Outptr_opt_ ID3D11Resource** texture,
|
_Outptr_opt_ ID3D11Resource** texture,
|
||||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
|
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
|
||||||
);
|
|
||||||
}
|
}
|
1476
DDSTextureLoader/DDSTextureLoader12.cpp
Normal file
1476
DDSTextureLoader/DDSTextureLoader12.cpp
Normal file
File diff suppressed because it is too large
Load Diff
88
DDSTextureLoader/DDSTextureLoader12.h
Normal file
88
DDSTextureLoader/DDSTextureLoader12.h
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// File: DDSTextureLoader12.h
|
||||||
|
//
|
||||||
|
// Functions for loading a DDS texture and creating a Direct3D 12 runtime resource for it
|
||||||
|
//
|
||||||
|
// Note these functions are useful as a light-weight runtime loader for DDS files. For
|
||||||
|
// a full-featured DDS file reader, writer, and texture processing pipeline see
|
||||||
|
// the 'Texconv' sample and the 'DirectXTex' library.
|
||||||
|
//
|
||||||
|
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||||
|
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||||
|
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
||||||
|
// PARTICULAR PURPOSE.
|
||||||
|
//
|
||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
//
|
||||||
|
// http://go.microsoft.com/fwlink/?LinkId=248926
|
||||||
|
// http://go.microsoft.com/fwlink/?LinkID=615561
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <d3d12.h>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace DirectX
|
||||||
|
{
|
||||||
|
enum DDS_ALPHA_MODE
|
||||||
|
{
|
||||||
|
DDS_ALPHA_MODE_UNKNOWN = 0,
|
||||||
|
DDS_ALPHA_MODE_STRAIGHT = 1,
|
||||||
|
DDS_ALPHA_MODE_PREMULTIPLIED = 2,
|
||||||
|
DDS_ALPHA_MODE_OPAQUE = 3,
|
||||||
|
DDS_ALPHA_MODE_CUSTOM = 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Standard version
|
||||||
|
HRESULT __cdecl LoadDDSTextureFromMemory(
|
||||||
|
_In_ ID3D12Device* d3dDevice,
|
||||||
|
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
||||||
|
size_t ddsDataSize,
|
||||||
|
_Outptr_ ID3D12Resource** texture,
|
||||||
|
std::vector<D3D12_SUBRESOURCE_DATA>& subresources,
|
||||||
|
size_t maxsize = 0,
|
||||||
|
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr,
|
||||||
|
_Out_opt_ bool* isCubeMap = nullptr);
|
||||||
|
|
||||||
|
HRESULT __cdecl LoadDDSTextureFromFile(
|
||||||
|
_In_ ID3D12Device* d3dDevice,
|
||||||
|
_In_z_ const wchar_t* szFileName,
|
||||||
|
_Outptr_ ID3D12Resource** texture,
|
||||||
|
std::unique_ptr<uint8_t[]>& ddsData,
|
||||||
|
std::vector<D3D12_SUBRESOURCE_DATA>& subresources,
|
||||||
|
size_t maxsize = 0,
|
||||||
|
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr,
|
||||||
|
_Out_opt_ bool* isCubeMap = nullptr);
|
||||||
|
|
||||||
|
// Extended version
|
||||||
|
HRESULT __cdecl LoadDDSTextureFromMemoryEx(
|
||||||
|
_In_ ID3D12Device* d3dDevice,
|
||||||
|
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
||||||
|
size_t ddsDataSize,
|
||||||
|
size_t maxsize,
|
||||||
|
D3D12_RESOURCE_FLAGS flags,
|
||||||
|
bool forceSRGB,
|
||||||
|
bool reserveFullMipChain,
|
||||||
|
_Outptr_ ID3D12Resource** texture,
|
||||||
|
std::vector<D3D12_SUBRESOURCE_DATA>& subresources,
|
||||||
|
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr,
|
||||||
|
_Out_opt_ bool* isCubeMap = nullptr);
|
||||||
|
|
||||||
|
HRESULT __cdecl LoadDDSTextureFromFileEx(
|
||||||
|
_In_ ID3D12Device* d3dDevice,
|
||||||
|
_In_z_ const wchar_t* szFileName,
|
||||||
|
size_t maxsize,
|
||||||
|
D3D12_RESOURCE_FLAGS flags,
|
||||||
|
bool forceSRGB,
|
||||||
|
bool reserveFullMipChain,
|
||||||
|
_Outptr_ ID3D12Resource** texture,
|
||||||
|
std::unique_ptr<uint8_t[]>& ddsData,
|
||||||
|
std::vector<D3D12_SUBRESOURCE_DATA>& subresources,
|
||||||
|
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr,
|
||||||
|
_Out_opt_ bool* isCubeMap = nullptr);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user