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,7 +121,6 @@ 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;
|
||||||
@ -139,15 +138,13 @@ inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_ const char
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
static HRESULT LoadTextureDataFromFile( _In_z_ const wchar_t* fileName,
|
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)
|
||||||
{
|
{
|
||||||
@ -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,7 +251,7 @@ 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;
|
||||||
}
|
}
|
||||||
@ -270,7 +260,7 @@ static HRESULT LoadTextureDataFromFile( _In_z_ const wchar_t* fileName,
|
|||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
// 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 )
|
||||||
{
|
{
|
||||||
@ -420,10 +410,11 @@ static size_t BitsPerPixel( _In_ DXGI_FORMAT fmt )
|
|||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
// 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 )
|
||||||
{
|
{
|
||||||
@ -552,7 +543,7 @@ static void GetSurfaceInfo( _In_ size_t width,
|
|||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
#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)
|
||||||
{
|
{
|
||||||
@ -788,7 +779,7 @@ static DXGI_FORMAT GetDXGIFormat( const DDS_PIXELFORMAT& ddpf )
|
|||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
static DXGI_FORMAT MakeSRGB( _In_ DXGI_FORMAT format )
|
DXGI_FORMAT MakeSRGB( _In_ DXGI_FORMAT format )
|
||||||
{
|
{
|
||||||
switch( format )
|
switch( format )
|
||||||
{
|
{
|
||||||
@ -820,7 +811,8 @@ static DXGI_FORMAT MakeSRGB( _In_ DXGI_FORMAT 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,
|
||||||
@ -918,7 +910,8 @@ static HRESULT FillInitData( _In_ size_t width,
|
|||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
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,
|
||||||
@ -1152,7 +1145,8 @@ static HRESULT CreateD3DResources( _In_ ID3D11Device* d3dDevice,
|
|||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
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,
|
||||||
@ -1503,7 +1497,7 @@ static HRESULT CreateTextureFromDDS( _In_ ID3D11Device* d3dDevice,
|
|||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
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 )
|
||||||
{
|
{
|
||||||
@ -1529,7 +1523,7 @@ 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