Fixed template class; illegal interface class. compiles on Windows

This commit is contained in:
Reece Wilson 2020-09-12 03:29:30 +01:00
parent 4af51876cb
commit be1a712e2c
10 changed files with 64 additions and 42 deletions

View File

@ -1027,7 +1027,6 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce
// Write blob // Write blob
auto bytesToWrite = static_cast<const DWORD>(blob.GetBufferSize()); auto bytesToWrite = static_cast<const DWORD>(blob.GetBufferSize());
DWORD bytesWritten;
if (!hFile.Write(blob.GetBufferPointer(), bytesToWrite)) if (!hFile.Write(blob.GetBufferPointer(), bytesToWrite))
{ {
return E_FAIL; return E_FAIL;
@ -1048,7 +1047,6 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce
auto headerLen = static_cast<DWORD>(strlen(header)); auto headerLen = static_cast<DWORD>(strlen(header));
DWORD bytesWritten;
if (!hFile.Write(header, headerLen)) if (!hFile.Write(header, headerLen))
{ {
return E_FAIL; return E_FAIL;

View File

@ -690,7 +690,7 @@ void ScratchImage::Release() noexcept
if (m_memory) if (m_memory)
{ {
std::free(m_memory); FreeVectorAligned(m_memory);
m_memory = nullptr; m_memory = nullptr;
} }

View File

@ -70,13 +70,17 @@
#pragma clang diagnostic ignored "-Wunknown-pragmas" #pragma clang diagnostic ignored "-Wunknown-pragmas"
#endif #endif
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS // We love the MSVC team `this library component should be retired to Annex D, along side , until a suitable replacement is standardized.`
#ifndef WIN32_LEAN_AND_MEAN #ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#endif #endif
#include <codecvt>
#include <malloc.h> #include <malloc.h>
#include <memory>
#include <vector> #include <vector>
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
@ -91,7 +95,7 @@
#include <filesystem> #include <filesystem>
#include <ios> #include <ios>
#include <fstream> #include <fstream>
#include <locale>
#include <assert.h> #include <assert.h>
#if !defined(_DXTX_NOWIN) #if !defined(_DXTX_NOWIN)
@ -144,7 +148,8 @@
#endif #endif
#include "StdFS.hpp" #include <DXMemory.hpp>
#include <StdFS.hpp>
#define _DXTEX_PRIVATE #define _DXTEX_PRIVATE
#include "DirectXTex.h" #include "DirectXTex.h"

View File

@ -150,12 +150,21 @@ bool DirectX::_DXGIToWIC(DXGI_FORMAT format, GUID& guid, bool ignoreRGBvsBGR) no
{ {
switch (format) switch (format)
{ {
case DXGI_FORMA#endif case DXGI_FORMAT_R8G8B8A8_UNORM:
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
if (ignoreRGBvsBGR)
{
// If we are not doing conversion so don't really care about BGR vs RGB color-order,
// we can use the canonical WIC 32bppBGRA format which avoids an extra format conversion when using the WIC scaler
memcpy(&guid, &GUID_WICPixelFormat32bppBGRA, sizeof(GUID));
}
else
{
memcpy(&guid, &GUID_WICPixelFormat32bppRGBA, sizeof(GUID)); memcpy(&guid, &GUID_WICPixelFormat32bppRGBA, sizeof(GUID));
} }
return true; return true;
case DXGI_FORMAT_D32_FLOAT: case DXGI_FORMAT_D32_FLOAT:
memcpy(&guid, &GUID_WICPixelFormat32bppGrayFloat, sizeof(GUID)); memcpy(&guid, &GUID_WICPixelFormat32bppGrayFloat, sizeof(GUID));
return true; return true;
@ -1454,7 +1463,7 @@ void Blob::Release() noexcept
{ {
if (m_buffer) if (m_buffer)
{ {
std::free(m_buffer); FreeVectorAligned(m_buffer);
m_buffer = nullptr; m_buffer = nullptr;
} }
@ -1469,7 +1478,7 @@ HRESULT Blob::Initialize(size_t size) noexcept
Release(); Release();
m_buffer = std::aligned_alloc(size, 16); m_buffer = AllocateVectorAligned(size);
if (!m_buffer) if (!m_buffer)
{ {
Release(); Release();

View File

@ -170,6 +170,8 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<DisableSpecificWarnings>26812</DisableSpecificWarnings> <DisableSpecificWarnings>26812</DisableSpecificWarnings>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>C:\Users\slowerboi\Desktop\test\DirectXTex-CrossPlatform\PlatformSupport </AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
@ -235,6 +237,8 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<DisableSpecificWarnings>26812</DisableSpecificWarnings> <DisableSpecificWarnings>26812</DisableSpecificWarnings>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>C:\Users\slowerboi\Desktop\test\DirectXTex-CrossPlatform\PlatformSupport </AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
@ -302,6 +306,8 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<DisableSpecificWarnings>26812</DisableSpecificWarnings> <DisableSpecificWarnings>26812</DisableSpecificWarnings>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>C:\Users\slowerboi\Desktop\test\DirectXTex-CrossPlatform\PlatformSupport </AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>

View File

@ -11,14 +11,8 @@
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
struct aligned_deleter { void operator()(void* p) noexcept { std::free(p); } }; struct aligned_deleter { void operator()(void* p) noexcept { FreeVectorAligned(p); } };
using ScopedAlignedArrayFloat = std::unique_ptr<float[], aligned_deleter>; using ScopedAlignedArrayFloat = std::unique_ptr<float[], aligned_deleter>;
using ScopedAlignedArrayXMVECTOR = std::unique_ptr<DirectX::XMVECTOR[], aligned_deleter>; using ScopedAlignedArrayXMVECTOR = std::unique_ptr<DirectX::XMVECTOR[], aligned_deleter>;
static inline void * AllocateVectorAligned(size_t length)
{
return std::aligned_alloc(16, length);
}

View File

@ -0,0 +1,19 @@
#pragma once
static inline void FreeVectorAligned(void * ptr)
{
#if defined(WIN32)
_aligned_free(ptr);
#else
std::free(ptr);
#endif
}
static inline void * AllocateVectorAligned(size_t length)
{
#if defined(WIN32)
return _aligned_malloc(length, 16);
#else
return std::aligned_alloc(16, length);
#endif
}

View File

@ -0,0 +1 @@

View File

@ -1,20 +1,20 @@
#pragma once #pragma once
template<typename T> template<typename T>
class ScopedFile class ScopedFile
{ {
public: public:
ScopedFile(const std::string & path, bool reset = false) ScopedFile(const std::string & path, bool reset = false)
{ {
init(path, reset); Init(path, reset);
} }
ScopedFile(const std::wstring & path, bool reset = false) ScopedFile(const std::wstring & path, bool reset = false)
{ {
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter; std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
init(converter.to_bytes(path), reset); Init(converter.to_bytes(path), reset);
} }
~ScopedFile() ~ScopedFile()
@ -23,13 +23,10 @@ public:
if (this->_temp) if (this->_temp)
{ {
DeleteFile(); std::filesystem::remove(_path);
} }
} }
virtual size_t GetLength();
virtual void SeekBegin(size_t offset);
virtual void DeleteFile();
void MakeTemp() void MakeTemp()
{ {
@ -43,7 +40,7 @@ protected:
private: private:
void init(const std::string & path, bool reset) void Init(const std::string & path, bool reset)
{ {
this->_path = path; this->_path = path;
this->_temp = false; this->_temp = false;
@ -75,12 +72,12 @@ public:
// - // -
} }
void SeekBegin(size_t offset) void SeekBegin(size_t offset)
{ {
_stream.seekp(offset, std::ios_base::beg); _stream.seekp(offset, std::ios_base::beg);
} }
size_t GetOffset() size_t GetOffset()
{ {
return static_cast<size_t>(_stream.tellp());; return static_cast<size_t>(_stream.tellp());;
} }
@ -110,11 +107,6 @@ public:
} }
return true; return true;
} }
void DeleteFile()
{
std::filesystem::remove(_path);
}
}; };
@ -176,9 +168,4 @@ public:
in.resize(length); in.resize(length);
return Read(in.data(), length); return Read(in.data(), length);
} }
void DeleteFile()
{
std::filesystem::remove(_path);
}
}; };

View File

@ -164,13 +164,14 @@
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<FloatingPointModel>Fast</FloatingPointModel> <FloatingPointModel>Fast</FloatingPointModel>
<AdditionalIncludeDirectories>..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>C:\Users\slowerboi\Desktop\test\DirectXTex-CrossPlatform\PlatformSupport;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
<ControlFlowGuard>Guard</ControlFlowGuard> <ControlFlowGuard>Guard</ControlFlowGuard>
<DisableSpecificWarnings>26812</DisableSpecificWarnings> <DisableSpecificWarnings>26812</DisableSpecificWarnings>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalDependencies>ole32.lib;windowscodecs.lib;uuid.lib;version.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>ole32.lib;windowscodecs.lib;uuid.lib;version.lib;%(AdditionalDependencies)</AdditionalDependencies>
@ -228,13 +229,14 @@
<WarningLevel>Level4</WarningLevel> <WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<FloatingPointModel>Fast</FloatingPointModel> <FloatingPointModel>Fast</FloatingPointModel>
<AdditionalIncludeDirectories>..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>C:\Users\slowerboi\Desktop\test\DirectXTex-CrossPlatform\PlatformSupport;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ControlFlowGuard>Guard</ControlFlowGuard> <ControlFlowGuard>Guard</ControlFlowGuard>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>26812</DisableSpecificWarnings> <DisableSpecificWarnings>26812</DisableSpecificWarnings>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalDependencies>ole32.lib;windowscodecs.lib;uuid.lib;version.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>ole32.lib;windowscodecs.lib;uuid.lib;version.lib;%(AdditionalDependencies)</AdditionalDependencies>
@ -294,13 +296,14 @@
<WarningLevel>Level4</WarningLevel> <WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<FloatingPointModel>Fast</FloatingPointModel> <FloatingPointModel>Fast</FloatingPointModel>
<AdditionalIncludeDirectories>..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>C:\Users\slowerboi\Desktop\test\DirectXTex-CrossPlatform\PlatformSupport;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
<ControlFlowGuard>Guard</ControlFlowGuard> <ControlFlowGuard>Guard</ControlFlowGuard>
<DisableSpecificWarnings>26812</DisableSpecificWarnings> <DisableSpecificWarnings>26812</DisableSpecificWarnings>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalDependencies>ole32.lib;windowscodecs.lib;uuid.lib;version.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>ole32.lib;windowscodecs.lib;uuid.lib;version.lib;%(AdditionalDependencies)</AdditionalDependencies>