зеркало из https://github.com/microsoft/DirectXTK.git
Add DDS_LOADER_IGNORE_SRGB parameter/functionality to CreateDDSTexture*Ex (#327)
This commit is contained in:
Родитель
8aea4445a0
Коммит
37b98af3b3
|
@ -40,6 +40,13 @@ namespace DirectX
|
|||
};
|
||||
#endif
|
||||
|
||||
enum DDS_LOADER_FLAGS : uint32_t
|
||||
{
|
||||
DDS_LOADER_DEFAULT = 0,
|
||||
DDS_LOADER_FORCE_SRGB = 0x1,
|
||||
DDS_LOADER_IGNORE_SRGB = 0x2,
|
||||
};
|
||||
|
||||
// Standard version
|
||||
HRESULT __cdecl CreateDDSTextureFromMemory(
|
||||
_In_ ID3D11Device* d3dDevice,
|
||||
|
@ -98,7 +105,7 @@ namespace DirectX
|
|||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_In_ bool forceSRGB,
|
||||
_In_ DDS_LOADER_FLAGS loadFlags,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr) noexcept;
|
||||
|
@ -111,7 +118,7 @@ namespace DirectX
|
|||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_In_ bool forceSRGB,
|
||||
_In_ DDS_LOADER_FLAGS loadFlags,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr) noexcept;
|
||||
|
@ -132,7 +139,7 @@ namespace DirectX
|
|||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_In_ bool forceSRGB,
|
||||
_In_ DDS_LOADER_FLAGS loadFlags,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr) noexcept;
|
||||
|
@ -151,8 +158,19 @@ namespace DirectX
|
|||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_In_ bool forceSRGB,
|
||||
_In_ DDS_LOADER_FLAGS loadFlags,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
|
||||
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr) noexcept;
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec"
|
||||
#endif
|
||||
|
||||
DEFINE_ENUM_FLAG_OPERATORS(DDS_LOADER_FLAGS);
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -144,7 +144,7 @@ namespace
|
|||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_In_ bool forceSRGB,
|
||||
_In_ DDS_LOADER_FLAGS loadFlags,
|
||||
_In_ bool isCubeMap,
|
||||
_In_reads_opt_(mipCount*arraySize) const D3D11_SUBRESOURCE_DATA* initData,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
|
@ -155,10 +155,14 @@ namespace
|
|||
|
||||
HRESULT hr = E_FAIL;
|
||||
|
||||
if (forceSRGB)
|
||||
if (loadFlags & DDS_LOADER_FORCE_SRGB)
|
||||
{
|
||||
format = MakeSRGB(format);
|
||||
}
|
||||
else if (loadFlags & DDS_LOADER_IGNORE_SRGB)
|
||||
{
|
||||
format = MakeLinear(format);
|
||||
}
|
||||
|
||||
switch (resDim)
|
||||
{
|
||||
|
@ -380,7 +384,7 @@ namespace
|
|||
_In_ unsigned int bindFlags,
|
||||
_In_ unsigned int cpuAccessFlags,
|
||||
_In_ unsigned int miscFlags,
|
||||
_In_ bool forceSRGB,
|
||||
_In_ DDS_LOADER_FLAGS loadFlags,
|
||||
_Outptr_opt_ ID3D11Resource** texture,
|
||||
_Outptr_opt_ ID3D11ShaderResourceView** textureView) noexcept
|
||||
{
|
||||
|
@ -612,7 +616,7 @@ namespace
|
|||
usage,
|
||||
bindFlags | D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET,
|
||||
cpuAccessFlags,
|
||||
miscFlags | D3D11_RESOURCE_MISC_GENERATE_MIPS, forceSRGB,
|
||||
miscFlags | D3D11_RESOURCE_MISC_GENERATE_MIPS, loadFlags,
|
||||
isCubeMap,
|
||||
nullptr,
|
||||
&tex, textureView);
|
||||
|
@ -789,7 +793,7 @@ namespace
|
|||
resDim, twidth, theight, tdepth, mipCount - skipMip, arraySize,
|
||||
format,
|
||||
usage, bindFlags, cpuAccessFlags, miscFlags,
|
||||
forceSRGB,
|
||||
loadFlags,
|
||||
isCubeMap,
|
||||
initData.get(),
|
||||
texture, textureView);
|
||||
|
@ -835,7 +839,7 @@ namespace
|
|||
resDim, twidth, theight, tdepth, mipCount - skipMip, arraySize,
|
||||
format,
|
||||
usage, bindFlags, cpuAccessFlags, miscFlags,
|
||||
forceSRGB,
|
||||
loadFlags,
|
||||
isCubeMap,
|
||||
initData.get(),
|
||||
texture, textureView);
|
||||
|
@ -939,7 +943,7 @@ HRESULT DirectX::CreateDDSTextureFromMemory(
|
|||
ddsData, ddsDataSize,
|
||||
maxsize,
|
||||
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0,
|
||||
false,
|
||||
DDS_LOADER_DEFAULT,
|
||||
texture, textureView, alphaMode);
|
||||
}
|
||||
|
||||
|
@ -964,7 +968,7 @@ HRESULT DirectX::CreateDDSTextureFromMemory(
|
|||
ddsData, ddsDataSize,
|
||||
maxsize,
|
||||
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0,
|
||||
false,
|
||||
DDS_LOADER_DEFAULT,
|
||||
texture, textureView, alphaMode);
|
||||
}
|
||||
|
||||
|
@ -978,7 +982,7 @@ HRESULT DirectX::CreateDDSTextureFromMemoryEx(
|
|||
unsigned int bindFlags,
|
||||
unsigned int cpuAccessFlags,
|
||||
unsigned int miscFlags,
|
||||
bool forceSRGB,
|
||||
DDS_LOADER_FLAGS loadFlags,
|
||||
ID3D11Resource** texture,
|
||||
ID3D11ShaderResourceView** textureView,
|
||||
DDS_ALPHA_MODE* alphaMode) noexcept
|
||||
|
@ -1028,7 +1032,7 @@ HRESULT DirectX::CreateDDSTextureFromMemoryEx(
|
|||
header, bitData, bitSize,
|
||||
maxsize,
|
||||
usage, bindFlags, cpuAccessFlags, miscFlags,
|
||||
forceSRGB,
|
||||
loadFlags,
|
||||
texture, textureView);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
|
@ -1066,7 +1070,7 @@ HRESULT DirectX::CreateDDSTextureFromMemoryEx(
|
|||
unsigned int bindFlags,
|
||||
unsigned int cpuAccessFlags,
|
||||
unsigned int miscFlags,
|
||||
bool forceSRGB,
|
||||
DDS_LOADER_FLAGS loadFlags,
|
||||
ID3D11Resource** texture,
|
||||
ID3D11ShaderResourceView** textureView,
|
||||
DDS_ALPHA_MODE* alphaMode) noexcept
|
||||
|
@ -1116,7 +1120,7 @@ HRESULT DirectX::CreateDDSTextureFromMemoryEx(
|
|||
header, bitData, bitSize,
|
||||
maxsize,
|
||||
usage, bindFlags, cpuAccessFlags, miscFlags,
|
||||
forceSRGB,
|
||||
loadFlags,
|
||||
texture, textureView);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
|
@ -1151,7 +1155,7 @@ HRESULT DirectX::CreateDDSTextureFromFile(
|
|||
fileName,
|
||||
maxsize,
|
||||
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0,
|
||||
false,
|
||||
DDS_LOADER_DEFAULT,
|
||||
texture, textureView, alphaMode);
|
||||
}
|
||||
|
||||
|
@ -1175,7 +1179,7 @@ HRESULT DirectX::CreateDDSTextureFromFile(
|
|||
fileName,
|
||||
maxsize,
|
||||
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0,
|
||||
false,
|
||||
DDS_LOADER_DEFAULT,
|
||||
texture, textureView, alphaMode);
|
||||
}
|
||||
|
||||
|
@ -1188,7 +1192,7 @@ HRESULT DirectX::CreateDDSTextureFromFileEx(
|
|||
unsigned int bindFlags,
|
||||
unsigned int cpuAccessFlags,
|
||||
unsigned int miscFlags,
|
||||
bool forceSRGB,
|
||||
DDS_LOADER_FLAGS loadFlags,
|
||||
ID3D11Resource** texture,
|
||||
ID3D11ShaderResourceView** textureView,
|
||||
DDS_ALPHA_MODE* alphaMode) noexcept
|
||||
|
@ -1239,7 +1243,7 @@ HRESULT DirectX::CreateDDSTextureFromFileEx(
|
|||
header, bitData, bitSize,
|
||||
maxsize,
|
||||
usage, bindFlags, cpuAccessFlags, miscFlags,
|
||||
forceSRGB,
|
||||
loadFlags,
|
||||
texture, textureView);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
|
@ -1269,7 +1273,7 @@ HRESULT DirectX::CreateDDSTextureFromFileEx(
|
|||
unsigned int bindFlags,
|
||||
unsigned int cpuAccessFlags,
|
||||
unsigned int miscFlags,
|
||||
bool forceSRGB,
|
||||
DDS_LOADER_FLAGS loadFlags,
|
||||
ID3D11Resource** texture,
|
||||
ID3D11ShaderResourceView** textureView,
|
||||
DDS_ALPHA_MODE* alphaMode) noexcept
|
||||
|
@ -1320,7 +1324,7 @@ HRESULT DirectX::CreateDDSTextureFromFileEx(
|
|||
header, bitData, bitSize,
|
||||
maxsize,
|
||||
usage, bindFlags, cpuAccessFlags, miscFlags,
|
||||
forceSRGB,
|
||||
loadFlags,
|
||||
texture, textureView);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
|
|
|
@ -413,7 +413,7 @@ void DGSLEffectFactory::Impl::CreateTexture(const wchar_t* name, ID3D11DeviceCon
|
|||
HRESULT hr = CreateDDSTextureFromFileEx(
|
||||
mDevice.Get(), fullName, 0,
|
||||
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0,
|
||||
mForceSRGB, nullptr, textureView);
|
||||
mForceSRGB ? DDS_LOADER_FORCE_SRGB : DDS_LOADER_DEFAULT, nullptr, textureView);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
DebugTrace("ERROR: CreateDDSTextureFromFile failed (%08X) for '%ls'\n",
|
||||
|
|
|
@ -411,7 +411,7 @@ void EffectFactory::Impl::CreateTexture(const wchar_t* name, ID3D11DeviceContext
|
|||
HRESULT hr = CreateDDSTextureFromFileEx(
|
||||
mDevice.Get(), fullName, 0,
|
||||
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0,
|
||||
mForceSRGB, nullptr, textureView);
|
||||
mForceSRGB ? DDS_LOADER_FORCE_SRGB : DDS_LOADER_DEFAULT, nullptr, textureView);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
DebugTrace("ERROR: CreateDDSTextureFromFile failed (%08X) for '%ls'\n",
|
||||
|
|
|
@ -221,6 +221,37 @@ namespace DirectX
|
|||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
inline DXGI_FORMAT MakeLinear(_In_ DXGI_FORMAT format) noexcept
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
|
||||
return DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
|
||||
case DXGI_FORMAT_BC1_UNORM_SRGB:
|
||||
return DXGI_FORMAT_BC1_UNORM;
|
||||
|
||||
case DXGI_FORMAT_BC2_UNORM_SRGB:
|
||||
return DXGI_FORMAT_BC2_UNORM;
|
||||
|
||||
case DXGI_FORMAT_BC3_UNORM_SRGB:
|
||||
return DXGI_FORMAT_BC3_UNORM;
|
||||
|
||||
case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
|
||||
return DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
|
||||
case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
|
||||
return DXGI_FORMAT_B8G8R8X8_UNORM;
|
||||
|
||||
case DXGI_FORMAT_BC7_UNORM_SRGB:
|
||||
return DXGI_FORMAT_BC7_UNORM;
|
||||
|
||||
default:
|
||||
return format;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
inline bool IsCompressed(_In_ DXGI_FORMAT fmt) noexcept
|
||||
{
|
||||
|
|
|
@ -243,7 +243,7 @@ void PBREffectFactory::Impl::CreateTexture(
|
|||
HRESULT hr = CreateDDSTextureFromFileEx(
|
||||
mDevice.Get(), fullName, 0,
|
||||
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0,
|
||||
mForceSRGB, nullptr, textureView);
|
||||
mForceSRGB ? DDS_LOADER_FORCE_SRGB : DDS_LOADER_DEFAULT, nullptr, textureView);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
DebugTrace("ERROR: CreateDDSTextureFromFile failed (%08X) for '%ls'\n",
|
||||
|
|
Загрузка…
Ссылка в новой задаче