mirror of
https://github.com/microsoft/DirectXTex
synced 2024-11-21 12:00:06 +00:00
Change bool forceSRGB parameters for D3D interop to CREATETEX_FLAGS (#281)
This commit is contained in:
parent
4333376df1
commit
10d8902e6c
@ -857,6 +857,15 @@ namespace DirectX
|
||||
_Out_ size_t& required) noexcept;
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
// Direct3D interop
|
||||
|
||||
enum CREATETEX_FLAGS : uint32_t
|
||||
{
|
||||
CREATETEX_DEFAULT = 0,
|
||||
CREATETEX_FORCE_SRGB = 0x1,
|
||||
CREATETEX_IGNORE_SRGB = 0x2,
|
||||
};
|
||||
|
||||
// Direct3D 11 functions
|
||||
#if defined(__d3d11_h__) || defined(__d3d11_x_h__)
|
||||
bool __cdecl IsSupportedTexture(_In_ ID3D11Device* pDevice, _In_ const TexMetadata& metadata) noexcept;
|
||||
@ -871,18 +880,17 @@ namespace DirectX
|
||||
|
||||
HRESULT __cdecl CreateTextureEx(
|
||||
_In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
|
||||
_In_ D3D11_USAGE usage, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, _In_ bool forceSRGB,
|
||||
_In_ D3D11_USAGE usage, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, _In_ CREATETEX_FLAGS flags,
|
||||
_Outptr_ ID3D11Resource** ppResource) noexcept;
|
||||
|
||||
HRESULT __cdecl CreateShaderResourceViewEx(
|
||||
_In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
|
||||
_In_ D3D11_USAGE usage, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, _In_ bool forceSRGB,
|
||||
_In_ D3D11_USAGE usage, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, _In_ CREATETEX_FLAGS flags,
|
||||
_Outptr_ ID3D11ShaderResourceView** ppSRV) noexcept;
|
||||
|
||||
HRESULT __cdecl CaptureTexture(_In_ ID3D11Device* pDevice, _In_ ID3D11DeviceContext* pContext, _In_ ID3D11Resource* pSource, _Out_ ScratchImage& result) noexcept;
|
||||
#endif
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
// Direct3D 12 functions
|
||||
#if defined(__d3d12_h__) || defined(__d3d12_x_h__) || defined(__XBOX_D3D12_X__)
|
||||
bool __cdecl IsSupportedTexture(_In_ ID3D12Device* pDevice, _In_ const TexMetadata& metadata) noexcept;
|
||||
@ -893,7 +901,7 @@ namespace DirectX
|
||||
|
||||
HRESULT __cdecl CreateTextureEx(
|
||||
_In_ ID3D12Device* pDevice, _In_ const TexMetadata& metadata,
|
||||
_In_ D3D12_RESOURCE_FLAGS resFlags, _In_ bool forceSRGB,
|
||||
_In_ D3D12_RESOURCE_FLAGS resFlags, _In_ CREATETEX_FLAGS flags,
|
||||
_Outptr_ ID3D12Resource** ppResource) noexcept;
|
||||
|
||||
HRESULT __cdecl PrepareUpload(
|
||||
|
@ -24,6 +24,7 @@ DEFINE_ENUM_FLAG_OPERATORS(TEX_PMALPHA_FLAGS);
|
||||
DEFINE_ENUM_FLAG_OPERATORS(TEX_COMPRESS_FLAGS);
|
||||
DEFINE_ENUM_FLAG_OPERATORS(CNMAP_FLAGS);
|
||||
DEFINE_ENUM_FLAG_OPERATORS(CMSE_FLAGS);
|
||||
DEFINE_ENUM_FLAG_OPERATORS(CREATETEX_FLAGS);
|
||||
|
||||
// WIC_FILTER modes match TEX_FILTER modes
|
||||
constexpr WIC_FLAGS operator|(WIC_FLAGS a, TEX_FILTER_FLAGS b) { return static_cast<WIC_FLAGS>(static_cast<unsigned long>(a) | static_cast<unsigned long>(b & TEX_FILTER_MODE_MASK)); }
|
||||
|
@ -411,7 +411,7 @@ HRESULT DirectX::CreateTexture(
|
||||
{
|
||||
return CreateTextureEx(
|
||||
pDevice, srcImages, nimages, metadata,
|
||||
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, false,
|
||||
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, CREATETEX_DEFAULT,
|
||||
ppResource);
|
||||
}
|
||||
|
||||
@ -425,7 +425,7 @@ HRESULT DirectX::CreateTextureEx(
|
||||
unsigned int bindFlags,
|
||||
unsigned int cpuAccessFlags,
|
||||
unsigned int miscFlags,
|
||||
bool forceSRGB,
|
||||
CREATETEX_FLAGS flags,
|
||||
ID3D11Resource** ppResource) noexcept
|
||||
{
|
||||
if (!pDevice || !srcImages || !nimages || !ppResource)
|
||||
@ -543,7 +543,15 @@ HRESULT DirectX::CreateTextureEx(
|
||||
// Create texture using static initialization data
|
||||
HRESULT hr = E_UNEXPECTED;
|
||||
|
||||
const DXGI_FORMAT tformat = (forceSRGB) ? MakeSRGB(metadata.format) : metadata.format;
|
||||
DXGI_FORMAT format = metadata.format;
|
||||
if (flags & CREATETEX_FORCE_SRGB)
|
||||
{
|
||||
format = MakeSRGB(format);
|
||||
}
|
||||
else if (flags & CREATETEX_IGNORE_SRGB)
|
||||
{
|
||||
format = MakeLinear(format);
|
||||
}
|
||||
|
||||
switch (metadata.dimension)
|
||||
{
|
||||
@ -553,7 +561,7 @@ HRESULT DirectX::CreateTextureEx(
|
||||
desc.Width = static_cast<UINT>(metadata.width);
|
||||
desc.MipLevels = static_cast<UINT>(metadata.mipLevels);
|
||||
desc.ArraySize = static_cast<UINT>(metadata.arraySize);
|
||||
desc.Format = tformat;
|
||||
desc.Format = format;
|
||||
desc.Usage = usage;
|
||||
desc.BindFlags = bindFlags;
|
||||
desc.CPUAccessFlags = cpuAccessFlags;
|
||||
@ -570,7 +578,7 @@ HRESULT DirectX::CreateTextureEx(
|
||||
desc.Height = static_cast<UINT>(metadata.height);
|
||||
desc.MipLevels = static_cast<UINT>(metadata.mipLevels);
|
||||
desc.ArraySize = static_cast<UINT>(metadata.arraySize);
|
||||
desc.Format = tformat;
|
||||
desc.Format = format;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.SampleDesc.Quality = 0;
|
||||
desc.Usage = usage;
|
||||
@ -592,7 +600,7 @@ HRESULT DirectX::CreateTextureEx(
|
||||
desc.Height = static_cast<UINT>(metadata.height);
|
||||
desc.Depth = static_cast<UINT>(metadata.depth);
|
||||
desc.MipLevels = static_cast<UINT>(metadata.mipLevels);
|
||||
desc.Format = tformat;
|
||||
desc.Format = format;
|
||||
desc.Usage = usage;
|
||||
desc.BindFlags = bindFlags;
|
||||
desc.CPUAccessFlags = cpuAccessFlags;
|
||||
@ -620,7 +628,7 @@ HRESULT DirectX::CreateShaderResourceView(
|
||||
{
|
||||
return CreateShaderResourceViewEx(
|
||||
pDevice, srcImages, nimages, metadata,
|
||||
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, false,
|
||||
D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, CREATETEX_DEFAULT,
|
||||
ppSRV);
|
||||
}
|
||||
|
||||
@ -634,7 +642,7 @@ HRESULT DirectX::CreateShaderResourceViewEx(
|
||||
unsigned int bindFlags,
|
||||
unsigned int cpuAccessFlags,
|
||||
unsigned int miscFlags,
|
||||
bool forceSRGB,
|
||||
CREATETEX_FLAGS flags,
|
||||
ID3D11ShaderResourceView** ppSRV) noexcept
|
||||
{
|
||||
if (!ppSRV)
|
||||
@ -647,7 +655,7 @@ HRESULT DirectX::CreateShaderResourceViewEx(
|
||||
|
||||
ComPtr<ID3D11Resource> resource;
|
||||
HRESULT hr = CreateTextureEx(pDevice, srcImages, nimages, metadata,
|
||||
usage, bindFlags, cpuAccessFlags, miscFlags, forceSRGB,
|
||||
usage, bindFlags, cpuAccessFlags, miscFlags, flags,
|
||||
resource.GetAddressOf());
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
@ -655,10 +663,18 @@ HRESULT DirectX::CreateShaderResourceViewEx(
|
||||
assert(resource);
|
||||
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = {};
|
||||
if (forceSRGB)
|
||||
if (flags & CREATETEX_FORCE_SRGB)
|
||||
{
|
||||
SRVDesc.Format = MakeSRGB(metadata.format);
|
||||
}
|
||||
else if (flags & CREATETEX_IGNORE_SRGB)
|
||||
{
|
||||
SRVDesc.Format = MakeLinear(metadata.format);
|
||||
}
|
||||
else
|
||||
{
|
||||
SRVDesc.Format = metadata.format;
|
||||
}
|
||||
|
||||
switch (metadata.dimension)
|
||||
{
|
||||
|
@ -440,7 +440,7 @@ HRESULT DirectX::CreateTexture(
|
||||
{
|
||||
return CreateTextureEx(
|
||||
pDevice, metadata,
|
||||
D3D12_RESOURCE_FLAG_NONE, false,
|
||||
D3D12_RESOURCE_FLAG_NONE, CREATETEX_DEFAULT,
|
||||
ppResource);
|
||||
}
|
||||
|
||||
@ -449,7 +449,7 @@ HRESULT DirectX::CreateTextureEx(
|
||||
ID3D12Device* pDevice,
|
||||
const TexMetadata& metadata,
|
||||
D3D12_RESOURCE_FLAGS resFlags,
|
||||
bool forceSRGB,
|
||||
CREATETEX_FLAGS flags,
|
||||
ID3D12Resource** ppResource) noexcept
|
||||
{
|
||||
if (!pDevice || !ppResource)
|
||||
@ -465,10 +465,14 @@ HRESULT DirectX::CreateTextureEx(
|
||||
return E_INVALIDARG;
|
||||
|
||||
DXGI_FORMAT format = metadata.format;
|
||||
if (forceSRGB)
|
||||
if (flags & CREATETEX_FORCE_SRGB)
|
||||
{
|
||||
format = MakeSRGB(format);
|
||||
}
|
||||
else if (flags & CREATETEX_IGNORE_SRGB)
|
||||
{
|
||||
format = MakeLinear(format);
|
||||
}
|
||||
|
||||
D3D12_RESOURCE_DESC desc = {};
|
||||
desc.Width = static_cast<UINT>(metadata.width);
|
||||
|
Loading…
Reference in New Issue
Block a user