diff --git a/DDSTextureLoader/DDSTextureLoader.cpp b/DDSTextureLoader/DDSTextureLoader.cpp index 66bcce3..d7e42c8 100644 --- a/DDSTextureLoader/DDSTextureLoader.cpp +++ b/DDSTextureLoader/DDSTextureLoader.cpp @@ -20,8 +20,9 @@ #include #include -#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) ) -#pragma comment(lib,"dxguid.lib") +#ifdef __clang__ +#pragma clang diagnostic ignored "-Wcovered-switch-default" +#pragma clang diagnostic ignored "-Wswitch-enum" #endif using namespace DirectX; @@ -65,7 +66,6 @@ struct DDS_PIXELFORMAT #define DDS_HEADER_FLAGS_VOLUME 0x00800000 // DDSD_DEPTH #define DDS_HEIGHT 0x00000002 // DDSD_HEIGHT -#define DDS_WIDTH 0x00000004 // DDSD_WIDTH #define DDS_CUBEMAP_POSITIVEX 0x00000600 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEX #define DDS_CUBEMAP_NEGATIVEX 0x00000a00 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX @@ -189,7 +189,7 @@ namespace // setup the pointers in the process request *header = hdr; - ptrdiff_t offset = sizeof(uint32_t) + auto offset = sizeof(uint32_t) + sizeof(DDS_HEADER) + (bDXT10Header ? sizeof(DDS_HEADER_DXT10) : 0); *bitData = ddsData + offset; @@ -309,7 +309,7 @@ namespace // setup the pointers in the process request *header = hdr; - ptrdiff_t offset = sizeof(uint32_t) + sizeof(DDS_HEADER) + auto offset = sizeof(uint32_t) + sizeof(DDS_HEADER) + (bDXT10Header ? sizeof(DDS_HEADER_DXT10) : 0); *bitData = ddsData.get() + offset; *bitSize = fileInfo.EndOfFile.LowPart - offset; @@ -950,7 +950,7 @@ namespace assert(index < mipCount * arraySize); _Analysis_assume_(index < mipCount * arraySize); - initData[index].pSysMem = (const void*)pSrcBits; + initData[index].pSysMem = pSrcBits; initData[index].SysMemPitch = static_cast(RowBytes); initData[index].SysMemSlicePitch = static_cast(NumBytes); ++index; @@ -1032,7 +1032,7 @@ namespace desc.Usage = usage; desc.BindFlags = bindFlags; desc.CPUAccessFlags = cpuAccessFlags; - desc.MiscFlags = miscFlags & ~D3D11_RESOURCE_MISC_TEXTURECUBE; + desc.MiscFlags = miscFlags & ~static_cast(D3D11_RESOURCE_MISC_TEXTURECUBE); ID3D11Texture1D* tex = nullptr; hr = d3dDevice->CreateTexture1D(&desc, @@ -1049,13 +1049,13 @@ namespace if (arraySize > 1) { SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1DARRAY; - SRVDesc.Texture1DArray.MipLevels = (!mipCount) ? -1 : desc.MipLevels; + SRVDesc.Texture1DArray.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels; SRVDesc.Texture1DArray.ArraySize = static_cast(arraySize); } else { SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D; - SRVDesc.Texture1D.MipLevels = (!mipCount) ? -1 : desc.MipLevels; + SRVDesc.Texture1D.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels; } hr = d3dDevice->CreateShaderResourceView(tex, @@ -1101,7 +1101,7 @@ namespace } else { - desc.MiscFlags = miscFlags & ~D3D11_RESOURCE_MISC_TEXTURECUBE; + desc.MiscFlags = miscFlags & ~static_cast(D3D11_RESOURCE_MISC_TEXTURECUBE); } ID3D11Texture2D* tex = nullptr; @@ -1121,7 +1121,7 @@ namespace if (arraySize > 6) { SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBEARRAY; - SRVDesc.TextureCubeArray.MipLevels = (!mipCount) ? -1 : desc.MipLevels; + SRVDesc.TextureCubeArray.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels; // Earlier we set arraySize to (NumCubes * 6) SRVDesc.TextureCubeArray.NumCubes = static_cast(arraySize / 6); @@ -1129,19 +1129,19 @@ namespace else { SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; - SRVDesc.TextureCube.MipLevels = (!mipCount) ? -1 : desc.MipLevels; + SRVDesc.TextureCube.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels; } } else if (arraySize > 1) { SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; - SRVDesc.Texture2DArray.MipLevels = (!mipCount) ? -1 : desc.MipLevels; + SRVDesc.Texture2DArray.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels; SRVDesc.Texture2DArray.ArraySize = static_cast(arraySize); } else { SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - SRVDesc.Texture2D.MipLevels = (!mipCount) ? -1 : desc.MipLevels; + SRVDesc.Texture2D.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels; } hr = d3dDevice->CreateShaderResourceView(tex, @@ -1179,7 +1179,7 @@ namespace desc.Usage = usage; desc.BindFlags = bindFlags; desc.CPUAccessFlags = cpuAccessFlags; - desc.MiscFlags = miscFlags & ~D3D11_RESOURCE_MISC_TEXTURECUBE; + desc.MiscFlags = miscFlags & ~static_cast(D3D11_RESOURCE_MISC_TEXTURECUBE); ID3D11Texture3D* tex = nullptr; hr = d3dDevice->CreateTexture3D(&desc, @@ -1194,7 +1194,7 @@ namespace SRVDesc.Format = format; SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D; - SRVDesc.Texture3D.MipLevels = (!mipCount) ? -1 : desc.MipLevels; + SRVDesc.Texture3D.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels; hr = d3dDevice->CreateShaderResourceView(tex, &SRVDesc, @@ -1260,7 +1260,7 @@ namespace if ((header->ddspf.flags & DDS_FOURCC) && (MAKEFOURCC('D', 'X', '1', '0') == header->ddspf.fourCC)) { - auto d3d10ext = reinterpret_cast((const char*)header + sizeof(DDS_HEADER)); + auto d3d10ext = reinterpret_cast(reinterpret_cast(header) + sizeof(DDS_HEADER)); arraySize = d3d10ext->arraySize; if (arraySize == 0) @@ -1604,7 +1604,7 @@ namespace { if (MAKEFOURCC('D', 'X', '1', '0') == header->ddspf.fourCC) { - auto d3d10ext = reinterpret_cast((const char*)header + sizeof(DDS_HEADER)); + auto d3d10ext = reinterpret_cast(reinterpret_cast(header) + sizeof(DDS_HEADER)); auto mode = static_cast(d3d10ext->miscFlags2 & DDS_MISC_FLAGS2_ALPHA_MODE_MASK); switch (mode) { @@ -1613,6 +1613,10 @@ namespace case DDS_ALPHA_MODE_OPAQUE: case DDS_ALPHA_MODE_CUSTOM: return mode; + + case DDS_ALPHA_MODE_UNKNOWN: + default: + break; } } else if ((MAKEFOURCC('D', 'X', 'T', '2') == header->ddspf.fourCC) diff --git a/DDSTextureLoader/DDSTextureLoader.h b/DDSTextureLoader/DDSTextureLoader.h index 0b5cb19..8f39366 100644 --- a/DDSTextureLoader/DDSTextureLoader.h +++ b/DDSTextureLoader/DDSTextureLoader.h @@ -126,4 +126,4 @@ namespace DirectX _Outptr_opt_ ID3D11Resource** texture, _Outptr_opt_ ID3D11ShaderResourceView** textureView, _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr); -} \ No newline at end of file +} diff --git a/DDSTextureLoader/DDSTextureLoader12.cpp b/DDSTextureLoader/DDSTextureLoader12.cpp index 3e810e6..7adae17 100644 --- a/DDSTextureLoader/DDSTextureLoader12.cpp +++ b/DDSTextureLoader/DDSTextureLoader12.cpp @@ -20,6 +20,14 @@ #include #include +#ifdef __clang__ +#pragma clang diagnostic ignored "-Wtautological-type-limit-compare" +#pragma clang diagnostic ignored "-Wcovered-switch-default" +#pragma clang diagnostic ignored "-Wswitch" +#pragma clang diagnostic ignored "-Wswitch-enum" +#endif + +#define D3DX12_NO_STATE_OBJECT_HELPERS #include "d3dx12.h" using namespace DirectX; @@ -63,7 +71,6 @@ struct DDS_PIXELFORMAT #define DDS_HEADER_FLAGS_VOLUME 0x00800000 // DDSD_DEPTH #define DDS_HEIGHT 0x00000002 // DDSD_HEIGHT -#define DDS_WIDTH 0x00000004 // DDSD_WIDTH #define DDS_CUBEMAP_POSITIVEX 0x00000600 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEX #define DDS_CUBEMAP_NEGATIVEX 0x00000a00 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX @@ -203,7 +210,7 @@ namespace // setup the pointers in the process request *header = hdr; - ptrdiff_t offset = sizeof(uint32_t) + auto offset = sizeof(uint32_t) + sizeof(DDS_HEADER) + (bDXT10Header ? sizeof(DDS_HEADER_DXT10) : 0); *bitData = ddsData + offset; @@ -313,7 +320,7 @@ namespace // setup the pointers in the process request *header = hdr; - ptrdiff_t offset = sizeof(uint32_t) + sizeof(DDS_HEADER) + auto offset = sizeof(uint32_t) + sizeof(DDS_HEADER) + (bDXT10Header ? sizeof(DDS_HEADER_DXT10) : 0); *bitData = ddsData.get() + offset; *bitSize = fileInfo.EndOfFile.LowPart - offset; @@ -938,13 +945,13 @@ namespace if (!slicePlane) { // Plane 0 - res.SlicePitch = res.RowPitch * height; + res.SlicePitch = res.RowPitch * static_cast(height); } else { // Plane 1 - res.pData = reinterpret_cast(res.pData) + res.RowPitch * height; - res.SlicePitch = res.RowPitch * ((height + 1) >> 1); + res.pData = reinterpret_cast(res.pData) + uintptr_t(res.RowPitch) * height; + res.SlicePitch = res.RowPitch * ((static_cast(height) + 1) >> 1); } break; @@ -952,14 +959,14 @@ namespace if (!slicePlane) { // Plane 0 - res.SlicePitch = res.RowPitch * height; + res.SlicePitch = res.RowPitch * static_cast(height); } else { // Plane 1 - res.pData = reinterpret_cast(res.pData) + res.RowPitch * height; + res.pData = reinterpret_cast(res.pData) + uintptr_t(res.RowPitch) * height; res.RowPitch = (res.RowPitch >> 1); - res.SlicePitch = res.RowPitch * height; + res.SlicePitch = res.RowPitch * static_cast(height); } break; } @@ -1116,7 +1123,7 @@ namespace &desc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, - IID_PPV_ARGS(texture)); + IID_ID3D12Resource, reinterpret_cast(texture)); if (SUCCEEDED(hr)) { _Analysis_assume_(*texture != nullptr); @@ -1159,7 +1166,7 @@ namespace if ((header->ddspf.flags & DDS_FOURCC) && (MAKEFOURCC('D', 'X', '1', '0') == header->ddspf.fourCC)) { - auto d3d10ext = reinterpret_cast((const char*)header + sizeof(DDS_HEADER)); + auto d3d10ext = reinterpret_cast(reinterpret_cast(header) + sizeof(DDS_HEADER)); arraySize = d3d10ext->arraySize; if (arraySize == 0) @@ -1388,7 +1395,7 @@ namespace { if ( MAKEFOURCC( 'D', 'X', '1', '0' ) == header->ddspf.fourCC ) { - auto d3d10ext = reinterpret_cast( (const char*)header + sizeof(DDS_HEADER) ); + auto d3d10ext = reinterpret_cast(reinterpret_cast(header) + sizeof(DDS_HEADER)); auto mode = static_cast( d3d10ext->miscFlags2 & DDS_MISC_FLAGS2_ALPHA_MODE_MASK ); switch( mode ) { @@ -1397,6 +1404,10 @@ namespace case DDS_ALPHA_MODE_OPAQUE: case DDS_ALPHA_MODE_CUSTOM: return mode; + + case DDS_ALPHA_MODE_UNKNOWN: + default: + break; } } else if ( ( MAKEFOURCC( 'D', 'X', 'T', '2' ) == header->ddspf.fourCC ) diff --git a/ScreenGrab/ScreenGrab.cpp b/ScreenGrab/ScreenGrab.cpp index 40f4125..d6b1f8c 100644 --- a/ScreenGrab/ScreenGrab.cpp +++ b/ScreenGrab/ScreenGrab.cpp @@ -80,9 +80,6 @@ namespace #define DDS_HEADER_FLAGS_PITCH 0x00000008 // DDSD_PITCH #define DDS_HEADER_FLAGS_LINEARSIZE 0x00080000 // DDSD_LINEARSIZE - #define DDS_HEIGHT 0x00000002 // DDSD_HEIGHT - #define DDS_WIDTH 0x00000004 // DDSD_WIDTH - #define DDS_SURFACE_FLAGS_TEXTURE 0x00001000 // DDSCAPS_TEXTURE typedef struct @@ -213,7 +210,7 @@ namespace } } - void clear() { m_handle = 0; } + void clear() { m_handle = nullptr; } private: HANDLE m_handle; @@ -225,7 +222,7 @@ namespace class auto_delete_file_wic { public: - auto_delete_file_wic(ComPtr& hFile, const wchar_t* szFile) : m_handle(hFile), m_filename(szFile) {} + auto_delete_file_wic(ComPtr& hFile, const wchar_t* szFile) : m_filename(szFile), m_handle(hFile) {} ~auto_delete_file_wic() { if (m_filename) @@ -235,7 +232,7 @@ namespace } } - void clear() { m_filename = 0; } + void clear() { m_filename = nullptr; } private: const wchar_t* m_filename; @@ -627,7 +624,7 @@ namespace return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED ); ComPtr pTexture; - HRESULT hr = pSource->QueryInterface(IID_PPV_ARGS(pTexture.GetAddressOf())); + HRESULT hr = pSource->QueryInterface(IID_ID3D11Texture2D, reinterpret_cast(pTexture.GetAddressOf())); if ( FAILED(hr) ) return hr; @@ -711,49 +708,53 @@ namespace //-------------------------------------------------------------------------------------- bool g_WIC2 = false; + BOOL WINAPI InitializeWICFactory(PINIT_ONCE, PVOID, PVOID* ifactory) noexcept + { +#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE) + HRESULT hr = CoCreateInstance( + CLSID_WICImagingFactory2, + nullptr, + CLSCTX_INPROC_SERVER, + __uuidof(IWICImagingFactory2), + ifactory + ); + + if (SUCCEEDED(hr)) + { + // WIC2 is available on Windows 10, Windows 8.x, and Windows 7 SP1 with KB 2670838 installed + g_WIC2 = true; + return TRUE; + } + else + { + hr = CoCreateInstance( + CLSID_WICImagingFactory1, + nullptr, + CLSCTX_INPROC_SERVER, + __uuidof(IWICImagingFactory), + ifactory + ); + return SUCCEEDED(hr) ? TRUE : FALSE; + } +#else + return SUCCEEDED(CoCreateInstance( + CLSID_WICImagingFactory, + nullptr, + CLSCTX_INPROC_SERVER, + __uuidof(IWICImagingFactory), + ifactory)) ? TRUE : FALSE; +#endif + } + IWICImagingFactory* _GetWIC() { static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT; IWICImagingFactory* factory = nullptr; InitOnceExecuteOnce(&s_initOnce, - [](PINIT_ONCE, PVOID, LPVOID *ifactory) -> BOOL - { - #if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE) - HRESULT hr = CoCreateInstance( - CLSID_WICImagingFactory2, - nullptr, - CLSCTX_INPROC_SERVER, - __uuidof(IWICImagingFactory2), - ifactory - ); - - if ( SUCCEEDED(hr) ) - { - // WIC2 is available on Windows 10, Windows 8.x, and Windows 7 SP1 with KB 2670838 installed - g_WIC2 = true; - return TRUE; - } - else - { - hr = CoCreateInstance( - CLSID_WICImagingFactory1, - nullptr, - CLSCTX_INPROC_SERVER, - __uuidof(IWICImagingFactory), - ifactory - ); - return SUCCEEDED(hr) ? TRUE : FALSE; - } - #else - return SUCCEEDED( CoCreateInstance( - CLSID_WICImagingFactory, - nullptr, - CLSCTX_INPROC_SERVER, - __uuidof(IWICImagingFactory), - ifactory) ) ? TRUE : FALSE; - #endif - }, nullptr, reinterpret_cast(&factory)); + InitializeWICFactory, + nullptr, + reinterpret_cast(&factory)); return factory; } diff --git a/ScreenGrab/ScreenGrab.h b/ScreenGrab/ScreenGrab.h index 1f18539..d507066 100644 --- a/ScreenGrab/ScreenGrab.h +++ b/ScreenGrab/ScreenGrab.h @@ -19,7 +19,7 @@ #include -#include +#include #include #include @@ -36,4 +36,4 @@ namespace DirectX _In_z_ const wchar_t* fileName, _In_opt_ const GUID* targetFormat = nullptr, _In_opt_ std::function setCustomProps = nullptr ); -} \ No newline at end of file +} diff --git a/ScreenGrab/ScreenGrab12.cpp b/ScreenGrab/ScreenGrab12.cpp index 4faffd2..778436b 100644 --- a/ScreenGrab/ScreenGrab12.cpp +++ b/ScreenGrab/ScreenGrab12.cpp @@ -31,6 +31,14 @@ #include +#ifdef __clang__ +#pragma clang diagnostic ignored "-Wtautological-type-limit-compare" +#pragma clang diagnostic ignored "-Wcovered-switch-default" +#pragma clang diagnostic ignored "-Wswitch" +#pragma clang diagnostic ignored "-Wswitch-enum" +#endif + +#define D3DX12_NO_STATE_OBJECT_HELPERS #include "d3dx12.h" using Microsoft::WRL::ComPtr; @@ -80,9 +88,6 @@ namespace #define DDS_HEADER_FLAGS_PITCH 0x00000008 // DDSD_PITCH #define DDS_HEADER_FLAGS_LINEARSIZE 0x00080000 // DDSD_LINEARSIZE - #define DDS_HEIGHT 0x00000002 // DDSD_HEIGHT - #define DDS_WIDTH 0x00000004 // DDSD_WIDTH - #define DDS_SURFACE_FLAGS_TEXTURE 0x00001000 // DDSCAPS_TEXTURE typedef struct @@ -213,7 +218,7 @@ namespace } } - void clear() { m_handle = 0; } + void clear() { m_handle = nullptr; } private: HANDLE m_handle; @@ -225,7 +230,7 @@ namespace class auto_delete_file_wic { public: - auto_delete_file_wic(ComPtr& hFile, LPCWSTR szFile) : m_handle(hFile), m_filename(szFile) {} + auto_delete_file_wic(ComPtr& hFile, LPCWSTR szFile) : m_filename(szFile), m_handle(hFile) {} ~auto_delete_file_wic() { if (m_filename) @@ -235,7 +240,7 @@ namespace } } - void clear() { m_filename = 0; } + void clear() { m_filename = nullptr; } private: LPCWSTR m_filename; @@ -676,19 +681,19 @@ namespace // Create a command allocator ComPtr commandAlloc; - hr = device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(commandAlloc.GetAddressOf())); + hr = device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_ID3D12CommandAllocator, reinterpret_cast(commandAlloc.GetAddressOf())); if (FAILED(hr)) return hr; // Spin up a new command list ComPtr commandList; - hr = device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, commandAlloc.Get(), nullptr, IID_PPV_ARGS(commandList.GetAddressOf())); + hr = device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, commandAlloc.Get(), nullptr, IID_ID3D12GraphicsCommandList, reinterpret_cast(commandList.GetAddressOf())); if (FAILED(hr)) return hr; // Create a fence ComPtr fence; - hr = device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(fence.GetAddressOf())); + hr = device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_ID3D12Fence, reinterpret_cast(fence.GetAddressOf())); if (FAILED(hr)) return hr; @@ -726,7 +731,8 @@ namespace &descCopy, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, - IID_PPV_ARGS(pTemp.GetAddressOf())); + IID_ID3D12Resource, + reinterpret_cast(pTemp.GetAddressOf())); if (FAILED(hr)) return hr; @@ -761,7 +767,8 @@ namespace &bufferDesc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, - IID_PPV_ARGS(pStaging.ReleaseAndGetAddressOf())); + IID_ID3D12Resource, + reinterpret_cast(pStaging.ReleaseAndGetAddressOf())); if (FAILED(hr)) return hr; @@ -806,21 +813,25 @@ namespace return S_OK; } + BOOL WINAPI InitializeWICFactory(PINIT_ONCE, PVOID, PVOID* ifactory) noexcept + { + return SUCCEEDED(CoCreateInstance( + CLSID_WICImagingFactory2, + nullptr, + CLSCTX_INPROC_SERVER, + __uuidof(IWICImagingFactory2), + ifactory)) ? TRUE : FALSE; + } + IWICImagingFactory2* _GetWIC() { static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT; IWICImagingFactory2* factory = nullptr; (void)InitOnceExecuteOnce(&s_initOnce, - [](PINIT_ONCE, PVOID, PVOID *ifactory) -> BOOL - { - return SUCCEEDED( CoCreateInstance( - CLSID_WICImagingFactory2, - nullptr, - CLSCTX_INPROC_SERVER, - __uuidof(IWICImagingFactory2), - ifactory) ) ? TRUE : FALSE; - }, nullptr, reinterpret_cast(&factory)); + InitializeWICFactory, + nullptr, + reinterpret_cast(&factory)); return factory; } @@ -840,7 +851,7 @@ HRESULT DirectX::SaveDDSTextureToFile( return E_INVALIDARG; ComPtr device; - pCommandQ->GetDevice(IID_PPV_ARGS(device.GetAddressOf())); + pCommandQ->GetDevice(IID_ID3D12Device, reinterpret_cast(device.GetAddressOf())); // Get the size of the image const auto desc = pSource->GetDesc(); @@ -863,7 +874,7 @@ HRESULT DirectX::SaveDDSTextureToFile( &totalResourceSize); // Round up the srcPitch to multiples of 256 - UINT64 dstRowPitch = (fpRowPitch + 255) & ~0xFF; + UINT64 dstRowPitch = (fpRowPitch + 255) & ~0xFFu; if (dstRowPitch > UINT32_MAX) return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); @@ -1045,7 +1056,7 @@ HRESULT DirectX::SaveWICTextureToFile( return E_INVALIDARG; ComPtr device; - pCommandQ->GetDevice(IID_PPV_ARGS(device.GetAddressOf())); + pCommandQ->GetDevice(IID_ID3D12Device, reinterpret_cast(device.GetAddressOf())); // Get the size of the image const auto desc = pSource->GetDesc(); @@ -1068,7 +1079,7 @@ HRESULT DirectX::SaveWICTextureToFile( &totalResourceSize); // Round up the srcPitch to multiples of 256 - UINT64 dstRowPitch = (fpRowPitch + 255) & ~0xFF; + UINT64 dstRowPitch = (fpRowPitch + 255) & ~0xFFu; if (dstRowPitch > UINT32_MAX) return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); diff --git a/ScreenGrab/ScreenGrab12.h b/ScreenGrab/ScreenGrab12.h index c7864cf..68cf3f9 100644 --- a/ScreenGrab/ScreenGrab12.h +++ b/ScreenGrab/ScreenGrab12.h @@ -19,7 +19,7 @@ #include -#include +#include #include #include @@ -42,4 +42,4 @@ namespace DirectX D3D12_RESOURCE_STATES afterState = D3D12_RESOURCE_STATE_RENDER_TARGET, _In_opt_ const GUID* targetFormat = nullptr, _In_opt_ std::function setCustomProps = nullptr); -} \ No newline at end of file +} diff --git a/WICTextureLoader/WICTextureLoader.cpp b/WICTextureLoader/WICTextureLoader.cpp index 1bd4c50..240700c 100644 --- a/WICTextureLoader/WICTextureLoader.cpp +++ b/WICTextureLoader/WICTextureLoader.cpp @@ -36,8 +36,9 @@ #include #include -#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) ) -#pragma comment(lib,"dxguid.lib") +#ifdef __clang__ +#pragma clang diagnostic ignored "-Wcovered-switch-default" +#pragma clang diagnostic ignored "-Wswitch-enum" #endif using namespace DirectX; @@ -164,49 +165,53 @@ namespace bool g_WIC2 = false; //-------------------------------------------------------------------------------------- + BOOL WINAPI InitializeWICFactory(PINIT_ONCE, PVOID, PVOID* ifactory) noexcept + { +#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE) + HRESULT hr = CoCreateInstance( + CLSID_WICImagingFactory2, + nullptr, + CLSCTX_INPROC_SERVER, + __uuidof(IWICImagingFactory2), + ifactory + ); + + if (SUCCEEDED(hr)) + { + // WIC2 is available on Windows 10, Windows 8.x, and Windows 7 SP1 with KB 2670838 installed + g_WIC2 = true; + return TRUE; + } + else + { + hr = CoCreateInstance( + CLSID_WICImagingFactory1, + nullptr, + CLSCTX_INPROC_SERVER, + __uuidof(IWICImagingFactory), + ifactory + ); + return SUCCEEDED(hr) ? TRUE : FALSE; + } +#else + return SUCCEEDED(CoCreateInstance( + CLSID_WICImagingFactory, + nullptr, + CLSCTX_INPROC_SERVER, + __uuidof(IWICImagingFactory), + ifactory)) ? TRUE : FALSE; +#endif + } + IWICImagingFactory* _GetWIC() { static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT; IWICImagingFactory* factory = nullptr; - InitOnceExecuteOnce(&s_initOnce, - [](PINIT_ONCE, PVOID, PVOID *ifactory) -> BOOL - { -#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE) - HRESULT hr = CoCreateInstance( - CLSID_WICImagingFactory2, - nullptr, - CLSCTX_INPROC_SERVER, - __uuidof(IWICImagingFactory2), - ifactory - ); - - if (SUCCEEDED(hr)) - { - // WIC2 is available on Windows 10, Windows 8.x, and Windows 7 SP1 with KB 2670838 installed - g_WIC2 = true; - return TRUE; - } - else - { - hr = CoCreateInstance( - CLSID_WICImagingFactory1, - nullptr, - CLSCTX_INPROC_SERVER, - __uuidof(IWICImagingFactory), - ifactory - ); - return SUCCEEDED(hr) ? TRUE : FALSE; - } -#else - return SUCCEEDED(CoCreateInstance( - CLSID_WICImagingFactory, - nullptr, - CLSCTX_INPROC_SERVER, - __uuidof(IWICImagingFactory), - ifactory)) ? TRUE : FALSE; -#endif - }, nullptr, reinterpret_cast(&factory)); + (void)InitOnceExecuteOnce(&s_initOnce, + InitializeWICFactory, + nullptr, + reinterpret_cast(&factory)); return factory; } @@ -647,7 +652,7 @@ namespace SRVDesc.Format = desc.Format; SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - SRVDesc.Texture2D.MipLevels = (autogen) ? -1 : 1; + SRVDesc.Texture2D.MipLevels = (autogen) ? UINT(-1) : 1; hr = d3dDevice->CreateShaderResourceView(tex, &SRVDesc, textureView); if (FAILED(hr)) diff --git a/WICTextureLoader/WICTextureLoader.h b/WICTextureLoader/WICTextureLoader.h index 8843c33..142a050 100644 --- a/WICTextureLoader/WICTextureLoader.h +++ b/WICTextureLoader/WICTextureLoader.h @@ -123,4 +123,5 @@ namespace DirectX _In_ unsigned int loadFlags, _Outptr_opt_ ID3D11Resource** texture, _Outptr_opt_ ID3D11ShaderResourceView** textureView); -} \ No newline at end of file +} + diff --git a/WICTextureLoader/WICTextureLoader12.cpp b/WICTextureLoader/WICTextureLoader12.cpp index 7ca4519..45cb828 100644 --- a/WICTextureLoader/WICTextureLoader12.cpp +++ b/WICTextureLoader/WICTextureLoader12.cpp @@ -30,6 +30,14 @@ #include +#ifdef __clang__ +#pragma clang diagnostic ignored "-Wtautological-type-limit-compare" +#pragma clang diagnostic ignored "-Wcovered-switch-default" +#pragma clang diagnostic ignored "-Wswitch" +#pragma clang diagnostic ignored "-Wswitch-enum" +#endif + +#define D3DX12_NO_STATE_OBJECT_HELPERS #include "d3dx12.h" using namespace DirectX; @@ -143,21 +151,25 @@ namespace // We don't support n-channel formats }; + BOOL WINAPI InitializeWICFactory(PINIT_ONCE, PVOID, PVOID* ifactory) noexcept + { + return SUCCEEDED(CoCreateInstance( + CLSID_WICImagingFactory2, + nullptr, + CLSCTX_INPROC_SERVER, + __uuidof(IWICImagingFactory2), + ifactory)) ? TRUE : FALSE; + } + IWICImagingFactory2* _GetWIC() { static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT; IWICImagingFactory2* factory = nullptr; (void)InitOnceExecuteOnce(&s_initOnce, - [](PINIT_ONCE, PVOID, PVOID *ifactory) -> BOOL - { - return SUCCEEDED( CoCreateInstance( - CLSID_WICImagingFactory2, - nullptr, - CLSCTX_INPROC_SERVER, - __uuidof(IWICImagingFactory2), - ifactory) ) ? TRUE : FALSE; - }, nullptr, reinterpret_cast(&factory)); + InitializeWICFactory, + nullptr, + reinterpret_cast(&factory)); return factory; } @@ -513,7 +525,8 @@ namespace &desc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, - IID_PPV_ARGS(&tex)); + IID_ID3D12Resource, + reinterpret_cast(&tex)); if (FAILED(hr)) { @@ -523,8 +536,8 @@ namespace _Analysis_assume_(tex != nullptr); subresource.pData = decodedData.get(); - subresource.RowPitch = rowPitch; - subresource.SlicePitch = imageSize; + subresource.RowPitch = static_cast(rowPitch); + subresource.SlicePitch = static_cast(imageSize); *texture = tex; return hr; diff --git a/WICTextureLoader/WICTextureLoader12.h b/WICTextureLoader/WICTextureLoader12.h index ff3e49d..8d44022 100644 --- a/WICTextureLoader/WICTextureLoader12.h +++ b/WICTextureLoader/WICTextureLoader12.h @@ -75,4 +75,4 @@ namespace DirectX _Outptr_ ID3D12Resource** texture, std::unique_ptr& decodedData, D3D12_SUBRESOURCE_DATA& subresource); -} \ No newline at end of file +}