├── .clang-format ├── .gitattributes ├── .gitignore ├── BasicXrApp.sln ├── Directory.Build.props ├── Directory.Build.targets ├── LICENSE ├── NOTICE ├── README.md ├── SECURITY.md ├── Samples.sln ├── WinXR.wprp ├── azure-pipelines.yml ├── openxr_preview └── include │ ├── openxr │ ├── openxr.h │ ├── openxr_platform.h │ ├── openxr_platform_defines.h │ ├── openxr_reflection.h │ ├── openxr_reflection_parent_structs.h │ └── openxr_reflection_structs.h │ └── openxr_preview │ └── openxr_msft_preview.h ├── samples ├── BasicXrApp │ ├── App.cpp │ ├── Assets │ │ ├── LockScreenLogo.scale-200.png │ │ ├── SplashScreen.scale-200.png │ │ ├── Square150x150Logo.scale-200.png │ │ ├── Square44x44Logo.scale-200.png │ │ ├── Square44x44Logo.targetsize-24_altform-unplated.png │ │ ├── StoreLogo.png │ │ └── Wide310x150Logo.scale-200.png │ ├── BasicXrApp_uwp.vcxproj │ ├── BasicXrApp_uwp.vcxproj.filters │ ├── BasicXrApp_win32.vcxproj │ ├── CubeGraphics.cpp │ ├── DxUtility.cpp │ ├── DxUtility.h │ ├── OpenXrProgram.cpp │ ├── OpenXrProgram.h │ ├── Package.appxmanifest │ ├── TemporaryKey.pfx │ ├── packages.config │ ├── pch.cpp │ └── pch.h ├── EyeGazeInteractionUwp │ ├── EyeGazeInteractionUwp.vcxproj │ ├── EyeGazeInteractionUwp.vcxproj.filters │ ├── Main.cpp │ ├── Package.appxmanifest │ ├── Scene_EyeGazeInteraction.cpp │ ├── TemporaryKey.pfx │ ├── packages.config │ ├── pch.cpp │ └── pch.h ├── SampleSceneUwp │ ├── Main.cpp │ ├── Package.appxmanifest │ ├── SampleSceneUwp.vcxproj │ ├── SampleSceneUwp.vcxproj.filters │ ├── Scene_HandTracking.cpp │ ├── Scene_Orbit.cpp │ ├── TemporaryKey.pfx │ ├── packages.config │ ├── pch.cpp │ └── pch.h ├── SampleSceneWin32 │ ├── Key.glb │ ├── Main.cpp │ ├── Main.ico │ ├── Main.rc │ ├── Resource.h │ ├── SampleSceneWin32.vcxproj │ ├── SampleSceneWin32.vcxproj.filters │ ├── Scene_ControllerActions.cpp │ ├── Scene_ControllerModel.cpp │ ├── Scene_TrackingState.cpp │ ├── packages.config │ ├── pch.cpp │ ├── pch.h │ └── small.ico ├── SceneUnderstandingUwp │ ├── Main.cpp │ ├── Package.appxmanifest │ ├── SceneUnderstandingUwp.vcxproj │ ├── SceneUnderstandingUwp.vcxproj.filters │ ├── Scene_Placement.cpp │ ├── Scene_QRCode.cpp │ ├── TemporaryKey.pfx │ ├── packages.config │ ├── pch.cpp │ └── pch.h └── ThreeSpacesUwp │ ├── Main.cpp │ ├── Package.appxmanifest │ ├── Scene_ThreeSpaces.cpp │ ├── TemporaryKey.pfx │ ├── ThreeSpacesUwp.vcxproj │ ├── ThreeSpacesUwp.vcxproj.filters │ ├── packages.config │ ├── pch.cpp │ └── pch.h └── shared ├── SampleShared ├── DirectXTK │ ├── DDSTextureLoader.cpp │ ├── DDSTextureLoader.h │ ├── DirectXHelpers.h │ ├── LoaderHelpers.h │ ├── PlatformHelpers.h │ └── dds.h ├── DxUtility.cpp ├── DxUtility.h ├── FileUtility.cpp ├── FileUtility.h ├── SampleShared_uwp.vcxproj ├── SampleShared_uwp.vcxproj.filters ├── SampleShared_win32.vcxproj ├── SampleShared_win32.vcxproj.filters ├── ScopeGuard.h ├── TextureUtility.cpp ├── TextureUtility.h ├── ThreadPool.h ├── Trace.h ├── UWPAssets │ ├── smallTile-sdk.png │ ├── splash-sdk.png │ ├── squareTile-sdk.png │ └── storeLogo-sdk.png ├── XrActionContext.h ├── XrInstanceContext.h ├── XrSessionContext.h ├── XrSystemContext.h ├── packages.config ├── pch.cpp ├── pch.h ├── sample_DiffuseHDR.dds └── sample_SpecularHDR.dds ├── XrSceneLib ├── CompositionLayers.h ├── Context.h ├── ControllerObject.cpp ├── ControllerObject.h ├── FrameTime.h ├── Object.cpp ├── Object.h ├── ObjectMotion.cpp ├── ObjectMotion.h ├── PbrModelObject.cpp ├── PbrModelObject.h ├── ProjectionLayer.cpp ├── ProjectionLayer.h ├── QuadLayerObject.cpp ├── QuadLayerObject.h ├── Scene.cpp ├── Scene.h ├── Scene_Title.cpp ├── SpaceObject.cpp ├── SpaceObject.h ├── TextTexture.cpp ├── TextTexture.h ├── XrApp.cpp ├── XrApp.h ├── XrSceneLib_uwp.vcxproj ├── XrSceneLib_uwp.vcxproj.filters ├── XrSceneLib_win32.vcxproj ├── XrSceneLib_win32.vcxproj.filters ├── packages.config ├── pch.cpp └── pch.h ├── XrUtility ├── XrDispatchTable.h ├── XrEnabledExtensions.h ├── XrEnumerate.h ├── XrError.h ├── XrExtensionDefined.h ├── XrGuid.h ├── XrHandle.h ├── XrListFunctions.h ├── XrMath.h ├── XrPlatformDependencies.h ├── XrSceneUnderstanding.h ├── XrSceneUnderstanding.hpp ├── XrSceneUnderstandingSerialization.hpp ├── XrSide.h ├── XrSpatialGraphBridge.h ├── XrStereoView.h ├── XrString.h ├── XrStruct.h ├── XrStructTraits.h ├── XrToString.h ├── XrUuid.h └── XrViewConfiguration.h ├── ext ├── DirectXMath │ ├── .gitignore │ ├── .nuget │ │ ├── directxmath.nuspec │ │ ├── directxmath.targets │ │ └── signconfig.xml │ ├── Extensions │ │ ├── DirectXMathAVX.h │ │ ├── DirectXMathAVX2.h │ │ ├── DirectXMathBE.h │ │ ├── DirectXMathF16C.h │ │ ├── DirectXMathFMA3.h │ │ ├── DirectXMathFMA4.h │ │ ├── DirectXMathSSE3.h │ │ └── DirectXMathSSE4.h │ ├── HISTORY.md │ ├── Inc │ │ ├── DirectXCollision.h │ │ ├── DirectXCollision.inl │ │ ├── DirectXColors.h │ │ ├── DirectXMath.h │ │ ├── DirectXMathConvert.inl │ │ ├── DirectXMathMatrix.inl │ │ ├── DirectXMathMisc.inl │ │ ├── DirectXMathVector.inl │ │ ├── DirectXPackedVector.h │ │ └── DirectXPackedVector.inl │ ├── LICENSE │ ├── README.md │ ├── SHMath │ │ ├── DirectXSH.cpp │ │ ├── DirectXSH.h │ │ ├── DirectXSHD3D11.cpp │ │ └── DirectXSHD3D12.cpp │ ├── Stereo3D │ │ ├── Stereo3DMatrixHelper.cpp │ │ └── Stereo3DMatrixHelper.h │ └── XDSP │ │ └── XDSP.h ├── d3dx12.h ├── fmt │ ├── args.h │ ├── chrono.h │ ├── color.h │ ├── compile.h │ ├── core.h │ ├── format-inl.h │ ├── format.h │ ├── locale.h │ ├── os.h │ ├── ostream.h │ ├── printf.h │ ├── ranges.h │ └── xchar.h ├── mikktspace.cpp ├── mikktspace.h ├── rapidjson │ ├── allocators.h │ ├── cursorstreamwrapper.h │ ├── document.h │ ├── encodedstream.h │ ├── encodings.h │ ├── error │ │ ├── en.h │ │ └── error.h │ ├── filereadstream.h │ ├── filewritestream.h │ ├── fwd.h │ ├── internal │ │ ├── biginteger.h │ │ ├── clzll.h │ │ ├── diyfp.h │ │ ├── dtoa.h │ │ ├── ieee754.h │ │ ├── itoa.h │ │ ├── meta.h │ │ ├── pow10.h │ │ ├── regex.h │ │ ├── stack.h │ │ ├── strfunc.h │ │ ├── strtod.h │ │ └── swap.h │ ├── istreamwrapper.h │ ├── memorybuffer.h │ ├── memorystream.h │ ├── msinttypes │ │ ├── inttypes.h │ │ └── stdint.h │ ├── ostreamwrapper.h │ ├── pointer.h │ ├── prettywriter.h │ ├── rapidjson.h │ ├── reader.h │ ├── schema.h │ ├── stream.h │ ├── stringbuffer.h │ └── writer.h ├── stb_image.h ├── stb_image_write.h └── tiny_gltf.h ├── gltf ├── ExternalImpl.cpp ├── GltfHelper.cpp ├── GltfHelper.h ├── Gltf_uwp.vcxproj ├── Gltf_uwp.vcxproj.filters ├── Gltf_win32.vcxproj ├── Gltf_win32.vcxproj.filters ├── pch.cpp └── pch.h └── pbr ├── GltfLoader.cpp ├── GltfLoader.h ├── PbrCommon.cpp ├── PbrCommon.h ├── PbrMaterial.cpp ├── PbrMaterial.h ├── PbrModel.cpp ├── PbrModel.h ├── PbrPrimitive.cpp ├── PbrPrimitive.h ├── PbrResources.cpp ├── PbrResources.h ├── Shaders ├── HighlightPixelShader.hlsl ├── HighlightShared.hlsl ├── HighlightVertexShader.hlsl ├── PbrPixelShader.hlsl ├── PbrShared.hlsl ├── PbrVertexShader.hlsl └── Shared.hlsl ├── brdf_lut.png ├── pbr_uwp.vcxproj ├── pbr_uwp.vcxproj.filters ├── pbr_win32.vcxproj ├── pbr_win32.vcxproj.filters ├── pch.cpp └── pch.h /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | # Created at https://zed0.co.uk/clang-format-configurator/ 3 | AllowShortBlocksOnASingleLine: 'false' 4 | AllowShortFunctionsOnASingleLine: 'false' 5 | AccessModifierOffset: '-4' 6 | AlignEscapedNewlines: 'Left' 7 | AlwaysBreakTemplateDeclarations: 'true' 8 | BinPackParameters: false 9 | BinPackArguments: false 10 | BreakBeforeBraces: Custom 11 | BreakConstructorInitializers: 'BeforeComma' 12 | ColumnLimit: '140' 13 | ConstructorInitializerAllOnOneLineOrOnePerLine: 'false' 14 | IndentCaseLabels: 'false' 15 | IndentWidth: '4' 16 | IndentWrappedFunctionNames: 'false' 17 | ForEachMacros: ['TEST_CLASS'] 18 | KeepEmptyLinesAtTheStartOfBlocks: 'false' 19 | MaxEmptyLinesToKeep: '1' 20 | NamespaceIndentation: All 21 | PenaltyReturnTypeOnItsOwnLine: 100 22 | PointerAlignment: Left 23 | SortIncludes: 'false' 24 | SpaceAfterCStyleCast: 'false' 25 | SpaceBeforeAssignmentOperators: 'true' 26 | SpaceBeforeParens: ControlStatements 27 | SpaceInEmptyParentheses: 'false' 28 | SpacesInAngles: 'false' 29 | SpacesInCStyleCastParentheses: 'false' 30 | SpacesInContainerLiterals: 'false' 31 | SpacesInParentheses: 'false' 32 | SpacesInSquareBrackets: 'false' 33 | Standard: Cpp11 34 | UseTab: Never 35 | 36 | ... 37 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.cpp text 3 | *.h text 4 | *.inl text 5 | *.vcproj text 6 | *.vcxproj text 7 | *.sln text 8 | *.props text 9 | *.targets text 10 | *.bat text eol=crlf 11 | *.cmd text eol=crlf 12 | *.sh text eol=lf 13 | *.html text eol=lf 14 | *.adoc text eol=lf 15 | -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | $(SolutionDir)bin\$(Configuration)\$(Platform)\ 9 | $(SolutionDir)obj\$(Configuration)\$(Platform)\$(MSBuildProjectName)\ 10 | $(SolutionDir)obj\$(Configuration)\$(Platform)\$(MSBuildProjectName)\GeneratedFiles 11 | 12 | $(MSBuildThisFileDirectory)shared 13 | $(MSBuildThisFileDirectory)openxr_preview 14 | 15 | 16 | 17 | true 18 | true 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Directory.Build.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | $(OpenXrSdkPath)\include;$(SharedPath);$(SharedPath)\ext;$(IntDir);%(AdditionalIncludeDirectories); 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) Microsoft Corporation. 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd). 40 | 41 | 42 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | # Universal Windows Platform 2 | # Build a Universal Windows Platform project using Visual Studio. 3 | # Add steps that test and distribute an app, save build artifacts, and more: 4 | # https://aka.ms/yaml 5 | 6 | trigger: 7 | - main 8 | 9 | pr: 10 | - main 11 | 12 | pool: 13 | vmImage: "windows-latest" 14 | 15 | stages: 16 | - stage: Build 17 | jobs: 18 | - job: Build 19 | timeoutInMinutes: 30 20 | strategy: 21 | maxParallel: 8 22 | matrix: 23 | Debug x86: 24 | BuildConfiguration: Debug 25 | BuildPlatform: x86 26 | Debug x64: 27 | BuildConfiguration: Debug 28 | BuildPlatform: x64 29 | Debug ARM: 30 | BuildConfiguration: Debug 31 | BuildPlatform: ARM 32 | Debug ARM64: 33 | BuildConfiguration: Debug 34 | BuildPlatform: ARM64 35 | Release x86: 36 | BuildConfiguration: Release 37 | BuildPlatform: x86 38 | Release x64: 39 | BuildConfiguration: Release 40 | BuildPlatform: x64 41 | Release ARM: 42 | BuildConfiguration: Release 43 | BuildPlatform: ARM 44 | Release ARM64: 45 | BuildConfiguration: Release 46 | BuildPlatform: ARM64 47 | steps: 48 | - checkout: self 49 | clean: true 50 | lfs: true 51 | 52 | - task: NuGetInstaller@0 53 | displayName: "NuGet Restore" 54 | inputs: 55 | solution: BasicXrApp.sln 56 | verbosity: Detailed 57 | 58 | - task: NuGetInstaller@0 59 | displayName: "NuGet Restore" 60 | inputs: 61 | solution: Samples.sln 62 | verbosity: Detailed 63 | 64 | - task: VSBuild@1 65 | displayName: "Build Samples.sln" 66 | inputs: 67 | solution: Samples.sln 68 | vsVersion: "16.0" 69 | msbuildArgs: '/fl /flp:LogFile=$(System.DefaultWorkingDirectory)\bin\Logs\MsBuild_$(BuildConfiguration)_$(BuildPlatform).log;Verbosity=diagnostic' 70 | platform: $(BuildPlatform) 71 | configuration: $(BuildConfiguration) 72 | maximumCpuCount: true 73 | 74 | - task: VSBuild@1 75 | displayName: "Build BasicXrApp.sln" 76 | inputs: 77 | solution: "BasicXrApp.sln" 78 | vsVersion: "16.0" 79 | msbuildArgs: '/fl /flp:LogFile=$(System.DefaultWorkingDirectory)\bin\Logs\MsBuild_$(BuildConfiguration)_$(BuildPlatform).log;Verbosity=diagnostic' 80 | platform: "$(BuildPlatform)" 81 | configuration: "$(BuildConfiguration)" 82 | maximumCpuCount: true 83 | -------------------------------------------------------------------------------- /openxr_preview/include/openxr_preview/openxr_msft_preview.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //////////////////////////////////////////////////////////////////////////////// 4 | // Copyright (C) Microsoft Corporation. All Rights Reserved 5 | 6 | // clang-format off 7 | 8 | // Supports XrStructTraits and ValidateStruct 9 | #define XR_LIST_STRUCTURE_TYPES_MSFT_PREVIEW(_) 10 | 11 | // Supports IXrExtensionConfiguration.EnabledExtensions() 12 | #define XR_LIST_EXTENSIONS_MSFT_PREVIEW(_) 13 | 14 | // Supports xrStructureTypeToString and IsKnownStructType 15 | #define XR_LIST_ENUM_XrStructureType_MSFT_PREVIEW(_) 16 | 17 | // Supports XrDispatchTable.h 18 | #define XR_LIST_FUNCTIONS_MSFT_PREVIEW(_) 19 | 20 | // clang-format on 21 | -------------------------------------------------------------------------------- /samples/BasicXrApp/App.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | 5 | #include "pch.h" 6 | #include "OpenXrProgram.h" 7 | 8 | #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) 9 | constexpr const char* ProgramName = "BasicXrApp_win32"; 10 | #else 11 | constexpr const char* ProgramName = "BasicXrApp_uwp"; 12 | #endif 13 | 14 | int __stdcall wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ LPWSTR, _In_ int) { 15 | try { 16 | auto graphics = sample::CreateCubeGraphics(); 17 | auto program = sample::CreateOpenXrProgram(ProgramName, std::move(graphics)); 18 | program->Run(); 19 | } catch (const std::exception& ex) { 20 | DEBUG_PRINT("Unhandled Exception: %s\n", ex.what()); 21 | return 1; 22 | } catch (...) { 23 | DEBUG_PRINT("Unhandled Exception\n"); 24 | return 1; 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /samples/BasicXrApp/Assets/LockScreenLogo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/samples/BasicXrApp/Assets/LockScreenLogo.scale-200.png -------------------------------------------------------------------------------- /samples/BasicXrApp/Assets/SplashScreen.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/samples/BasicXrApp/Assets/SplashScreen.scale-200.png -------------------------------------------------------------------------------- /samples/BasicXrApp/Assets/Square150x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/samples/BasicXrApp/Assets/Square150x150Logo.scale-200.png -------------------------------------------------------------------------------- /samples/BasicXrApp/Assets/Square44x44Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/samples/BasicXrApp/Assets/Square44x44Logo.scale-200.png -------------------------------------------------------------------------------- /samples/BasicXrApp/Assets/Square44x44Logo.targetsize-24_altform-unplated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/samples/BasicXrApp/Assets/Square44x44Logo.targetsize-24_altform-unplated.png -------------------------------------------------------------------------------- /samples/BasicXrApp/Assets/StoreLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/samples/BasicXrApp/Assets/StoreLogo.png -------------------------------------------------------------------------------- /samples/BasicXrApp/Assets/Wide310x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/samples/BasicXrApp/Assets/Wide310x150Logo.scale-200.png -------------------------------------------------------------------------------- /samples/BasicXrApp/BasicXrApp_uwp.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | Assets 18 | 19 | 20 | Assets 21 | 22 | 23 | Assets 24 | 25 | 26 | Assets 27 | 28 | 29 | Assets 30 | 31 | 32 | Assets 33 | 34 | 35 | Assets 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | {ba51acbc-acf1-43fd-bb49-7c52d6095d7a} 44 | 45 | 46 | 47 | 48 | Assets 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /samples/BasicXrApp/DxUtility.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include //ID3DBlob 7 | 8 | namespace sample::dx { 9 | 10 | winrt::com_ptr GetAdapter(LUID adapterId); 11 | 12 | void CreateD3D11DeviceAndContext(IDXGIAdapter1* adapter, 13 | const std::vector& featureLevels, 14 | ID3D11Device** device, 15 | ID3D11DeviceContext** deviceContext); 16 | 17 | winrt::com_ptr CompileShader(const char* hlsl, const char* entrypoint, const char* shaderTarget); 18 | } // namespace sample::dx 19 | -------------------------------------------------------------------------------- /samples/BasicXrApp/OpenXrProgram.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | namespace sample { 7 | struct Cube { 8 | xr::SpaceHandle Space{}; 9 | std::optional PoseInSpace{}; // Relative pose in cube Space. Default to identity. 10 | XrVector3f Scale{0.1f, 0.1f, 0.1f}; 11 | 12 | XrPosef PoseInAppSpace = xr::math::Pose::Identity(); // Cube pose in app space that gets updated every frame 13 | }; 14 | 15 | struct IOpenXrProgram { 16 | virtual ~IOpenXrProgram() = default; 17 | virtual void Run() = 0; 18 | }; 19 | 20 | struct IGraphicsPluginD3D11 { 21 | virtual ~IGraphicsPluginD3D11() = default; 22 | 23 | // Create an instance of this graphics api for the provided instance and systemId. 24 | virtual ID3D11Device* InitializeDevice(LUID adapterLuid, const std::vector& featureLevels) = 0; 25 | 26 | // List of color pixel formats supported by this app. 27 | virtual const std::vector& SupportedColorFormats() const = 0; 28 | virtual const std::vector& SupportedDepthFormats() const = 0; 29 | 30 | // Render to swapchain images using stereo image array 31 | virtual void RenderView(const XrRect2Di& imageRect, 32 | const float renderTargetClearColor[4], 33 | const std::vector& viewProjections, 34 | DXGI_FORMAT colorSwapchainFormat, 35 | ID3D11Texture2D* colorTexture, 36 | DXGI_FORMAT depthSwapchainFormat, 37 | ID3D11Texture2D* depthTexture, 38 | const std::vector& cubes) = 0; 39 | }; 40 | 41 | std::unique_ptr CreateCubeGraphics(); 42 | std::unique_ptr CreateOpenXrProgram(std::string applicationName, std::unique_ptr graphicsPlugin); 43 | 44 | } // namespace sample 45 | -------------------------------------------------------------------------------- /samples/BasicXrApp/Package.appxmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | BasicXrApp 18 | Microsoft Corporation 19 | Assets\StoreLogo.png 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 34 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /samples/BasicXrApp/TemporaryKey.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/samples/BasicXrApp/TemporaryKey.pfx -------------------------------------------------------------------------------- /samples/BasicXrApp/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /samples/BasicXrApp/pch.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "pch.h" 5 | -------------------------------------------------------------------------------- /samples/BasicXrApp/pch.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #define WIN32_LEAN_AND_MEAN 20 | #define NOMINMAX 21 | #include 22 | 23 | #include 24 | 25 | #define XR_USE_PLATFORM_WIN32 26 | #define XR_USE_GRAPHICS_API_D3D11 27 | #include 28 | #include 29 | #include 30 | 31 | #define ENABLE_GLOBAL_XR_DISPATCH_TABLE 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include // winrt::com_ptr 39 | -------------------------------------------------------------------------------- /samples/EyeGazeInteractionUwp/EyeGazeInteractionUwp.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | {f0e9b0db-7d42-4f9e-b789-fa0c1172575c} 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /samples/EyeGazeInteractionUwp/Main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "pch.h" 5 | #include 6 | 7 | std::unique_ptr TryCreateTitleScene(engine::Context& context); 8 | std::unique_ptr TryCreateEyeGazeInteractionScene(engine::Context& context); 9 | 10 | int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { 11 | try { 12 | CHECK_HRCMD(::CoInitializeEx(nullptr, COINIT_MULTITHREADED)); 13 | auto on_exit = MakeScopeGuard([] { ::CoUninitialize(); }); 14 | 15 | engine::XrAppConfiguration appConfig({"EyeGazeInteractionUwp", 1}); 16 | appConfig.RequestedExtensions.push_back(XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME); 17 | 18 | auto app = CreateXrApp(appConfig); 19 | app->AddScene(TryCreateTitleScene(app->Context())); 20 | app->AddScene(TryCreateEyeGazeInteractionScene(app->Context())); 21 | app->Run(); 22 | } catch (const std::exception& ex) { 23 | sample::Trace("Unhandled Exception: {}", ex.what()); 24 | return 1; 25 | } catch (...) { 26 | sample::Trace("Unhandled Exception"); 27 | return 1; 28 | } 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /samples/EyeGazeInteractionUwp/Package.appxmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | EyeGazeInteractionUwp 7 | Microsoft Corporation 8 | SampleShared_uwp\UWPAssets\storelogo-sdk.png 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /samples/EyeGazeInteractionUwp/TemporaryKey.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/samples/EyeGazeInteractionUwp/TemporaryKey.pfx -------------------------------------------------------------------------------- /samples/EyeGazeInteractionUwp/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /samples/EyeGazeInteractionUwp/pch.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "pch.h" 5 | -------------------------------------------------------------------------------- /samples/EyeGazeInteractionUwp/pch.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #define NOMINMAX 9 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #define XR_USE_PLATFORM_WIN32 30 | #define XR_USE_GRAPHICS_API_D3D11 31 | #include 32 | #include 33 | #include 34 | 35 | #define ENABLE_GLOBAL_XR_DISPATCH_TABLE 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include 43 | -------------------------------------------------------------------------------- /samples/SampleSceneUwp/Package.appxmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | SampleSceneUwp 7 | Microsoft Corporation 8 | SampleShared_uwp\UWPAssets\storelogo-sdk.png 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /samples/SampleSceneUwp/SampleSceneUwp.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | {8eb32a1e-ec4a-4c3c-881e-2e7e281f7df2} 25 | 26 | 27 | {a67580aa-7f1a-4463-8062-9c107745a7ce} 28 | 29 | 30 | -------------------------------------------------------------------------------- /samples/SampleSceneUwp/TemporaryKey.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/samples/SampleSceneUwp/TemporaryKey.pfx -------------------------------------------------------------------------------- /samples/SampleSceneUwp/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /samples/SampleSceneUwp/pch.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "pch.h" 5 | -------------------------------------------------------------------------------- /samples/SampleSceneUwp/pch.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #define NOMINMAX 9 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #define XR_USE_PLATFORM_WIN32 30 | #define XR_USE_GRAPHICS_API_D3D11 31 | #include 32 | #include 33 | #include 34 | 35 | #define ENABLE_GLOBAL_XR_DISPATCH_TABLE 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include 43 | -------------------------------------------------------------------------------- /samples/SampleSceneWin32/Key.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/samples/SampleSceneWin32/Key.glb -------------------------------------------------------------------------------- /samples/SampleSceneWin32/Main.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/samples/SampleSceneWin32/Main.ico -------------------------------------------------------------------------------- /samples/SampleSceneWin32/Main.rc: -------------------------------------------------------------------------------- 1 | //Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE resource. 9 | // 10 | #ifndef APSTUDIO_INVOKED 11 | #include 12 | #endif 13 | #define APSTUDIO_HIDDEN_SYMBOLS 14 | #include "windows.h" 15 | #undef APSTUDIO_HIDDEN_SYMBOLS 16 | ///////////////////////////////////////////////////////////////////////////// 17 | #undef APSTUDIO_READONLY_SYMBOLS 18 | 19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 20 | LANGUAGE 9, 1 21 | 22 | ///////////////////////////////////////////////////////////////////////////// 23 | // 24 | // Icon 25 | // 26 | 27 | // Icon with lowest ID value placed first to ensure application icon 28 | // remains consistent on all systems. 29 | 30 | IDI_DIALOGBOX ICON "Main.ico" 31 | IDI_SMALL ICON "small.ico" 32 | 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | // 36 | // Dialog 37 | // 38 | 39 | IDD_DIALOGBOX DIALOGEX 0, 0, 320, 200 40 | STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU 41 | CAPTION "SampleSceneWin32" 42 | FONT 8, "MS Shell Dlg" 43 | BEGIN 44 | ICON IDR_MAINFRAME,IDC_STATIC,14,14,21,20 45 | LTEXT "OpenXR Win32 sample, Version 1.0",IDC_STATIC,42,14,114,8,SS_NOPREFIX 46 | LTEXT "Copyright (c) 2020",IDC_STATIC,42,26,114,8 47 | DEFPUSHBUTTON "Enter &VR",IDOK,113,41,50,14,WS_GROUP 48 | DEFPUSHBUTTON "E&xit",IDCANCEL,168,41,50,14,WS_GROUP 49 | END 50 | 51 | ///////////////////////////////////////////////////////////////////////////// 52 | // 53 | // DESIGNINFO 54 | // 55 | 56 | #ifdef APSTUDIO_INVOKED 57 | GUIDELINES DESIGNINFO 58 | BEGIN 59 | IDD_DIALOGBOX, DIALOG 60 | BEGIN 61 | LEFTMARGIN, 7 62 | RIGHTMARGIN, 163 63 | TOPMARGIN, 7 64 | BOTTOMMARGIN, 55 65 | END 66 | END 67 | #endif // APSTUDIO_INVOKED 68 | 69 | #ifdef APSTUDIO_INVOKED 70 | ///////////////////////////////////////////////////////////////////////////// 71 | // 72 | // TEXTINCLUDE 73 | // 74 | 1 TEXTINCLUDE 75 | BEGIN 76 | "resource.h\0" 77 | END 78 | 79 | 2 TEXTINCLUDE 80 | BEGIN 81 | "#ifndef APSTUDIO_INVOKED\r\n" 82 | "#include ""targetver.h""\r\n" 83 | "#endif\r\n" 84 | "#define APSTUDIO_HIDDEN_SYMBOLS\r\n" 85 | "#include ""windows.h""\r\n" 86 | "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" 87 | "\0" 88 | END 89 | 90 | 3 TEXTINCLUDE 91 | BEGIN 92 | "\r\n" 93 | "\0" 94 | END 95 | 96 | #endif // APSTUDIO_INVOKED 97 | 98 | ///////////////////////////////////////////////////////////////////////////// 99 | // 100 | // String Table 101 | // 102 | 103 | STRINGTABLE 104 | BEGIN 105 | IDC_DIALOGBOX "SampleSceneWin32" 106 | IDS_APP_TITLE "SampleSceneWin32" 107 | END 108 | 109 | #endif 110 | ///////////////////////////////////////////////////////////////////////////// 111 | 112 | 113 | 114 | #ifndef APSTUDIO_INVOKED 115 | ///////////////////////////////////////////////////////////////////////////// 116 | // 117 | // Generated from the TEXTINCLUDE resource. 118 | // 119 | 120 | ///////////////////////////////////////////////////////////////////////////// 121 | #endif // not APSTUDIO_INVOKED 122 | -------------------------------------------------------------------------------- /samples/SampleSceneWin32/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Main.rc 4 | 5 | #define IDS_APP_TITLE 103 6 | 7 | #define IDR_MAINFRAME 128 8 | #define IDD_DIALOGBOX 103 9 | #define IDI_DIALOGBOX 107 10 | #define IDI_SMALL 108 11 | #define IDC_DIALOGBOX 109 12 | #define IDC_MYICON 2 13 | #ifndef IDC_STATIC 14 | #define IDC_STATIC -1 15 | #endif 16 | // Next default values for new objects 17 | // 18 | #ifdef APSTUDIO_INVOKED 19 | #ifndef APSTUDIO_READONLY_SYMBOLS 20 | 21 | #define _APS_NO_MFC 130 22 | #define _APS_NEXT_RESOURCE_VALUE 129 23 | #define _APS_NEXT_COMMAND_VALUE 32771 24 | #define _APS_NEXT_CONTROL_VALUE 1000 25 | #define _APS_NEXT_SYMED_VALUE 110 26 | #endif 27 | #endif 28 | -------------------------------------------------------------------------------- /samples/SampleSceneWin32/SampleSceneWin32.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Resources 15 | 16 | 17 | 18 | 19 | Resources 20 | 21 | 22 | Resources 23 | 24 | 25 | 26 | 27 | 28 | 29 | SceneAssets 30 | 31 | 32 | 33 | 34 | {d833b40e-3939-4c3b-8788-8d0a14dc2bd8} 35 | 36 | 37 | {0663c26d-ed88-4d16-b85f-328ecb7ef765} 38 | 39 | 40 | 41 | 42 | Resources 43 | 44 | 45 | -------------------------------------------------------------------------------- /samples/SampleSceneWin32/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /samples/SampleSceneWin32/pch.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "pch.h" 5 | -------------------------------------------------------------------------------- /samples/SampleSceneWin32/pch.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #define NOMINMAX 9 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #define XR_USE_PLATFORM_WIN32 30 | #define XR_USE_GRAPHICS_API_D3D11 31 | #include 32 | #include 33 | #include 34 | 35 | #define ENABLE_GLOBAL_XR_DISPATCH_TABLE 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | -------------------------------------------------------------------------------- /samples/SampleSceneWin32/small.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/samples/SampleSceneWin32/small.ico -------------------------------------------------------------------------------- /samples/SceneUnderstandingUwp/Main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "pch.h" 5 | #include 6 | 7 | std::unique_ptr TryCreateTitleScene(engine::Context& context); 8 | std::unique_ptr TryCreatePlacementScene(engine::Context& context); 9 | std::unique_ptr TryCreateQRCodeScene(engine::Context& context); 10 | 11 | int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { 12 | try { 13 | CHECK_HRCMD(::CoInitializeEx(nullptr, COINIT_MULTITHREADED)); 14 | auto on_exit = MakeScopeGuard([] { ::CoUninitialize(); }); 15 | 16 | engine::XrAppConfiguration appConfig({"SceneUnderstandingUwp", 1}); 17 | appConfig.RequestedExtensions.push_back(XR_MSFT_SPATIAL_ANCHOR_EXTENSION_NAME); 18 | appConfig.RequestedExtensions.push_back(XR_MSFT_SCENE_UNDERSTANDING_EXTENSION_NAME); 19 | appConfig.RequestedExtensions.push_back(XR_MSFT_SCENE_UNDERSTANDING_SERIALIZATION_EXTENSION_NAME); 20 | appConfig.RequestedExtensions.push_back(XR_MSFT_SCENE_MARKER_EXTENSION_NAME); 21 | 22 | auto app = CreateXrApp(appConfig); 23 | app->AddScene(TryCreateTitleScene(app->Context())); 24 | app->AddScene(TryCreatePlacementScene(app->Context())); 25 | app->AddScene(TryCreateQRCodeScene(app->Context())); 26 | app->Run(); 27 | } catch (const std::exception& ex) { 28 | sample::Trace("Unhandled Exception: {}", ex.what()); 29 | return 1; 30 | } catch (...) { 31 | sample::Trace("Unhandled Exception"); 32 | return 1; 33 | } 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /samples/SceneUnderstandingUwp/Package.appxmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | SceneUnderstandingUwp 7 | Microsoft Corporation 8 | SampleShared_uwp\UWPAssets\storelogo-sdk.png 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /samples/SceneUnderstandingUwp/SceneUnderstandingUwp.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | {f0e9b0db-7d42-4f9e-b789-fa0c1172575c} 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /samples/SceneUnderstandingUwp/TemporaryKey.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/samples/SceneUnderstandingUwp/TemporaryKey.pfx -------------------------------------------------------------------------------- /samples/SceneUnderstandingUwp/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /samples/SceneUnderstandingUwp/pch.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "pch.h" 5 | -------------------------------------------------------------------------------- /samples/SceneUnderstandingUwp/pch.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #define NOMINMAX 9 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #define XR_USE_PLATFORM_WIN32 30 | #define XR_USE_GRAPHICS_API_D3D11 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #define ENABLE_GLOBAL_XR_DISPATCH_TABLE 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #include 45 | -------------------------------------------------------------------------------- /samples/ThreeSpacesUwp/Main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "pch.h" 5 | #include 6 | 7 | std::unique_ptr TryCreateTitleScene(engine::Context& context); 8 | std::unique_ptr TryCreateThreeSpacesScene(engine::Context& context); 9 | 10 | int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { 11 | try { 12 | CHECK_HRCMD(::CoInitializeEx(nullptr, COINIT_MULTITHREADED)); 13 | auto on_exit = MakeScopeGuard([] { ::CoUninitialize(); }); 14 | 15 | engine::XrAppConfiguration appConfig({"ThreeSpacesUwp", 1}); 16 | appConfig.RequestedExtensions.push_back(XR_MSFT_UNBOUNDED_REFERENCE_SPACE_EXTENSION_NAME); 17 | appConfig.RequestedExtensions.push_back(XR_MSFT_SPATIAL_ANCHOR_EXTENSION_NAME); 18 | appConfig.RequestedExtensions.push_back(XR_MSFT_HAND_INTERACTION_EXTENSION_NAME); 19 | appConfig.RequestedExtensions.push_back(XR_EXT_HAND_INTERACTION_EXTENSION_NAME); 20 | 21 | auto app = engine::CreateXrApp(appConfig); 22 | app->AddScene(TryCreateTitleScene(app->Context())); 23 | app->AddScene(TryCreateThreeSpacesScene(app->Context())); 24 | app->Run(); 25 | } catch (const std::exception& ex) { 26 | sample::Trace("Unhandled Exception: {}", ex.what()); 27 | return 1; 28 | } catch (...) { 29 | sample::Trace("Unhandled Exception"); 30 | return 1; 31 | } 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /samples/ThreeSpacesUwp/Package.appxmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ThreeSpacesUwp 7 | Microsoft Corporation 8 | SampleShared_uwp\UWPAssets\storelogo-sdk.png 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /samples/ThreeSpacesUwp/TemporaryKey.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/samples/ThreeSpacesUwp/TemporaryKey.pfx -------------------------------------------------------------------------------- /samples/ThreeSpacesUwp/ThreeSpacesUwp.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | {f0e9b0db-7d42-4f9e-b789-fa0c1172575c} 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /samples/ThreeSpacesUwp/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /samples/ThreeSpacesUwp/pch.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "pch.h" 5 | -------------------------------------------------------------------------------- /samples/ThreeSpacesUwp/pch.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #define NOMINMAX 9 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #define XR_USE_PLATFORM_WIN32 30 | #define XR_USE_GRAPHICS_API_D3D11 31 | #include 32 | #include 33 | #include 34 | 35 | #define ENABLE_GLOBAL_XR_DISPATCH_TABLE 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include 43 | -------------------------------------------------------------------------------- /shared/SampleShared/DxUtility.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include // winrt::com_ptr 7 | #include //ID3DBlob 8 | #include 9 | #include 10 | 11 | namespace sample::dx { 12 | 13 | winrt::com_ptr GetAdapter(LUID adapterId); 14 | 15 | std::tuple, winrt::com_ptr> CreateD3D11DeviceAndContext( 16 | IDXGIAdapter1* adapter, const std::vector& featureLevels, bool singleThreadedD3D11Device); 17 | 18 | std::tuple, winrt::com_ptr> 19 | CreateD3D11Binding(XrInstance instance, 20 | XrSystemId systemId, 21 | const xr::EnabledExtensions& extensions, 22 | bool singleThreadedD3D11Device, 23 | const std::vector& appSupportedFeatureLevels); 24 | 25 | struct SwapchainD3D11 { 26 | xr::SwapchainHandle Handle; 27 | DXGI_FORMAT Format{DXGI_FORMAT_UNKNOWN}; 28 | int32_t Width{0}; 29 | int32_t Height{0}; 30 | std::vector Images; 31 | }; 32 | 33 | SwapchainD3D11 CreateSwapchainD3D11(XrSession session, 34 | DXGI_FORMAT format, 35 | int32_t width, 36 | int32_t height, 37 | uint32_t arrayLength, 38 | uint32_t sampleCount, 39 | XrSwapchainCreateFlags createFlags, 40 | XrSwapchainUsageFlags usageFlags, 41 | std::optional viewConfigurationForSwapchain = std::nullopt); 42 | } // namespace sample::dx 43 | -------------------------------------------------------------------------------- /shared/SampleShared/FileUtility.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | #include 6 | 7 | namespace Pbr { 8 | struct Model; 9 | struct Resources; 10 | } // namespace Pbr 11 | 12 | namespace sample { 13 | std::vector ReadFileBytes(const std::filesystem::path& path); 14 | 15 | // Get a path in app folder, the path might not exist 16 | std::filesystem::path GetPathInAppFolder(const std::filesystem::path& filename); 17 | 18 | // Find a file in given search folders relative to the app folder. 19 | // Returns the path to file if exist, or throw error if file is not found. 20 | std::filesystem::path FindFileInAppFolder(const std::filesystem::path& filename, 21 | const std::vector& searchFolders = {""}); 22 | 23 | Pbr::Resources InitializePbrResources(ID3D11Device* device, bool environmentIBL = true); 24 | } // namespace sample 25 | -------------------------------------------------------------------------------- /shared/SampleShared/SampleShared_uwp.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | DirectXTK 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | DirectXTK 16 | 17 | 18 | DirectXTK 19 | 20 | 21 | DirectXTK 22 | 23 | 24 | DirectXTK 25 | 26 | 27 | DirectXTK 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | {fae7caa5-87c8-49d7-9ac1-6f7e2466a532} 44 | 45 | 46 | {3f7fd9dc-72ea-462c-b880-45d9cbba4afd} 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | UWPAssets 57 | 58 | 59 | UWPAssets 60 | 61 | 62 | UWPAssets 63 | 64 | 65 | UWPAssets 66 | 67 | 68 | -------------------------------------------------------------------------------- /shared/SampleShared/SampleShared_win32.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | DirectXTK 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | DirectXTK 16 | 17 | 18 | DirectXTK 19 | 20 | 21 | DirectXTK 22 | 23 | 24 | DirectXTK 25 | 26 | 27 | DirectXTK 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | {4f521880-4ed3-411f-93f7-646a063395e4} 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /shared/SampleShared/ScopeGuard.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | template 9 | struct ScopeGuard { 10 | static_assert(std::is_invocable_v, "Type must be invocable function."); 11 | 12 | ScopeGuard(bool active, TFunction&& guard) 13 | : m_guard(std::move(guard)) 14 | , m_active(active) { 15 | } 16 | 17 | ScopeGuard(ScopeGuard&&) = default; 18 | ScopeGuard& operator=(ScopeGuard&&) = default; 19 | 20 | ~ScopeGuard() { 21 | if (m_active.load()) { 22 | m_guard(); 23 | } 24 | } 25 | 26 | void Activate() { 27 | m_active.store(true); 28 | } 29 | 30 | void Deactivate() { 31 | m_active.store(false); 32 | } 33 | 34 | private: 35 | ScopeGuard(ScopeGuard&) = delete; 36 | ScopeGuard& operator=(ScopeGuard&) = delete; 37 | 38 | TFunction m_guard; 39 | std::atomic m_active; 40 | }; 41 | 42 | // Usage: auto guard = MakeScopeGuard([&] { foobar; }); 43 | template 44 | ScopeGuard MakeScopeGuard(TFunction&& guard) { 45 | return ScopeGuard(true, std::forward(guard)); 46 | } 47 | 48 | // Usage: auto guard = MakeInactiveScopeGuard([&] { foobar; }); 49 | // if (some_condition == satisified) { 50 | // guard.Activate() 51 | // } 52 | template 53 | ScopeGuard MakeInactiveScopeGuard(TFunction&& guard) { 54 | return ScopeGuard(false, std::forward(guard)); 55 | } 56 | 57 | // Usage: auto guard = MakeFailureGuard([&] { foobar; }); 58 | // Executes guard only if destruction is caused due to exception unwind. 59 | template 60 | auto MakeFailureGuard(TFunction&& guard) { 61 | auto failureGuard = [initialUncaughtExceptionCount{std::uncaught_exceptions()}, guard{std::move(guard)}]() { 62 | // Execute only if this lambda is being destroyed due to exception stack unwind. 63 | // In the case of this guard running while an exception is being handled as part of a stack unwind due to another 64 | // exception, there may already be an uncaught exception that should ignored. This is why the exception count 65 | // is compared against a snapshot. 66 | if (std::uncaught_exceptions() > initialUncaughtExceptionCount) { 67 | guard(); 68 | } 69 | }; 70 | return MakeScopeGuard(std::move(failureGuard)); 71 | } 72 | -------------------------------------------------------------------------------- /shared/SampleShared/TextureUtility.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "pch.h" 5 | #include "TextureUtility.h" 6 | 7 | namespace sample { 8 | std::vector CreateTileTextureBytes(size_t sideLength) { 9 | constexpr uint32_t White = 0xFFFFFFFF; 10 | constexpr uint32_t Black = 0x000000FF; 11 | std::vector rgba(sideLength * sideLength, White); 12 | if (sideLength == 0) { 13 | return rgba; 14 | } 15 | const size_t Last = sideLength - 1; 16 | // make the border black 17 | for (size_t col = 0; col < sideLength; ++col) { 18 | rgba[col] = Black; 19 | rgba[Last + col] = Black; 20 | } 21 | for (size_t row = 0; row < sideLength * sideLength; row += sideLength) { 22 | rgba[row] = Black; 23 | rgba[row + Last] = Black; 24 | } 25 | return rgba; 26 | } 27 | } // namespace sample 28 | -------------------------------------------------------------------------------- /shared/SampleShared/TextureUtility.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | #include 6 | 7 | namespace sample { 8 | 9 | std::vector CreateTileTextureBytes(size_t sideLength); 10 | 11 | } // namespace sample 12 | -------------------------------------------------------------------------------- /shared/SampleShared/Trace.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define FMT_HEADER_ONLY 15 | #include 16 | #include 17 | 18 | namespace sample { 19 | 20 | inline void FormatHeader(fmt::memory_buffer& buffer, const char* formatStr) { 21 | using namespace std::chrono; 22 | const auto now = system_clock::now(); 23 | const auto posixTime = system_clock::to_time_t(now); 24 | const auto remainingTime = now - system_clock::from_time_t(posixTime); 25 | const uint64_t remainingMicroseconds = duration_cast(remainingTime).count(); 26 | const uint32_t threadId = ::GetCurrentThreadId(); 27 | 28 | tm localTime; 29 | ::localtime_s(&localTime, &posixTime); 30 | 31 | fmt::format_to( 32 | fmt::appender(buffer), formatStr, localTime.tm_hour, localTime.tm_min, localTime.tm_sec, remainingMicroseconds, threadId); 33 | } 34 | 35 | template 36 | inline void Trace(std::string_view format_str, const Args&... args) { 37 | fmt::memory_buffer buffer; 38 | FormatHeader(buffer, "[{:02d}-{:02d}-{:02d}.{:06d}] (t:{:04x}): "); 39 | fmt::format_to(fmt::appender(buffer), format_str, args...); 40 | buffer.push_back('\n'); 41 | buffer.push_back('\0'); 42 | ::OutputDebugStringA(buffer.data()); 43 | } 44 | } // namespace sample 45 | -------------------------------------------------------------------------------- /shared/SampleShared/UWPAssets/smallTile-sdk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/shared/SampleShared/UWPAssets/smallTile-sdk.png -------------------------------------------------------------------------------- /shared/SampleShared/UWPAssets/splash-sdk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/shared/SampleShared/UWPAssets/splash-sdk.png -------------------------------------------------------------------------------- /shared/SampleShared/UWPAssets/squareTile-sdk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/shared/SampleShared/UWPAssets/squareTile-sdk.png -------------------------------------------------------------------------------- /shared/SampleShared/UWPAssets/storeLogo-sdk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/shared/SampleShared/UWPAssets/storeLogo-sdk.png -------------------------------------------------------------------------------- /shared/SampleShared/XrInstanceContext.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include "XrUtility/XrHandle.h" 7 | #include "XrUtility/XrStruct.h" 8 | #include "XrUtility/XrString.h" 9 | 10 | namespace sample { 11 | struct InstanceContext { 12 | const XrInstance Handle; 13 | const xr::NameVersion AppInfo; 14 | const xr::NameVersion EngineInfo; 15 | const XrInstanceProperties Properties{XR_TYPE_INSTANCE_PROPERTIES}; 16 | const XrPath LeftHandPath; 17 | const XrPath RightHandPath; 18 | 19 | public: 20 | InstanceContext(xr::InstanceHandle instance, 21 | xr::NameVersion appInfo, 22 | xr::NameVersion engineInfo, 23 | XrInstanceProperties instanceProperties) 24 | : Handle(instance.Get()) 25 | , AppInfo(std::move(appInfo)) 26 | , EngineInfo(std::move(engineInfo)) 27 | , Properties(std::move(instanceProperties)) 28 | , m_instance(std::move(instance)) 29 | , LeftHandPath(xr::StringToPath(Handle, "/user/hand/left")) 30 | , RightHandPath(xr::StringToPath(Handle, "/user/hand/right")) { 31 | } 32 | 33 | private: 34 | xr::InstanceHandle m_instance; 35 | }; 36 | 37 | inline InstanceContext CreateInstanceContext(xr::NameVersion appInfo, 38 | xr::NameVersion engineInfo, 39 | const std::vector& extensions) { 40 | XrInstanceCreateInfo instanceCreateInfo{XR_TYPE_INSTANCE_CREATE_INFO}; 41 | xr::SetEnabledExtensions(instanceCreateInfo, extensions); 42 | xr::SetApplicationInfo(instanceCreateInfo.applicationInfo, appInfo, engineInfo); 43 | 44 | xr::InstanceHandle instance; 45 | CHECK_XRCMD(xrCreateInstance(&instanceCreateInfo, instance.Put(xrDestroyInstance))); 46 | 47 | XrInstanceProperties instanceProperties{XR_TYPE_INSTANCE_PROPERTIES}; 48 | CHECK_XRCMD(xrGetInstanceProperties(instance.Get(), &instanceProperties)); 49 | 50 | return InstanceContext(std::move(instance), std::move(appInfo), std::move(engineInfo), std::move(instanceProperties)); 51 | } 52 | 53 | } // namespace sample 54 | -------------------------------------------------------------------------------- /shared/SampleShared/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /shared/SampleShared/pch.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "pch.h" 5 | -------------------------------------------------------------------------------- /shared/SampleShared/pch.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #define NOMINMAX 9 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 10 | #include 11 | #include 12 | #include // for winrt::com_ptr 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #define XR_NO_PROTOTYPES 33 | #define XR_USE_PLATFORM_WIN32 34 | #define XR_USE_GRAPHICS_API_D3D11 35 | #include 36 | #include 37 | #include 38 | 39 | #define ENABLE_GLOBAL_XR_DISPATCH_TABLE 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #include 46 | #include 47 | 48 | #ifndef FMT_HEADER_ONLY 49 | #define FMT_HEADER_ONLY 50 | #endif 51 | #include 52 | #include 53 | -------------------------------------------------------------------------------- /shared/SampleShared/sample_DiffuseHDR.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/shared/SampleShared/sample_DiffuseHDR.dds -------------------------------------------------------------------------------- /shared/SampleShared/sample_SpecularHDR.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/shared/SampleShared/sample_SpecularHDR.dds -------------------------------------------------------------------------------- /shared/XrSceneLib/CompositionLayers.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | namespace engine { 7 | struct QuadLayerObject; 8 | class ProjectionLayer; 9 | class CompositionLayers; 10 | 11 | void AppendQuadLayer(CompositionLayers& layers, QuadLayerObject* quad); 12 | void AppendProjectionLayer(CompositionLayers& layers, ProjectionLayer* layer, XrViewConfigurationType type); 13 | 14 | class CompositionLayers { 15 | public: 16 | 17 | XrCompositionLayerQuad& AddQuadLayer() { 18 | XrCompositionLayerQuad& quadLayer = m_quadLayers.emplace_back(); 19 | quadLayer.type = XR_TYPE_COMPOSITION_LAYER_QUAD; 20 | m_compositionLayers.push_back(reinterpret_cast(&quadLayer)); 21 | return m_quadLayers.back(); 22 | } 23 | 24 | XrCompositionLayerProjection& AddProjectionLayer(XrCompositionLayerFlags layerFlags) { 25 | XrCompositionLayerProjection& projectionLayer = m_projectionLayers.emplace_back(); 26 | projectionLayer.type = XR_TYPE_COMPOSITION_LAYER_PROJECTION; 27 | projectionLayer.layerFlags = layerFlags; 28 | m_compositionLayers.push_back(reinterpret_cast(&projectionLayer)); 29 | return m_projectionLayers.back(); 30 | } 31 | 32 | uint32_t LayerCount() const { 33 | return (uint32_t)m_compositionLayers.size(); 34 | } 35 | 36 | const XrCompositionLayerBaseHeader* const* LayerData() const { 37 | return m_compositionLayers.data(); 38 | } 39 | 40 | private: 41 | std::list m_quadLayers; 42 | std::list m_projectionLayers; 43 | std::vector m_compositionLayers; 44 | }; 45 | } // namespace engine 46 | 47 | -------------------------------------------------------------------------------- /shared/XrSceneLib/Context.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace engine { 14 | 15 | // Session-related resources shared across multiple Scenes. 16 | struct Context final { 17 | Context(sample::InstanceContext instance, 18 | xr::EnabledExtensions extensions, 19 | sample::SystemContext system, 20 | sample::SessionContext session, 21 | XrSpace appSpace, 22 | Pbr::Resources pbrResources, 23 | winrt::com_ptr device, 24 | winrt::com_ptr deviceContext) 25 | : Instance(std::move(instance)) 26 | , Extensions(std::move(extensions)) 27 | , System(std::move(system)) 28 | , Session(std::move(session)) 29 | , AppSpace(appSpace) 30 | , PbrResources(std::move(pbrResources)) 31 | , Device(std::move(device)) 32 | , DeviceContext(std::move(deviceContext)) { 33 | } 34 | 35 | const xr::EnabledExtensions Extensions; 36 | const sample::InstanceContext Instance; 37 | const sample::SystemContext System; 38 | const sample::SessionContext Session; 39 | 40 | const XrSpace AppSpace; 41 | 42 | const winrt::com_ptr DeviceContext; 43 | const winrt::com_ptr Device; 44 | Pbr::Resources PbrResources; 45 | }; 46 | 47 | } // namespace engine 48 | -------------------------------------------------------------------------------- /shared/XrSceneLib/ControllerObject.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include "PbrModelObject.h" 7 | 8 | namespace engine { 9 | std::shared_ptr CreateControllerObject(Context& context, XrPath controllerUserPath); 10 | } 11 | -------------------------------------------------------------------------------- /shared/XrSceneLib/FrameTime.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | namespace engine { 7 | 8 | // Information of frame timing 9 | struct FrameTime { 10 | using clock = std::chrono::high_resolution_clock; 11 | 12 | uint64_t FrameIndex = 0; 13 | const clock::time_point StartTime = clock::now(); 14 | clock::time_point Now = StartTime; 15 | clock::duration Elapsed = {}; 16 | clock::duration TotalElapsed = {}; 17 | float ElapsedSeconds = {}; 18 | float TotalElapsedSeconds = {}; 19 | 20 | XrTime PredictedDisplayTime = {}; 21 | XrDuration PredictedDisplayPeriod = {}; 22 | bool ShouldRender = {}; 23 | bool IsSessionFocused = {}; 24 | 25 | void Update(const XrFrameState& frameState, XrSessionState sessionState) { 26 | FrameIndex++; 27 | PredictedDisplayTime = frameState.predictedDisplayTime; 28 | PredictedDisplayPeriod = frameState.predictedDisplayPeriod; 29 | ShouldRender = frameState.shouldRender; 30 | IsSessionFocused = sessionState == XR_SESSION_STATE_FOCUSED; 31 | 32 | const auto now = FrameTime::clock::now(); 33 | Elapsed = now - Now; 34 | Now = now; 35 | TotalElapsed = now - StartTime; 36 | 37 | ElapsedSeconds = std::chrono::duration_cast>(Elapsed).count(); 38 | TotalElapsedSeconds = std::chrono::duration_cast>(TotalElapsed).count(); 39 | } 40 | }; 41 | } // namespace engine 42 | -------------------------------------------------------------------------------- /shared/XrSceneLib/Object.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "pch.h" 5 | #include "Object.h" 6 | 7 | using engine::Object; 8 | 9 | void Object::SetOnlyVisibleForViewIndex(uint32_t viewIndex) { 10 | assert(viewIndex < m_visibleViewIndexMask.MaxViewCount); 11 | m_visibleViewIndexMask.m_mask = 1 << viewIndex; 12 | } 13 | 14 | bool Object::IsVisibleForViewIndex(uint32_t viewIndex) const { 15 | assert(viewIndex < m_visibleViewIndexMask.MaxViewCount); 16 | return (m_visibleViewIndexMask.m_mask & (1 << viewIndex)) > 0; 17 | } 18 | 19 | void Object::Update(engine::Context& /*context*/, const FrameTime& frameTime) { 20 | Motion.UpdateMotionAndPose(Pose(), frameTime.Elapsed); 21 | } 22 | 23 | void Object::Render(Context& context) const { 24 | } 25 | 26 | DirectX::XMMATRIX Object::LocalTransform() const { 27 | if (!m_localTransformDirty) { 28 | return DirectX::XMLoadFloat4x4(&m_localTransform); 29 | } 30 | 31 | const DirectX::XMMATRIX modelScale = DirectX::XMMatrixScalingFromVector(xr::math::LoadXrVector3(m_scale)); 32 | const DirectX::XMMATRIX modelRotation = DirectX::XMMatrixRotationQuaternion(xr::math::LoadXrQuaternion(m_pose.orientation)); 33 | const DirectX::XMMATRIX modelTranslation = DirectX::XMMatrixTranslationFromVector(xr::math::LoadXrVector3(m_pose.position)); 34 | const DirectX::XMMATRIX localTransform = modelScale * modelRotation * modelTranslation; 35 | 36 | DirectX::XMStoreFloat4x4(&m_localTransform, localTransform); 37 | m_localTransformDirty = false; 38 | 39 | return localTransform; 40 | } 41 | 42 | DirectX::XMMATRIX Object::WorldTransform() const { 43 | return m_parent ? XMMatrixMultiply(LocalTransform(), m_parent->WorldTransform()) : LocalTransform(); 44 | } 45 | -------------------------------------------------------------------------------- /shared/XrSceneLib/Object.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include 7 | #include "Context.h" 8 | #include "FrameTime.h" 9 | #include "ObjectMotion.h" 10 | 11 | namespace engine { 12 | enum class ObjectState { InitializePending, Initialized, RemovePending }; 13 | 14 | class Object { 15 | public: 16 | virtual ~Object() = default; 17 | ObjectState State; 18 | Motion Motion; 19 | 20 | public: 21 | void SetParent(std::shared_ptr parent) { 22 | m_parent = std::move(parent); 23 | } 24 | 25 | void SetVisible(bool visible) { 26 | m_isVisible = visible; 27 | } 28 | bool IsVisible() const { 29 | return State == ObjectState::Initialized && m_isVisible && (m_parent ? m_parent->IsVisible() : true); 30 | } 31 | 32 | void SetOnlyVisibleForViewIndex(uint32_t viewIndex); 33 | bool IsVisibleForViewIndex(uint32_t viewIndex) const; 34 | 35 | const XrPosef& Pose() const { 36 | return m_pose; 37 | } 38 | XrPosef& Pose() { 39 | m_localTransformDirty = true; 40 | return m_pose; 41 | } 42 | 43 | const XrVector3f& Scale() const { 44 | return m_scale; 45 | } 46 | XrVector3f& Scale() { 47 | m_localTransformDirty = true; 48 | return m_scale; 49 | } 50 | 51 | DirectX::XMMATRIX LocalTransform() const; 52 | DirectX::XMMATRIX WorldTransform() const; 53 | 54 | virtual void Update(engine::Context& context, const FrameTime& frameTime); 55 | virtual void Render(Context& context) const; 56 | 57 | private: 58 | bool m_isVisible{true}; 59 | 60 | XrPosef m_pose = xr::math::Pose::Identity(); 61 | XrVector3f m_scale = {1, 1, 1}; 62 | 63 | std::shared_ptr m_parent; 64 | 65 | // Scene Object is visible to all views by default 66 | struct ViewIndexMask { 67 | // bit location = view index 68 | uint32_t m_mask{static_cast(-1)}; 69 | static constexpr uint32_t MaxViewCount = sizeof(m_mask) * 8; 70 | } m_visibleViewIndexMask{}; 71 | 72 | // Local transform is relative to parent 73 | // Only recompute when transform is changed. 74 | mutable DirectX::XMFLOAT4X4 m_localTransform; 75 | mutable bool m_localTransformDirty{true}; 76 | }; 77 | 78 | inline std::shared_ptr CreateObject() { 79 | return std::make_shared(); 80 | } 81 | } // namespace engine 82 | -------------------------------------------------------------------------------- /shared/XrSceneLib/ObjectMotion.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "pch.h" 5 | #include "ObjectMotion.h" 6 | 7 | using engine::Motion; 8 | 9 | void Motion::SetGravity(float gravitationalAcceleration) { 10 | LinearAcceleration = {0, -gravitationalAcceleration, 0}; 11 | } 12 | 13 | void Motion::SetRotation(const XrVector3f& axis, float radiansPerSecond) { 14 | AngularVelocity = {axis.x * radiansPerSecond, axis.y * radiansPerSecond, axis.z * radiansPerSecond}; 15 | } 16 | 17 | void Motion::SetVelocity(const XrSpaceVelocity& velocity) { 18 | LinearVelocity = (velocity.velocityFlags & XR_SPACE_VELOCITY_LINEAR_VALID_BIT) ? xr::math::cast(velocity.linearVelocity) 19 | : DirectX::XMFLOAT3{0, 0, 0}; 20 | AngularVelocity = (velocity.velocityFlags & XR_SPACE_VELOCITY_ANGULAR_VALID_BIT) ? xr::math::cast(velocity.angularVelocity) 21 | : DirectX::XMFLOAT3{0, 0, 0}; 22 | } 23 | 24 | void Motion::UpdateMotionAndPose(XrPosef& pose, std::chrono::duration durationInSeconds) { 25 | using namespace DirectX; 26 | 27 | if (!Enabled) { 28 | return; 29 | } 30 | 31 | const float dt = durationInSeconds.count(); 32 | 33 | const auto position = xr::math::LoadXrVector3(pose.position); 34 | const auto orientation = xr::math::LoadXrQuaternion(pose.orientation); 35 | const auto linearVelocity = XMLoadFloat3(&LinearVelocity); 36 | const auto angularVelocity = XMLoadFloat3(&AngularVelocity); 37 | const auto linearAcceleration = XMLoadFloat3(&LinearAcceleration); 38 | const auto angularAcceleration = XMLoadFloat3(&AngularAcceleration); 39 | 40 | XMStoreFloat3(&LinearVelocity, linearVelocity + XMVectorScale(linearAcceleration, dt)); 41 | XMStoreFloat3(&AngularVelocity, angularVelocity + XMVectorScale(angularAcceleration, dt)); 42 | 43 | xr::math::StoreXrVector3(&pose.position, position + XMVectorScale(linearVelocity, dt)); 44 | 45 | // Convert angularVelocity from object space to world space 46 | auto angularVelocityInWorld = XMVector3Rotate(angularVelocity, XMQuaternionInverse(orientation)); 47 | 48 | auto angle = XMVectorGetX(XMVector3Length(angularVelocityInWorld)); 49 | if (angle > 0.0f) { 50 | xr::math::StoreXrQuaternion(&pose.orientation, 51 | XMQuaternionMultiply(XMQuaternionRotationAxis(angularVelocityInWorld, angle * dt), orientation)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /shared/XrSceneLib/ObjectMotion.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | namespace engine { 7 | 8 | struct Motion { 9 | bool Enabled{false}; 10 | DirectX::XMFLOAT3 LinearVelocity{}; 11 | DirectX::XMFLOAT3 LinearAcceleration{}; 12 | DirectX::XMFLOAT3 AngularVelocity{}; 13 | DirectX::XMFLOAT3 AngularAcceleration{}; 14 | 15 | void SetGravity(float gravitationalAcceleration = 9.8f); 16 | void SetVelocity(const XrSpaceVelocity& velocity); 17 | void SetRotation(const XrVector3f& axis, float radiansPerSecond); 18 | void UpdateMotionAndPose(XrPosef& pose, std::chrono::duration durationInSeconds); 19 | }; 20 | } // namespace engine 21 | -------------------------------------------------------------------------------- /shared/XrSceneLib/PbrModelObject.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include "Scene.h" 10 | #include "Context.h" 11 | 12 | namespace engine { 13 | 14 | class PbrModelObject : public Object { 15 | public: 16 | PbrModelObject(std::shared_ptr pbrModel = nullptr, 17 | Pbr::ShadingMode shadingMode = Pbr::ShadingMode::Regular, 18 | Pbr::FillMode fillMode = Pbr::FillMode::Solid); 19 | 20 | void SetModel(std::shared_ptr model); 21 | std::shared_ptr GetModel() const; 22 | 23 | void SetShadingMode(const Pbr::ShadingMode& shadingMode); 24 | void SetFillMode(const Pbr::FillMode& fillMode); 25 | void SetBaseColorFactor(Pbr::RGBAColor color); 26 | 27 | void Render(Context& context) const override; 28 | 29 | private: 30 | std::shared_ptr m_pbrModel; 31 | Pbr::ShadingMode m_shadingMode; 32 | Pbr::FillMode m_fillMode; 33 | }; 34 | 35 | // Helper for loading GLB files in the background. 36 | struct PbrModelLoadOperation { 37 | PbrModelLoadOperation() = default; 38 | PbrModelLoadOperation(PbrModelLoadOperation&&) = default; 39 | PbrModelLoadOperation& operator=(PbrModelLoadOperation&&) = default; 40 | 41 | static PbrModelLoadOperation LoadGltfBinaryAsync(Pbr::Resources& pbrResources, std::wstring filename); 42 | 43 | // Take the model (can only be done once) once it has been loaded. 44 | std::shared_ptr TakeModelWhenReady(); 45 | 46 | // Dtor ensures outstanding operation is complete before returning. 47 | ~PbrModelLoadOperation(); 48 | 49 | private: 50 | explicit PbrModelLoadOperation(std::future> loadModelTask); 51 | 52 | std::future> m_loadModelTask; 53 | }; 54 | 55 | std::shared_ptr CreateCube(const Pbr::Resources& pbrResources, 56 | DirectX::XMFLOAT3 sideLengths, 57 | Pbr::RGBAColor color, 58 | float roughness = 1.0f, 59 | float metallic = 0.0f); 60 | 61 | std::shared_ptr CreateQuad(const Pbr::Resources& pbrResources, 62 | DirectX::XMFLOAT2 sideLengths, 63 | std::shared_ptr material); 64 | 65 | std::shared_ptr CreateSphere(const Pbr::Resources& pbrResources, 66 | float size, 67 | uint32_t tesselation, 68 | Pbr::RGBAColor color, 69 | float roughness = 1.0f, 70 | float metallic = 0.0f); 71 | 72 | std::shared_ptr CreateAxis(const Pbr::Resources& pbrResources, 73 | float axisLength = 1.0f, 74 | float axisThickness = 0.01f, 75 | float originAdditionalThickness = 0.01f, 76 | float roughness = 0.85f, 77 | float metallic = 0.01f); 78 | 79 | } // namespace engine 80 | -------------------------------------------------------------------------------- /shared/XrSceneLib/QuadLayerObject.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "pch.h" 5 | #include "QuadLayerObject.h" 6 | #include "CompositionLayers.h" 7 | 8 | using namespace DirectX; 9 | 10 | std::shared_ptr engine::CreateQuadLayerObject(XrSpace space, XrSwapchainSubImage image) { 11 | auto result = std::make_shared(); 12 | result->Image = std::move(image); 13 | result->Space = space; 14 | return result; 15 | } 16 | 17 | void engine::AppendQuadLayer(engine::CompositionLayers& layers, engine::QuadLayerObject* quad) { 18 | XrCompositionLayerQuad& quadLayer = layers.AddQuadLayer(); 19 | quadLayer.type = XR_TYPE_COMPOSITION_LAYER_QUAD; 20 | quadLayer.subImage = quad->Image; 21 | quadLayer.space = quad->Space; 22 | quadLayer.layerFlags = quad->CompositionLayerFlags; 23 | quadLayer.eyeVisibility = quad->EyeVisibility; 24 | 25 | 26 | XMVECTOR scale, position, orientation; 27 | if (!DirectX::XMMatrixDecompose(&scale, &orientation, &position, quad->WorldTransform())) { 28 | throw std::runtime_error("Failed to decompose quad layer world transform"); 29 | } 30 | 31 | xr::math::StoreXrQuaternion(&quadLayer.pose.orientation, orientation); 32 | xr::math::StoreXrVector3(&quadLayer.pose.position, position); 33 | 34 | xr::math::StoreXrExtent(&quadLayer.size, scale); // Use x and y but ignore z. 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /shared/XrSceneLib/QuadLayerObject.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include "Object.h" 7 | #include "Context.h" 8 | 9 | namespace engine { 10 | 11 | enum class LayerGrouping { 12 | Underlay, // Behind all projection layers 13 | Overlay // In front of all projection layers 14 | }; 15 | 16 | struct QuadLayerObject : public Object { 17 | XrSwapchainSubImage Image; 18 | 19 | XrSpace Space{XR_NULL_HANDLE}; 20 | XrCompositionLayerFlags CompositionLayerFlags{}; 21 | XrEyeVisibility EyeVisibility{XR_EYE_VISIBILITY_BOTH}; 22 | LayerGrouping LayerGroup = LayerGrouping::Overlay; 23 | DirectX::XMFLOAT4 ColorScale = {1, 1, 1, 1}; 24 | DirectX::XMFLOAT4 ColorBias = {0, 0, 0, 0}; 25 | }; 26 | 27 | std::shared_ptr CreateQuadLayerObject(XrSpace space, XrSwapchainSubImage image); 28 | 29 | } // namespace engine 30 | -------------------------------------------------------------------------------- /shared/XrSceneLib/Scene.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "pch.h" 5 | #include "Scene.h" 6 | 7 | using namespace DirectX; 8 | 9 | namespace { 10 | template 11 | void AddPendingObjects(std::vector>* objects, std::vector>&& uninitializedObjects) { 12 | for (auto& object : uninitializedObjects) { 13 | if (object->State == engine::ObjectState::InitializePending) { 14 | object->State = engine::ObjectState::Initialized; 15 | objects->push_back(std::move(object)); 16 | } 17 | } 18 | } 19 | 20 | template 21 | void RemoveDestroyedObjects(std::vector>* objects) { 22 | auto newEnd = std::remove_if( 23 | objects->begin(), objects->end(), [](auto&& object) { return object->State == engine::ObjectState::RemovePending; }); 24 | 25 | objects->erase(newEnd, objects->end()); 26 | } 27 | 28 | template 29 | void UpdateObjects(std::vector> const& objects, engine::Context& context, engine::FrameTime const& frameTime) { 30 | for (const auto& object : objects) { 31 | object->Update(context, frameTime); 32 | } 33 | } 34 | 35 | template 36 | void RenderObjects(std::vector> const& objects, engine::Context& context, uint32_t viewIndex) { 37 | for (const auto& object : objects) { 38 | if (object->IsVisibleForViewIndex(viewIndex)) { 39 | object->Render(context); 40 | } 41 | } 42 | } 43 | } // namespace 44 | 45 | engine::Scene::Scene(engine::Context& context) 46 | : m_context(context) 47 | , m_actionContext(context.Instance.Handle) { 48 | } 49 | 50 | void engine::Scene::Update(const engine::FrameTime& frameTime) { 51 | std::unique_lock lk(m_uninitializedMutex); 52 | std::vector uninitializedObjects = std::move(m_uninitializedObjects); 53 | std::vector uninitializedQuadLayerObjects = std::move(m_uninitializedQuadLayerObjects); 54 | lk.unlock(); 55 | 56 | AddPendingObjects(&m_objects, std::move(uninitializedObjects)); 57 | AddPendingObjects(&m_quadLayerObjects, std::move(uninitializedQuadLayerObjects)); 58 | 59 | RemoveDestroyedObjects(&m_objects); 60 | RemoveDestroyedObjects(&m_quadLayerObjects); 61 | 62 | UpdateObjects(m_objects, m_context, frameTime); 63 | UpdateObjects(m_quadLayerObjects, m_context, frameTime); 64 | 65 | OnUpdate(frameTime); 66 | } 67 | 68 | void engine::Scene::BeforeRender(const FrameTime& frameTime) { 69 | OnBeforeRender(frameTime); 70 | } 71 | 72 | void engine::Scene::Render(const FrameTime& frameTime, uint32_t viewIndex) { 73 | RenderObjects(m_objects, m_context, viewIndex); 74 | RenderObjects(m_quadLayerObjects, m_context, viewIndex); 75 | } 76 | -------------------------------------------------------------------------------- /shared/XrSceneLib/SpaceObject.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "pch.h" 5 | #include "SpaceObject.h" 6 | 7 | namespace { 8 | 9 | class SpaceObject : public engine::Object { 10 | public: 11 | SpaceObject(xr::SpaceHandle space, bool hideWhenPoseInvalid) 12 | : m_space(std::move(space)) 13 | , m_hideWhenPoseInvalid(hideWhenPoseInvalid) { 14 | assert(m_space.Get() != XR_NULL_HANDLE); 15 | } 16 | 17 | void Update(engine::Context& context, const engine::FrameTime& frameTime) override { 18 | XrSpaceLocation location{XR_TYPE_SPACE_LOCATION}; 19 | CHECK_XRCMD(xrLocateSpace(m_space.Get(), context.AppSpace, frameTime.PredictedDisplayTime, &location)); 20 | const bool poseValid = xr::math::Pose::IsPoseValid(location); 21 | if (poseValid) { 22 | Pose() = location.pose; 23 | } 24 | if (m_hideWhenPoseInvalid) { 25 | SetVisible(poseValid); 26 | } 27 | } 28 | 29 | private: 30 | xr::SpaceHandle m_space; 31 | const bool m_hideWhenPoseInvalid; 32 | }; 33 | } // namespace 34 | 35 | namespace engine { 36 | std::shared_ptr CreateSpaceObject(xr::SpaceHandle space, bool hideWhenPoseInvalid) { 37 | return std::make_shared(std::move(space), hideWhenPoseInvalid); 38 | } 39 | } // namespace engine 40 | -------------------------------------------------------------------------------- /shared/XrSceneLib/SpaceObject.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include "Object.h" 7 | 8 | namespace engine { 9 | std::shared_ptr CreateSpaceObject(xr::SpaceHandle space, bool hideWhenPoseInvalid = true); 10 | } // namespace engine 11 | -------------------------------------------------------------------------------- /shared/XrSceneLib/TextTexture.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "pbr/PbrMaterial.h" 11 | #include "Context.h" 12 | 13 | namespace engine { 14 | 15 | struct TextTextureInfo { 16 | TextTextureInfo(uint32_t width, uint32_t height) 17 | : Width(width) 18 | , Height(height) { 19 | } 20 | 21 | uint32_t Width; 22 | uint32_t Height; 23 | const wchar_t* FontName = L"Segoe UI"; 24 | float FontSize = 18; 25 | float Margin = 0; 26 | Pbr::RGBAColor Foreground = Pbr::RGBA::White; 27 | Pbr::RGBAColor Background = Pbr::RGBA::Transparent; 28 | DWRITE_TEXT_ALIGNMENT TextAlignment = DWRITE_TEXT_ALIGNMENT_CENTER; 29 | DWRITE_PARAGRAPH_ALIGNMENT ParagraphAlignment = DWRITE_PARAGRAPH_ALIGNMENT_CENTER; 30 | }; 31 | 32 | // Manages a texture which can be drawn to. 33 | class TextTexture { 34 | public: 35 | TextTexture(Context& context, TextTextureInfo textInfo); 36 | 37 | void Draw(std::string_view text); 38 | ID3D11Texture2D* Texture() const; 39 | std::shared_ptr CreatePbrMaterial(const Pbr::Resources& pbrResources) const; 40 | 41 | private: 42 | const TextTextureInfo m_textInfo; 43 | winrt::com_ptr m_d2dFactory; 44 | winrt::com_ptr m_d2dDevice; 45 | winrt::com_ptr m_d2dContext; 46 | winrt::com_ptr m_d2dTargetBitmap; 47 | winrt::com_ptr m_brush; 48 | winrt::com_ptr m_stateBlock; 49 | winrt::com_ptr m_dwriteFactory; 50 | winrt::com_ptr m_textFormat; 51 | winrt::com_ptr m_textDWriteTexture; 52 | }; 53 | 54 | } // namespace engine 55 | -------------------------------------------------------------------------------- /shared/XrSceneLib/XrApp.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include "Scene.h" 7 | #include "Context.h" 8 | #include "ProjectionLayer.h" 9 | 10 | namespace engine { 11 | class XrApp { 12 | public: 13 | virtual ~XrApp() = default; 14 | 15 | virtual Context& Context() const = 0; 16 | 17 | virtual void AddScene(std::unique_ptr scene) = 0; 18 | virtual const std::vector>& Scenes() const = 0; 19 | 20 | virtual void Run() = 0; 21 | virtual bool Step() = 0; 22 | virtual void Stop() = 0; 23 | 24 | virtual ProjectionLayers& ProjectionLayers() = 0; 25 | 26 | }; 27 | 28 | struct XrAppConfiguration { 29 | XrAppConfiguration(const xr::NameVersion appInfo) 30 | : AppInfo(std::move(appInfo)) { 31 | } 32 | 33 | const xr::NameVersion AppInfo; 34 | std::vector RequestedExtensions; 35 | std::vector InteractionProfilesFilter; 36 | bool SingleThreadedD3D11Device{false}; 37 | bool RenderSynchronously{false}; 38 | std::optional HolographicWindowAttachment{std::nullopt}; 39 | }; 40 | 41 | std::unique_ptr CreateXrApp(XrAppConfiguration appConfiguration); 42 | } // namespace engine 43 | 44 | -------------------------------------------------------------------------------- /shared/XrSceneLib/XrSceneLib_uwp.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Objects 8 | 9 | 10 | Objects 11 | 12 | 13 | Objects 14 | 15 | 16 | Layers 17 | 18 | 19 | Scenes 20 | 21 | 22 | Scenes 23 | 24 | 25 | Layers 26 | 27 | 28 | Objects 29 | 30 | 31 | Objects 32 | 33 | 34 | Objects 35 | 36 | 37 | 38 | 39 | 40 | 41 | Objects 42 | 43 | 44 | Objects 45 | 46 | 47 | Scenes 48 | 49 | 50 | Scenes 51 | 52 | 53 | Objects 54 | 55 | 56 | Layers 57 | 58 | 59 | Layers 60 | 61 | 62 | Scenes 63 | 64 | 65 | Layers 66 | 67 | 68 | Objects 69 | 70 | 71 | Objects 72 | 73 | 74 | Objects 75 | 76 | 77 | 78 | 79 | {15a8b794-5b3c-4b3b-b082-ad2956aa9cee} 80 | 81 | 82 | {ff777324-cf8c-4816-b6f0-30473a5ec800} 83 | 84 | 85 | {757d01b5-59f7-4d8a-8faa-53ea62f2ec25} 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /shared/XrSceneLib/XrSceneLib_win32.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | Objects 8 | 9 | 10 | Objects 11 | 12 | 13 | Objects 14 | 15 | 16 | Layers 17 | 18 | 19 | Scenes 20 | 21 | 22 | Scenes 23 | 24 | 25 | Layers 26 | 27 | 28 | Objects 29 | 30 | 31 | Objects 32 | 33 | 34 | Objects 35 | 36 | 37 | 38 | 39 | 40 | 41 | Objects 42 | 43 | 44 | Scenes 45 | 46 | 47 | Scenes 48 | 49 | 50 | Objects 51 | 52 | 53 | Objects 54 | 55 | 56 | Layers 57 | 58 | 59 | Layers 60 | 61 | 62 | Scenes 63 | 64 | 65 | Layers 66 | 67 | 68 | Objects 69 | 70 | 71 | Objects 72 | 73 | 74 | Objects 75 | 76 | 77 | 78 | 79 | {c8fee26b-99f6-4972-b4c7-59860905328d} 80 | 81 | 82 | {823681fb-5d10-4e98-84fe-d248dc171376} 83 | 84 | 85 | {2e2f732d-d965-47b1-88cf-6f5085d0ff77} 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /shared/XrSceneLib/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /shared/XrSceneLib/pch.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "pch.h" 5 | -------------------------------------------------------------------------------- /shared/XrSceneLib/pch.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #define NOMINMAX 9 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #define XR_USE_PLATFORM_WIN32 35 | #define XR_USE_GRAPHICS_API_D3D11 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | 44 | #define ENABLE_GLOBAL_XR_DISPATCH_TABLE 45 | #include 46 | 47 | #include // for winrt::com_ptr 48 | 49 | #define FMT_HEADER_ONLY 50 | #include 51 | -------------------------------------------------------------------------------- /shared/XrUtility/XrEnabledExtensions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace xr { 7 | 8 | // Struct of enabled flags is generated using openxr_reflection. Any non-public extensions will need to be added manually. 9 | struct EnabledExtensions { 10 | EnabledExtensions() = default; 11 | EnabledExtensions(const std::vector& enabledExtensions, const std::vector& extensionProperties) 12 | : EnabledExtensions(enabledExtensions.data(), (uint32_t)enabledExtensions.size(), extensionProperties) { 13 | } 14 | EnabledExtensions(const char* const* enabledExtensionNames, 15 | uint32_t enabledExtensionNamesCount, 16 | const std::vector& extensionProperties) { 17 | auto getExtensionVersion = [&](const char* extensionName) -> uint32_t { 18 | for (const auto& extension : extensionProperties) { 19 | if (strcmp(extension.extensionName, extensionName) == 0) { 20 | return extension.extensionVersion; 21 | } 22 | } 23 | return 0; 24 | }; 25 | 26 | // "_enabled" or "_version" is token concat to the name because the extension name is also a C MACRO that can conflict. 27 | #define SET_EXTENSION_IF_MATCH(name, _) \ 28 | if (strcmp(enabledExtensionNames[i], #name) == 0) { \ 29 | name##_enabled = true; \ 30 | name##_version = getExtensionVersion(#name); \ 31 | continue; \ 32 | } 33 | 34 | for (uint32_t i = 0; i < enabledExtensionNamesCount; i++) { 35 | XR_LIST_EXTENSIONS(SET_EXTENSION_IF_MATCH) 36 | XR_LIST_EXTENSIONS_MSFT_PREVIEW(SET_EXTENSION_IF_MATCH) 37 | } 38 | 39 | #undef SET_EXTENSION_IF_MATCH 40 | } 41 | 42 | // Example: for extension name `XR_KHR_extension_name`, there will be two fields define for it. 43 | // bool XR_KHR_extension_name_enabled; // it will be true if the extension is enabled by the current xrInstance 44 | // uint32 XR_KHR_extension_name_version; // it will be > 0 if the extension is enabled by the current xrInstance. 45 | #define DEFINE_EXTENSION_FIELD(name, _) \ 46 | bool name##_enabled = false; \ 47 | uint32_t name##_version = 0; 48 | 49 | XR_LIST_EXTENSIONS(DEFINE_EXTENSION_FIELD) 50 | XR_LIST_EXTENSIONS_MSFT_PREVIEW(DEFINE_EXTENSION_FIELD) 51 | 52 | #undef MSXR_ADD_EXTENSION_FIELD 53 | }; 54 | 55 | } // namespace xr 56 | 57 | -------------------------------------------------------------------------------- /shared/XrUtility/XrGuid.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace xr { 10 | 11 | // GUID_DEFINED is defined in guiddef.h 12 | #ifdef GUID_DEFINED 13 | 14 | inline constexpr GUID ToGuid(const XrUuidMSFT& src) noexcept { 15 | GUID dest{}; 16 | const auto& u = src.bytes; 17 | // Data1, Data2, and Data3 are encoded as big-endian for Variant-1 18 | dest.Data1 = u[0] * 0x01000000u + u[1] * 0x00010000u + u[2] * 0x00000100u + u[3]; 19 | dest.Data2 = uint16_t(u[4] * 0x0100u + u[5]); 20 | dest.Data3 = uint16_t(u[6] * 0x0100u + u[7]); 21 | dest.Data4[0] = u[8]; 22 | dest.Data4[1] = u[9]; 23 | dest.Data4[2] = u[10]; 24 | dest.Data4[3] = u[11]; 25 | dest.Data4[4] = u[12]; 26 | dest.Data4[5] = u[13]; 27 | dest.Data4[6] = u[14]; 28 | dest.Data4[7] = u[15]; 29 | return dest; 30 | } 31 | 32 | inline constexpr XrUuidMSFT ToXrUuidMSFT(const GUID& src) noexcept { 33 | XrUuidMSFT dest{}; 34 | auto& u = dest.bytes; 35 | // Data1, Data2, and Data3 are encoded as big-endian for Variant-1 36 | u[0] = uint8_t(src.Data1 >> 24); 37 | u[1] = uint8_t(src.Data1 >> 16); 38 | u[2] = uint8_t(src.Data1 >> 8); 39 | u[3] = uint8_t(src.Data1); 40 | 41 | u[4] = uint8_t(src.Data2 >> 8); 42 | u[5] = uint8_t(src.Data2); 43 | 44 | u[6] = uint8_t(src.Data3 >> 8); 45 | u[7] = uint8_t(src.Data3); 46 | 47 | u[8] = src.Data4[0]; 48 | u[9] = src.Data4[1]; 49 | u[10] = src.Data4[2]; 50 | u[11] = src.Data4[3]; 51 | u[12] = src.Data4[4]; 52 | u[13] = src.Data4[5]; 53 | u[14] = src.Data4[6]; 54 | u[15] = src.Data4[7]; 55 | return dest; 56 | } 57 | 58 | #endif // GUID_DEFINED 59 | } // namespace xr 60 | -------------------------------------------------------------------------------- /shared/XrUtility/XrHandle.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | namespace xr { 9 | 10 | template 11 | class UniqueXrHandle { 12 | using PFN_DestroyFunction = XrResult(XRAPI_PTR*)(HandleType); 13 | 14 | public: 15 | UniqueXrHandle() = default; 16 | UniqueXrHandle(const UniqueXrHandle&) = delete; 17 | UniqueXrHandle(UniqueXrHandle&& other) noexcept { 18 | *this = std::move(other); 19 | } 20 | 21 | ~UniqueXrHandle() noexcept { 22 | Reset(); 23 | } 24 | 25 | UniqueXrHandle& operator=(const UniqueXrHandle&) = delete; 26 | UniqueXrHandle& operator=(UniqueXrHandle&& other) noexcept { 27 | if (m_handle != other.m_handle || m_destroyer != other.m_destroyer) { 28 | Reset(); 29 | 30 | m_handle = other.m_handle; 31 | m_destroyer = other.m_destroyer; 32 | 33 | other.m_handle = XR_NULL_HANDLE; 34 | other.m_destroyer = nullptr; 35 | } 36 | return *this; 37 | } 38 | 39 | bool operator==(const UniqueXrHandle& other) noexcept { 40 | return m_handle == other.m_handle; 41 | } 42 | 43 | bool operator!=(const UniqueXrHandle& other) noexcept { 44 | return m_handle != other.m_handle; 45 | } 46 | 47 | explicit operator bool() const noexcept { 48 | return m_handle != XR_NULL_HANDLE; 49 | } 50 | 51 | HandleType Get() const noexcept { 52 | return m_handle; 53 | } 54 | 55 | // Extension functions cannot be statically linked, so the creator must pass in the destroy function. 56 | HandleType* Put(PFN_DestroyFunction destroyFunction) noexcept { 57 | assert(destroyFunction != nullptr); 58 | Reset(); 59 | m_destroyer = destroyFunction; 60 | return &m_handle; 61 | } 62 | 63 | void Reset() noexcept { 64 | if (m_handle != XR_NULL_HANDLE) { 65 | m_destroyer(m_handle); 66 | m_handle = XR_NULL_HANDLE; 67 | } 68 | 69 | m_destroyer = nullptr; 70 | } 71 | 72 | private: 73 | HandleType m_handle{XR_NULL_HANDLE}; 74 | PFN_DestroyFunction m_destroyer{nullptr}; 75 | }; 76 | 77 | class ActionHandle : public UniqueXrHandle {}; 78 | class ActionSetHandle : public UniqueXrHandle {}; 79 | class InstanceHandle : public UniqueXrHandle {}; 80 | class SessionHandle : public UniqueXrHandle {}; 81 | class SpaceHandle : public UniqueXrHandle {}; 82 | class SwapchainHandle : public UniqueXrHandle {}; 83 | class SpatialAnchorHandle : public UniqueXrHandle {}; 84 | class HandTrackerHandle : public UniqueXrHandle {}; 85 | 86 | } // namespace xr 87 | -------------------------------------------------------------------------------- /shared/XrUtility/XrPlatformDependencies.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018-2022, The Khronos Group Inc. 2 | // 3 | // SPDX-License-Identifier: Apache-2.0 OR MIT 4 | // 5 | // This file includes headers with types which openxr.h depends on in order 6 | // to compile when platforms, graphics apis, and the like are enabled. 7 | 8 | #pragma once 9 | 10 | // Adapted from OpenXR-SDK on github: 11 | // https://github.com/KhronosGroup/OpenXR-SDK/blob/master/src/common/xr_dependencies.h 12 | 13 | #ifdef XR_USE_PLATFORM_ANDROID 14 | #include 15 | #include 16 | #include 17 | #endif // XR_USE_PLATFORM_ANDROID 18 | 19 | #ifdef XR_USE_PLATFORM_WIN32 20 | 21 | // OLE desktop APIs cannot be overriden with the following desktop parition flag. 22 | #include 23 | 24 | #include 25 | #if !(WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM)) 26 | // Enable desktop partition APIs, such as RegOpenKeyEx, LoadLibraryEx, PathFileExists etc. 27 | #undef WINAPI_PARTITION_DESKTOP 28 | #define WINAPI_PARTITION_DESKTOP 1 29 | #endif 30 | 31 | #ifndef NOMINMAX 32 | #define NOMINMAX 33 | #endif // !NOMINMAX 34 | 35 | #ifndef WIN32_LEAN_AND_MEAN 36 | #define WIN32_LEAN_AND_MEAN 37 | #endif // !WIN32_LEAN_AND_MEAN 38 | 39 | #include 40 | #include 41 | 42 | #endif // XR_USE_PLATFORM_WIN32 43 | 44 | #ifdef XR_USE_GRAPHICS_API_D3D11 45 | #include 46 | #endif // XR_USE_GRAPHICS_API_D3D11 47 | 48 | #ifdef XR_USE_GRAPHICS_API_D3D12 49 | #include 50 | #endif // XR_USE_GRAPHICS_API_D3D12 51 | 52 | #ifdef XR_USE_PLATFORM_XLIB 53 | #include 54 | #include 55 | 56 | #ifdef Success 57 | #undef Success 58 | #endif // Success 59 | 60 | #ifdef Always 61 | #undef Always 62 | #endif // Always 63 | 64 | #ifdef None 65 | #undef None 66 | #endif // None 67 | #endif // XR_USE_PLATFORM_XLIB 68 | 69 | #ifdef XR_USE_PLATFORM_XCB 70 | #include 71 | #endif // XR_USE_PLATFORM_XCB 72 | 73 | #ifdef XR_USE_GRAPHICS_API_OPENGL 74 | #if defined(XR_USE_PLATFORM_XLIB) || defined(XR_USE_PLATFORM_XCB) 75 | #include 76 | #endif // (XR_USE_PLATFORM_XLIB || XR_USE_PLATFORM_XCB) 77 | #ifdef XR_USE_PLATFORM_XCB 78 | #include 79 | #endif // XR_USE_PLATFORM_XCB 80 | #ifdef XR_USE_PLATFORM_MACOS 81 | #include 82 | #endif // XR_USE_PLATFORM_MACOS 83 | #endif // XR_USE_GRAPHICS_API_OPENGL 84 | 85 | #ifdef XR_USE_GRAPHICS_API_OPENGL_ES 86 | #include 87 | #endif // XR_USE_GRAPHICS_API_OPENGL_ES 88 | 89 | #ifdef XR_USE_GRAPHICS_API_VULKAN 90 | #include 91 | #endif // XR_USE_GRAPHICS_API_VULKAN 92 | 93 | #ifdef XR_USE_PLATFORM_WAYLAND 94 | #include "wayland-client.h" 95 | #endif // XR_USE_PLATFORM_WAYLAND 96 | -------------------------------------------------------------------------------- /shared/XrUtility/XrSceneUnderstandingSerialization.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include "XrSceneUnderstanding.hpp" 7 | 8 | namespace xr::su { 9 | struct SceneFragment { 10 | using Id = TypedUuid; 11 | Id id; 12 | XrTime updateTime; 13 | }; 14 | 15 | inline std::vector GetSerializedSceneFragments(XrSceneMSFT scene) { 16 | XrSceneComponentsGetInfoMSFT getInfo{XR_TYPE_SCENE_COMPONENTS_GET_INFO_MSFT}; 17 | getInfo.componentType = XR_SCENE_COMPONENT_TYPE_SERIALIZED_SCENE_FRAGMENT_MSFT; 18 | 19 | XrSceneComponentsMSFT sceneComponents{XR_TYPE_SCENE_COMPONENTS_MSFT}; 20 | CHECK_XRCMD(xrGetSceneComponentsMSFT(scene, &getInfo, &sceneComponents)); 21 | const uint32_t count = sceneComponents.componentCountOutput; 22 | 23 | std::vector components(count); 24 | sceneComponents.componentCapacityInput = count; 25 | sceneComponents.components = components.data(); 26 | 27 | CHECK_XRCMD(xrGetSceneComponentsMSFT(scene, &getInfo, &sceneComponents)); 28 | 29 | std::vector result(count); 30 | for (uint32_t k = 0; k < count; k++) { 31 | result[k].id = components[k].id; 32 | result[k].updateTime = components[k].updateTime; 33 | } 34 | return result; 35 | } 36 | 37 | inline std::vector ReadSceneFragmentData(XrSceneMSFT scene, const SceneFragment::Id& id) { 38 | uint32_t readOutput = 0; 39 | XrSerializedSceneFragmentDataGetInfoMSFT getInfo{XR_TYPE_SERIALIZED_SCENE_FRAGMENT_DATA_GET_INFO_MSFT}; 40 | getInfo.sceneFragmentId = static_cast(id); 41 | CHECK_XRCMD(xrGetSerializedSceneFragmentDataMSFT(scene, &getInfo, 0, &readOutput, nullptr)); 42 | 43 | std::vector buffer(readOutput); 44 | CHECK_XRCMD(xrGetSerializedSceneFragmentDataMSFT(scene, &getInfo, readOutput, &readOutput, buffer.data())); 45 | return buffer; 46 | } 47 | 48 | } // namespace xr::su 49 | -------------------------------------------------------------------------------- /shared/XrUtility/XrSide.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | namespace xr { 7 | 8 | typedef uint32_t side_t; 9 | 10 | namespace Side { 11 | constexpr side_t Left = 0; 12 | constexpr side_t Right = 1; 13 | constexpr side_t Count = 2; 14 | } // namespace Side 15 | 16 | } // namespace xr 17 | -------------------------------------------------------------------------------- /shared/XrUtility/XrSpatialGraphBridge.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include "XrStruct.h" 9 | #include "XrHandle.h" 10 | #include "XrGuid.h" 11 | 12 | namespace xr { 13 | class SpatialGraphNodeBindingHandle : public xr::UniqueXrHandle {}; 14 | 15 | // GUID_DEFINED is defined in guiddef.h 16 | #ifdef GUID_DEFINED 17 | 18 | struct SpatialGraphNodeBindingProperties { 19 | GUID nodeId; 20 | XrPosef poseInNodeSpace; 21 | }; 22 | 23 | inline void SetNodeId(XrSpatialGraphNodeSpaceCreateInfoMSFT& createInfo, const GUID& guid) { 24 | #ifdef __STDC_LIB_EXT1__ 25 | memcpy_s(&createInfo.nodeId, sizeof(createInfo.nodeId), &guid, sizeof(guid)); 26 | #else 27 | memcpy(&createInfo.nodeId, &guid, sizeof(guid)); 28 | #endif 29 | } 30 | 31 | inline const GUID& GetNodeIdAsGuid(const XrSpatialGraphNodeBindingPropertiesMSFT& properties) { 32 | return reinterpret_cast(properties.nodeId); 33 | } 34 | 35 | inline xr::SpaceHandle 36 | CreateSpatialGraphNodeSpace(XrSession session, XrSpatialGraphNodeTypeMSFT nodeType, const GUID& nodeId, const XrPosef& pose) { 37 | XrSpatialGraphNodeSpaceCreateInfoMSFT spaceCreateInfo{XR_TYPE_SPATIAL_GRAPH_NODE_SPACE_CREATE_INFO_MSFT}; 38 | spaceCreateInfo.nodeType = nodeType; 39 | spaceCreateInfo.pose = pose; 40 | SetNodeId(spaceCreateInfo, nodeId); 41 | xr::SpaceHandle space; 42 | CHECK_XRCMD(xrCreateSpatialGraphNodeSpaceMSFT(session, &spaceCreateInfo, space.Put(xrDestroySpace))); 43 | return space; 44 | } 45 | 46 | inline xr::SpatialGraphNodeBindingHandle 47 | TryCreateSpatialGraphStaticNodeBinding(XrSession session, XrSpace space, XrPosef poseInSpace, XrTime time) { 48 | xr::SpatialGraphNodeBindingHandle nodeBinding; 49 | XrSpatialGraphStaticNodeBindingCreateInfoMSFT createInfo{XR_TYPE_SPATIAL_GRAPH_STATIC_NODE_BINDING_CREATE_INFO_MSFT}; 50 | createInfo.space = space; 51 | createInfo.poseInSpace = poseInSpace; 52 | createInfo.time = time; 53 | CHECK_XRCMD( 54 | xrTryCreateSpatialGraphStaticNodeBindingMSFT(session, &createInfo, nodeBinding.Put(xrDestroySpatialGraphNodeBindingMSFT))); 55 | return nodeBinding; 56 | } 57 | 58 | inline SpatialGraphNodeBindingProperties GetSpatialGraphNodeBindingProperties(XrSpatialGraphNodeBindingMSFT nodeBinding) { 59 | XrSpatialGraphNodeBindingPropertiesMSFT properties{XR_TYPE_SPATIAL_GRAPH_NODE_BINDING_PROPERTIES_MSFT}; 60 | CHECK_XRCMD(xrGetSpatialGraphNodeBindingPropertiesMSFT(nodeBinding, nullptr, &properties)); 61 | return {GetNodeIdAsGuid(properties), properties.poseInNodeSpace}; 62 | } 63 | #endif // GUID_DEFINED 64 | } // namespace xr 65 | -------------------------------------------------------------------------------- /shared/XrUtility/XrStereoView.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | namespace xr { 7 | 8 | namespace StereoView { 9 | constexpr uint32_t Left = 0; 10 | constexpr uint32_t Right = 1; 11 | constexpr uint32_t Count = 2; 12 | } // namespace StereoView 13 | 14 | } // namespace xr 15 | -------------------------------------------------------------------------------- /shared/XrUtility/XrString.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include "XrToString.h" 15 | #include "XrError.h" 16 | 17 | namespace xr { 18 | 19 | inline XrPath StringToPath(XrInstance instance, const char* str) { 20 | XrPath path; 21 | CHECK_XRCMD(xrStringToPath(instance, str, &path)); 22 | return path; 23 | } 24 | 25 | inline std::string PathToString(XrInstance instance, XrPath path) { 26 | uint32_t count; 27 | CHECK_XRCMD(xrPathToString(instance, path, 0, &count, nullptr)); 28 | std::string string; 29 | string.resize(count - 1); // OpenXR size includes '\0', std::string::size doesn't. 30 | CHECK_XRCMD(xrPathToString(instance, path, count, &count, string.data())); 31 | return string; 32 | } 33 | 34 | inline std::vector StringsToPaths(XrInstance instance, const std::vector& strings) { 35 | std::vector paths; 36 | 37 | for (auto& string : strings) { 38 | paths.push_back(xr::StringToPath(instance, string.c_str())); 39 | } 40 | 41 | return paths; 42 | } 43 | 44 | inline std::vector StringsToCStrings(const std::vector& strings) { 45 | std::vector cStrings; 46 | for (auto& string : strings) { 47 | cStrings.push_back(string.c_str()); 48 | } 49 | return cStrings; 50 | } 51 | 52 | #ifdef _WIN32 53 | inline std::wstring utf8_to_wide(std::string_view utf8Text) { 54 | if (utf8Text.empty()) { 55 | return {}; 56 | } 57 | 58 | std::wstring wideText; 59 | const int wideLength = ::MultiByteToWideChar(CP_UTF8, 0, utf8Text.data(), (int)utf8Text.size(), nullptr, 0); 60 | if (wideLength == 0) { 61 | DEBUG_PRINT("utf8_to_wide get size error."); 62 | return {}; 63 | } 64 | 65 | // MultiByteToWideChar returns number of chars of the input buffer, regardless of null terminitor 66 | wideText.resize(wideLength, 0); 67 | const int length = ::MultiByteToWideChar(CP_UTF8, 0, utf8Text.data(), (int)utf8Text.size(), wideText.data(), wideLength); 68 | if (length != wideLength) { 69 | DEBUG_PRINT("utf8_to_wide convert string error."); 70 | return {}; 71 | } 72 | 73 | return wideText; 74 | } 75 | 76 | inline std::string wide_to_utf8(std::wstring_view wideText) { 77 | if (wideText.empty()) { 78 | return {}; 79 | } 80 | 81 | std::string narrowText; 82 | int narrowLength = ::WideCharToMultiByte(CP_UTF8, 0, wideText.data(), (int)wideText.size(), nullptr, 0, nullptr, nullptr); 83 | if (narrowLength == 0) { 84 | DEBUG_PRINT("wide_to_utf8 get size error."); 85 | return {}; 86 | } 87 | 88 | // WideCharToMultiByte returns number of chars of the input buffer, regardless of null terminitor 89 | narrowText.resize(narrowLength, 0); 90 | const int length = 91 | ::WideCharToMultiByte(CP_UTF8, 0, wideText.data(), (int)wideText.size(), narrowText.data(), narrowLength, nullptr, nullptr); 92 | if (length != narrowLength) { 93 | DEBUG_PRINT("wide_to_utf8 convert string error."); 94 | return {}; 95 | } 96 | 97 | return narrowText; 98 | } 99 | #endif 100 | 101 | } // namespace xr 102 | -------------------------------------------------------------------------------- /shared/XrUtility/XrStructTraits.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace msxr { 10 | 11 | // Type trait which can be used for validation of extensible struct types. Does not validate position of member variables yet. 12 | template 13 | using is_xr_struct = 14 | std::conjunction>, // T::type is XrStructureType 15 | std::is_same>>>; // T::next is void* or const 16 | // void* 17 | template 18 | inline constexpr bool is_xr_struct_v = is_xr_struct::value; 19 | 20 | using namespace std::literals::string_view_literals; 21 | 22 | template 23 | struct XrStructTraits { 24 | static_assert(sizeof(T) == -1, "Must define traits for your struct"); 25 | }; 26 | 27 | #define DECLARE_XR_STRUCT_TRAITS(Type, Enum) \ 28 | template <> \ 29 | struct XrStructTraits { \ 30 | static constexpr std::string_view name{#Type##sv}; \ 31 | static constexpr XrStructureType type{static_cast(Enum)}; \ 32 | }; 33 | 34 | XR_LIST_STRUCTURE_TYPES(DECLARE_XR_STRUCT_TRAITS) 35 | XR_LIST_STRUCTURE_TYPES_MSFT_PREVIEW(DECLARE_XR_STRUCT_TRAITS) 36 | } // namespace msxr 37 | 38 | -------------------------------------------------------------------------------- /shared/XrUtility/XrToString.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | // Macro to generate stringify functions for OpenXR enumerations based data provided in openxr_reflection.h 12 | // clang-format off 13 | #define ENUM_CASE_STR(name, val) case name: return #name; 14 | 15 | // Returns C string pointing to a string literal. Unknown values are returned as 'Unknown '. 16 | #define MAKE_TO_CSTRING_FUNC(enumType) \ 17 | constexpr const char* ToCString(enumType e) noexcept { \ 18 | switch (e) { \ 19 | XR_LIST_ENUM_##enumType(ENUM_CASE_STR) \ 20 | default: return "Unknown " #enumType; \ 21 | } \ 22 | } 23 | 24 | // Returns a STL string. Unknown values are stringified as an integer. 25 | #define MAKE_TO_STRING_FUNC(enumType) \ 26 | inline std::string ToString(enumType e) { \ 27 | switch (e) { \ 28 | XR_LIST_ENUM_##enumType(ENUM_CASE_STR) \ 29 | default: return std::to_string(e); \ 30 | } \ 31 | } 32 | 33 | #define MAKE_TO_STRING_FUNCS(enumType) \ 34 | MAKE_TO_CSTRING_FUNC(enumType) \ 35 | MAKE_TO_STRING_FUNC(enumType) 36 | // clang-format on 37 | 38 | namespace xr { 39 | MAKE_TO_STRING_FUNCS(XrReferenceSpaceType); 40 | MAKE_TO_STRING_FUNCS(XrViewConfigurationType); 41 | MAKE_TO_STRING_FUNCS(XrEnvironmentBlendMode); 42 | MAKE_TO_STRING_FUNCS(XrSessionState); 43 | MAKE_TO_STRING_FUNCS(XrResult); 44 | MAKE_TO_STRING_FUNCS(XrStructureType); 45 | MAKE_TO_STRING_FUNCS(XrFormFactor); 46 | MAKE_TO_STRING_FUNCS(XrEyeVisibility); 47 | MAKE_TO_STRING_FUNCS(XrObjectType); 48 | MAKE_TO_STRING_FUNCS(XrActionType); 49 | MAKE_TO_STRING_FUNCS(XrHandEXT); 50 | MAKE_TO_STRING_FUNCS(XrHandPoseTypeMSFT); 51 | MAKE_TO_CSTRING_FUNC(XrHandJointEXT); 52 | MAKE_TO_STRING_FUNCS(XrVisibilityMaskTypeKHR); 53 | MAKE_TO_STRING_FUNCS(XrReprojectionModeMSFT); 54 | MAKE_TO_STRING_FUNCS(XrSceneComponentTypeMSFT); 55 | MAKE_TO_STRING_FUNCS(XrSceneComputeStateMSFT); 56 | MAKE_TO_STRING_FUNCS(XrSceneComputeFeatureMSFT); 57 | MAKE_TO_STRING_FUNCS(XrSpatialGraphNodeTypeMSFT); 58 | MAKE_TO_STRING_FUNCS(XrSceneComputeConsistencyMSFT); 59 | MAKE_TO_STRING_FUNCS(XrMeshComputeLodMSFT); 60 | } // namespace xr 61 | -------------------------------------------------------------------------------- /shared/XrUtility/XrUuid.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | inline bool operator==(const XrUuidMSFT& lh, const XrUuidMSFT& rh) noexcept { 10 | return memcmp(&rh, &lh, sizeof(XrUuidMSFT)) == 0; 11 | } 12 | 13 | inline bool operator!=(const XrUuidMSFT& lh, const XrUuidMSFT& rh) noexcept { 14 | return !(lh == rh); 15 | } 16 | 17 | inline bool operator<(const XrUuidMSFT& lh, const XrUuidMSFT& rh) noexcept { 18 | return memcmp(&lh, &rh, sizeof(XrUuidMSFT)) < 0; 19 | } 20 | 21 | namespace xr { 22 | // Type safe UUID for ensuring that two different types of UUIDs do not get mixed. 23 | // Example: 24 | // XrUuidMSFT uuid {}; 25 | // TypedUuid planeId(uuid); // allowed 26 | // TypedUuid meshId{planeId}; // compile error 27 | // meshId = planeId; // compile error 28 | // meshId = uuid; // allowed 29 | // uuid = meshId; // compiler error 30 | // uuid = static_cast(meshId); // allowed 31 | // if (meshId < meshId_2) {} // allowed 32 | // if (meshId != planeId) {} // compiler error 33 | // To access the uint8_t[16] array in TypedUuid, use 34 | // static_cast(meshId).bytes 35 | // 36 | template 37 | struct TypedUuid { 38 | TypedUuid() noexcept = default; 39 | explicit TypedUuid(const XrUuidMSFT& uuid) noexcept 40 | : m_uuid(uuid) { 41 | } 42 | 43 | TypedUuid& operator=(const XrUuidMSFT& uuid) noexcept { 44 | m_uuid = uuid; 45 | return *this; 46 | } 47 | 48 | explicit operator XrUuidMSFT() const noexcept { 49 | return m_uuid; 50 | } 51 | 52 | bool operator==(const TypedUuid& other) const noexcept { 53 | return m_uuid == other.m_uuid; 54 | } 55 | 56 | bool operator!=(const TypedUuid& other) const noexcept { 57 | return m_uuid != other.m_uuid; 58 | } 59 | 60 | bool operator<(const TypedUuid& other) const noexcept { 61 | return m_uuid < other.m_uuid; 62 | } 63 | 64 | private: 65 | XrUuidMSFT m_uuid; 66 | }; 67 | 68 | } // namespace xr 69 | 70 | namespace std { 71 | // This template specialization allows XrUuidMSFT to be used as the key in a std::unordered_map. 72 | template <> 73 | struct hash { 74 | std::size_t operator()(const XrUuidMSFT& uuid) const noexcept { 75 | static_assert(sizeof(XrUuidMSFT) == sizeof(uint64_t) * 2); 76 | const uint64_t* v = reinterpret_cast(uuid.bytes); 77 | return std::hash{}(v[0]) ^ (std::hash{}(v[1]) << 1); 78 | } 79 | }; 80 | 81 | // This template specialization allows TypedUuid to be used as the key in a std::unordered_map. 82 | template 83 | struct hash> { 84 | std::size_t operator()(const xr::TypedUuid& uuid) const noexcept { 85 | return std::hash{}(static_cast(uuid)); 86 | } 87 | }; 88 | } // namespace std 89 | -------------------------------------------------------------------------------- /shared/XrUtility/XrViewConfiguration.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | namespace xr { 7 | // The properties of a view configuration that's immutable for a system 8 | struct ViewProperties { 9 | XrViewConfigurationType Type; 10 | XrBool32 FovMutable; 11 | XrEnvironmentBlendMode BlendMode; 12 | std::vector SupportedBlendModes; 13 | }; 14 | 15 | // The state of a view configuration that's changing during a session but immutable for a frame 16 | struct ViewConfigurationState { 17 | XrViewConfigurationType Type; 18 | std::vector ViewConfigViews; 19 | std::vector Views; 20 | bool Active; 21 | }; 22 | 23 | constexpr bool IsPrimaryViewConfigurationType(XrViewConfigurationType type) { 24 | return type == XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO || type == XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO || 25 | type == XR_VIEW_CONFIGURATION_TYPE_PRIMARY_QUAD_VARJO; 26 | } 27 | 28 | inline ViewProperties CreateViewProperties(XrInstance instance, 29 | XrSystemId systemId, 30 | XrViewConfigurationType viewConfigurationType, 31 | const std::vector& appSupportedEnvironmentBlendModes) { 32 | XrViewConfigurationProperties viewConfigProperties{XR_TYPE_VIEW_CONFIGURATION_PROPERTIES}; 33 | CHECK_XRCMD(xrGetViewConfigurationProperties(instance, systemId, viewConfigurationType, &viewConfigProperties)); 34 | 35 | ViewProperties properties{}; 36 | properties.Type = viewConfigurationType; 37 | properties.FovMutable = viewConfigProperties.fovMutable; 38 | properties.SupportedBlendModes = xr::EnumerateEnvironmentBlendModes(instance, systemId, viewConfigurationType); 39 | properties.BlendMode = xr::PickEnvironmentBlendMode(properties.SupportedBlendModes, appSupportedEnvironmentBlendModes); 40 | 41 | return properties; 42 | } 43 | 44 | inline ViewConfigurationState CreateViewConfigurationState(XrViewConfigurationType viewConfigurationType, 45 | XrInstance instance, 46 | XrSystemId systemId) { 47 | ViewConfigurationState state{}; 48 | state.Type = viewConfigurationType; 49 | state.ViewConfigViews = xr::EnumerateViewConfigurationViews(instance, systemId, viewConfigurationType); 50 | state.Views.resize(state.ViewConfigViews.size(), {XR_TYPE_VIEW}); 51 | 52 | return state; 53 | } 54 | 55 | inline bool IsRecommendedSwapchainSizeChanged(const std::vector& oldConfigs, 56 | const std::vector& newConfigs) { 57 | assert(oldConfigs.size() == newConfigs.size()); 58 | size_t end = (std::min)(oldConfigs.size(), newConfigs.size()); 59 | for (size_t i = 0; i < end; i++) { 60 | if ((oldConfigs[i].recommendedImageRectWidth != newConfigs[i].recommendedImageRectWidth) || 61 | (oldConfigs[i].recommendedImageRectHeight != newConfigs[i].recommendedImageRectHeight)) { 62 | return true; 63 | } 64 | } 65 | return false; 66 | } 67 | } // namespace xr 68 | -------------------------------------------------------------------------------- /shared/ext/DirectXMath/.gitignore: -------------------------------------------------------------------------------- 1 | *.psess 2 | *.vsp 3 | *.log 4 | *.err 5 | *.wrn 6 | *.suo 7 | *.sdf 8 | *.user 9 | *.i 10 | *.vspscc 11 | *.opensdf 12 | *.opendb 13 | *.ipch 14 | *.cache 15 | *.tlog 16 | *.lastbuildstate 17 | *.ilk 18 | *.VC.db 19 | *.nupkg 20 | .vs 21 | /Tests 22 | /wiki -------------------------------------------------------------------------------- /shared/ext/DirectXMath/.nuget/directxmath.nuspec: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | directxmath 5 | 0.0.0-SpecifyVersionOnCommandline 6 | DirectXMath 7 | Microsoft 8 | microsoft,directxtk 9 | DirectXMath is an all inline SIMD C++ linear algebra library for use in games and graphics apps. 10 | The DirectXMath API provides SIMD-friendly C++ types and functions for common linear algebra and graphics math operations common to DirectX applications. The library provides optimized versions for Windows 32-bit (x86), Windows 64-bit (x64), and Windows on ARM through SSE2 and ARM-NEON intrinsics support in the Visual Studio compiler. 11 | Matches the August 2019 release. 12 | http://go.microsoft.com/fwlink/?LinkID=615560 13 | https://github.com/Microsoft/DirectXMath/wiki/X_jpg.jpg 14 | MIT 15 | false 16 | © Microsoft Corporation. All rights reserved. 17 | C++ native DirectX math nativepackage 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /shared/ext/DirectXMath/.nuget/directxmath.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | HAS_DIRECTXMATH;%(PreprocessorDefinitions) 7 | $(MSBuildThisFileDirectory)..\..\include;%(AdditionalIncludeDirectories) 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /shared/ext/DirectXMath/.nuget/signconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /shared/ext/DirectXMath/Extensions/DirectXMathBE.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------------- 2 | // DirectXMathBE.h -- Big-endian swap extensions for SIMD C++ Math library 3 | // 4 | // Copyright (c) Microsoft Corporation. All rights reserved. 5 | // Licensed under the MIT License. 6 | // 7 | // http://go.microsoft.com/fwlink/?LinkID=615560 8 | //------------------------------------------------------------------------------------- 9 | 10 | #pragma once 11 | 12 | #if (defined(_M_IX86) || defined(_M_X64) || __i386__ || __x86_64__) && !defined(_M_HYBRID_X86_ARM64) 13 | #include 14 | #endif 15 | 16 | #include 17 | 18 | namespace DirectX 19 | { 20 | 21 | inline XMVECTOR XM_CALLCONV XMVectorEndian 22 | ( 23 | FXMVECTOR V 24 | ) 25 | { 26 | #if defined(_XM_ARM_NEON_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) 27 | static const XMVECTORU32 idx = { { { 0x00010203u, 0x04050607u, 0x08090A0Bu, 0x0C0D0E0Fu } } }; 28 | 29 | uint8x8x2_t tbl; 30 | tbl.val[0] = vreinterpret_u8_f32(vget_low_f32(V)); 31 | tbl.val[1] = vreinterpret_u8_f32(vget_high_f32(V)); 32 | 33 | const uint8x8_t rL = vtbl2_u8(tbl, vget_low_u32(idx)); 34 | const uint8x8_t rH = vtbl2_u8(tbl, vget_high_u32(idx)); 35 | return vcombine_f32(vreinterpret_f32_u8(rL), vreinterpret_f32_u8(rH)); 36 | #else 37 | XMVECTORU32 E; 38 | E.v = V; 39 | uint32_t value = E.u[0]; 40 | E.u[0] = ( (value << 24) | ((value & 0xFF00) << 8) | ((value & 0xFF0000) >> 8) | (value >> 24) ); 41 | value = E.u[1]; 42 | E.u[1] = ( (value << 24) | ((value & 0xFF00) << 8) | ((value & 0xFF0000) >> 8) | (value >> 24) ); 43 | value = E.u[2]; 44 | E.u[2] = ( (value << 24) | ((value & 0xFF00) << 8) | ((value & 0xFF0000) >> 8) | (value >> 24) ); 45 | value = E.u[3]; 46 | E.u[3] = ( (value << 24) | ((value & 0xFF00) << 8) | ((value & 0xFF0000) >> 8) | (value >> 24) ); 47 | return E.v; 48 | #endif 49 | } 50 | 51 | 52 | #if (defined(_M_IX86) || defined(_M_X64) || __i386__ || __x86_64__) && !defined(_M_HYBRID_X86_ARM64) 53 | namespace SSSE3 54 | { 55 | 56 | inline bool XMVerifySSSE3Support() 57 | { 58 | // Should return true on AMD Bulldozer, Intel Core i7/i5/i3, Intel Atom, or later processors 59 | 60 | // See http://msdn.microsoft.com/en-us/library/hskdteyh.aspx 61 | int CPUInfo[4] = { -1 }; 62 | #if defined(__clang__) || defined(__GNUC__) 63 | __cpuid(0, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]); 64 | #else 65 | __cpuid(CPUInfo, 0); 66 | #endif 67 | 68 | if ( CPUInfo[0] < 1 ) 69 | return false; 70 | 71 | #if defined(__clang__) || defined(__GNUC__) 72 | __cpuid(1, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]); 73 | #else 74 | __cpuid(CPUInfo, 1); 75 | #endif 76 | 77 | // Check for SSSE3 instruction set. 78 | return ( (CPUInfo[2] & 0x200) != 0 ); 79 | } 80 | 81 | inline XMVECTOR XM_CALLCONV XMVectorEndian 82 | ( 83 | FXMVECTOR V 84 | ) 85 | { 86 | static const XMVECTORU32 idx = { { { 0x00010203u, 0x04050607u, 0x08090A0Bu, 0x0C0D0E0Fu } } }; 87 | 88 | __m128i Result = _mm_shuffle_epi8( _mm_castps_si128(V), idx ); 89 | return _mm_castsi128_ps( Result ); 90 | } 91 | 92 | } // namespace SSSE3 93 | #endif // X86 || X64 94 | 95 | } // namespace DirectX 96 | -------------------------------------------------------------------------------- /shared/ext/DirectXMath/Extensions/DirectXMathSSE3.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------------- 2 | // DirectXMathSSE3.h -- SSE3 extensions for SIMD C++ Math library 3 | // 4 | // Copyright (c) Microsoft Corporation. All rights reserved. 5 | // Licensed under the MIT License. 6 | // 7 | // http://go.microsoft.com/fwlink/?LinkID=615560 8 | //------------------------------------------------------------------------------------- 9 | 10 | #pragma once 11 | 12 | #if defined(_M_ARM) || defined(_M_ARM64) || defined(_M_HYBRID_X86_ARM64) || __arm__ || __aarch64__ 13 | #error SSE3 not supported on ARM platform 14 | #endif 15 | 16 | #include 17 | 18 | #include 19 | 20 | namespace DirectX 21 | { 22 | 23 | namespace SSE3 24 | { 25 | 26 | inline bool XMVerifySSE3Support() 27 | { 28 | // Should return true on AMD Athlon 64, AMD Phenom, and Intel Pentium 4 or later processors 29 | 30 | // See http://msdn.microsoft.com/en-us/library/hskdteyh.aspx 31 | int CPUInfo[4] = { -1 }; 32 | #if defined(__clang__) || defined(__GNUC__) 33 | __cpuid(0, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]); 34 | #else 35 | __cpuid(CPUInfo, 0); 36 | #endif 37 | if ( CPUInfo[0] < 1 ) 38 | return false; 39 | 40 | #if defined(__clang__) || defined(__GNUC__) 41 | __cpuid(1, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]); 42 | #else 43 | __cpuid(CPUInfo, 1); 44 | #endif 45 | 46 | // We only check for SSE3 instruction set. SSSE3 instructions are not used. 47 | return ( (CPUInfo[2] & 0x1) != 0 ); 48 | } 49 | 50 | inline XMVECTOR XM_CALLCONV XMVector2Dot 51 | ( 52 | FXMVECTOR V1, 53 | FXMVECTOR V2 54 | ) 55 | { 56 | XMVECTOR vTemp = _mm_mul_ps(V1,V2); 57 | vTemp = _mm_hadd_ps(vTemp,vTemp); 58 | return _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(0,0,0,0)); 59 | } 60 | 61 | inline XMVECTOR XM_CALLCONV XMVector2LengthSq( FXMVECTOR V ) 62 | { 63 | return SSE3::XMVector2Dot(V, V); 64 | } 65 | 66 | inline XMVECTOR XM_CALLCONV XMVector3Dot 67 | ( 68 | FXMVECTOR V1, 69 | FXMVECTOR V2 70 | ) 71 | { 72 | XMVECTOR vTemp = _mm_mul_ps(V1,V2); 73 | vTemp = _mm_and_ps( vTemp, g_XMMask3 ); 74 | vTemp = _mm_hadd_ps(vTemp,vTemp); 75 | return _mm_hadd_ps(vTemp,vTemp); 76 | } 77 | 78 | inline XMVECTOR XM_CALLCONV XMVector3LengthSq( FXMVECTOR V ) 79 | { 80 | return SSE3::XMVector3Dot(V, V); 81 | } 82 | 83 | inline XMVECTOR XM_CALLCONV XMVector4Dot 84 | ( 85 | FXMVECTOR V1, 86 | FXMVECTOR V2 87 | ) 88 | { 89 | XMVECTOR vTemp = _mm_mul_ps(V1,V2); 90 | vTemp = _mm_hadd_ps( vTemp, vTemp ); 91 | return _mm_hadd_ps( vTemp, vTemp ); 92 | } 93 | 94 | inline XMVECTOR XM_CALLCONV XMVector4LengthSq( FXMVECTOR V ) 95 | { 96 | return SSE3::XMVector4Dot(V, V); 97 | } 98 | 99 | inline XMVECTOR XM_CALLCONV XMVectorSwizzle_0022( FXMVECTOR V ) 100 | { 101 | return _mm_moveldup_ps(V); 102 | } 103 | 104 | inline XMVECTOR XM_CALLCONV XMVectorSwizzle_1133( FXMVECTOR V ) 105 | { 106 | return _mm_movehdup_ps(V); 107 | } 108 | 109 | } // namespace SSE3 110 | 111 | } // namespace DirectX 112 | -------------------------------------------------------------------------------- /shared/ext/DirectXMath/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2011-2020 Microsoft Corp 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this 6 | software and associated documentation files (the "Software"), to deal in the Software 7 | without restriction, including without limitation the rights to use, copy, modify, 8 | merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all copies 13 | or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 17 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 18 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 19 | CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 20 | OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | -------------------------------------------------------------------------------- /shared/ext/DirectXMath/README.md: -------------------------------------------------------------------------------- 1 | ![DirectX Logo](https://github.com/Microsoft/DirectXMath/wiki/X_jpg.jpg) 2 | 3 | # DirectXMath 4 | 5 | https://github.com/Microsoft/DirectXMath 6 | 7 | Copyright (c) Microsoft Corporation. All rights reserved. 8 | 9 | **August 2019** 10 | 11 | This package contains the DirectXMath library, an all inline SIMD C++ linear algebra library for use in games and graphics apps 12 | 13 | This code is designed to build with Visual Studio 2017, Visual Studio 2019, or clang for Windows. It is recommended that you make use of the latest updates (VS 2017 15.9 update, or VS 2019 Update 4 or later). 14 | 15 | These components are designed to work without requiring any content from the legacy DirectX SDK. For details, see [Where is the DirectX SDK?](https://aka.ms/dxsdk). 16 | 17 | ## Directory Layout 18 | 19 | * ``Inc\`` 20 | 21 | + DirectXMath Files (in the DirectX C++ namespace) 22 | 23 | * DirectXMath.h - Core library 24 | * DirectXPackedVector.h - Load/Store functions and types for working with various compressed GPU formats 25 | * DirectXColors.h - .NET-style Color defines in sRGB color space 26 | * DirectXCollision.h - Bounding volume collision library 27 | 28 | * ``Extentions\`` 29 | 30 | + Advanced instruction set variants for guarded codepaths 31 | 32 | * DirectXMathSSE3.h - SSE3 33 | * DirectXMathBE.h - Supplemental SSE3 (SSSE3) 34 | * DirectXMathSSE4.h - SSE4.1 35 | * DirectXMathAVX.h - Advanced Vector Extensions (AVX) 36 | * DirectXMathAVX2.h - Advanced Vector Extensions 2 (AVX2) 37 | * DirectXMathF16C.h - Half-precision conversions (F16C) 38 | * DirectXMathFMA3.h - Fused multiply-accumulate (FMA3) 39 | * DirectXMathFMA4.h - Fused multiply-accumulate (FMA4) 40 | 41 | * ``SHMath\`` 42 | 43 | + Spherical Harmonics math functions 44 | 45 | * DirectXSH.h - Header for SHMath functions 46 | * DirectXSH.cpp, DirectXSHD3D11.cpp, DirectXSHD3D12.cpp - Implementation 47 | 48 | * ``XDSP\`` 49 | 50 | + XDSP.h - Digital Signal Processing helper functions 51 | 52 | ## Documentation 53 | 54 | Documentation is available on the [Microsoft Docs](https://docs.microsoft.com/en-us/windows/desktop/dxmath/directxmath-portal). Additional information can be found on the [project wiki](https://github.com/microsoft/DirectXMath/wiki). 55 | 56 | ## Compiler support 57 | 58 | Officially the library is supported with Microsoft Visual C++ and clang/LLVM. It should also compile with the Intel C++ compiler, GCC, and MinGW compilers. 59 | 60 | To build for non-Windows platforms, you need to provide a ``sal.h`` header in your include path. You can obtain an open source version from [GitHub](https://github.com/dotnet/corert/blob/master/src/Native/inc/unix/sal.h). 61 | 62 | ## Notices 63 | 64 | All content and source code for this package are subject to the terms of the [MIT License](http://opensource.org/licenses/MIT). 65 | 66 | For the latest version of DirectXMath, bug reports, etc. please visit the project site on [GitHub](https://github.com/microsoft/DirectXMath). 67 | 68 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 69 | -------------------------------------------------------------------------------- /shared/ext/DirectXMath/Stereo3D/Stereo3DMatrixHelper.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------------- 2 | // Stereo3DMatrixHelper.h -- SIMD C++ Math helper for Stereo 3D matrices 3 | // 4 | // Copyright (c) Microsoft Corporation. All rights reserved. 5 | // Licensed under the MIT License. 6 | //------------------------------------------------------------------------------------- 7 | 8 | #pragma once 9 | 10 | #include "DirectXMath.h" 11 | 12 | namespace DirectX 13 | { 14 | // Enumeration for stereo channels (left and right). 15 | enum STEREO_CHANNEL 16 | { 17 | STEREO_CHANNEL_LEFT = 0, 18 | STEREO_CHANNEL_RIGHT 19 | }; 20 | 21 | // Enumeration for stereo mode (normal or inverted). 22 | enum STEREO_MODE 23 | { 24 | STEREO_MODE_NORMAL = 0, 25 | STEREO_MODE_INVERTED, 26 | }; 27 | 28 | //------------------------------------------------------------------------------ 29 | // 30 | // Stereo calibration settings 31 | // 32 | // * Viewer distance to the display 33 | // * Physical display size 34 | // * Render resolution 35 | // 36 | // The stereo separation factor indicates how much separation is between the left and right 37 | // eyes. 0 is no separation, 1 is full separation. It defaults to 1.0. 38 | // 39 | // The debug stereo exaggeration factor indicates how much to increase the interocular spacing and 40 | // maximum acuity angle from comfortable defaults. For retail builds, this value should always 41 | // be 1.0, but during development, on small screens, this value can be raised to up to 2.0 in 42 | // order to exaggerate the 3D effect. Values over 1.0 may cause discomfort on normal sized 43 | // displays. It defaults to 1.0. 44 | // 45 | struct STEREO_PARAMETERS 46 | { 47 | float fViewerDistanceInches; 48 | float fDisplaySizeInches; 49 | float fPixelResolutionWidth; 50 | float fPixelResolutionHeight; 51 | float fStereoSeparationFactor; 52 | float fStereoExaggerationFactor; 53 | }; 54 | 55 | void StereoCreateDefaultParameters(STEREO_PARAMETERS& stereoParameters); 56 | 57 | XMMATRIX StereoProjectionFovLH(_In_opt_ const STEREO_PARAMETERS* pStereoParameters, 58 | STEREO_CHANNEL Channel, float FovAngleY, float AspectRatio, float NearZ, float FarZ, 59 | STEREO_MODE StereoMode = STEREO_MODE_NORMAL); 60 | 61 | XMMATRIX StereoProjectionFovRH(_In_opt_ const STEREO_PARAMETERS* pStereoParameters, 62 | STEREO_CHANNEL Channel, float FovAngleY, float AspectRatio, float NearZ, float FarZ, 63 | STEREO_MODE StereoMode = STEREO_MODE_NORMAL); 64 | } -------------------------------------------------------------------------------- /shared/ext/fmt/locale.h: -------------------------------------------------------------------------------- 1 | #include "xchar.h" 2 | #ifdef _WIN32 3 | #pragma message ("fmt/locale.h is deprecated, include fmt/format.h or fmt/xchar.h instead") 4 | #else 5 | #warning fmt/locale.h is deprecated, include fmt/format.h or fmt/xchar.h instead 6 | #endif 7 | -------------------------------------------------------------------------------- /shared/ext/rapidjson/cursorstreamwrapper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_CURSORSTREAMWRAPPER_H_ 16 | #define RAPIDJSON_CURSORSTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | 20 | #if defined(__GNUC__) 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(effc++) 23 | #endif 24 | 25 | #if defined(_MSC_VER) && _MSC_VER <= 1800 26 | RAPIDJSON_DIAG_PUSH 27 | RAPIDJSON_DIAG_OFF(4702) // unreachable code 28 | RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated 29 | #endif 30 | 31 | RAPIDJSON_NAMESPACE_BEGIN 32 | 33 | 34 | //! Cursor stream wrapper for counting line and column number if error exists. 35 | /*! 36 | \tparam InputStream Any stream that implements Stream Concept 37 | */ 38 | template > 39 | class CursorStreamWrapper : public GenericStreamWrapper { 40 | public: 41 | typedef typename Encoding::Ch Ch; 42 | 43 | CursorStreamWrapper(InputStream& is): 44 | GenericStreamWrapper(is), line_(1), col_(0) {} 45 | 46 | // counting line and column number 47 | Ch Take() { 48 | Ch ch = this->is_.Take(); 49 | if(ch == '\n') { 50 | line_ ++; 51 | col_ = 0; 52 | } else { 53 | col_ ++; 54 | } 55 | return ch; 56 | } 57 | 58 | //! Get the error line number, if error exists. 59 | size_t GetLine() const { return line_; } 60 | //! Get the error column number, if error exists. 61 | size_t GetColumn() const { return col_; } 62 | 63 | private: 64 | size_t line_; //!< Current Line 65 | size_t col_; //!< Current Column 66 | }; 67 | 68 | #if defined(_MSC_VER) && _MSC_VER <= 1800 69 | RAPIDJSON_DIAG_POP 70 | #endif 71 | 72 | #if defined(__GNUC__) 73 | RAPIDJSON_DIAG_POP 74 | #endif 75 | 76 | RAPIDJSON_NAMESPACE_END 77 | 78 | #endif // RAPIDJSON_CURSORSTREAMWRAPPER_H_ 79 | -------------------------------------------------------------------------------- /shared/ext/rapidjson/filereadstream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_FILEREADSTREAM_H_ 16 | #define RAPIDJSON_FILEREADSTREAM_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(padded) 24 | RAPIDJSON_DIAG_OFF(unreachable-code) 25 | RAPIDJSON_DIAG_OFF(missing-noreturn) 26 | #endif 27 | 28 | RAPIDJSON_NAMESPACE_BEGIN 29 | 30 | //! File byte stream for input using fread(). 31 | /*! 32 | \note implements Stream concept 33 | */ 34 | class FileReadStream { 35 | public: 36 | typedef char Ch; //!< Character type (byte). 37 | 38 | //! Constructor. 39 | /*! 40 | \param fp File pointer opened for read. 41 | \param buffer user-supplied buffer. 42 | \param bufferSize size of buffer in bytes. Must >=4 bytes. 43 | */ 44 | FileReadStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) { 45 | RAPIDJSON_ASSERT(fp_ != 0); 46 | RAPIDJSON_ASSERT(bufferSize >= 4); 47 | Read(); 48 | } 49 | 50 | Ch Peek() const { return *current_; } 51 | Ch Take() { Ch c = *current_; Read(); return c; } 52 | size_t Tell() const { return count_ + static_cast(current_ - buffer_); } 53 | 54 | // Not implemented 55 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 56 | void Flush() { RAPIDJSON_ASSERT(false); } 57 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 58 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 59 | 60 | // For encoding detection only. 61 | const Ch* Peek4() const { 62 | return (current_ + 4 - !eof_ <= bufferLast_) ? current_ : 0; 63 | } 64 | 65 | private: 66 | void Read() { 67 | if (current_ < bufferLast_) 68 | ++current_; 69 | else if (!eof_) { 70 | count_ += readCount_; 71 | readCount_ = std::fread(buffer_, 1, bufferSize_, fp_); 72 | bufferLast_ = buffer_ + readCount_ - 1; 73 | current_ = buffer_; 74 | 75 | if (readCount_ < bufferSize_) { 76 | buffer_[readCount_] = '\0'; 77 | ++bufferLast_; 78 | eof_ = true; 79 | } 80 | } 81 | } 82 | 83 | std::FILE* fp_; 84 | Ch *buffer_; 85 | size_t bufferSize_; 86 | Ch *bufferLast_; 87 | Ch *current_; 88 | size_t readCount_; 89 | size_t count_; //!< Number of characters read 90 | bool eof_; 91 | }; 92 | 93 | RAPIDJSON_NAMESPACE_END 94 | 95 | #ifdef __clang__ 96 | RAPIDJSON_DIAG_POP 97 | #endif 98 | 99 | #endif // RAPIDJSON_FILESTREAM_H_ 100 | -------------------------------------------------------------------------------- /shared/ext/rapidjson/filewritestream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_FILEWRITESTREAM_H_ 16 | #define RAPIDJSON_FILEWRITESTREAM_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(unreachable-code) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Wrapper of C file stream for output using fwrite(). 29 | /*! 30 | \note implements Stream concept 31 | */ 32 | class FileWriteStream { 33 | public: 34 | typedef char Ch; //!< Character type. Only support char. 35 | 36 | FileWriteStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferEnd_(buffer + bufferSize), current_(buffer_) { 37 | RAPIDJSON_ASSERT(fp_ != 0); 38 | } 39 | 40 | void Put(char c) { 41 | if (current_ >= bufferEnd_) 42 | Flush(); 43 | 44 | *current_++ = c; 45 | } 46 | 47 | void PutN(char c, size_t n) { 48 | size_t avail = static_cast(bufferEnd_ - current_); 49 | while (n > avail) { 50 | std::memset(current_, c, avail); 51 | current_ += avail; 52 | Flush(); 53 | n -= avail; 54 | avail = static_cast(bufferEnd_ - current_); 55 | } 56 | 57 | if (n > 0) { 58 | std::memset(current_, c, n); 59 | current_ += n; 60 | } 61 | } 62 | 63 | void Flush() { 64 | if (current_ != buffer_) { 65 | size_t result = std::fwrite(buffer_, 1, static_cast(current_ - buffer_), fp_); 66 | if (result < static_cast(current_ - buffer_)) { 67 | // failure deliberately ignored at this time 68 | // added to avoid warn_unused_result build errors 69 | } 70 | current_ = buffer_; 71 | } 72 | } 73 | 74 | // Not implemented 75 | char Peek() const { RAPIDJSON_ASSERT(false); return 0; } 76 | char Take() { RAPIDJSON_ASSERT(false); return 0; } 77 | size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } 78 | char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 79 | size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } 80 | 81 | private: 82 | // Prohibit copy constructor & assignment operator. 83 | FileWriteStream(const FileWriteStream&); 84 | FileWriteStream& operator=(const FileWriteStream&); 85 | 86 | std::FILE* fp_; 87 | char *buffer_; 88 | char *bufferEnd_; 89 | char *current_; 90 | }; 91 | 92 | //! Implement specialized version of PutN() with memset() for better performance. 93 | template<> 94 | inline void PutN(FileWriteStream& stream, char c, size_t n) { 95 | stream.PutN(c, n); 96 | } 97 | 98 | RAPIDJSON_NAMESPACE_END 99 | 100 | #ifdef __clang__ 101 | RAPIDJSON_DIAG_POP 102 | #endif 103 | 104 | #endif // RAPIDJSON_FILESTREAM_H_ 105 | -------------------------------------------------------------------------------- /shared/ext/rapidjson/internal/clzll.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_CLZLL_H_ 16 | #define RAPIDJSON_CLZLL_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(_MSC_VER) 21 | #include 22 | #if defined(_WIN64) 23 | #pragma intrinsic(_BitScanReverse64) 24 | #else 25 | #pragma intrinsic(_BitScanReverse) 26 | #endif 27 | #endif 28 | 29 | RAPIDJSON_NAMESPACE_BEGIN 30 | namespace internal { 31 | 32 | #if (defined(__GNUC__) && __GNUC__ >= 4) || RAPIDJSON_HAS_BUILTIN(__builtin_clzll) 33 | #define RAPIDJSON_CLZLL __builtin_clzll 34 | #else 35 | 36 | inline uint32_t clzll(uint64_t x) { 37 | // Passing 0 to __builtin_clzll is UB in GCC and results in an 38 | // infinite loop in the software implementation. 39 | RAPIDJSON_ASSERT(x != 0); 40 | 41 | #if defined(_MSC_VER) 42 | unsigned long r = 0; 43 | #if defined(_WIN64) 44 | _BitScanReverse64(&r, x); 45 | #else 46 | // Scan the high 32 bits. 47 | if (_BitScanReverse(&r, static_cast(x >> 32))) 48 | return 63 - (r + 32); 49 | 50 | // Scan the low 32 bits. 51 | _BitScanReverse(&r, static_cast(x & 0xFFFFFFFF)); 52 | #endif // _WIN64 53 | 54 | return 63 - r; 55 | #else 56 | uint32_t r; 57 | while (!(x & (static_cast(1) << 63))) { 58 | x <<= 1; 59 | ++r; 60 | } 61 | 62 | return r; 63 | #endif // _MSC_VER 64 | } 65 | 66 | #define RAPIDJSON_CLZLL RAPIDJSON_NAMESPACE::internal::clzll 67 | #endif // (defined(__GNUC__) && __GNUC__ >= 4) || RAPIDJSON_HAS_BUILTIN(__builtin_clzll) 68 | 69 | } // namespace internal 70 | RAPIDJSON_NAMESPACE_END 71 | 72 | #endif // RAPIDJSON_CLZLL_H_ -------------------------------------------------------------------------------- /shared/ext/rapidjson/internal/ieee754.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_IEEE754_ 16 | #define RAPIDJSON_IEEE754_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | class Double { 24 | public: 25 | Double() {} 26 | Double(double d) : d_(d) {} 27 | Double(uint64_t u) : u_(u) {} 28 | 29 | double Value() const { return d_; } 30 | uint64_t Uint64Value() const { return u_; } 31 | 32 | double NextPositiveDouble() const { 33 | RAPIDJSON_ASSERT(!Sign()); 34 | return Double(u_ + 1).Value(); 35 | } 36 | 37 | bool Sign() const { return (u_ & kSignMask) != 0; } 38 | uint64_t Significand() const { return u_ & kSignificandMask; } 39 | int Exponent() const { return static_cast(((u_ & kExponentMask) >> kSignificandSize) - kExponentBias); } 40 | 41 | bool IsNan() const { return (u_ & kExponentMask) == kExponentMask && Significand() != 0; } 42 | bool IsInf() const { return (u_ & kExponentMask) == kExponentMask && Significand() == 0; } 43 | bool IsNanOrInf() const { return (u_ & kExponentMask) == kExponentMask; } 44 | bool IsNormal() const { return (u_ & kExponentMask) != 0 || Significand() == 0; } 45 | bool IsZero() const { return (u_ & (kExponentMask | kSignificandMask)) == 0; } 46 | 47 | uint64_t IntegerSignificand() const { return IsNormal() ? Significand() | kHiddenBit : Significand(); } 48 | int IntegerExponent() const { return (IsNormal() ? Exponent() : kDenormalExponent) - kSignificandSize; } 49 | uint64_t ToBias() const { return (u_ & kSignMask) ? ~u_ + 1 : u_ | kSignMask; } 50 | 51 | static int EffectiveSignificandSize(int order) { 52 | if (order >= -1021) 53 | return 53; 54 | else if (order <= -1074) 55 | return 0; 56 | else 57 | return order + 1074; 58 | } 59 | 60 | private: 61 | static const int kSignificandSize = 52; 62 | static const int kExponentBias = 0x3FF; 63 | static const int kDenormalExponent = 1 - kExponentBias; 64 | static const uint64_t kSignMask = RAPIDJSON_UINT64_C2(0x80000000, 0x00000000); 65 | static const uint64_t kExponentMask = RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000); 66 | static const uint64_t kSignificandMask = RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF); 67 | static const uint64_t kHiddenBit = RAPIDJSON_UINT64_C2(0x00100000, 0x00000000); 68 | 69 | union { 70 | double d_; 71 | uint64_t u_; 72 | }; 73 | }; 74 | 75 | } // namespace internal 76 | RAPIDJSON_NAMESPACE_END 77 | 78 | #endif // RAPIDJSON_IEEE754_ 79 | -------------------------------------------------------------------------------- /shared/ext/rapidjson/internal/pow10.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_POW10_ 16 | #define RAPIDJSON_POW10_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | //! Computes integer powers of 10 in double (10.0^n). 24 | /*! This function uses lookup table for fast and accurate results. 25 | \param n non-negative exponent. Must <= 308. 26 | \return 10.0^n 27 | */ 28 | inline double Pow10(int n) { 29 | static const double e[] = { // 1e-0...1e308: 309 * 8 bytes = 2472 bytes 30 | 1e+0, 31 | 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, 1e+8, 1e+9, 1e+10, 1e+11, 1e+12, 1e+13, 1e+14, 1e+15, 1e+16, 1e+17, 1e+18, 1e+19, 1e+20, 32 | 1e+21, 1e+22, 1e+23, 1e+24, 1e+25, 1e+26, 1e+27, 1e+28, 1e+29, 1e+30, 1e+31, 1e+32, 1e+33, 1e+34, 1e+35, 1e+36, 1e+37, 1e+38, 1e+39, 1e+40, 33 | 1e+41, 1e+42, 1e+43, 1e+44, 1e+45, 1e+46, 1e+47, 1e+48, 1e+49, 1e+50, 1e+51, 1e+52, 1e+53, 1e+54, 1e+55, 1e+56, 1e+57, 1e+58, 1e+59, 1e+60, 34 | 1e+61, 1e+62, 1e+63, 1e+64, 1e+65, 1e+66, 1e+67, 1e+68, 1e+69, 1e+70, 1e+71, 1e+72, 1e+73, 1e+74, 1e+75, 1e+76, 1e+77, 1e+78, 1e+79, 1e+80, 35 | 1e+81, 1e+82, 1e+83, 1e+84, 1e+85, 1e+86, 1e+87, 1e+88, 1e+89, 1e+90, 1e+91, 1e+92, 1e+93, 1e+94, 1e+95, 1e+96, 1e+97, 1e+98, 1e+99, 1e+100, 36 | 1e+101,1e+102,1e+103,1e+104,1e+105,1e+106,1e+107,1e+108,1e+109,1e+110,1e+111,1e+112,1e+113,1e+114,1e+115,1e+116,1e+117,1e+118,1e+119,1e+120, 37 | 1e+121,1e+122,1e+123,1e+124,1e+125,1e+126,1e+127,1e+128,1e+129,1e+130,1e+131,1e+132,1e+133,1e+134,1e+135,1e+136,1e+137,1e+138,1e+139,1e+140, 38 | 1e+141,1e+142,1e+143,1e+144,1e+145,1e+146,1e+147,1e+148,1e+149,1e+150,1e+151,1e+152,1e+153,1e+154,1e+155,1e+156,1e+157,1e+158,1e+159,1e+160, 39 | 1e+161,1e+162,1e+163,1e+164,1e+165,1e+166,1e+167,1e+168,1e+169,1e+170,1e+171,1e+172,1e+173,1e+174,1e+175,1e+176,1e+177,1e+178,1e+179,1e+180, 40 | 1e+181,1e+182,1e+183,1e+184,1e+185,1e+186,1e+187,1e+188,1e+189,1e+190,1e+191,1e+192,1e+193,1e+194,1e+195,1e+196,1e+197,1e+198,1e+199,1e+200, 41 | 1e+201,1e+202,1e+203,1e+204,1e+205,1e+206,1e+207,1e+208,1e+209,1e+210,1e+211,1e+212,1e+213,1e+214,1e+215,1e+216,1e+217,1e+218,1e+219,1e+220, 42 | 1e+221,1e+222,1e+223,1e+224,1e+225,1e+226,1e+227,1e+228,1e+229,1e+230,1e+231,1e+232,1e+233,1e+234,1e+235,1e+236,1e+237,1e+238,1e+239,1e+240, 43 | 1e+241,1e+242,1e+243,1e+244,1e+245,1e+246,1e+247,1e+248,1e+249,1e+250,1e+251,1e+252,1e+253,1e+254,1e+255,1e+256,1e+257,1e+258,1e+259,1e+260, 44 | 1e+261,1e+262,1e+263,1e+264,1e+265,1e+266,1e+267,1e+268,1e+269,1e+270,1e+271,1e+272,1e+273,1e+274,1e+275,1e+276,1e+277,1e+278,1e+279,1e+280, 45 | 1e+281,1e+282,1e+283,1e+284,1e+285,1e+286,1e+287,1e+288,1e+289,1e+290,1e+291,1e+292,1e+293,1e+294,1e+295,1e+296,1e+297,1e+298,1e+299,1e+300, 46 | 1e+301,1e+302,1e+303,1e+304,1e+305,1e+306,1e+307,1e+308 47 | }; 48 | RAPIDJSON_ASSERT(n >= 0 && n <= 308); 49 | return e[n]; 50 | } 51 | 52 | } // namespace internal 53 | RAPIDJSON_NAMESPACE_END 54 | 55 | #endif // RAPIDJSON_POW10_ 56 | -------------------------------------------------------------------------------- /shared/ext/rapidjson/internal/strfunc.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_ 16 | #define RAPIDJSON_INTERNAL_STRFUNC_H_ 17 | 18 | #include "../stream.h" 19 | #include 20 | 21 | RAPIDJSON_NAMESPACE_BEGIN 22 | namespace internal { 23 | 24 | //! Custom strlen() which works on different character types. 25 | /*! \tparam Ch Character type (e.g. char, wchar_t, short) 26 | \param s Null-terminated input string. 27 | \return Number of characters in the string. 28 | \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints. 29 | */ 30 | template 31 | inline SizeType StrLen(const Ch* s) { 32 | RAPIDJSON_ASSERT(s != 0); 33 | const Ch* p = s; 34 | while (*p) ++p; 35 | return SizeType(p - s); 36 | } 37 | 38 | template <> 39 | inline SizeType StrLen(const char* s) { 40 | return SizeType(std::strlen(s)); 41 | } 42 | 43 | template <> 44 | inline SizeType StrLen(const wchar_t* s) { 45 | return SizeType(std::wcslen(s)); 46 | } 47 | 48 | //! Returns number of code points in a encoded string. 49 | template 50 | bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { 51 | RAPIDJSON_ASSERT(s != 0); 52 | RAPIDJSON_ASSERT(outCount != 0); 53 | GenericStringStream is(s); 54 | const typename Encoding::Ch* end = s + length; 55 | SizeType count = 0; 56 | while (is.src_ < end) { 57 | unsigned codepoint; 58 | if (!Encoding::Decode(is, &codepoint)) 59 | return false; 60 | count++; 61 | } 62 | *outCount = count; 63 | return true; 64 | } 65 | 66 | } // namespace internal 67 | RAPIDJSON_NAMESPACE_END 68 | 69 | #endif // RAPIDJSON_INTERNAL_STRFUNC_H_ 70 | -------------------------------------------------------------------------------- /shared/ext/rapidjson/internal/swap.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_SWAP_H_ 16 | #define RAPIDJSON_INTERNAL_SWAP_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(__clang__) 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(c++98-compat) 23 | #endif 24 | 25 | RAPIDJSON_NAMESPACE_BEGIN 26 | namespace internal { 27 | 28 | //! Custom swap() to avoid dependency on C++ header 29 | /*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only. 30 | \note This has the same semantics as std::swap(). 31 | */ 32 | template 33 | inline void Swap(T& a, T& b) RAPIDJSON_NOEXCEPT { 34 | T tmp = a; 35 | a = b; 36 | b = tmp; 37 | } 38 | 39 | } // namespace internal 40 | RAPIDJSON_NAMESPACE_END 41 | 42 | #if defined(__clang__) 43 | RAPIDJSON_DIAG_POP 44 | #endif 45 | 46 | #endif // RAPIDJSON_INTERNAL_SWAP_H_ 47 | -------------------------------------------------------------------------------- /shared/ext/rapidjson/memorybuffer.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_MEMORYBUFFER_H_ 16 | #define RAPIDJSON_MEMORYBUFFER_H_ 17 | 18 | #include "stream.h" 19 | #include "internal/stack.h" 20 | 21 | RAPIDJSON_NAMESPACE_BEGIN 22 | 23 | //! Represents an in-memory output byte stream. 24 | /*! 25 | This class is mainly for being wrapped by EncodedOutputStream or AutoUTFOutputStream. 26 | 27 | It is similar to FileWriteBuffer but the destination is an in-memory buffer instead of a file. 28 | 29 | Differences between MemoryBuffer and StringBuffer: 30 | 1. StringBuffer has Encoding but MemoryBuffer is only a byte buffer. 31 | 2. StringBuffer::GetString() returns a null-terminated string. MemoryBuffer::GetBuffer() returns a buffer without terminator. 32 | 33 | \tparam Allocator type for allocating memory buffer. 34 | \note implements Stream concept 35 | */ 36 | template 37 | struct GenericMemoryBuffer { 38 | typedef char Ch; // byte 39 | 40 | GenericMemoryBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 41 | 42 | void Put(Ch c) { *stack_.template Push() = c; } 43 | void Flush() {} 44 | 45 | void Clear() { stack_.Clear(); } 46 | void ShrinkToFit() { stack_.ShrinkToFit(); } 47 | Ch* Push(size_t count) { return stack_.template Push(count); } 48 | void Pop(size_t count) { stack_.template Pop(count); } 49 | 50 | const Ch* GetBuffer() const { 51 | return stack_.template Bottom(); 52 | } 53 | 54 | size_t GetSize() const { return stack_.GetSize(); } 55 | 56 | static const size_t kDefaultCapacity = 256; 57 | mutable internal::Stack stack_; 58 | }; 59 | 60 | typedef GenericMemoryBuffer<> MemoryBuffer; 61 | 62 | //! Implement specialized version of PutN() with memset() for better performance. 63 | template<> 64 | inline void PutN(MemoryBuffer& memoryBuffer, char c, size_t n) { 65 | std::memset(memoryBuffer.stack_.Push(n), c, n * sizeof(c)); 66 | } 67 | 68 | RAPIDJSON_NAMESPACE_END 69 | 70 | #endif // RAPIDJSON_MEMORYBUFFER_H_ 71 | -------------------------------------------------------------------------------- /shared/ext/rapidjson/memorystream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_MEMORYSTREAM_H_ 16 | #define RAPIDJSON_MEMORYSTREAM_H_ 17 | 18 | #include "stream.h" 19 | 20 | #ifdef __clang__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(unreachable-code) 23 | RAPIDJSON_DIAG_OFF(missing-noreturn) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Represents an in-memory input byte stream. 29 | /*! 30 | This class is mainly for being wrapped by EncodedInputStream or AutoUTFInputStream. 31 | 32 | It is similar to FileReadBuffer but the source is an in-memory buffer instead of a file. 33 | 34 | Differences between MemoryStream and StringStream: 35 | 1. StringStream has encoding but MemoryStream is a byte stream. 36 | 2. MemoryStream needs size of the source buffer and the buffer don't need to be null terminated. StringStream assume null-terminated string as source. 37 | 3. MemoryStream supports Peek4() for encoding detection. StringStream is specified with an encoding so it should not have Peek4(). 38 | \note implements Stream concept 39 | */ 40 | struct MemoryStream { 41 | typedef char Ch; // byte 42 | 43 | MemoryStream(const Ch *src, size_t size) : src_(src), begin_(src), end_(src + size), size_(size) {} 44 | 45 | Ch Peek() const { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_; } 46 | Ch Take() { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_++; } 47 | size_t Tell() const { return static_cast(src_ - begin_); } 48 | 49 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 50 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 51 | void Flush() { RAPIDJSON_ASSERT(false); } 52 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 53 | 54 | // For encoding detection only. 55 | const Ch* Peek4() const { 56 | return Tell() + 4 <= size_ ? src_ : 0; 57 | } 58 | 59 | const Ch* src_; //!< Current read position. 60 | const Ch* begin_; //!< Original head of the string. 61 | const Ch* end_; //!< End of stream. 62 | size_t size_; //!< Size of the stream. 63 | }; 64 | 65 | RAPIDJSON_NAMESPACE_END 66 | 67 | #ifdef __clang__ 68 | RAPIDJSON_DIAG_POP 69 | #endif 70 | 71 | #endif // RAPIDJSON_MEMORYBUFFER_H_ 72 | -------------------------------------------------------------------------------- /shared/ext/rapidjson/ostreamwrapper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_OSTREAMWRAPPER_H_ 16 | #define RAPIDJSON_OSTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(padded) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Wrapper of \c std::basic_ostream into RapidJSON's Stream concept. 29 | /*! 30 | The classes can be wrapped including but not limited to: 31 | 32 | - \c std::ostringstream 33 | - \c std::stringstream 34 | - \c std::wpstringstream 35 | - \c std::wstringstream 36 | - \c std::ifstream 37 | - \c std::fstream 38 | - \c std::wofstream 39 | - \c std::wfstream 40 | 41 | \tparam StreamType Class derived from \c std::basic_ostream. 42 | */ 43 | 44 | template 45 | class BasicOStreamWrapper { 46 | public: 47 | typedef typename StreamType::char_type Ch; 48 | BasicOStreamWrapper(StreamType& stream) : stream_(stream) {} 49 | 50 | void Put(Ch c) { 51 | stream_.put(c); 52 | } 53 | 54 | void Flush() { 55 | stream_.flush(); 56 | } 57 | 58 | // Not implemented 59 | char Peek() const { RAPIDJSON_ASSERT(false); return 0; } 60 | char Take() { RAPIDJSON_ASSERT(false); return 0; } 61 | size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } 62 | char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 63 | size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } 64 | 65 | private: 66 | BasicOStreamWrapper(const BasicOStreamWrapper&); 67 | BasicOStreamWrapper& operator=(const BasicOStreamWrapper&); 68 | 69 | StreamType& stream_; 70 | }; 71 | 72 | typedef BasicOStreamWrapper OStreamWrapper; 73 | typedef BasicOStreamWrapper WOStreamWrapper; 74 | 75 | #ifdef __clang__ 76 | RAPIDJSON_DIAG_POP 77 | #endif 78 | 79 | RAPIDJSON_NAMESPACE_END 80 | 81 | #endif // RAPIDJSON_OSTREAMWRAPPER_H_ 82 | -------------------------------------------------------------------------------- /shared/gltf/ExternalImpl.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (C) Microsoft Corporation. All Rights Reserved 3 | // Licensed under the MIT License. See License.txt in the project root for license information. 4 | 5 | #include "pch.h" 6 | 7 | // Enable iterative parsing to avoid possible stack overflow 8 | #define RAPIDJSON_PARSE_DEFAULT_FLAGS kParseIterativeFlag 9 | #define TINYGLTF_USE_RAPIDJSON 10 | #define TINYGLTF_USE_RAPIDJSON_CRTALLOCATOR 11 | #define TINYGLTF_NO_STB_IMAGE_WRITE 12 | #define TINYGLTF_IMPLEMENTATION 13 | #define STB_IMAGE_IMPLEMENTATION 14 | #include 15 | 16 | #include 17 | -------------------------------------------------------------------------------- /shared/gltf/GltfHelper.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (C) Microsoft Corporation. All Rights Reserved 3 | // Licensed under the MIT License. See License.txt in the project root for license information. 4 | // GltfHelper provides additional glTF parsing functionality, built on top of tinygltf. 5 | // This library has no rendering dependencies and can be used for any purpose, such as 6 | // format transcoding or by a rendering engine. 7 | 8 | #pragma once 9 | 10 | #include "pch.h" 11 | 12 | #include 13 | #include 14 | 15 | namespace tinygltf 16 | { 17 | class Node; 18 | class Model; 19 | struct Primitive; 20 | struct Material; 21 | struct Image; 22 | struct Sampler; 23 | } 24 | 25 | namespace GltfHelper 26 | { 27 | // Vertex data. 28 | struct Vertex 29 | { 30 | DirectX::XMFLOAT3 Position; 31 | DirectX::XMFLOAT3 Normal; 32 | DirectX::XMFLOAT4 Tangent; 33 | DirectX::XMFLOAT2 TexCoord0; 34 | DirectX::XMFLOAT4 Color0; 35 | // Note: This implementation does not currently support TexCoord1 attributes. 36 | }; 37 | 38 | // A primitive is a collection of vertices and indices. 39 | struct Primitive 40 | { 41 | std::vector Vertices; 42 | std::vector Indices; 43 | }; 44 | 45 | enum class AlphaMode { Opaque, Mask, Blend }; 46 | 47 | // Metallic-roughness material definition. 48 | struct Material 49 | { 50 | struct Texture 51 | { 52 | const tinygltf::Image* Image; 53 | const tinygltf::Sampler* Sampler; 54 | }; 55 | 56 | Texture BaseColorTexture; 57 | Texture MetallicRoughnessTexture; 58 | Texture EmissiveTexture; 59 | Texture NormalTexture; 60 | Texture OcclusionTexture; 61 | 62 | DirectX::XMFLOAT4 BaseColorFactor; 63 | float MetallicFactor; 64 | float RoughnessFactor; 65 | DirectX::XMFLOAT3 EmissiveFactor; 66 | 67 | float NormalScale; 68 | float OcclusionStrength; 69 | 70 | AlphaMode AlphaMode; 71 | float AlphaCutoff; 72 | bool DoubleSided; 73 | }; 74 | 75 | // Reads the "transform" or "TRS" data for a Node as an XMMATRIX. 76 | DirectX::XMMATRIX XM_CALLCONV ReadNodeLocalTransform(const tinygltf::Node& gltfNode); 77 | 78 | // Parses the primitive attributes and indices from the glTF accessors/bufferviews/buffers into a common simplified data structure, the Primitive. 79 | Primitive ReadPrimitive(const tinygltf::Model& gltfModel, const tinygltf::Primitive& gltfPrimitive); 80 | 81 | // Parses the material values into a simplified data structure, the Material. 82 | Material ReadMaterial(const tinygltf::Model& gltfModel, const tinygltf::Material& gltfMaterial); 83 | 84 | // Converts the image to RGBA if necessary. Requires a temporary buffer only if it needs to be converted. 85 | const uint8_t* ReadImageAsRGBA(const tinygltf::Image& image, _Inout_ std::vector* tempBuffer); 86 | } 87 | -------------------------------------------------------------------------------- /shared/gltf/Gltf_uwp.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 6 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /shared/gltf/Gltf_win32.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 6 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /shared/gltf/pch.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (C) Microsoft Corporation. All Rights Reserved 3 | // Licensed under the MIT License. See License.txt in the project root for license information. 4 | #include "pch.h" 5 | -------------------------------------------------------------------------------- /shared/gltf/pch.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (C) Microsoft Corporation. All Rights Reserved 3 | // Licensed under the MIT License. See License.txt in the project root for license information. 4 | #pragma once 5 | 6 | #define NOMINMAX 7 | -------------------------------------------------------------------------------- /shared/pbr/GltfLoader.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (C) Microsoft Corporation. All Rights Reserved 3 | // Licensed under the MIT License. See License.txt in the project root for license information. 4 | // 5 | // Functions to load glTF 2.0 content into a renderable Pbr::Model. 6 | // 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "PbrResources.h" 12 | #include "PbrModel.h" 13 | 14 | namespace tinygltf { class Model; } 15 | 16 | namespace Gltf 17 | { 18 | // Creates a Pbr Model from tinygltf model. 19 | std::shared_ptr FromGltfObject( 20 | const Pbr::Resources& pbrResources, 21 | const tinygltf::Model& gltfModel); 22 | 23 | 24 | // Creates a Pbr Model from glTF 2.0 GLB file content. 25 | std::shared_ptr FromGltfBinary( 26 | const Pbr::Resources& pbrResources, 27 | _In_reads_bytes_(bufferBytes) const uint8_t* buffer, 28 | uint32_t bufferBytes); 29 | 30 | template 31 | std::shared_ptr FromGltfBinary(const Pbr::Resources& pbrResources, const Container& buffer) { 32 | return FromGltfBinary(pbrResources, buffer.data(), static_cast(buffer.size())); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /shared/pbr/PbrMaterial.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (C) Microsoft Corporation. All Rights Reserved 3 | // Licensed under the MIT License. See License.txt in the project root for license information. 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "PbrResources.h" 16 | 17 | namespace Pbr { 18 | // A Material contains the metallic roughness parameters and textures. 19 | // Primitives specify which Material to use when being rendered. 20 | struct Material final { 21 | #pragma warning(push) 22 | #pragma warning(disable:4324) 23 | // Coefficients used by the shader. Each texture is sampled and multiplied by these coefficients. 24 | struct ConstantBufferData { 25 | // packoffset(c0) 26 | alignas(16) RGBAColor BaseColorFactor{1, 1, 1, 1}; 27 | // packoffset(c1.x and c1.y) 28 | alignas(16) float MetallicFactor{1}; 29 | float RoughnessFactor{1}; 30 | // packoffset(c2) 31 | alignas(16) RGBColor EmissiveFactor{1, 1, 1}; 32 | // packoffset(c3.x, c3.y and c3.z) 33 | alignas(16) float NormalScale{1}; 34 | float OcclusionStrength{1}; 35 | float AlphaCutoff{0}; 36 | }; 37 | #pragma warning(pop) 38 | 39 | static_assert((sizeof(ConstantBufferData) % 16) == 0, "Constant Buffer must be divisible by 16 bytes"); 40 | 41 | // Create a uninitialized material. Textures and shader coefficients must be set. 42 | Material(Pbr::Resources const& pbrResources); 43 | 44 | // Create a clone of this material. 45 | std::shared_ptr Clone(Pbr::Resources const& pbrResources) const; 46 | 47 | // Create a flat (no texture) material. 48 | static std::shared_ptr CreateFlat(const Resources& pbrResources, 49 | RGBAColor baseColorFactor, 50 | float roughnessFactor = 1.0f, 51 | float metallicFactor = 0.0f, 52 | RGBColor emissiveFactor = RGB::Black); 53 | 54 | // Set a Metallic-Roughness texture. 55 | void SetTexture(ShaderSlots::PSMaterial slot, 56 | _In_ ID3D11ShaderResourceView* textureView, 57 | _In_opt_ ID3D11SamplerState* sampler = nullptr); 58 | 59 | void SetDoubleSided(bool doubleSided); 60 | void SetWireframe(bool wireframeMode); 61 | void SetAlphaBlended(bool alphaBlended); 62 | 63 | // Bind this material to current context. 64 | void Bind(_In_ ID3D11DeviceContext* context, const Resources& pbrResources) const; 65 | 66 | ConstantBufferData& Parameters(); 67 | const ConstantBufferData& Parameters() const; 68 | 69 | std::string Name; 70 | bool Hidden{false}; 71 | 72 | private: 73 | mutable bool m_parametersChanged{true}; 74 | ConstantBufferData m_parameters; 75 | 76 | bool m_alphaBlended{false}; 77 | bool m_doubleSided{false}; 78 | bool m_wireframe{false}; 79 | 80 | static constexpr size_t TextureCount = ShaderSlots::LastMaterialSlot + 1; 81 | std::array, TextureCount> m_textures; 82 | std::array, TextureCount> m_samplers; 83 | winrt::com_ptr m_constantBuffer; 84 | }; 85 | } // namespace Pbr 86 | -------------------------------------------------------------------------------- /shared/pbr/PbrPrimitive.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (C) Microsoft Corporation. All Rights Reserved 3 | // Licensed under the MIT License. See License.txt in the project root for license information. 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "PbrMaterial.h" 11 | 12 | namespace Pbr { 13 | // A primitive holds a vertex buffer, index buffer, and a pointer to a PBR material. 14 | struct Primitive final { 15 | using Collection = std::vector; 16 | 17 | Primitive() = delete; 18 | Primitive(UINT indexCount, 19 | winrt::com_ptr indexBuffer, 20 | winrt::com_ptr vertexBuffer, 21 | std::shared_ptr material); 22 | Primitive(Pbr::Resources const& pbrResources, 23 | const Pbr::PrimitiveBuilder& primitiveBuilder, 24 | std::shared_ptr material, 25 | bool updatableBuffers = false); 26 | 27 | void UpdateBuffers(_In_ ID3D11Device* device, _In_ ID3D11DeviceContext* context, const Pbr::PrimitiveBuilder& primitiveBuilder); 28 | 29 | // Get the material for the primitive. 30 | std::shared_ptr& GetMaterial() { 31 | return m_material; 32 | } 33 | const std::shared_ptr& GetMaterial() const { 34 | return m_material; 35 | } 36 | 37 | // Replace the material for the primitive 38 | void SetMaterial(std::shared_ptr material) { 39 | m_material = std::move(material); 40 | } 41 | 42 | protected: 43 | friend struct Model; 44 | void Render(_In_ ID3D11DeviceContext* context) const; 45 | Primitive Clone(Pbr::Resources const& pbrResources) const; 46 | 47 | private: 48 | UINT m_indexCount; 49 | winrt::com_ptr m_indexBuffer; 50 | winrt::com_ptr m_vertexBuffer; 51 | std::shared_ptr m_material; 52 | }; 53 | } // namespace Pbr 54 | -------------------------------------------------------------------------------- /shared/pbr/Shaders/HighlightPixelShader.hlsl: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (C) Microsoft Corporation. All Rights Reserved 3 | // Licensed under the MIT License. See License.txt in the project root for license information. 4 | 5 | #include "HighlightShared.hlsl" 6 | 7 | static const float PI = 3.141592653589793; 8 | 9 | float HighlightFromLocation(float3 sourcePosition, float animationTime, float3 position) 10 | { 11 | const float rippleSpeed = 2; // m/s 12 | float smoothStart = animationTime * rippleSpeed - 1.25; 13 | float smoothEnd = animationTime * rippleSpeed; 14 | return 1 - smoothstep(smoothStart, smoothEnd, distance(sourcePosition, position)); 15 | } 16 | 17 | float4 main(PSInputFlat input) : SV_TARGET 18 | { 19 | const float3 highlightColor = float3(1.0f, 1.0f, 1.0f); 20 | const float timemax = 15; 21 | const float animationTime1 = min(max(0.01, AnimationTime + 0.25), 10); 22 | const float animationTime2 = min(max(0.01, AnimationTime - 0.5), 10); 23 | 24 | const float spot1 = HighlightFromLocation(HighlightPosition, animationTime1, input.PositionWorld); 25 | const float spot2 = HighlightFromLocation(HighlightPosition, animationTime2, input.PositionWorld); 26 | 27 | return float4(highlightColor * (input.NormalWorld.y * 0.5f + 0.5f) * (spot1 - spot2), 1.0f); 28 | } 29 | -------------------------------------------------------------------------------- /shared/pbr/Shaders/HighlightShared.hlsl: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (C) Microsoft Corporation. All Rights Reserved 3 | // Licensed under the MIT License. See License.txt in the project root for license information. 4 | 5 | #include "Shared.hlsl" 6 | 7 | struct PSInputFlat 8 | { 9 | float4 PositionProj : SV_POSITION; 10 | float3 PositionWorld: POSITION1; 11 | nointerpolation float3 NormalWorld : Normal; 12 | }; -------------------------------------------------------------------------------- /shared/pbr/Shaders/HighlightVertexShader.hlsl: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (C) Microsoft Corporation. All Rights Reserved 3 | // Licensed under the MIT License. See License.txt in the project root for license information. 4 | // 5 | 6 | #include "HighlightShared.hlsl" 7 | 8 | StructuredBuffer Transforms : register(t0); 9 | 10 | cbuffer ModelConstantBuffer : register(b1) 11 | { 12 | float4x4 ModelToWorld : packoffset(c0); 13 | }; 14 | 15 | struct VSInputFlat 16 | { 17 | float4 Position : POSITION; 18 | float3 Normal : NORMAL; 19 | float4 Tangent : TANGENT; 20 | float4 Color0 : COLOR0; 21 | float2 TexCoord0 : TEXCOORD0; 22 | min16uint ModelTransformIndex : TRANSFORMINDEX; 23 | }; 24 | 25 | #define VSOutputFlat PSInputFlat 26 | VSOutputFlat main(VSInputFlat input) 27 | { 28 | VSOutputFlat output; 29 | 30 | const float4x4 modelTransform = mul(Transforms[input.ModelTransformIndex], ModelToWorld); 31 | const float4 transformedPosWorld = mul(input.Position, modelTransform); 32 | output.PositionProj = mul(transformedPosWorld, ViewProjection); 33 | output.PositionWorld = transformedPosWorld.xyz / transformedPosWorld.w; 34 | output.NormalWorld = mul(input.Normal, (float3x3)modelTransform).xyz; 35 | 36 | return output; 37 | } 38 | -------------------------------------------------------------------------------- /shared/pbr/Shaders/PbrShared.hlsl: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (C) Microsoft Corporation. All Rights Reserved 3 | // Licensed under the MIT License. See License.txt in the project root for license information. 4 | 5 | #include "Shared.hlsl" 6 | 7 | struct PSInputPbr 8 | { 9 | float4 PositionProj : SV_POSITION; 10 | float3 PositionWorld: POSITION1; 11 | float3x3 TBN : TANGENT; 12 | float2 TexCoord0 : TEXCOORD0; 13 | float4 Color0 : COLOR0; 14 | }; -------------------------------------------------------------------------------- /shared/pbr/Shaders/PbrVertexShader.hlsl: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (C) Microsoft Corporation. All Rights Reserved 3 | // Licensed under the MIT License. See License.txt in the project root for license information. 4 | // 5 | // This shader is based on the vertex shader at https://github.com/KhronosGroup/glTF-WebGL-PBR 6 | // with modifications for HLSL and stereoscopic rendering. 7 | // 8 | // The MIT License 9 | // 10 | // Copyright(c) 2016 - 2017 Mohamad Moneimne and Contributors 11 | // 12 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions : 13 | // 14 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 17 | // 18 | 19 | #include "PbrShared.hlsl" 20 | 21 | StructuredBuffer Transforms : register(t0); 22 | 23 | cbuffer ModelConstantBuffer : register(b1) 24 | { 25 | float4x4 ModelToWorld : packoffset(c0); 26 | 27 | }; 28 | 29 | struct VSInputPbr 30 | { 31 | float4 Position : POSITION; 32 | float3 Normal : NORMAL; 33 | float4 Tangent : TANGENT; 34 | float4 Color0 : COLOR0; 35 | float2 TexCoord0 : TEXCOORD0; 36 | min16uint ModelTransformIndex : TRANSFORMINDEX; 37 | }; 38 | 39 | #define VSOutputPbr PSInputPbr 40 | VSOutputPbr main(VSInputPbr input) 41 | { 42 | VSOutputPbr output; 43 | 44 | const float4x4 modelTransform = mul(Transforms[input.ModelTransformIndex], ModelToWorld); 45 | const float4 transformedPosWorld = mul(input.Position, modelTransform); 46 | output.PositionProj = mul(transformedPosWorld, ViewProjection); 47 | output.PositionWorld = transformedPosWorld.xyz / transformedPosWorld.w; 48 | 49 | const float3 normalW = normalize(mul(float4(input.Normal, 0.0), modelTransform).xyz); 50 | const float3 tangentW = normalize(mul(float4(input.Tangent.xyz, 0.0), modelTransform).xyz); 51 | const float3 bitangentW = cross(normalW, tangentW) * input.Tangent.w; 52 | output.TBN = float3x3(tangentW, bitangentW, normalW); 53 | 54 | output.TexCoord0 = input.TexCoord0; 55 | output.Color0 = input.Color0; 56 | 57 | return output; 58 | } 59 | -------------------------------------------------------------------------------- /shared/pbr/Shaders/Shared.hlsl: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (C) Microsoft Corporation. All Rights Reserved 3 | // Licensed under the MIT License. See License.txt in the project root for license information. 4 | 5 | cbuffer SceneBuffer : register(b0) 6 | { 7 | float4x4 ViewProjection : packoffset(c0); 8 | float3 EyePosition : packoffset(c4); 9 | float3 LightDirection : packoffset(c5); 10 | float3 LightColor : packoffset(c6); 11 | int NumSpecularMipLevels : packoffset(c7); 12 | float3 HighlightPosition : packoffset(c8); 13 | float AnimationTime : packoffset(c9); 14 | }; 15 | -------------------------------------------------------------------------------- /shared/pbr/brdf_lut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/OpenXR-MixedReality/65f472305206d24846701a7496befb0c104e6cb2/shared/pbr/brdf_lut.png -------------------------------------------------------------------------------- /shared/pbr/pbr_uwp.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Shaders 6 | 7 | 8 | Shaders 9 | 10 | 11 | Shaders 12 | 13 | 14 | Shaders 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | {025dce54-9985-49b5-96c5-e89d618b33f3} 38 | 39 | 40 | {42dd56b0-5d6b-4bb1-9219-15b8d3954fe5} 41 | 42 | 43 | 44 | 45 | Resources 46 | 47 | 48 | 49 | 50 | Shaders 51 | 52 | 53 | Shaders 54 | 55 | 56 | Shaders 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /shared/pbr/pbr_win32.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Shaders 6 | 7 | 8 | Shaders 9 | 10 | 11 | Shaders 12 | 13 | 14 | Shaders 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | Shaders 38 | 39 | 40 | Shaders 41 | 42 | 43 | Shaders 44 | 45 | 46 | 47 | 48 | 49 | {025dce54-9985-49b5-96c5-e89d618b33f3} 50 | 51 | 52 | {42dd56b0-5d6b-4bb1-9219-15b8d3954fe5} 53 | 54 | 55 | -------------------------------------------------------------------------------- /shared/pbr/pch.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (C) Microsoft Corporation. All Rights Reserved 3 | // Licensed under the MIT License. See License.txt in the project root for license information. 4 | #include "pch.h" 5 | -------------------------------------------------------------------------------- /shared/pbr/pch.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (C) Microsoft Corporation. All Rights Reserved 3 | // Licensed under the MIT License. See License.txt in the project root for license information. 4 | #pragma once 5 | 6 | #define NOMINMAX 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include // winrt::com_ptr 18 | --------------------------------------------------------------------------------