Support for Windows Subsystem for Linux (#54)

This commit is contained in:
Chuck Walbourn 2021-01-08 02:07:47 -08:00 коммит произвёл GitHub
Родитель a4a13839f5
Коммит cd781c6b72
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
18 изменённых файлов: 210 добавлений и 91 удалений

9
.gitignore поставляемый
Просмотреть файл

@ -18,7 +18,7 @@
*.VC.db
*.nupkg
.vs
Bin
[Bb]in
/ipch
Debug
Profile
@ -26,4 +26,9 @@ Release
x64
/Tests
/wiki
/out
/out
/CMakeCache.txt
/CMakeFiles
/Makefile
/cmake
/cmake_install.cmake

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

@ -74,6 +74,12 @@ if(MSVC)
string(REPLACE "/GR " "/GR- " CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
endif()
if (NOT WIN32)
find_package(directx-headers CONFIG REQUIRED)
find_package(directxmath CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE Microsoft::DirectX-Headers Microsoft::DirectXMath)
endif()
#--- Utilities
set(UTILS_HEADERS
Utilities/WaveFrontReader.h)
@ -136,7 +142,7 @@ install(FILES
DESTINATION cmake/)
#--- Command-line tool
if(BUILD_TOOLS)
if(BUILD_TOOLS AND WIN32)
add_executable(meshconvert
Meshconvert/Meshconvert.cpp
Meshconvert/MeshOBJ.cpp
@ -149,13 +155,13 @@ if(BUILD_TOOLS)
endif()
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /fp:fast)
if(BUILD_TOOLS)
if(BUILD_TOOLS AND WIN32)
target_compile_options(meshconvert PRIVATE /fp:fast)
endif()
if(${CMAKE_SIZEOF_VOID_P} EQUAL "4")
target_compile_options(${PROJECT_NAME} PRIVATE /arch:SSE2)
if(BUILD_TOOLS)
if(BUILD_TOOLS AND WIN32)
target_compile_options(meshconvert PRIVATE /arch:SSE2)
endif()
endif()
@ -165,32 +171,32 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(WarningsLib "-Wpedantic" "-Wextra")
target_compile_options(${PROJECT_NAME} PRIVATE ${WarningsLib})
if(BUILD_TOOLS)
if(BUILD_TOOLS AND WIN32)
set(WarningsEXE ${WarningsLib} "-Wno-c++98-compat" "-Wno-c++98-compat-pedantic" "-Wno-switch" "-Wno-switch-enum" "-Wno-double-promotion" "-Wno-exit-time-destructors" "-Wno-missing-prototypes")
target_compile_options(meshconvert PRIVATE ${WarningsEXE})
endif()
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(${PROJECT_NAME} PRIVATE /permissive- /JMC- /Zc:__cplusplus)
if(BUILD_TOOLS)
if(BUILD_TOOLS AND WIN32)
target_compile_options(meshconvert PRIVATE /permissive- /JMC- /Zc:__cplusplus)
endif()
if(ENABLE_CODE_ANALYSIS)
target_compile_options(${PROJECT_NAME} PRIVATE /analyze)
if(BUILD_TOOLS)
if(BUILD_TOOLS AND WIN32)
target_compile_options(meshconvert PRIVATE /analyze)
endif()
endif()
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.26)
target_compile_options(${PROJECT_NAME} PRIVATE /Zc:preprocessor /wd5105)
if(BUILD_TOOLS)
if(BUILD_TOOLS AND WIN32)
target_compile_options(meshconvert PRIVATE /Zc:preprocessor /wd5105)
endif()
endif()
if(BUILD_TOOLS)
if(BUILD_TOOLS AND WIN32)
set(WarningsEXE "/wd4061" "/wd4365" "/wd4668" "/wd4710" "/wd4820" "/wd5039" "/wd5045" "/wd5219")
target_compile_options(meshconvert PRIVATE ${WarningsEXE})
endif()
@ -199,7 +205,7 @@ endif()
if(WIN32)
# Windows 10 is used here to build the DirectX 12 code paths as well as 11
target_compile_definitions(${PROJECT_NAME} PRIVATE _UNICODE UNICODE)
if(BUILD_TOOLS)
if(BUILD_TOOLS AND WIN32)
target_compile_definitions(meshconvert PRIVATE _UNICODE UNICODE _WIN32_WINNT=0x0601)
endif()
@ -210,6 +216,6 @@ if(WIN32)
endif()
endif()
if(BUILD_TOOLS)
if(BUILD_TOOLS AND WIN32)
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT meshconvert)
endif()

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

