Resync DDSTextureLoader, WICTextureLoader

This commit is contained in:
Chuck Walbourn 2016-09-22 22:34:50 -07:00
Родитель d74689c111
Коммит 2f31eb519c
8 изменённых файлов: 1020 добавлений и 1020 удалений

Просмотреть файл

@ -1,7 +1,7 @@
//--------------------------------------------------------------------------------------
// File: DDSTextureLoader.cpp
//
// Functions for loading a DDS texture and creating a Direct3D 11 runtime resource for it
// Functions for loading a DDS texture and creating a Direct3D 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
@ -142,8 +142,8 @@ namespace
HRESULT LoadTextureDataFromFile(
_In_z_ const wchar_t* fileName,
std::unique_ptr<uint8_t[]>& ddsData,
DDS_HEADER** header,
uint8_t** bitData,
const DDS_HEADER** header,
const uint8_t** bitData,
size_t* bitSize)
{
if (!header || !bitData || !bitSize)
@ -217,13 +217,13 @@ namespace
}
// DDS files always start with the same magic number ("DDS ")
uint32_t dwMagicNumber = *( const uint32_t* )( ddsData.get() );
uint32_t dwMagicNumber = *reinterpret_cast<const uint32_t*>(ddsData.get());
if (dwMagicNumber != DDS_MAGIC)
{
return E_FAIL;
}
auto hdr = reinterpret_cast<DDS_HEADER*>( ddsData.get() + sizeof( uint32_t ) );
auto hdr = reinterpret_cast<const DDS_HEADER*>(ddsData.get() + sizeof(uint32_t));
// Verify header to validate DDS file
if (hdr->size != sizeof(DDS_HEADER) ||
@ -1747,8 +1747,8 @@ HRESULT DirectX::CreateDDSTextureFromFileEx( ID3D11Device* d3dDevice,
return E_INVALIDARG;
}
DDS_HEADER* header = nullptr;
uint8_t* bitData = nullptr;
const DDS_HEADER* header = nullptr;
const uint8_t* bitData = nullptr;
size_t bitSize = 0;
std::unique_ptr<uint8_t[]> ddsData;

Просмотреть файл

@ -1,7 +1,7 @@
//--------------------------------------------------------------------------------------
// File: DDSTextureLoader.h
//
// Functions for loading a DDS texture and creating a Direct3D 11 runtime resource for it
// Functions for loading a DDS texture and creating a Direct3D 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

Просмотреть файл

@ -1,7 +1,7 @@
//--------------------------------------------------------------------------------------
// File: DDSTextureLoader12.cpp
//
// Functions for loading a DDS texture and creating a Direct3D 12 runtime resource for it
// Functions for loading a DDS texture and creating a Direct3D 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
@ -155,8 +155,8 @@ namespace
HRESULT LoadTextureDataFromFile(
_In_z_ const wchar_t* fileName,
std::unique_ptr<uint8_t[]>& ddsData,
DDS_HEADER** header,
uint8_t** bitData,
const DDS_HEADER** header,
const uint8_t** bitData,
size_t* bitSize)
{
if (!header || !bitData || !bitSize)
@ -220,13 +220,13 @@ namespace
}
// DDS files always start with the same magic number ("DDS ")
uint32_t dwMagicNumber = *( const uint32_t* )( ddsData.get() );
uint32_t dwMagicNumber = *reinterpret_cast<const uint32_t*>(ddsData.get());
if (dwMagicNumber != DDS_MAGIC)
{
return E_FAIL;
}
auto hdr = reinterpret_cast<DDS_HEADER*>( ddsData.get() + sizeof( uint32_t ) );
auto hdr = reinterpret_cast<const DDS_HEADER*>(ddsData.get() + sizeof(uint32_t));
// Verify header to validate DDS file
if (hdr->size != sizeof(DDS_HEADER) ||
@ -914,15 +914,15 @@ namespace
//--------------------------------------------------------------------------------------
HRESULT CreateTextureResource(
_In_ ID3D12Device* d3dDevice,
_In_ D3D12_RESOURCE_DIMENSION resDim,
_In_ size_t width,
_In_ size_t height,
_In_ size_t depth,
_In_ size_t mipCount,
_In_ size_t arraySize,
_In_ DXGI_FORMAT format,
_In_ D3D12_RESOURCE_FLAGS flags,
_In_ bool forceSRGB,
D3D12_RESOURCE_DIMENSION resDim,
size_t width,
size_t height,
size_t depth,
size_t mipCount,
size_t arraySize,
DXGI_FORMAT format,
D3D12_RESOURCE_FLAGS resFlags,
unsigned int loadFlags,
_Outptr_ ID3D12Resource** texture)
{
if (!d3dDevice)
@ -930,7 +930,7 @@ namespace
HRESULT hr = E_FAIL;
if (forceSRGB)
if (loadFlags & DDS_LOADER_FORCE_SRGB)
{
format = MakeSRGB(format);
}
@ -941,7 +941,7 @@ namespace
desc.MipLevels = static_cast<UINT16>(mipCount);
desc.DepthOrArraySize = (resDim == D3D12_RESOURCE_DIMENSION_TEXTURE3D) ? static_cast<UINT16>(depth) : static_cast<UINT16>(arraySize);
desc.Format = format;
desc.Flags = flags;
desc.Flags = resFlags;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Dimension = resDim;
@ -969,13 +969,12 @@ namespace
HRESULT CreateTextureFromDDS(_In_ ID3D12Device* d3dDevice,
_In_ const DDS_HEADER* header,
_In_reads_bytes_(bitSize) const uint8_t* bitData,
_In_ size_t bitSize,
_In_ size_t maxsize,
_In_ D3D12_RESOURCE_FLAGS flags,
_In_ bool forceSRGB,
_In_ bool reserveFullMipChain,
size_t bitSize,
size_t maxsize,
D3D12_RESOURCE_FLAGS resFlags,
unsigned int loadFlags,
_Outptr_ ID3D12Resource** texture,
_Out_ std::vector<D3D12_SUBRESOURCE_DATA>& subresources,
std::vector<D3D12_SUBRESOURCE_DATA>& subresources,
_Out_opt_ bool* outIsCubeMap)
{
HRESULT hr = S_OK;
@ -1165,13 +1164,13 @@ namespace
if (SUCCEEDED(hr))
{
size_t reservedMips = mipCount;
if (reserveFullMipChain)
if (loadFlags & DDS_LOADER_MIP_RESERVE)
{
reservedMips = std::min<size_t>(D3D12_REQ_MIP_LEVELS, CountMips(width, height));
}
hr = CreateTextureResource(d3dDevice, resDim, twidth, theight, tdepth, reservedMips - skipMip, arraySize,
format, flags, forceSRGB, texture);
format, resFlags, loadFlags, texture);
if (FAILED(hr) && !maxsize && (mipCount > 1))
{
@ -1184,7 +1183,7 @@ namespace
if (SUCCEEDED(hr))
{
hr = CreateTextureResource(d3dDevice, resDim, twidth, theight, tdepth, mipCount - skipMip, arraySize,
format, flags, forceSRGB, texture);
format, resFlags, loadFlags, texture);
}
}
}
@ -1224,7 +1223,6 @@ namespace
return DDS_ALPHA_MODE_UNKNOWN;
}
} // anonymous namespace
@ -1246,8 +1244,7 @@ HRESULT DirectX::LoadDDSTextureFromMemory(
ddsDataSize,
maxsize,
D3D12_RESOURCE_FLAG_NONE,
false,
false,
DDS_LOADER_DEFAULT,
texture,
subresources,
alphaMode,
@ -1261,9 +1258,8 @@ HRESULT DirectX::LoadDDSTextureFromMemoryEx(
const uint8_t* ddsData,
size_t ddsDataSize,
size_t maxsize,
D3D12_RESOURCE_FLAGS flags,
bool forceSRGB,
bool reserveFullMipChain,
D3D12_RESOURCE_FLAGS resFlags,
unsigned int loadFlags,
ID3D12Resource** texture,
std::vector<D3D12_SUBRESOURCE_DATA>& subresources,
DDS_ALPHA_MODE* alphaMode,
@ -1328,7 +1324,7 @@ HRESULT DirectX::LoadDDSTextureFromMemoryEx(
HRESULT hr = CreateTextureFromDDS(d3dDevice,
header, ddsData + offset, ddsDataSize - offset, maxsize,
flags, forceSRGB, reserveFullMipChain,
resFlags, loadFlags,
texture, subresources, isCubeMap);
if (SUCCEEDED(hr))
{
@ -1362,8 +1358,7 @@ HRESULT DirectX::LoadDDSTextureFromFile(
fileName,
maxsize,
D3D12_RESOURCE_FLAG_NONE,
false,
false,
DDS_LOADER_DEFAULT,
texture,
ddsData,
subresources,
@ -1376,9 +1371,8 @@ HRESULT DirectX::LoadDDSTextureFromFileEx(
ID3D12Device* d3dDevice,
const wchar_t* fileName,
size_t maxsize,
D3D12_RESOURCE_FLAGS flags,
bool forceSRGB,
bool reserveFullMipChain,
D3D12_RESOURCE_FLAGS resFlags,
unsigned int loadFlags,
ID3D12Resource** texture,
std::unique_ptr<uint8_t[]>& ddsData,
std::vector<D3D12_SUBRESOURCE_DATA>& subresources,
@ -1403,8 +1397,8 @@ HRESULT DirectX::LoadDDSTextureFromFileEx(
return E_INVALIDARG;
}
DDS_HEADER* header = nullptr;
uint8_t* bitData = nullptr;
const DDS_HEADER* header = nullptr;
const uint8_t* bitData = nullptr;
size_t bitSize = 0;
HRESULT hr = LoadTextureDataFromFile(fileName,
@ -1420,7 +1414,7 @@ HRESULT DirectX::LoadDDSTextureFromFileEx(
hr = CreateTextureFromDDS(d3dDevice,
header, bitData, bitSize, maxsize,
flags, forceSRGB, reserveFullMipChain,
resFlags, loadFlags,
texture, subresources, isCubeMap);
if (SUCCEEDED(hr))

Просмотреть файл

@ -1,7 +1,7 @@
//--------------------------------------------------------------------------------------
// File: DDSTextureLoader12.h
//
// Functions for loading a DDS texture and creating a Direct3D 12 runtime resource for it
// Functions for loading a DDS texture and creating a Direct3D 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
@ -38,6 +38,13 @@ namespace DirectX
DDS_ALPHA_MODE_CUSTOM = 4,
};
enum DDS_LOADER_FLAGS
{
DDS_LOADER_DEFAULT = 0,
DDS_LOADER_FORCE_SRGB = 0x1,
DDS_LOADER_MIP_RESERVE = 0x8,
};
// Standard version
HRESULT __cdecl LoadDDSTextureFromMemory(
_In_ ID3D12Device* d3dDevice,
@ -65,9 +72,8 @@ namespace DirectX
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
size_t ddsDataSize,
size_t maxsize,
D3D12_RESOURCE_FLAGS flags,
bool forceSRGB,
bool reserveFullMipChain,
D3D12_RESOURCE_FLAGS resFlags,
unsigned int loadFlags,
_Outptr_ ID3D12Resource** texture,
std::vector<D3D12_SUBRESOURCE_DATA>& subresources,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr,
@ -77,9 +83,8 @@ namespace DirectX
_In_ ID3D12Device* d3dDevice,
_In_z_ const wchar_t* szFileName,
size_t maxsize,
D3D12_RESOURCE_FLAGS flags,
bool forceSRGB,
bool reserveFullMipChain,
D3D12_RESOURCE_FLAGS resFlags,
unsigned int loadFlags,
_Outptr_ ID3D12Resource** texture,
std::unique_ptr<uint8_t[]>& ddsData,
std::vector<D3D12_SUBRESOURCE_DATA>& subresources,

Просмотреть файл

@ -1,7 +1,7 @@
//--------------------------------------------------------------------------------------
// File: WICTextureLoader.cpp
//
// Function for loading a WIC image and creating a Direct3D 11 runtime texture for it
// Function for loading a WIC image and creating a Direct3D runtime texture for it
// (auto-generating mipmaps if possible)
//
// Note: Assumes application has already called CoInitializeEx
@ -43,6 +43,7 @@
#pragma comment(lib,"dxguid.lib")
#endif
using namespace DirectX;
using Microsoft::WRL::ComPtr;
namespace
@ -236,7 +237,7 @@ namespace
//---------------------------------------------------------------------------------
size_t _WICBitsPerPixel(REFGUID targetGuid)
{
IWICImagingFactory* pWIC = _GetWIC();
auto pWIC = _GetWIC();
if (!pWIC)
return 0;
@ -296,8 +297,7 @@ namespace
//---------------------------------------------------------------------------------
HRESULT CreateTextureFromWIC(
_In_ ID3D11Device* d3dDevice,
HRESULT CreateTextureFromWIC(_In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
_In_ IWICBitmapFrameDecode *frame,
_In_ size_t maxsize,
@ -305,9 +305,9 @@ namespace
_In_ unsigned int bindFlags,
_In_ unsigned int cpuAccessFlags,
_In_ unsigned int miscFlags,
_In_ bool forceSRGB,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView )
_In_ unsigned int loadFlags,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView)
{
UINT width, height;
HRESULT hr = frame->GetSize(&width, &height);
@ -441,11 +441,11 @@ namespace
return E_FAIL;
// Handle sRGB formats
if ( forceSRGB )
if (loadFlags & WIC_LOADER_FORCE_SRGB)
{
format = MakeSRGB(format);
}
else
else if (!(loadFlags & WIC_LOADER_IGNORE_SRGB))
{
ComPtr<IWICMetadataQueryReader> metareader;
if (SUCCEEDED(frame->GetMetadataQueryReader(metareader.GetAddressOf())))
@ -513,7 +513,7 @@ namespace
else if (twidth != width || theight != height)
{
// Resize
IWICImagingFactory* pWIC = _GetWIC();
auto pWIC = _GetWIC();
if (!pWIC)
return E_NOINTERFACE;
@ -564,7 +564,7 @@ namespace
else
{
// Format conversion but no resize
IWICImagingFactory* pWIC = _GetWIC();
auto pWIC = _GetWIC();
if (!pWIC)
return E_NOINTERFACE;
@ -681,7 +681,7 @@ HRESULT DirectX::CreateWICTextureFromMemory( ID3D11Device* d3dDevice,
size_t maxsize)
{
return CreateWICTextureFromMemoryEx(d3dDevice, nullptr, wicData, wicDataSize, maxsize,
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, false,
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, WIC_LOADER_DEFAULT,
texture, textureView);
}
@ -695,7 +695,7 @@ HRESULT DirectX::CreateWICTextureFromMemory( ID3D11Device* d3dDevice,
size_t maxsize)
{
return CreateWICTextureFromMemoryEx(d3dDevice, d3dContext, wicData, wicDataSize, maxsize,
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, false,
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, WIC_LOADER_DEFAULT,
texture, textureView);
}
@ -708,12 +708,12 @@ HRESULT DirectX::CreateWICTextureFromMemoryEx( ID3D11Device* d3dDevice,
unsigned int bindFlags,
unsigned int cpuAccessFlags,
unsigned int miscFlags,
bool forceSRGB,
unsigned int loadFlags,
ID3D11Resource** texture,
ID3D11ShaderResourceView** textureView)
{
return CreateWICTextureFromMemoryEx(d3dDevice, nullptr, wicData, wicDataSize, maxsize,
usage, bindFlags, cpuAccessFlags, miscFlags, forceSRGB,
usage, bindFlags, cpuAccessFlags, miscFlags, loadFlags,
texture, textureView);
}
@ -727,7 +727,7 @@ HRESULT DirectX::CreateWICTextureFromMemoryEx( ID3D11Device* d3dDevice,
unsigned int bindFlags,
unsigned int cpuAccessFlags,
unsigned int miscFlags,
bool forceSRGB,
unsigned int loadFlags,
ID3D11Resource** texture,
ID3D11ShaderResourceView** textureView)
{
@ -749,7 +749,7 @@ HRESULT DirectX::CreateWICTextureFromMemoryEx( ID3D11Device* d3dDevice,
if (wicDataSize > UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_FILE_TOO_LARGE);
IWICImagingFactory* pWIC = _GetWIC();
auto pWIC = _GetWIC();
if (!pWIC)
return E_NOINTERFACE;
@ -775,7 +775,7 @@ HRESULT DirectX::CreateWICTextureFromMemoryEx( ID3D11Device* d3dDevice,
return hr;
hr = CreateTextureFromWIC(d3dDevice, d3dContext, frame.Get(), maxsize,
usage, bindFlags, cpuAccessFlags, miscFlags, forceSRGB,
usage, bindFlags, cpuAccessFlags, miscFlags, loadFlags,
texture, textureView);
if (FAILED(hr))
return hr;
@ -802,7 +802,7 @@ HRESULT DirectX::CreateWICTextureFromFile( ID3D11Device* d3dDevice,
size_t maxsize)
{
return CreateWICTextureFromFileEx(d3dDevice, nullptr, fileName, maxsize,
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, false,
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, WIC_LOADER_DEFAULT,
texture, textureView);
}
@ -815,7 +815,7 @@ HRESULT DirectX::CreateWICTextureFromFile( ID3D11Device* d3dDevice,
size_t maxsize)
{
return CreateWICTextureFromFileEx(d3dDevice, d3dContext, fileName, maxsize,
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, false,
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, WIC_LOADER_DEFAULT,
texture, textureView);
}
@ -827,12 +827,12 @@ HRESULT DirectX::CreateWICTextureFromFileEx( ID3D11Device* d3dDevice,
unsigned int bindFlags,
unsigned int cpuAccessFlags,
unsigned int miscFlags,
bool forceSRGB,
unsigned int loadFlags,
ID3D11Resource** texture,
ID3D11ShaderResourceView** textureView)
{
return CreateWICTextureFromFileEx(d3dDevice, nullptr, fileName, maxsize,
usage, bindFlags, cpuAccessFlags, miscFlags, forceSRGB,
usage, bindFlags, cpuAccessFlags, miscFlags, loadFlags,
texture, textureView);
}
@ -845,7 +845,7 @@ HRESULT DirectX::CreateWICTextureFromFileEx( ID3D11Device* d3dDevice,
unsigned int bindFlags,
unsigned int cpuAccessFlags,
unsigned int miscFlags,
bool forceSRGB,
unsigned int loadFlags,
ID3D11Resource** texture,
ID3D11ShaderResourceView** textureView)
{
@ -861,7 +861,7 @@ HRESULT DirectX::CreateWICTextureFromFileEx( ID3D11Device* d3dDevice,
if (!d3dDevice || !fileName || (!texture && !textureView))
return E_INVALIDARG;
IWICImagingFactory* pWIC = _GetWIC();
auto pWIC = _GetWIC();
if (!pWIC)
return E_NOINTERFACE;
@ -877,7 +877,7 @@ HRESULT DirectX::CreateWICTextureFromFileEx( ID3D11Device* d3dDevice,
return hr;
hr = CreateTextureFromWIC(d3dDevice, d3dContext, frame.Get(), maxsize,
usage, bindFlags, cpuAccessFlags, miscFlags, forceSRGB,
usage, bindFlags, cpuAccessFlags, miscFlags, loadFlags,
texture, textureView);
#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )

Просмотреть файл

@ -1,7 +1,7 @@
//--------------------------------------------------------------------------------------
// File: WICTextureLoader.h
//
// Function for loading a WIC image and creating a Direct3D 11 runtime texture for it
// Function for loading a WIC image and creating a Direct3D runtime texture for it
// (auto-generating mipmaps if possible)
//
// Note: Assumes application has already called CoInitializeEx
@ -33,23 +33,28 @@
namespace DirectX
{
enum WIC_LOADER_FLAGS
{
WIC_LOADER_DEFAULT = 0,
WIC_LOADER_FORCE_SRGB = 0x1,
WIC_LOADER_IGNORE_SRGB = 0x2,
};
// Standard version
HRESULT CreateWICTextureFromMemory(
_In_ ID3D11Device* d3dDevice,
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
_In_ size_t wicDataSize,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0
);
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0);
HRESULT CreateWICTextureFromFile(
_In_ ID3D11Device* d3dDevice,
_In_z_ const wchar_t* szFileName,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0
);
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0);
// Standard version with optional auto-gen mipmap support
HRESULT CreateWICTextureFromMemory(
@ -57,19 +62,17 @@ namespace DirectX
_In_opt_ ID3D11DeviceContext* d3dContext,
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
_In_ size_t wicDataSize,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0
);
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0);
HRESULT CreateWICTextureFromFile(
_In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
_In_z_ const wchar_t* szFileName,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0
);
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0);
// Extended version
HRESULT CreateWICTextureFromMemoryEx(
@ -77,14 +80,13 @@ namespace DirectX
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
_In_ size_t wicDataSize,
_In_ size_t maxsize,
D3D11_USAGE usage,
_In_ D3D11_USAGE usage,
_In_ unsigned int bindFlags,
_In_ unsigned int cpuAccessFlags,
_In_ unsigned int miscFlags,
_In_ bool forceSRGB,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView
);
_In_ unsigned int loadFlags,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView);
HRESULT CreateWICTextureFromFileEx(
_In_ ID3D11Device* d3dDevice,
@ -94,10 +96,9 @@ namespace DirectX
_In_ unsigned int bindFlags,
_In_ unsigned int cpuAccessFlags,
_In_ unsigned int miscFlags,
_In_ bool forceSRGB,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView
);
_In_ unsigned int loadFlags,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView);
// Extended version with optional auto-gen mipmap support
HRESULT CreateWICTextureFromMemoryEx(
@ -110,10 +111,9 @@ namespace DirectX
_In_ unsigned int bindFlags,
_In_ unsigned int cpuAccessFlags,
_In_ unsigned int miscFlags,
_In_ bool forceSRGB,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView
);
_In_ unsigned int loadFlags,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView);
HRESULT CreateWICTextureFromFileEx(
_In_ ID3D11Device* d3dDevice,
@ -124,8 +124,7 @@ namespace DirectX
_In_ unsigned int bindFlags,
_In_ unsigned int cpuAccessFlags,
_In_ unsigned int miscFlags,
_In_ bool forceSRGB,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView
);
_In_ unsigned int loadFlags,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView);
}

Просмотреть файл

@ -269,9 +269,8 @@ namespace
HRESULT CreateTextureFromWIC(_In_ ID3D12Device* d3dDevice,
_In_ IWICBitmapFrameDecode *frame,
size_t maxsize,
D3D12_RESOURCE_FLAGS flags,
bool forceSRGB,
bool reserveFullMipChain,
D3D12_RESOURCE_FLAGS resFlags,
unsigned int loadFlags,
_Outptr_ ID3D12Resource** texture,
std::unique_ptr<uint8_t[]>& decodedData,
D3D12_SUBRESOURCE_DATA& subresource)
@ -351,11 +350,11 @@ namespace
return E_FAIL;
// Handle sRGB formats
if (forceSRGB)
if (loadFlags & WIC_LOADER_FORCE_SRGB)
{
format = MakeSRGB(format);
}
else
else if (!(loadFlags & WIC_LOADER_IGNORE_SRGB))
{
ComPtr<IWICMetadataQueryReader> metareader;
if (SUCCEEDED(frame->GetMetadataQueryReader(metareader.GetAddressOf())))
@ -488,7 +487,7 @@ namespace
}
// Count the number of mips
uint32_t mipCount = (reserveFullMipChain) ? CountMips(twidth, theight) : 1;
uint32_t mipCount = (loadFlags & (WIC_LOADER_MIP_AUTOGEN | WIC_LOADER_MIP_RESERVE)) ? CountMips(twidth, theight) : 1;
// Create texture
D3D12_RESOURCE_DESC desc = {};
@ -499,7 +498,7 @@ namespace
desc.Format = format;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Flags = flags;
desc.Flags = resFlags;
desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
CD3DX12_HEAP_PROPERTIES defaultHeapProperties(D3D12_HEAP_TYPE_DEFAULT);
@ -547,8 +546,7 @@ HRESULT DirectX::LoadWICTextureFromMemory(
wicDataSize,
maxsize,
D3D12_RESOURCE_FLAG_NONE,
false,
false,
WIC_LOADER_DEFAULT,
texture,
decodedData,
subresource);
@ -562,9 +560,8 @@ HRESULT DirectX::LoadWICTextureFromMemoryEx(
const uint8_t* wicData,
size_t wicDataSize,
size_t maxsize,
D3D12_RESOURCE_FLAGS flags,
bool forceSRGB,
bool reserveFullMipChain,
D3D12_RESOURCE_FLAGS resFlags,
unsigned int loadFlags,
ID3D12Resource** texture,
std::unique_ptr<uint8_t[]>& decodedData,
D3D12_SUBRESOURCE_DATA& subresource)
@ -610,7 +607,7 @@ HRESULT DirectX::LoadWICTextureFromMemoryEx(
hr = CreateTextureFromWIC( d3dDevice,
frame.Get(), maxsize,
flags, forceSRGB, reserveFullMipChain,
resFlags, loadFlags,
texture, decodedData, subresource);
if ( FAILED(hr))
return hr;
@ -637,8 +634,7 @@ HRESULT DirectX::LoadWICTextureFromFile(
fileName,
maxsize,
D3D12_RESOURCE_FLAG_NONE,
false,
false,
WIC_LOADER_DEFAULT,
texture,
wicData,
subresource);
@ -651,9 +647,8 @@ HRESULT DirectX::LoadWICTextureFromFileEx(
ID3D12Device* d3dDevice,
const wchar_t* fileName,
size_t maxsize,
D3D12_RESOURCE_FLAGS flags,
bool forceSRGB,
bool reserveFullMipChain,
D3D12_RESOURCE_FLAGS resFlags,
unsigned int loadFlags,
ID3D12Resource** texture,
std::unique_ptr<uint8_t[]>& decodedData,
D3D12_SUBRESOURCE_DATA& subresource)
@ -682,7 +677,7 @@ HRESULT DirectX::LoadWICTextureFromFileEx(
return hr;
hr = CreateTextureFromWIC( d3dDevice, frame.Get(), maxsize,
flags, forceSRGB, reserveFullMipChain,
resFlags, loadFlags,
texture, decodedData, subresource );
#if !defined(NO_D3D12_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )

Просмотреть файл

@ -1,7 +1,7 @@
//--------------------------------------------------------------------------------------
// File: WICTextureLoader12.h
//
// Function for loading a WIC image and creating a Direct3D 12 runtime texture for it
// Function for loading a WIC image and creating a Direct3D runtime texture for it
// (auto-generating mipmaps if possible)
//
// Note: Assumes application has already called CoInitializeEx
@ -31,6 +31,15 @@
namespace DirectX
{
enum WIC_LOADER_FLAGS
{
WIC_LOADER_DEFAULT = 0,
WIC_LOADER_FORCE_SRGB = 0x1,
WIC_LOADER_IGNORE_SRGB = 0x2,
WIC_LOADER_MIP_AUTOGEN = 0x4,
WIC_LOADER_MIP_RESERVE = 0x8,
};
// Standard version
HRESULT __cdecl LoadWICTextureFromMemory(
_In_ ID3D12Device* d3dDevice,
@ -55,9 +64,8 @@ namespace DirectX
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
size_t wicDataSize,
size_t maxsize,
D3D12_RESOURCE_FLAGS flags,
bool forceSRGB,
bool reserveFullMipChain,
D3D12_RESOURCE_FLAGS resFlags,
unsigned int loadFlags,
_Outptr_ ID3D12Resource** texture,
std::unique_ptr<uint8_t[]>& decodedData,
D3D12_SUBRESOURCE_DATA& subresource);
@ -66,9 +74,8 @@ namespace DirectX
_In_ ID3D12Device* d3dDevice,
_In_z_ const wchar_t* szFileName,
size_t maxsize,
D3D12_RESOURCE_FLAGS flags,
bool forceSRGB,
bool reserveFullMipChain,
D3D12_RESOURCE_FLAGS resFlags,
unsigned int loadFlags,
_Outptr_ ID3D12Resource** texture,
std::unique_ptr<uint8_t[]>& decodedData,
D3D12_SUBRESOURCE_DATA& subresource);