@ -19,6 +19,7 @@
#include <utility>
#include <vector>
#if defined(WIN32) || defined(WINAPI_FAMILY)
#if !defined(__d3d11_h__) && !defined(__d3d11_x_h__) && !defined(__d3d12_h__) && !defined(__d3d12_x_h__) && !defined(__XBOX_D3D12_X__)
#ifdef _GAMING_XBOX_SCARLETT
#include <d3d12_xs.h>
@ -30,6 +31,10 @@
#include <d3d11_1.h>
#endif
#endif
#else
#include <directx/dxgiformat.h>
#include <wsl/winadapter.h>
#endif
#include <DirectXMath.h>
#include <DirectXCollision.h>

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

@ -1,6 +1,6 @@
//-------------------------------------------------------------------------------------
// DirectXMeshAdjacency.cpp
//
//
// DirectX Mesh Geometry Library - Adjacency computation
//
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -645,7 +645,7 @@ HRESULT DirectX::GenerateAdjacencyAndPointReps(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
std::unique_ptr<uint32_t[]> temp;
if (!pointRep)
@ -687,7 +687,7 @@ HRESULT DirectX::GenerateAdjacencyAndPointReps(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
std::unique_ptr<uint32_t[]> temp;
if (!pointRep)
@ -727,7 +727,7 @@ HRESULT DirectX::ConvertPointRepsToAdjacency(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
std::unique_ptr<uint32_t[]> temp;
if (!pointRep)
@ -763,7 +763,7 @@ HRESULT DirectX::ConvertPointRepsToAdjacency(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
std::unique_ptr<uint32_t[]> temp;
if (!pointRep)

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

@ -1,6 +1,6 @@
//-------------------------------------------------------------------------------------
// DirectXMeshClean.cpp
//
//
// DirectX Mesh Geometry Library - Mesh clean-up
//
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -27,7 +27,7 @@ namespace
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
dupVerts.clear();
size_t curNewVert = nVerts;
@ -390,7 +390,7 @@ namespace
}
if ((uint64_t(nVerts) + uint64_t(dupVerts.size())) >= index_t(-1))
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
if (!dupVerts.empty())
{

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

@ -1,6 +1,6 @@
//-------------------------------------------------------------------------------------
// DirectXMeshGSAdjacency.cpp
//
//
// DirectX Mesh Geometry Library - Geometry Shader adjacency computation
//
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -36,11 +36,11 @@ namespace
if (indices == indicesAdj)
{
// Does not support in-place conversion of the index buffer
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
return HRESULT_E_NOT_SUPPORTED;
}
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
size_t inputi = 0;
size_t outputi = 0;

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

@ -1,6 +1,6 @@
//-------------------------------------------------------------------------------------
// DirectXMeshNormals.cpp
//
//
// DirectX Mesh Geometry Library - Normal computation
//
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -280,7 +280,7 @@ HRESULT DirectX::ComputeNormals(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
bool cw = (flags & CNORM_WIND_CW) ? true : false;
@ -314,7 +314,7 @@ HRESULT DirectX::ComputeNormals(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
bool cw = (flags & CNORM_WIND_CW) ? true : false;

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

@ -1,6 +1,6 @@
//-------------------------------------------------------------------------------------
// DirectXMeshOptimize.cpp
//
//
// DirectX Mesh Geometry Library - Mesh optimization
//
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -33,7 +33,7 @@ namespace
}
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
std::unique_ptr<uint32_t[]> tempRemap(new (std::nothrow) uint32_t[nVerts]);
if (!tempRemap)
@ -102,7 +102,7 @@ HRESULT DirectX::AttributeSort(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
using intpair_t = std::pair<uint32_t, uint32_t>;

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

@ -1,6 +1,6 @@
//-------------------------------------------------------------------------------------
// DirectXMeshOptimizeLRU.cpp
//
//
// DirectX Mesh Geometry Library - Mesh optimization
//
// Forsyth "Linear-Speed Vertex Cache Optimisation"
@ -78,9 +78,15 @@ namespace
float s_vertexCacheScores[kMaxVertexCacheSize + 1][kMaxVertexCacheSize];
float s_vertexValenceScores[kMaxPrecomputedVertexValenceScores];
#ifdef WIN32
static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT;
BOOL WINAPI ComputeVertexScores(PINIT_ONCE, PVOID, PVOID*) noexcept
#else
std::once_flag s_initOnce;
void ComputeVertexScores() noexcept
#endif
{
for (uint32_t cacheSize = 0; cacheSize <= kMaxVertexCacheSize; ++cacheSize)
{
@ -95,7 +101,9 @@ namespace
s_vertexValenceScores[valence] = ComputeVertexValenceScore(valence);
}
#ifdef WIN32
return TRUE;
#endif
}
float FindVertexScore(uint32_t numActiveFaces, uint32_t cachePosition, uint32_t vertexCacheSize) noexcept
@ -508,9 +516,13 @@ HRESULT DirectX::OptimizeFacesLRU(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
#ifdef WIN32
InitOnceExecuteOnce(&s_initOnce, ComputeVertexScores, nullptr, nullptr);
#else
std::call_once(s_initOnce, ComputeVertexScores);
#endif
return OptimizeFacesImpl<uint16_t>(indices, static_cast<uint32_t>(nFaces * 3), faceRemap, lruCacheSize, 0);
}
@ -529,9 +541,13 @@ HRESULT DirectX::OptimizeFacesLRU(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
#ifdef WIN32
InitOnceExecuteOnce(&s_initOnce, ComputeVertexScores, nullptr, nullptr);
#else
std::call_once(s_initOnce, ComputeVertexScores);
#endif
return OptimizeFacesImpl<uint32_t>(indices, static_cast<uint32_t>(nFaces * 3), faceRemap, lruCacheSize, 0);
}
@ -553,9 +569,13 @@ HRESULT DirectX::OptimizeFacesLRUEx(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
#ifdef WIN32
InitOnceExecuteOnce(&s_initOnce, ComputeVertexScores, nullptr, nullptr);
#else
std::call_once(s_initOnce, ComputeVertexScores);
#endif
auto subsets = ComputeSubsets(attributes, nFaces);
@ -570,7 +590,7 @@ HRESULT DirectX::OptimizeFacesLRUEx(
return E_UNEXPECTED;
if ((uint64_t(it->first) + uint64_t(it->second)) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
uint32_t faceMax = uint32_t(it->first + it->second);
@ -602,9 +622,13 @@ HRESULT DirectX::OptimizeFacesLRUEx(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
#ifdef WIN32
InitOnceExecuteOnce(&s_initOnce, ComputeVertexScores, nullptr, nullptr);
#else
std::call_once(s_initOnce, ComputeVertexScores);
#endif
auto subsets = ComputeSubsets(attributes, nFaces);
@ -619,7 +643,7 @@ HRESULT DirectX::OptimizeFacesLRUEx(
return E_UNEXPECTED;
if ((uint64_t(it->first) + uint64_t(it->second)) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
uint32_t faceMax = uint32_t(it->first + it->second);

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

@ -1,6 +1,6 @@
//-------------------------------------------------------------------------------------
// DirectXMeshOptimizeTVC.cpp
//
//
// DirectX Mesh Geometry Library - Mesh optimization
//
// Hoppe "Optimization of mesh locality for transparent vertex caching"
@ -56,7 +56,7 @@ namespace
for (auto it = subsets.cbegin(); it != subsets.cend(); ++it)
{
if ((uint64_t(it->first) + uint64_t(it->second)) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
if (it->second > mMaxSubset)
{
@ -174,7 +174,7 @@ namespace
return E_POINTER;
if ((uint64_t(faceOffset) + uint64_t(faceCount)) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
uint32_t faceMax = uint32_t(faceOffset + faceCount);
@ -781,7 +781,7 @@ HRESULT DirectX::OptimizeFaces(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
if (vertexCache == OPTFACES_V_STRIPORDER)
{
@ -809,7 +809,7 @@ HRESULT DirectX::OptimizeFaces(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
if (vertexCache == OPTFACES_V_STRIPORDER)
{
@ -840,7 +840,7 @@ HRESULT DirectX::OptimizeFacesEx(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
if (vertexCache == OPTFACES_V_STRIPORDER)
{
@ -869,7 +869,7 @@ HRESULT DirectX::OptimizeFacesEx(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
if (vertexCache == OPTFACES_V_STRIPORDER)
{

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

@ -57,6 +57,7 @@
#pragma clang diagnostic ignored "-Wreserved-id-macro"
#endif
#if defined(WIN32) || defined(WINAPI_FAMILY)
#pragma warning(push)
#pragma warning(disable : 4005)
#define WIN32_LEAN_AND_MEAN
@ -88,10 +89,11 @@
#else
#include <d3d11_1.h>
#endif
#define _XM_NO_XMVECTOR_OVERLOADS_
#include "DirectXMesh.h"
#else // !WIN32
#include <wsl/winadapter.h>
#include <wsl/wrladapter.h>
#include <directx/d3d12.h>
#endif
#include <array>
#include <algorithm>
@ -105,6 +107,14 @@
#include <unordered_map>
#include <unordered_set>
#ifndef WIN32
#include <mutex>
#endif
#define _XM_NO_XMVECTOR_OVERLOADS_
#include "DirectXMesh.h"
#include <malloc.h>
#include "scoped.h"
@ -113,6 +123,19 @@
#define XBOX_DXGI_FORMAT_R10G10B10_SNORM_A2_UNORM DXGI_FORMAT(189)
#endif
// HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW)
#define HRESULT_E_ARITHMETIC_OVERFLOW static_cast<HRESULT>(0x80070216L)
// HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED)
#define HRESULT_E_NOT_SUPPORTED static_cast<HRESULT>(0x80070032L)
// HRESULT_FROM_WIN32(ERROR_INVALID_NAME)
#define HRESULT_E_INVALID_NAME static_cast<HRESULT>(0x8007007BL)
// E_BOUNDS
#ifndef E_BOUNDS
#define E_BOUNDS static_cast<HRESULT>(0x8000000BL)
#endif
namespace DirectX
{

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

@ -1,6 +1,6 @@
//-------------------------------------------------------------------------------------
// DirectXMeshRemap.cpp
//
//
// DirectX Mesh Geometry Library - Remap functions for applying face/vertex mappings
//
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -285,7 +285,7 @@ namespace
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
if (nVerts >= index_t(-1))
return E_INVALIDARG;
@ -348,7 +348,7 @@ namespace
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
if (nVerts >= index_t(-1))
return E_INVALIDARG;
@ -413,10 +413,10 @@ HRESULT DirectX::ReorderIB(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
if (ibin == ibout)
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
return HRESULT_E_NOT_SUPPORTED;
return ReorderFaces<uint16_t>(ibin, nFaces, nullptr, faceRemap, ibout, nullptr);
}
@ -431,7 +431,7 @@ HRESULT DirectX::ReorderIB(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
return SwapFaces<uint16_t>(ib, nFaces, nullptr, faceRemap);
}
@ -449,10 +449,10 @@ HRESULT DirectX::ReorderIB(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
if (ibin == ibout)
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
return HRESULT_E_NOT_SUPPORTED;
return ReorderFaces<uint32_t>(ibin, nFaces, nullptr, faceRemap, ibout, nullptr);
}
@ -467,7 +467,7 @@ HRESULT DirectX::ReorderIB(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
return SwapFaces<uint32_t>(ib, nFaces, nullptr, faceRemap);
}
@ -489,10 +489,10 @@ HRESULT DirectX::ReorderIBAndAdjacency(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
if ((ibin == ibout) || (adjin == adjout))
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
return HRESULT_E_NOT_SUPPORTED;
return ReorderFaces<uint16_t>(ibin, nFaces, adjin, faceRemap, ibout, adjout);
}
@ -508,7 +508,7 @@ HRESULT DirectX::ReorderIBAndAdjacency(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
return SwapFaces<uint16_t>(ib, nFaces, adj, faceRemap);
}
@ -528,10 +528,10 @@ HRESULT DirectX::ReorderIBAndAdjacency(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
if ((ibin == ibout) || (adjin == adjout))
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
return HRESULT_E_NOT_SUPPORTED;
return ReorderFaces<uint32_t>(ibin, nFaces, adjin, faceRemap, ibout, adjout);
}
@ -547,7 +547,7 @@ HRESULT DirectX::ReorderIBAndAdjacency(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
return SwapFaces<uint32_t>(ib, nFaces, adj, faceRemap);
}
@ -636,10 +636,10 @@ HRESULT DirectX::FinalizeVB(
return E_INVALIDARG;
if ((uint64_t(nVerts) + uint64_t(nDupVerts)) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
if (vbin == vbout)
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
return HRESULT_E_NOT_SUPPORTED;
size_t newVerts = nVerts + nDupVerts;
@ -734,14 +734,14 @@ HRESULT DirectX::FinalizeVBAndPointReps(
return E_INVALIDARG;
if ((uint64_t(nVerts) + uint64_t(nDupVerts)) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
if (vbin == vbout)
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
return HRESULT_E_NOT_SUPPORTED;
size_t newVerts = nVerts + nDupVerts;
std::unique_ptr<uint32_t[]> vertexRemapInverse;
std::unique_ptr<uint32_t[]> vertexRemapInverse;
if (vertexRemap)
{
vertexRemapInverse.reset(new (std::nothrow) uint32_t[newVerts]);
@ -890,7 +890,7 @@ HRESULT DirectX::CompactVB(
return E_INVALIDARG;
if (vbin == vbout)
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
return HRESULT_E_NOT_SUPPORTED;
size_t newVerts = nVerts - trailingUnused;
@ -921,4 +921,3 @@ HRESULT DirectX::CompactVB(
return S_OK;
}

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

@ -1,6 +1,6 @@
//-------------------------------------------------------------------------------------
// DirectXMeshTangentFrame.cpp
//
//
// DirectX Mesh Geometry Library - Normals, Tangents, and Bi-Tangents Computation
//
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -36,7 +36,7 @@ namespace
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
static constexpr float EPSILON = 0.0001f;
static const XMVECTORF32 s_flips = { { { 1.f, -1.f, -1.f, 1.f } } };

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

@ -1,6 +1,6 @@
//-------------------------------------------------------------------------------------
// DirectXMeshVBReader.cpp
//
//
// DirectX Mesh Geometry Library - Vertex Buffer Reader
//
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -14,6 +14,10 @@
using namespace DirectX;
using namespace DirectX::PackedVector;
#ifndef WIN32
#define _stricmp strcasecmp
#endif
namespace
{
constexpr size_t c_MaxSlot = 32;
@ -166,7 +170,7 @@ HRESULT VBReader::Impl::Initialize(const InputElementDesc* vbDecl, size_t nDecl)
{
// Does not currently support instance data layouts
Release();
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
return HRESULT_E_NOT_SUPPORTED;
}
mInputDesc.push_back(vbDecl[j]);
@ -291,7 +295,7 @@ HRESULT VBReader::Impl::Read(XMVECTOR* buffer, const char* semanticName, unsigne
}
if (it == range.second)
return HRESULT_FROM_WIN32(ERROR_INVALID_NAME);
return HRESULT_E_INVALID_NAME;
uint32_t inputSlot = mInputDesc[it->second].InputSlot;

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

@ -1,6 +1,6 @@
//-------------------------------------------------------------------------------------
// DirectXMeshVBWriter.cpp
//
//
// DirectX Mesh Geometry Library - Vertex Buffer Writer
//
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -14,6 +14,10 @@
using namespace DirectX;
using namespace DirectX::PackedVector;
#ifndef WIN32
#define _stricmp strcasecmp
#endif
namespace
{
constexpr size_t c_MaxSlot = 32;
@ -165,7 +169,7 @@ HRESULT VBWriter::Impl::Initialize(const InputElementDesc* vbDecl, size_t nDecl)
{
// Does not currently support instance data layouts
Release();
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
return HRESULT_E_NOT_SUPPORTED;
}
mInputDesc.push_back(vbDecl[j]);
@ -259,7 +263,7 @@ HRESULT VBWriter::Impl::Write(const XMVECTOR* buffer, const char* semanticName,
}
if (it == range.second)
return HRESULT_FROM_WIN32(ERROR_INVALID_NAME);
return HRESULT_E_INVALID_NAME;
uint32_t inputSlot = mInputDesc[it->second].InputSlot;

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

@ -1,6 +1,6 @@
//-------------------------------------------------------------------------------------
// DirectXMeshValidate.cpp
//
//
// DirectX Mesh Geometry Library - Mesh validation
//
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -13,8 +13,25 @@
using namespace DirectX;
#ifndef WIN32
#include <cstdarg>
#endif
namespace
{
#ifndef WIN32
template<size_t sizeOfBuffer>
inline int swprintf_s(wchar_t (&buffer)[sizeOfBuffer], const wchar_t* format, ...)
{
// This is adapter code. It is not a full implementation of swprintf_s!
va_list ap;
va_start(ap, format);
int result = vswprintf(buffer, sizeOfBuffer, format, ap);
va_end(ap);
return result;
}
#endif
//---------------------------------------------------------------------------------
// Validates indices and optionally the adjacency information
//---------------------------------------------------------------------------------
@ -61,7 +78,7 @@ namespace
result = false;
wchar_t buff[128];
wchar_t buff[128] = {};
swprintf_s(buff, L"An invalid index value (%u) was found on face %zu\n", i, face);
*msgs += buff;
}
@ -76,7 +93,7 @@ namespace
result = false;
wchar_t buff[128];
wchar_t buff[128] = {};
swprintf_s(buff, L"An invalid neighbor index value (%u) was found on face %zu\n", j, face);
*msgs += buff;
}
@ -102,7 +119,7 @@ namespace
result = false;
wchar_t buff[128];
wchar_t buff[128] = {};
swprintf_s(buff, L"An unused face (%zu) contains 'valid' but ignored vertices (%u,%u,%u)\n", face, i0, i1, i2);
*msgs += buff;
}
@ -119,7 +136,7 @@ namespace
result = false;
wchar_t buff[128];
wchar_t buff[128] = {};
swprintf_s(buff, L"An unused face (%zu) has a neighbor %u\n", face, k);
*msgs += buff;
}
@ -151,7 +168,7 @@ namespace
else
bad = i0;
wchar_t buff[128];
wchar_t buff[128] = {};
swprintf_s(buff, L"A point (%u) was found more than once in triangle %zu\n", bad, face);
*msgs += buff;
@ -194,7 +211,7 @@ namespace
result = false;
wchar_t buff[256];
wchar_t buff[256] = {};
swprintf_s(buff, L"A neighbor triangle (%u) does not reference back to this face (%zu) as expected\n", k, face);
*msgs += buff;
}
@ -371,7 +388,7 @@ HRESULT DirectX::Validate(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
if (msgs)
msgs->clear();
@ -408,7 +425,7 @@ HRESULT DirectX::Validate(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
if (msgs)
msgs->clear();

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

@ -1,6 +1,6 @@
//-------------------------------------------------------------------------------------
// DirectXMeshWeldVertices.cpp
//
//
// DirectX Mesh Geometry Library - Vertex welding
//
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -159,7 +159,7 @@ HRESULT DirectX::WeldVertices(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
return WeldVerticesImpl<uint16_t>(indices, nFaces, nVerts, pointRep, vertexRemap, weldTest);
}
@ -178,7 +178,7 @@ HRESULT DirectX::WeldVertices(
return E_INVALIDARG;
if ((uint64_t(nFaces) * 3) >= UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
return HRESULT_E_ARITHMETIC_OVERFLOW;
return WeldVerticesImpl<uint32_t>(indices, nFaces, nVerts, pointRep, vertexRemap, weldTest);
}

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

@ -1,6 +1,6 @@
//-------------------------------------------------------------------------------------
// scoped.h
//
//
// Utility header with helper classes for exception-safe handling of resources
//
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -14,9 +14,39 @@
#include <cstdint>
#include <memory>
#ifndef WIN32
#include <cstdlib>
struct aligned_deleter { void operator()(void* p) noexcept { free(p); } };
using ScopedAlignedArrayFloat = std::unique_ptr<float[], aligned_deleter>;
inline ScopedAlignedArrayFloat make_AlignedArrayFloat(uint64_t count)
{
uint64_t size = sizeof(float) * count;
size = (size + 15u) & ~0xF;
if (size > static_cast<uint64_t>(UINT32_MAX))
return nullptr;
auto ptr = aligned_alloc(16, static_cast<size_t>(size) );
return ScopedAlignedArrayFloat(static_cast<float*>(ptr));
}
using ScopedAlignedArrayXMVECTOR = std::unique_ptr<DirectX::XMVECTOR[], aligned_deleter>;
inline ScopedAlignedArrayXMVECTOR make_AlignedArrayXMVECTOR(uint64_t count)
{
uint64_t size = sizeof(DirectX::XMVECTOR) * count;
if (size > static_cast<uint64_t>(UINT32_MAX))
return nullptr;
auto ptr = aligned_alloc(16, static_cast<size_t>(size));
return ScopedAlignedArrayXMVECTOR(static_cast<DirectX::XMVECTOR*>(ptr));
}
#else // WIN32
//---------------------------------------------------------------------------------
#include <malloc.h>
//---------------------------------------------------------------------------------
struct aligned_deleter { void operator()(void* p) noexcept { _aligned_free(p); } };
using ScopedAlignedArrayFloat = std::unique_ptr<float[], aligned_deleter>;
@ -77,3 +107,5 @@ public:
private:
HANDLE m_handle;
};
#endif // WIN32