├── .clang-format ├── .gitattributes ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── config.yml │ └── question.md └── workflows │ └── msbuild.yml ├── .gitignore ├── .gitmodules ├── LICENSE ├── OpenXR-Toolkit.sln ├── README.md ├── RELEASING.md ├── THIRD_PARTY ├── XR_APILAYER_MBUCCHIA_toolkit ├── CAS.hlsl ├── FSR.hlsl ├── NIS.hlsl ├── VRS.hlsl ├── XR_APILAYER_MBUCCHIA_toolkit.json ├── XR_APILAYER_MBUCCHIA_toolkit.vcxproj ├── XR_APILAYER_MBUCCHIA_toolkit.vcxproj.filters ├── cas.cpp ├── config.cpp ├── d3d11.cpp ├── d3d12.cpp ├── d3dcommon.h ├── detours_helpers.h ├── eyetracker.cpp ├── factories.h ├── frameanalyzer.cpp ├── framework │ ├── __init__.py │ ├── dispatch.cpp │ ├── dispatch.gen.cpp │ ├── dispatch.gen.h │ ├── dispatch.h │ ├── dispatch_generator.py │ ├── entry.cpp │ └── layer_apis.py ├── fsr.cpp ├── hand2controller.cpp ├── imageprocess.cpp ├── interfaces.h ├── layer.cpp ├── layer.h ├── log.cpp ├── log.h ├── menu.cpp ├── nis.cpp ├── packages.config ├── pch.cpp ├── pch.h ├── postprocess.hlsl ├── resource.aps ├── resource.h ├── resource.rc ├── shader_utilities.h ├── utilities.cpp ├── utils │ ├── ScreenGrab11.cpp │ ├── ScreenGrab11.h │ ├── ScreenGrab12.cpp │ └── ScreenGrab12.h └── vrs.cpp ├── companion ├── App.config ├── CustomSetupActions.cs ├── Form1.Designer.cs ├── Form1.cs ├── Form1.resx ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── banner.png ├── companion.csproj ├── icon.ico ├── openxr_loader.dll └── packages.config ├── external ├── FB │ └── openxr │ │ ├── fb_eye_tracking_social.h │ │ └── openxr_extension_helpers.h ├── FW1FontWrapper │ ├── FW1FontWrapper.vcxproj │ ├── FW1FontWrapper.vcxproj.filters │ ├── README.md │ └── Source │ │ ├── CFW1ColorRGBA.cpp │ │ ├── CFW1ColorRGBA.h │ │ ├── CFW1ColorRGBAInterface.cpp │ │ ├── CFW1DWriteRenderTarget.cpp │ │ ├── CFW1DWriteRenderTarget.h │ │ ├── CFW1DWriteRenderTargetInterface.cpp │ │ ├── CFW1Factory.cpp │ │ ├── CFW1Factory.h │ │ ├── CFW1FactoryInterface.cpp │ │ ├── CFW1FontWrapper.cpp │ │ ├── CFW1FontWrapper.h │ │ ├── CFW1FontWrapperInterface.cpp │ │ ├── CFW1GlyphAtlas.cpp │ │ ├── CFW1GlyphAtlas.h │ │ ├── CFW1GlyphAtlasInterface.cpp │ │ ├── CFW1GlyphProvider.cpp │ │ ├── CFW1GlyphProvider.h │ │ ├── CFW1GlyphProviderInterface.cpp │ │ ├── CFW1GlyphRenderStates.cpp │ │ ├── CFW1GlyphRenderStates.h │ │ ├── CFW1GlyphRenderStatesInterface.cpp │ │ ├── CFW1GlyphSheet.cpp │ │ ├── CFW1GlyphSheet.h │ │ ├── CFW1GlyphSheetInterface.cpp │ │ ├── CFW1GlyphVertexDrawer.cpp │ │ ├── CFW1GlyphVertexDrawer.h │ │ ├── CFW1GlyphVertexDrawerInterface.cpp │ │ ├── CFW1Object.h │ │ ├── CFW1StateSaver.cpp │ │ ├── CFW1StateSaver.h │ │ ├── CFW1TextGeometry.cpp │ │ ├── CFW1TextGeometry.h │ │ ├── CFW1TextGeometryInterface.cpp │ │ ├── CFW1TextRenderer.cpp │ │ ├── CFW1TextRenderer.h │ │ ├── CFW1TextRendererInterface.cpp │ │ ├── FW1CompileSettings.h │ │ ├── FW1FontWrapper.cpp │ │ ├── FW1FontWrapper.h │ │ ├── FW1Precompiled.cpp │ │ └── FW1Precompiled.h ├── aSeeVRClient │ ├── bin │ │ └── aSeeVRClient.dll │ ├── include │ │ ├── aSeeVRClient.h │ │ ├── aSeeVRTypes.h │ │ └── aSeeVRUtility.h │ └── lib │ │ └── aSeeVRClient.lib └── d3dx12 │ └── d3dx12.h ├── installer ├── .gitignore ├── EULA.rtf ├── README.rtf ├── banner.bmp ├── comodo.pfx ├── installer.vdproj ├── selfsigncert.pfx └── signtool.exe ├── mappings └── FS2020.cfg ├── mappingstool ├── App.config ├── Form1.Designer.cs ├── Form1.cs ├── Form1.resx ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── icon.ico ├── mappingtool.csproj └── packages.config ├── patches ├── FidelityFX-FSR │ └── 0000-conditionaly-compile-denoise-code-fsr-v1.20210629.patch ├── NVIDIAImageScaling │ └── 0000-allow-compileshader-option-wx-nis-1-0-2.patch ├── msys-2.0.dll ├── msys-iconv-2.dll ├── msys-intl-8.dll ├── patch.exe └── sed.exe └── scripts ├── DisableDebugLayer.reg ├── EnableDebugLayer.reg ├── Install-Layer.ps1 ├── OXRTK.wprp ├── OXRTK_WMR.wprp └── Uninstall-Layer.ps1 /.clang-format: -------------------------------------------------------------------------------- 1 | Language: Cpp 2 | IndentWidth: 4 3 | ColumnLimit: 120 4 | AllowShortBlocksOnASingleLine: false 5 | AllowShortFunctionsOnASingleLine: false 6 | AlwaysBreakTemplateDeclarations: true 7 | BinPackParameters: false 8 | BinPackArguments: false 9 | IndentWrappedFunctionNames: false 10 | KeepEmptyLinesAtTheStartOfBlocks: false 11 | MaxEmptyLinesToKeep: 1 12 | NamespaceIndentation: All 13 | PenaltyReturnTypeOnItsOwnLine: 100 14 | PointerAlignment: Left 15 | SortIncludes: false 16 | SpaceAfterCStyleCast: false 17 | SpaceBeforeAssignmentOperators: true 18 | SpaceBeforeParens: ControlStatements 19 | SpaceInEmptyParentheses: false 20 | SpacesInAngles: false 21 | SpacesInCStyleCastParentheses: false 22 | SpacesInContainerLiterals: false 23 | SpacesInParentheses: false 24 | SpacesInSquareBrackets: false 25 | UseTab: Never 26 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.gen.* text eol=lf 2 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: mbucchia 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **ANY ISSUE FILED WITHOUT THE INFORMATION REQUIRED BELOW WILL BE CLOSED WITHOUT BEING LOOKED AT. NO EXCEPTIONS.** 11 | 12 | **Describe the bug** 13 | 14 | _A clear and concise description of what the bug is._ 15 | _Always attach (upload, do not copy/paste) the log file that can be found at `%LocalAppData%\OpenXR-Toolkit\logs` or opened from the OpenXR Toolkit Companion app._ 16 | 17 | **Environment** 18 | 19 | - _Application/Game and version_: 20 | - _Make and model of VR device_: 21 | 22 | **To Reproduce** 23 | 24 | _Steps to reproduce the behavior:_ 25 | 26 | 1. Run '....' game 27 | 2. Enable option '....' 28 | 3. See error 29 | 30 | **Expected behavior** 31 | 32 | _A clear and concise description of what you expected to happen._ 33 | 34 | **Screenshots** 35 | 36 | _If applicable, add screenshots to help explain your problem. Use the Companion app to enable screenshots, then use Ctrl+F12 to capture. The files are placed in `%LocalAppData%\OpenXR-Toolkit\screenshots` or can be opened from the OpenXR Toolkit Companion app._ 37 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: OpenXR Toolkit Homepage 4 | url: https://mbucchia.github.io/OpenXR-Toolkit/ 5 | about: The homepage has A LOT OF INFORMATION. Check there first for the answer to your questions/issues. There is a Search bar at the top. 6 | - name: OpenXR Toolkit Discord (NO OPENCOMPOSITE SUPPORT) 7 | url: https://discord.gg/mPKJYeGUjH 8 | about: If you have checked all the information above, but still cannot address your questions/issues, ask and answer questions on our Discord. 9 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question 3 | about: 'Ask about this project. ' 4 | title: '' 5 | labels: question 6 | assignees: '' 7 | 8 | --- 9 | 10 | _Give us as much details as possible_ 11 | -------------------------------------------------------------------------------- /.github/workflows/msbuild.yml: -------------------------------------------------------------------------------- 1 | name: MSBuild 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - release/* 8 | tags: 9 | - '[0-9]+.[0-9]+.[0-9]+' 10 | pull_request: 11 | branches: 12 | - release/* 13 | workflow_dispatch: 14 | 15 | env: 16 | SOLUTION_FILE_PATH: OpenXR-Toolkit.sln 17 | BUILD_CONFIGURATION: Release 18 | 19 | jobs: 20 | build: 21 | runs-on: windows-latest 22 | environment: build-and-sign 23 | 24 | steps: 25 | - name: Checkout project 26 | uses: actions/checkout@v2 27 | 28 | - name: Checkout submodules 29 | working-directory: ${{env.GITHUB_WORKSPACE}} 30 | run: git submodule update --init 31 | 32 | - name: Setup DevEnv 33 | uses: seanmiddleditch/gha-setup-vsdevenv@v4 34 | 35 | - name: Setup Python 36 | uses: actions/setup-python@v2.3.1 37 | with: 38 | python-version: 3.8 39 | 40 | - name: Restore NuGet packages 41 | working-directory: ${{env.GITHUB_WORKSPACE}} 42 | run: nuget restore ${{env.SOLUTION_FILE_PATH}} 43 | 44 | - name: Build 45 | env: 46 | PFX_PASSWORD: ${{ secrets.PFX_PASSWORD }} 47 | PFX_NAME: "comodo" 48 | working-directory: ${{env.GITHUB_WORKSPACE}} 49 | run: | 50 | # Need to build vdproj. We must invoke this tool from inside its own folder. 51 | $DisableOutOfProcBuild=$(vswhere -latest -find **\DisableOutOfProcBuild.exe) 52 | Push-Location $(Split-Path $DisableOutOfProcBuild) 53 | & $DisableOutOfProcBuild 54 | Pop-Location 55 | 56 | # Finally, we may build the project. 57 | devenv.com ${{env.SOLUTION_FILE_PATH}} /Build ${{env.BUILD_CONFIGURATION}} 58 | 59 | - name: Signing 60 | env: 61 | PFX_PASSWORD: ${{ secrets.PFX_PASSWORD }} 62 | PFX_NAME: "comodo" 63 | working-directory: ${{env.GITHUB_WORKSPACE}} 64 | run: | 65 | $pfxName = if ($env:PFX_NAME) { $env:PFX_NAME } else { "selfsigncert" }; 66 | installer/signtool.exe sign /d "OpenXR Toolkit" /du "https://mbucchia.github.io/OpenXR-Toolkit/" /f installer/$pfxName.pfx /p "$env:PFX_PASSWORD" /v installer/output/OpenXR-Toolkit.msi 67 | 68 | - name: Publish 69 | uses: actions/upload-artifact@v2 70 | with: 71 | name: Setup 72 | path: | 73 | installer/output/OpenXR-Toolkit.msi 74 | bin/x64/Release/XR_APILAYER_MBUCCHIA_toolkit.pdb 75 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vs/ 2 | packages/ 3 | bin/ 4 | **/x64/ 5 | **/obj/ 6 | **/__pycache__/ 7 | *.pyc 8 | *.vcxproj.user 9 | *.csproj.user 10 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "external/OpenXR-SDK-Source"] 2 | path = external/OpenXR-SDK-Source 3 | url = https://github.com/KhronosGroup/OpenXR-SDK-Source.git 4 | [submodule "external/OpenXR-MixedReality"] 5 | path = external/OpenXR-MixedReality 6 | url = https://github.com/microsoft/OpenXR-MixedReality.git 7 | [submodule "external/OpenXR-SDK"] 8 | path = external/OpenXR-SDK 9 | url = https://github.com/KhronosGroup/OpenXR-SDK.git 10 | [submodule "external/NVIDIAImageScaling"] 11 | path = external/NVIDIAImageScaling 12 | url = https://github.com/NVIDIAGameWorks/NVIDIAImageScaling/ 13 | [submodule "external/FidelityFX-FSR"] 14 | path = external/FidelityFX-FSR 15 | url = https://github.com/GPUOpen-Effects/FidelityFX-FSR.git 16 | [submodule "external/NVAPI"] 17 | path = external/NVAPI 18 | url = https://github.com/mbucchia/NVAPI.git 19 | [submodule "external/Omnicept-SDK"] 20 | path = external/Omnicept-SDK 21 | url = https://github.com/mbucchia/Omnicept-SDK.git 22 | [submodule "external/FidelityFX-CAS"] 23 | path = external/FidelityFX-CAS 24 | url = https://github.com/GPUOpen-Effects/FidelityFX-CAS.git 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021-2022 Matthieu Bucchianeri 4 | Copyright (c) 2021-2022 Jean-Luc Dupiot - Reality XP 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /OpenXR-Toolkit.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31911.196 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XR_APILAYER_MBUCCHIA_toolkit", "XR_APILAYER_MBUCCHIA_toolkit\XR_APILAYER_MBUCCHIA_toolkit.vcxproj", "{93D573D0-634F-4BA0-8FE0-FB63D7D00A05}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | {9F62DB07-EA42-4388-82AB-E6FAA371F353} = {9F62DB07-EA42-4388-82AB-E6FAA371F353} 9 | EndProjectSection 10 | EndProject 11 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Files", "Solution Files", "{387062F2-BCA2-4776-A414-B6DE41FC9E12}" 12 | ProjectSection(SolutionItems) = preProject 13 | .clang-format = .clang-format 14 | .gitattributes = .gitattributes 15 | .gitignore = .gitignore 16 | LICENSE = LICENSE 17 | README.md = README.md 18 | RELEASING.md = RELEASING.md 19 | version.info = version.info 20 | EndProjectSection 21 | EndProject 22 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{1E41057B-9167-4ED0-A3FA-6F2CA6B55922}" 23 | ProjectSection(SolutionItems) = preProject 24 | scripts\Install-Layer.ps1 = scripts\Install-Layer.ps1 25 | scripts\OXRTK.wprp = scripts\OXRTK.wprp 26 | scripts\OXRTK_WMR.wprp = scripts\OXRTK_WMR.wprp 27 | scripts\Uninstall-Layer.ps1 = scripts\Uninstall-Layer.ps1 28 | EndProjectSection 29 | EndProject 30 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "companion", "companion\companion.csproj", "{69C43742-D646-44B8-A869-3D8016D525CE}" 31 | ProjectSection(ProjectDependencies) = postProject 32 | {93D573D0-634F-4BA0-8FE0-FB63D7D00A05} = {93D573D0-634F-4BA0-8FE0-FB63D7D00A05} 33 | EndProjectSection 34 | EndProject 35 | Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "Setup", "installer\installer.vdproj", "{9D1EF86B-6B13-4C14-BBD7-E70CF7DD48DE}" 36 | EndProject 37 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mappingtool", "mappingstool\mappingtool.csproj", "{F64486BA-421E-43A7-8E97-DC9981EA5C6F}" 38 | ProjectSection(ProjectDependencies) = postProject 39 | {93D573D0-634F-4BA0-8FE0-FB63D7D00A05} = {93D573D0-634F-4BA0-8FE0-FB63D7D00A05} 40 | EndProjectSection 41 | EndProject 42 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GitHub", "GitHub", "{3F9F661B-0558-4FF0-862C-4D1920CC2782}" 43 | ProjectSection(SolutionItems) = preProject 44 | .github\workflows\msbuild.yml = .github\workflows\msbuild.yml 45 | EndProjectSection 46 | EndProject 47 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FW1FontWrapper", "external\FW1FontWrapper\FW1FontWrapper.vcxproj", "{9F62DB07-EA42-4388-82AB-E6FAA371F353}" 48 | EndProject 49 | Global 50 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 51 | Debug|x64 = Debug|x64 52 | Release|x64 = Release|x64 53 | EndGlobalSection 54 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 55 | {93D573D0-634F-4BA0-8FE0-FB63D7D00A05}.Debug|x64.ActiveCfg = Debug|x64 56 | {93D573D0-634F-4BA0-8FE0-FB63D7D00A05}.Debug|x64.Build.0 = Debug|x64 57 | {93D573D0-634F-4BA0-8FE0-FB63D7D00A05}.Release|x64.ActiveCfg = Release|x64 58 | {93D573D0-634F-4BA0-8FE0-FB63D7D00A05}.Release|x64.Build.0 = Release|x64 59 | {69C43742-D646-44B8-A869-3D8016D525CE}.Debug|x64.ActiveCfg = Debug|Any CPU 60 | {69C43742-D646-44B8-A869-3D8016D525CE}.Debug|x64.Build.0 = Debug|Any CPU 61 | {69C43742-D646-44B8-A869-3D8016D525CE}.Release|x64.ActiveCfg = Release|Any CPU 62 | {69C43742-D646-44B8-A869-3D8016D525CE}.Release|x64.Build.0 = Release|Any CPU 63 | {9D1EF86B-6B13-4C14-BBD7-E70CF7DD48DE}.Debug|x64.ActiveCfg = Debug 64 | {9D1EF86B-6B13-4C14-BBD7-E70CF7DD48DE}.Release|x64.ActiveCfg = Release 65 | {9D1EF86B-6B13-4C14-BBD7-E70CF7DD48DE}.Release|x64.Build.0 = Release 66 | {F64486BA-421E-43A7-8E97-DC9981EA5C6F}.Debug|x64.ActiveCfg = Debug|Any CPU 67 | {F64486BA-421E-43A7-8E97-DC9981EA5C6F}.Debug|x64.Build.0 = Debug|Any CPU 68 | {F64486BA-421E-43A7-8E97-DC9981EA5C6F}.Release|x64.ActiveCfg = Release|Any CPU 69 | {F64486BA-421E-43A7-8E97-DC9981EA5C6F}.Release|x64.Build.0 = Release|Any CPU 70 | {9F62DB07-EA42-4388-82AB-E6FAA371F353}.Debug|x64.ActiveCfg = Debug|x64 71 | {9F62DB07-EA42-4388-82AB-E6FAA371F353}.Debug|x64.Build.0 = Debug|x64 72 | {9F62DB07-EA42-4388-82AB-E6FAA371F353}.Release|x64.ActiveCfg = Release|x64 73 | {9F62DB07-EA42-4388-82AB-E6FAA371F353}.Release|x64.Build.0 = Release|x64 74 | EndGlobalSection 75 | GlobalSection(SolutionProperties) = preSolution 76 | HideSolutionNode = FALSE 77 | EndGlobalSection 78 | GlobalSection(NestedProjects) = preSolution 79 | {1E41057B-9167-4ED0-A3FA-6F2CA6B55922} = {387062F2-BCA2-4776-A414-B6DE41FC9E12} 80 | {3F9F661B-0558-4FF0-862C-4D1920CC2782} = {387062F2-BCA2-4776-A414-B6DE41FC9E12} 81 | EndGlobalSection 82 | GlobalSection(ExtensibilityGlobals) = postSolution 83 | SolutionGuid = {777B0DEC-4E36-4B64-BD29-1832B32A076B} 84 | EndGlobalSection 85 | EndGlobal 86 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenXR Toolkit 2 | 3 | This software provides a collection of useful features to customize and improve existing OpenXR applications, 4 | including render upscaling and sharpening, foveated rendering, hand tracking to controller input simulation, 5 | image adjustments and other game-enhancing tweaks. 6 | 7 | Please visit the official page at https://mbucchia.github.io/OpenXR-Toolkit/ for detailed instructions on how to download, 8 | install, and use this software. 9 | 10 | DISCLAIMER: This software is distributed as-is, without any warranties or conditions of any kind. Use at your own risks. 11 | 12 | ## Donate 13 | 14 | Donations are welcome and totally optional. Please use [my GitHub sponsorship page](https://github.com/sponsors/mbucchia) to make one-time or recurring donations! 15 | 16 | Thank you! 17 | 18 | ## Contributions 19 | 20 | This software was created by Matthieu Bucchianeri and Jean-Luc Dupiot. 21 | 22 | Logo and icons designed by RPthreenine. 23 | 24 | User Experience designed by Andrew Lilley (FarFutureFox). 25 | 26 | Additional contributions by James Lacey (Jabbah), Bernhard Berger, and Erik Uri. 27 | 28 | Many thanks to the https://forums.flightsimulator.com/ community for the testing and feedback! 29 | -------------------------------------------------------------------------------- /RELEASING.md: -------------------------------------------------------------------------------- 1 | In order to make a release with number X.Y.Z: 2 | 3 | 1) Create or update the branch `release/x.y` 4 | 5 | 2) Create or update the definitions in `version.info`, eg: 6 | 7 | ``` 8 | major=0 9 | minor=9 10 | patch=4 11 | pretty_name=Beta-2 12 | ``` 13 | 14 | 3) Update the label in `installer/README.rtf`, eg: 15 | 16 | ``` 17 | OpenXR Toolkit - Beta-2 (v0.9.4) 18 | ``` 19 | 20 | 4) Update the `Setup` project, property `Version`. When prompted to update the product code, choose Yes. 21 | 22 | 5) Push the release to the server. 23 | 24 | 6) Create a tag for the release: `x.y.z`. 25 | -------------------------------------------------------------------------------- /THIRD_PARTY: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/THIRD_PARTY -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/CAS.hlsl: -------------------------------------------------------------------------------- 1 | // CAS Sample 2 | // 3 | // Copyright(c) 2019 Advanced Micro Devices, Inc.All rights reserved. 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files(the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions : 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE 15 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 18 | // THE SOFTWARE. 19 | 20 | cbuffer cb : register(b0) { 21 | uint4 const0; 22 | uint4 const1; 23 | }; 24 | 25 | Texture2D InputTexture : register(t0); 26 | RWTexture2D OutputTexture : register(u0); 27 | 28 | #define A_GPU 1 29 | #define A_HLSL 1 30 | 31 | #if CAS_SAMPLE_FP16 32 | 33 | #define A_HALF 1 34 | #define CAS_PACKED_ONLY 1 35 | 36 | #endif 37 | 38 | #include "ffx_a.h" 39 | 40 | #if CAS_SAMPLE_FP16 41 | 42 | AH3 CasLoadH(ASW2 p) { 43 | return InputTexture.Load(ASU3(p, 0)).rgb; 44 | } 45 | 46 | // Lets you transform input from the load into a linear color space between 0 and 1. See ffx_cas.h 47 | // In this case, our input is already linear and between 0 and 1 48 | void CasInputH(inout AH2 r, inout AH2 g, inout AH2 b) { 49 | } 50 | 51 | #else 52 | 53 | AF3 CasLoad(ASU2 p) { 54 | return InputTexture.Load(int3(p, 0)).rgb; 55 | } 56 | 57 | // Lets you transform input from the load into a linear color space between 0 and 1. See ffx_cas.h 58 | // In this case, our input is already linear and between 0 and 1 59 | void CasInput(inout AF1 r, inout AF1 g, inout AF1 b) { 60 | } 61 | 62 | #endif 63 | 64 | #include "ffx_cas.h" 65 | 66 | [numthreads(CAS_THREAD_GROUP_SIZE, 1, 1)] 67 | void mainCS(uint3 LocalThreadId 68 | : SV_GroupThreadID, uint3 WorkGroupId 69 | : SV_GroupID) { 70 | // Do remapping of local xy in workgroup for a more PS-like swizzle pattern. 71 | AU2 gxy = ARmp8x8(LocalThreadId.x) + AU2(WorkGroupId.x << 4u, WorkGroupId.y << 4u); 72 | 73 | bool sharpenOnly; 74 | #if CAS_SAMPLE_SHARPEN_ONLY 75 | sharpenOnly = true; 76 | #else 77 | sharpenOnly = false; 78 | #endif 79 | 80 | #if CAS_SAMPLE_FP16 81 | 82 | // Filter. 83 | AH4 c0, c1; 84 | AH2 cR, cG, cB; 85 | 86 | CasFilterH(cR, cG, cB, gxy, const0, const1, sharpenOnly); 87 | CasDepack(c0, c1, cR, cG, cB); 88 | OutputTexture[ASU2(gxy)] = AF4(c0); 89 | OutputTexture[ASU2(gxy) + ASU2(8, 0)] = AF4(c1); 90 | gxy.y += 8u; 91 | 92 | CasFilterH(cR, cG, cB, gxy, const0, const1, sharpenOnly); 93 | CasDepack(c0, c1, cR, cG, cB); 94 | OutputTexture[ASU2(gxy)] = AF4(c0); 95 | OutputTexture[ASU2(gxy) + ASU2(8, 0)] = AF4(c1); 96 | 97 | #else 98 | 99 | // Filter. 100 | AF3 c; 101 | 102 | CasFilter(c.r, c.g, c.b, gxy, const0, const1, sharpenOnly); 103 | OutputTexture[ASU2(gxy)] = AF4(c, 1); 104 | gxy.x += 8u; 105 | 106 | CasFilter(c.r, c.g, c.b, gxy, const0, const1, sharpenOnly); 107 | OutputTexture[ASU2(gxy)] = AF4(c, 1); 108 | gxy.y += 8u; 109 | 110 | CasFilter(c.r, c.g, c.b, gxy, const0, const1, sharpenOnly); 111 | OutputTexture[ASU2(gxy)] = AF4(c, 1); 112 | gxy.x -= 8u; 113 | 114 | CasFilter(c.r, c.g, c.b, gxy, const0, const1, sharpenOnly); 115 | OutputTexture[ASU2(gxy)] = AF4(c, 1); 116 | 117 | #endif 118 | } 119 | -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/FSR.hlsl: -------------------------------------------------------------------------------- 1 | // FidelityFX Super Resolution Sample 2 | // 3 | // Copyright (c) 2021 Advanced Micro Devices, Inc. All rights reserved. 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files(the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and / or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions : 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE 15 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 18 | // THE SOFTWARE. 19 | 20 | // clang-format off 21 | 22 | // combine EASU and RCAS constants in a single buffer 23 | cbuffer cb : register(b0) 24 | { 25 | uint4 Const0; 26 | uint4 Const1; 27 | uint4 Const2; 28 | uint4 Const3; 29 | uint4 Const4; 30 | }; 31 | 32 | #define A_GPU 1 33 | #define A_HLSL 1 34 | 35 | SamplerState samLinearClamp : register(s0); 36 | 37 | #if SAMPLE_SLOW_FALLBACK 38 | #include "ffx_a.h" 39 | Texture2D InputTexture : register(t0); 40 | RWTexture2D OutputTexture : register(u0); 41 | #if SAMPLE_EASU 42 | #define FSR_EASU_F 1 43 | AF4 FsrEasuRF(AF2 p) { AF4 res = InputTexture.GatherRed(samLinearClamp, p, int2(0, 0)); return res; } 44 | AF4 FsrEasuGF(AF2 p) { AF4 res = InputTexture.GatherGreen(samLinearClamp, p, int2(0, 0)); return res; } 45 | AF4 FsrEasuBF(AF2 p) { AF4 res = InputTexture.GatherBlue(samLinearClamp, p, int2(0, 0)); return res; } 46 | #endif 47 | #if SAMPLE_RCAS 48 | #define FSR_RCAS_F 49 | #if SAMPLE_HDR_OUTPUT 50 | AF4 FsrRcasLoadF(ASU2 p) { return sqrt(InputTexture.Load(int3(ASU2(p), 0))); } 51 | #else 52 | AF4 FsrRcasLoadF(ASU2 p) { return InputTexture.Load(int3(ASU2(p), 0)); } 53 | #endif 54 | void FsrRcasInputF(inout AF1 r, inout AF1 g, inout AF1 b) { 55 | } 56 | #endif 57 | #else 58 | #define A_HALF 59 | #include "ffx_a.h" 60 | Texture2D InputTexture : register(t0); 61 | RWTexture2D OutputTexture : register(u0); 62 | #if SAMPLE_EASU 63 | #define FSR_EASU_H 1 64 | AH4 FsrEasuRH(AF2 p) { AH4 res = InputTexture.GatherRed(samLinearClamp, p, int2(0, 0)); return res; } 65 | AH4 FsrEasuGH(AF2 p) { AH4 res = InputTexture.GatherGreen(samLinearClamp, p, int2(0, 0)); return res; } 66 | AH4 FsrEasuBH(AF2 p) { AH4 res = InputTexture.GatherBlue(samLinearClamp, p, int2(0, 0)); return res; } 67 | #endif 68 | #if SAMPLE_RCAS 69 | #define FSR_RCAS_H 70 | AH4 FsrRcasLoadH(ASW2 p) { return InputTexture.Load(ASW3(ASW2(p), 0)); } 71 | void FsrRcasInputH(inout AH1 r,inout AH1 g,inout AH1 b){} 72 | #endif 73 | #endif 74 | 75 | #include "ffx_fsr1.h" 76 | 77 | void CurrFilter(int2 pos) 78 | { 79 | #if SAMPLE_BILINEAR 80 | AF2 pp = (AF2(pos) * AF2_AU2(Const0.xy) + AF2_AU2(Const0.zw)) * AF2_AU2(Const1.xy) + AF2(0.5, -0.5) * AF2_AU2(Const1.zw); 81 | OutputTexture[pos] = InputTexture.SampleLevel(samLinearClamp, pp, 0.0); 82 | #endif 83 | #if SAMPLE_EASU 84 | #if SAMPLE_SLOW_FALLBACK 85 | AF3 c; 86 | FsrEasuF(c, pos, Const0, Const1, Const2, Const3); 87 | #if SAMPLE_HDR_OUTPUT 88 | c *= c; 89 | #endif 90 | OutputTexture[pos] = float4(c, 1); 91 | #else 92 | AH3 c; 93 | FsrEasuH(c, pos, Const0, Const1, Const2, Const3); 94 | #if SAMPLE_HDR_OUTPUT 95 | c *= c; 96 | #endif 97 | OutputTexture[pos] = AH4(c, 1); 98 | #endif 99 | #endif 100 | #if SAMPLE_RCAS 101 | #if SAMPLE_SLOW_FALLBACK 102 | AF3 c; 103 | FsrRcasF(c.r, c.g, c.b, pos, Const4); 104 | #if SAMPLE_HDR_OUTPUT 105 | c *= c; 106 | #endif 107 | OutputTexture[pos] = float4(c, 1); 108 | #else 109 | AH3 c; 110 | FsrRcasH(c.r, c.g, c.b, pos, Const4); 111 | #if SAMPLE_HDR_OUTPUT 112 | c *= c; 113 | #endif 114 | OutputTexture[pos] = AH4(c, 1); 115 | #endif 116 | #endif 117 | } 118 | 119 | [numthreads(FSR_THREAD_GROUP_SIZE, 1, 1)] 120 | void mainCS(uint3 LocalThreadId : SV_GroupThreadID, uint3 WorkGroupId : SV_GroupID, uint3 Dtid : SV_DispatchThreadID) 121 | { 122 | // Do remapping of local xy in workgroup for a more PS-like swizzle pattern. 123 | AU2 gxy = ARmp8x8(LocalThreadId.x) + AU2(WorkGroupId.x << 4u, WorkGroupId.y << 4u); 124 | CurrFilter(gxy); 125 | gxy.x += 8u; 126 | CurrFilter(gxy); 127 | gxy.y += 8u; 128 | CurrFilter(gxy); 129 | gxy.x -= 8u; 130 | CurrFilter(gxy); 131 | } 132 | 133 | // clang-format on 134 | -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/NIS.hlsl: -------------------------------------------------------------------------------- 1 | // The MIT License(MIT) 2 | // 3 | // Copyright(c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 4 | // Copyright(c) 2021 Matthieu Bucchianeri 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | // this software and associated documentation files(the "Software"), to deal in 8 | // the Software without restriction, including without limitation the rights to 9 | // use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of 10 | // the Software, and to permit persons to whom the Software is furnished to do so, 11 | // subject to the following conditions : 12 | // 13 | // The above copyright notice and this permission notice shall be included in all 14 | // copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR 19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | #define NIS_HLSL 1 24 | 25 | #ifndef NIS_SCALER 26 | #define NIS_SCALER 1 27 | #endif 28 | 29 | #ifndef NIS_DXC 30 | #define NIS_DXC 0 31 | #endif 32 | 33 | #if NIS_DXC 34 | #define NIS_PUSH_CONSTANT [[vk::push_constant]] 35 | #define NIS_BINDING(bindingIndex) [[vk::binding(bindingIndex, 0)]] 36 | #else 37 | #define NIS_PUSH_CONSTANT 38 | #define NIS_BINDING(bindingIndex) 39 | #endif 40 | 41 | NIS_BINDING(0) cbuffer cb : register(b0) { 42 | float kDetectRatio; 43 | float kDetectThres; 44 | float kMinContrastRatio; 45 | float kRatioNorm; 46 | 47 | float kContrastBoost; 48 | float kEps; 49 | float kSharpStartY; 50 | float kSharpScaleY; 51 | 52 | float kSharpStrengthMin; 53 | float kSharpStrengthScale; 54 | float kSharpLimitMin; 55 | float kSharpLimitScale; 56 | 57 | float kScaleX; 58 | float kScaleY; 59 | 60 | float kDstNormX; 61 | float kDstNormY; 62 | float kSrcNormX; 63 | float kSrcNormY; 64 | 65 | uint kInputViewportOriginX; 66 | uint kInputViewportOriginY; 67 | uint kInputViewportWidth; 68 | uint kInputViewportHeight; 69 | 70 | uint kOutputViewportOriginX; 71 | uint kOutputViewportOriginY; 72 | uint kOutputViewportWidth; 73 | uint kOutputViewportHeight; 74 | 75 | float reserved0; 76 | float reserved1; 77 | }; 78 | 79 | NIS_BINDING(1) SamplerState samplerLinearClamp : register(s0); 80 | 81 | NIS_BINDING(2) Texture2D in_texture : register(t0); 82 | NIS_BINDING(3) RWTexture2D out_texture : register(u0); 83 | 84 | #if NIS_SCALER 85 | NIS_BINDING(4) Texture2D coef_scaler : register(t1); 86 | NIS_BINDING(5) Texture2D coef_usm : register(t2); 87 | #endif 88 | 89 | #include "NIS_Scaler.h" 90 | 91 | [numthreads(NIS_THREAD_GROUP_SIZE, 1, 1)] void main(uint3 blockIdx 92 | : SV_GroupID, uint3 threadIdx 93 | : SV_GroupThreadID) { 94 | #if NIS_SCALER 95 | NVScaler(blockIdx.xy, threadIdx.x); 96 | #else 97 | NVSharpen(blockIdx.xy, threadIdx.x); 98 | #endif 99 | } 100 | -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/VRS.hlsl: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Variable Rate Shading Compute Shader 4 | // Copyright(c) 2021-2022 Jean-Luc Dupiot - Reality XP 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files(the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and / or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions : 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 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 21 | // THE SOFTWARE. 22 | 23 | // clang-format off 24 | 25 | #ifndef VRS_TILE_X 26 | #define VRS_TILE_X 16 27 | #endif 28 | 29 | #ifndef VRS_TILE_Y 30 | #define VRS_TILE_Y 16 31 | #endif 32 | 33 | #ifndef VRS_NUM_RATES 34 | #define VRS_NUM_RATES 4 35 | #endif 36 | 37 | #ifndef VRS_DEFAULT_RATE 38 | #define VRS_DEFAULT_RATE 0 39 | #endif 40 | 41 | #ifndef VRS_USE_DIM_RATIO 42 | #define VRS_USE_DIM_RATIO 0 43 | #endif 44 | 45 | // Render up to 4 ellipses with their shading rates 46 | // Equation: x^2 / a^2 + y^2 / b^2 == 1 47 | // https://www.desmos.com/calculator/tevuazt8xl 48 | 49 | cbuffer cb : register(b0) 50 | { 51 | float4 Gaze; // ndc_x, ndc_y, 1/w, 1/h 52 | float4 Rings12; // 1/(a1^2), 1/(b1^2), 1/(a2^2), 1/(b2^2) 53 | float4 Rings34; // 1/(a3^2), 1/(b3^2), 1/(a4^2), 1/(b4^2) 54 | uint4 Rates; // r1, r2, r3, r4 55 | }; 56 | 57 | RWTexture2D u_Output : register(u0); 58 | 59 | [numthreads(VRS_NUM_THREADS_X, VRS_NUM_THREADS_Y, 1)] 60 | void mainCS(in int2 pos : SV_DispatchThreadID) { 61 | // screen space (w,h) to uv (0,1) 62 | float2 pos_uv = (pos + 0.5f) * Gaze.zw; 63 | 64 | // uv to ndc (y flip) 65 | float2 pos_xy = float2(2.0f,-2.0f) * pos_uv + float2(-1.0f,+1.0f); 66 | 67 | // ndc to gaze ndc 68 | pos_xy -= Gaze.xy; 69 | 70 | #if VRS_USE_DIM_RATIO 71 | // adjust ellipse scale with texture scale ratio 72 | // (w > h) ? scale x by w/h : scale y by h/w 73 | // (1/w < 1/h) ? scale x by (1/h)/(1/w) : scale y by (1/w)/(1/h) 74 | float2 scale = (Gaze.z < Gaze.w) ? float2(Gaze.w / Gaze.z, 1.0f) : float2(1.0f, Gaze.z / Gaze.w); 75 | pos_xy *= scale; 76 | #endif 77 | 78 | // Numerators (x^2, y^2) 79 | pos_xy *= pos_xy; 80 | 81 | uint rate; 82 | if (dot(pos_xy, Rings12.xy) <= 1.0f) rate = Rates.x; 83 | #if VRS_NUM_RATES >= 2 84 | else if (dot(pos_xy, Rings12.zw) <= 1.0f) rate = Rates.y; 85 | #if VRS_NUM_RATES >= 3 86 | else if (dot(pos_xy, Rings34.xy) <= 1.0f) rate = Rates.z; 87 | #if VRS_NUM_RATES >= 4 88 | else if (dot(pos_xy, Rings34.zw) <= 1.0f) rate = Rates.w; 89 | #endif 90 | #endif 91 | #endif 92 | else rate = VRS_DEFAULT_RATE; 93 | 94 | u_Output[pos] = min(u_Output[pos], rate); 95 | } 96 | 97 | // clang-format on 98 | -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/XR_APILAYER_MBUCCHIA_toolkit.json: -------------------------------------------------------------------------------- 1 | { 2 | "file_format_version" : "1.0.0", 3 | "api_layer": { 4 | "name": "XR_APILAYER_MBUCCHIA_toolkit", 5 | "library_path": ".\\XR_APILAYER_MBUCCHIA_toolkit.dll", 6 | "api_version": "1.0", 7 | "implementation_version": "1", 8 | "description": "OpenXR toolkit API layer", 9 | "functions": { 10 | "xrNegotiateLoaderApiLayerInterface": "xrNegotiateLoaderApiLayerInterface" 11 | }, 12 | "disable_environment": "DISABLE_XR_APILAYER_MBUCCHIA_toolkit" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/d3dcommon.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "pch.h" 4 | 5 | namespace toolkit::graphics::d3dcommon { 6 | struct ModelConstantBuffer { 7 | DirectX::XMFLOAT4X4 Model; 8 | }; 9 | 10 | struct ViewProjectionConstantBuffer { 11 | DirectX::XMFLOAT4X4 ViewProjection; 12 | }; 13 | 14 | const std::string_view MeshShaders = R"_( 15 | struct VSOutput { 16 | float4 Pos : SV_POSITION; 17 | float3 Color : COLOR0; 18 | }; 19 | struct VSInput { 20 | float3 Pos : POSITION; 21 | float3 Color : COLOR0; 22 | }; 23 | cbuffer ModelConstantBuffer : register(b0) { 24 | float4x4 Model; 25 | }; 26 | cbuffer ViewProjectionConstantBuffer : register(b1) { 27 | float4x4 ViewProjection; 28 | }; 29 | 30 | VSOutput vsMain(VSInput input) { 31 | VSOutput output; 32 | output.Pos = mul(mul(float4(input.Pos, 1), Model), ViewProjection); 33 | output.Color = input.Color; 34 | return output; 35 | } 36 | 37 | float4 psMain(VSOutput input) : SV_TARGET { 38 | return float4(input.Color, 1); 39 | } 40 | )_"; 41 | 42 | const std::string_view QuadVertexShader = R"_( 43 | void vsMain(in uint id : SV_VertexID, out float4 position : SV_Position, out float2 texcoord : TEXCOORD0) 44 | { 45 | texcoord = float2((id == 1) ? 2.0 : 0.0, (id == 2) ? 2.0 : 0.0); 46 | position = float4(texcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0); 47 | } 48 | )_"; 49 | } // namespace toolkit::graphics::d3dcommon 50 | -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/detours_helpers.h: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright(c) 2022 Matthieu Bucchianeri 4 | // Copyright(c) 2021-2022 Jean-Luc Dupiot - Reality XP 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this softwareand associated documentation files(the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and /or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions : 12 | // 13 | // The above copyright noticeand this permission notice shall be included in all 14 | // copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | // SOFTWARE. 23 | 24 | #pragma once 25 | 26 | // Helper to detour a function. 27 | template 28 | void DetourFunctionAttach(TMethod target, TMethod hooked, TMethod& original) { 29 | if (original) { 30 | // Already hooked. 31 | return; 32 | } 33 | 34 | DetourTransactionBegin(); 35 | DetourUpdateThread(GetCurrentThread()); 36 | 37 | original = target; 38 | DetourAttach((PVOID*)&original, hooked); 39 | 40 | CHECK_MSG(DetourTransactionCommit() == NO_ERROR, "Detour failed"); 41 | } 42 | 43 | template 44 | void DetourFunctionDetach(TMethod target, TMethod hooked, TMethod& original) { 45 | if (!original) { 46 | // Not hooked. 47 | return; 48 | } 49 | 50 | DetourTransactionBegin(); 51 | DetourUpdateThread(GetCurrentThread()); 52 | 53 | DetourDetach((PVOID*)&original, hooked); 54 | 55 | CHECK_MSG(DetourTransactionCommit() == NO_ERROR, "Detour failed"); 56 | 57 | original = nullptr; 58 | } 59 | 60 | // Helper to detour a function in a DLL. 61 | template 62 | void DetourDllAttach(const char* dll, const char* target, TMethod hooked, TMethod& original) { 63 | if (original) { 64 | // Already hooked. 65 | return; 66 | } 67 | 68 | HMODULE handle; 69 | CHECK_MSG(GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_PIN, dll, &handle), "Failed to get DLL handle"); 70 | 71 | DetourTransactionBegin(); 72 | DetourUpdateThread(GetCurrentThread()); 73 | 74 | original = (TMethod)GetProcAddress(handle, target); 75 | CHECK_MSG(original, "Failed to resolve symbol"); 76 | DetourAttach((PVOID*)&original, hooked); 77 | 78 | CHECK_MSG(DetourTransactionCommit() == NO_ERROR, "Detour failed"); 79 | } 80 | 81 | template 82 | void DetourDllDetach(const char* dll, const char* target, TMethod hooked, TMethod& original) { 83 | if (!original) { 84 | // Not hooked. 85 | return; 86 | } 87 | 88 | DetourTransactionBegin(); 89 | DetourUpdateThread(GetCurrentThread()); 90 | 91 | DetourDetach((PVOID*)&original, hooked); 92 | 93 | CHECK_MSG(DetourTransactionCommit() == NO_ERROR, "Detour failed"); 94 | 95 | original = nullptr; 96 | } 97 | 98 | // Helper to detour a class method. 99 | template 100 | void DetourMethodAttach(T* instance, unsigned int methodOffset, TMethod hooked, TMethod& original) { 101 | if (original) { 102 | // Already hooked. 103 | return; 104 | } 105 | 106 | LPVOID* vtable = *((LPVOID**)instance); 107 | LPVOID target = vtable[methodOffset]; 108 | 109 | DetourTransactionBegin(); 110 | DetourUpdateThread(GetCurrentThread()); 111 | 112 | original = (TMethod)target; 113 | DetourAttach((PVOID*)&original, hooked); 114 | 115 | CHECK_MSG(DetourTransactionCommit() == NO_ERROR, "Detour failed"); 116 | } 117 | 118 | template 119 | void DetourMethodDetach(T* instance, unsigned int methodOffset, TMethod hooked, TMethod& original) { 120 | if (!original) { 121 | // Not hooked. 122 | return; 123 | } 124 | 125 | LPVOID* vtable = *((LPVOID**)instance); 126 | LPVOID target = vtable[methodOffset]; 127 | 128 | DetourTransactionBegin(); 129 | DetourUpdateThread(GetCurrentThread()); 130 | 131 | DetourDetach((PVOID*)&original, hooked); 132 | 133 | CHECK_MSG(DetourTransactionCommit() == NO_ERROR, "Detour failed"); 134 | 135 | original = nullptr; 136 | } 137 | 138 | #define DECLARE_DETOUR_FUNCTION(ReturnType, Callconv, FunctionName, ...) \ 139 | inline ReturnType(Callconv* g_original_##FunctionName)(##__VA_ARGS__) = nullptr; \ 140 | ReturnType Callconv hooked_##FunctionName(##__VA_ARGS__) 141 | -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/framework/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/XR_APILAYER_MBUCCHIA_toolkit/framework/__init__.py -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/framework/dispatch.h: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright(c) 2021 Matthieu Bucchianeri 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this softwareand 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 noticeand 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. 22 | 23 | #pragma once 24 | 25 | #ifndef LAYER_NAMESPACE 26 | #error Must define LAYER_NAMESPACE 27 | #endif 28 | 29 | namespace LAYER_NAMESPACE { 30 | 31 | XrResult xrGetInstanceProcAddr(XrInstance instance, 32 | const char* name, 33 | PFN_xrVoidFunction* function); 34 | XrResult xrDestroyInstance(XrInstance instance); 35 | XrResult xrCreateApiLayerInstance(const XrInstanceCreateInfo* instanceCreateInfo, 36 | const struct XrApiLayerCreateInfo* apiLayerInfo, 37 | XrInstance* instance); 38 | 39 | } // namespace LAYER_NAMESPACE 40 | -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/framework/entry.cpp: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright(c) 2021-2022 Matthieu Bucchianeri 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this softwareand 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 noticeand 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. 22 | 23 | #include "pch.h" 24 | 25 | #include 26 | 27 | #include "dispatch.h" 28 | #include "log.h" 29 | 30 | #ifndef LAYER_NAMESPACE 31 | #error Must define LAYER_NAMESPACE 32 | #endif 33 | 34 | namespace LAYER_NAMESPACE { 35 | // The path where the DLL loads config files and stores logs. 36 | std::filesystem::path dllHome; 37 | 38 | // The path to store logs & others. 39 | std::filesystem::path localAppData; 40 | 41 | namespace log { 42 | // The file logger. 43 | std::ofstream logStream; 44 | } // namespace log 45 | } // namespace LAYER_NAMESPACE 46 | 47 | using namespace LAYER_NAMESPACE; 48 | using namespace LAYER_NAMESPACE::log; 49 | 50 | extern "C" { 51 | 52 | // Entry point for the loader. 53 | XrResult __declspec(dllexport) XRAPI_CALL 54 | xrNegotiateLoaderApiLayerInterface(const XrNegotiateLoaderInfo* const loaderInfo, 55 | const char* const apiLayerName, 56 | XrNegotiateApiLayerRequest* const apiLayerRequest) { 57 | TraceLocalActivity(local); 58 | TraceLoggingWriteStart(local, "xrNegotiateLoaderApiLayerInterface"); 59 | 60 | // Retrieve the path of the DLL. 61 | if (dllHome.empty()) { 62 | HMODULE module; 63 | if (GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, 64 | (LPCSTR)&dllHome, 65 | &module)) { 66 | char path[_MAX_PATH]; 67 | GetModuleFileNameA(module, path, sizeof(path)); 68 | dllHome = std::filesystem::path(path).parent_path(); 69 | } else { 70 | // Falling back to loading config/writing logs to the current working directory. 71 | DebugLog("Failed to locate DLL\n"); 72 | } 73 | } 74 | 75 | // Create the necessary subfolders in LocalAppData (if they don't exist). 76 | localAppData = std::filesystem::path(getenv("LOCALAPPDATA")) / LayerPrettyName; 77 | CreateDirectoryA(localAppData.string().c_str(), nullptr); 78 | CreateDirectoryA((localAppData / "logs").string().c_str(), nullptr); 79 | CreateDirectoryA((localAppData / "stats").string().c_str(), nullptr); 80 | CreateDirectoryA((localAppData / "screenshots").string().c_str(), nullptr); 81 | CreateDirectoryA((localAppData / "configs").string().c_str(), nullptr); 82 | 83 | // Start logging to file. 84 | if (!logStream.is_open()) { 85 | std::string logFile = (localAppData / "logs" / (LayerName + ".log")).string(); 86 | logStream.open(logFile, std::ios_base::ate); 87 | } 88 | 89 | Log("%s\n", LayerPrettyNameFull.c_str()); 90 | Log("dllHome is \"%s\"\n", dllHome.string().c_str()); 91 | 92 | // Initialize Detours early on. 93 | DetourRestoreAfterWith(); 94 | 95 | if (apiLayerName && apiLayerName != LayerName) { 96 | Log("Invalid apiLayerName \"%s\"\n", apiLayerName); 97 | return XR_ERROR_INITIALIZATION_FAILED; 98 | } 99 | 100 | if (!loaderInfo || !apiLayerRequest || loaderInfo->structType != XR_LOADER_INTERFACE_STRUCT_LOADER_INFO || 101 | loaderInfo->structVersion != XR_LOADER_INFO_STRUCT_VERSION || 102 | loaderInfo->structSize != sizeof(XrNegotiateLoaderInfo) || 103 | apiLayerRequest->structType != XR_LOADER_INTERFACE_STRUCT_API_LAYER_REQUEST || 104 | apiLayerRequest->structVersion != XR_API_LAYER_INFO_STRUCT_VERSION || 105 | apiLayerRequest->structSize != sizeof(XrNegotiateApiLayerRequest) || 106 | loaderInfo->minInterfaceVersion > XR_CURRENT_LOADER_API_LAYER_VERSION || 107 | loaderInfo->maxInterfaceVersion < XR_CURRENT_LOADER_API_LAYER_VERSION || 108 | loaderInfo->maxInterfaceVersion > XR_CURRENT_LOADER_API_LAYER_VERSION || 109 | loaderInfo->maxApiVersion < XR_CURRENT_API_VERSION || loaderInfo->minApiVersion > XR_CURRENT_API_VERSION) { 110 | Log("xrNegotiateLoaderApiLayerInterface validation failed\n"); 111 | return XR_ERROR_INITIALIZATION_FAILED; 112 | } 113 | 114 | // Setup our layer to intercept OpenXR calls. 115 | apiLayerRequest->layerInterfaceVersion = XR_CURRENT_LOADER_API_LAYER_VERSION; 116 | apiLayerRequest->layerApiVersion = XR_CURRENT_API_VERSION; 117 | apiLayerRequest->getInstanceProcAddr = reinterpret_cast(xrGetInstanceProcAddr); 118 | apiLayerRequest->createApiLayerInstance = reinterpret_cast(xrCreateApiLayerInstance); 119 | 120 | Log("%s layer is active\n", LayerPrettyName.c_str()); 121 | 122 | TraceLoggingWriteStop(local, "xrNegotiateLoaderApiLayerInterface"); 123 | 124 | return XR_SUCCESS; 125 | } 126 | 127 | __declspec(dllexport) const char* WINAPI getVersionString() { 128 | return LayerPrettyNameFull.c_str(); 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/framework/layer_apis.py: -------------------------------------------------------------------------------- 1 | # The list of OpenXR functions our layer will override. 2 | override_functions = [ 3 | "xrGetSystem", 4 | "xrEnumerateViewConfigurationViews", 5 | "xrCreateSession", 6 | "xrBeginSession", 7 | "xrEndSession", 8 | "xrDestroySession", 9 | "xrCreateSwapchain", 10 | "xrDestroySwapchain", 11 | "xrSuggestInteractionProfileBindings", 12 | "xrCreateAction", 13 | "xrDestroyAction", 14 | "xrCreateActionSpace", 15 | "xrDestroySpace", 16 | "xrAttachSessionActionSets", 17 | "xrEnumerateSwapchainImages", 18 | "xrWaitSwapchainImage", 19 | "xrAcquireSwapchainImage", 20 | "xrReleaseSwapchainImage", 21 | "xrPollEvent", 22 | "xrGetCurrentInteractionProfile", 23 | "xrLocateViews", 24 | "xrLocateSpace", 25 | "xrSyncActions", 26 | "xrGetActionStateBoolean", 27 | "xrGetActionStateFloat", 28 | "xrGetActionStatePose", 29 | "xrApplyHapticFeedback", 30 | "xrStopHapticFeedback", 31 | "xrWaitFrame", 32 | "xrBeginFrame", 33 | "xrEndFrame", 34 | "xrGetVisibilityMaskKHR", 35 | ] 36 | 37 | # The list of OpenXR functions our layer will use from the runtime. 38 | # Might repeat entries from override_functions above. 39 | requested_functions = [ 40 | "xrGetSystem", 41 | "xrGetInstanceProperties", 42 | "xrGetSystemProperties", 43 | "xrEnumerateViewConfigurationViews", 44 | "xrEnumerateSwapchainFormats", 45 | "xrCreateSwapchain", 46 | "xrEnumerateSwapchainImages", 47 | "xrWaitSwapchainImage", 48 | "xrAcquireSwapchainImage", 49 | "xrReleaseSwapchainImage", 50 | "xrCreateActionSet", 51 | "xrDestroyActionSet", 52 | "xrCreateAction", 53 | "xrDestroyAction", 54 | "xrCreateActionSpace", 55 | "xrCreateReferenceSpace", 56 | "xrDestroySpace", 57 | "xrLocateSpace", 58 | "xrSyncActions", 59 | "xrGetActionStatePose", 60 | "xrPathToString", 61 | "xrStringToPath", 62 | "xrConvertWin32PerformanceCounterToTimeKHR", 63 | "xrCreateHandTrackerEXT", 64 | "xrDestroyHandTrackerEXT", 65 | "xrLocateHandJointsEXT", 66 | "xrGetVisibilityMaskKHR", 67 | ] 68 | 69 | extensions_to_search = ["XR_KHR_visibility_mask", "XR_KHR_win32_convert_performance_counter_time", "XR_EXT_hand_tracking"] 70 | -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/layer.h: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright(c) 2021-2022 Matthieu Bucchianeri 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this softwareand 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 noticeand 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. 22 | 23 | #pragma once 24 | 25 | #include "framework/dispatch.gen.h" 26 | 27 | namespace toolkit { 28 | 29 | const std::string LayerPrettyName = "OpenXR-Toolkit"; 30 | const std::string LayerPrettyNameFull = "OpenXR Toolkit - Unreleased (v0.0.0)"; 31 | 32 | const std::string LayerName = "XR_APILAYER_MBUCCHIA_toolkit"; 33 | const std::string VersionString = "Unreleased"; 34 | const std::string RegPrefix = "SOFTWARE\\OpenXR_Toolkit"; 35 | 36 | // Singleton accessor. 37 | OpenXrApi* GetInstance(); 38 | 39 | // A function to reset (delete) the singleton. 40 | void ResetInstance(); 41 | 42 | extern std::filesystem::path dllHome; 43 | extern std::filesystem::path localAppData; 44 | 45 | } // namespace toolkit 46 | -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/log.cpp: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright(c) 2021-2022 Matthieu Bucchianeri 4 | // Copyright(c) 2021-2022 Jean-Luc Dupiot - Reality XP 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this softwareand associated documentation files(the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and /or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions : 12 | // 13 | // The above copyright noticeand this permission notice shall be included in all 14 | // copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | // SOFTWARE. 23 | 24 | #include "pch.h" 25 | 26 | #include "log.h" 27 | 28 | namespace toolkit::log { 29 | extern std::ofstream logStream; 30 | 31 | // {cbf3adcd-42b1-4c38-830b-91980af201f5} 32 | TRACELOGGING_DEFINE_PROVIDER(g_traceProvider, 33 | "OpenXRToolkit", 34 | (0xcbf3adcd, 0x42b1, 0x4c38, 0x83, 0x0b, 0x91, 0x98, 0x0a, 0xf2, 0x01, 0xf5)); 35 | 36 | TraceLoggingActivity g_traceActivity; 37 | 38 | namespace { 39 | 40 | // Utility logging function. 41 | void InternalLog(const char* fmt, va_list va) { 42 | const std::time_t now = std::time(nullptr); 43 | 44 | char buf[1024]; 45 | size_t offset = std::strftime(buf, sizeof(buf), "[OXRTK] %Y-%m-%d %H:%M:%S %z: ", std::localtime(&now)); 46 | vsnprintf_s(buf + offset, sizeof(buf) - offset, _TRUNCATE, fmt, va); 47 | OutputDebugStringA(buf); 48 | if (logStream.is_open()) { 49 | logStream << buf; 50 | logStream.flush(); 51 | } 52 | } 53 | } // namespace 54 | 55 | void Log(const char* fmt, ...) { 56 | va_list va; 57 | va_start(va, fmt); 58 | InternalLog(fmt, va); 59 | va_end(va); 60 | } 61 | 62 | void DebugLog(const char* fmt, ...) { 63 | #ifdef _DEBUG 64 | va_list va; 65 | va_start(va, fmt); 66 | InternalLog(fmt, va); 67 | va_end(va); 68 | #endif 69 | } 70 | 71 | } // namespace toolkit::log 72 | -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/log.h: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright(c) 2021 Matthieu Bucchianeri 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this softwareand 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 noticeand 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. 22 | 23 | #pragma once 24 | 25 | #include "pch.h" 26 | 27 | namespace xr { 28 | static inline std::string ToString(XrVersion version) { 29 | return fmt::format("{}.{}.{}", XR_VERSION_MAJOR(version), XR_VERSION_MINOR(version), XR_VERSION_PATCH(version)); 30 | } 31 | 32 | static inline std::string ToString(XrPosef pose) { 33 | return fmt::format("p: ({:.3f}, {:.3f}, {:.3f}), o:({:.3f}, {:.3f}, {:.3f}, {:.3f})", 34 | pose.position.x, 35 | pose.position.y, 36 | pose.position.z, 37 | pose.orientation.x, 38 | pose.orientation.y, 39 | pose.orientation.z, 40 | pose.orientation.w); 41 | } 42 | 43 | static inline std::string ToString(XrVector3f vec) { 44 | return fmt::format("({:.3f}, {:.3f}, {:.3f})", vec.x, vec.y, vec.z); 45 | } 46 | 47 | static inline std::string ToString(XrFovf fov) { 48 | return fmt::format( 49 | "(l:{:.3f}, r:{:.3f}, u:{:.3f}, d:{:.3f})", fov.angleLeft, fov.angleRight, fov.angleUp, fov.angleDown); 50 | } 51 | 52 | static inline std::string ToString(XrRect2Di rect) { 53 | return fmt::format("x:{}, y:{} w:{} h:{}", rect.offset.x, rect.offset.y, rect.extent.width, rect.extent.height); 54 | } 55 | } 56 | 57 | namespace toolkit::log { 58 | 59 | TRACELOGGING_DECLARE_PROVIDER(g_traceProvider); 60 | 61 | extern TraceLoggingActivity g_traceGlobal; 62 | 63 | #define IsTraceEnabled() TraceLoggingProviderEnabled(g_traceProvider, 0, 0) 64 | 65 | #define TraceLocalActivity(activity) TraceLoggingActivity activity; 66 | 67 | #define TLArg(var, ...) TraceLoggingValue(var, ##__VA_ARGS__) 68 | #define TLPArg(var, ...) TraceLoggingValue(fmt::format("0x{:08x}", (uintptr_t)(var)).c_str(), ##__VA_ARGS__) 69 | 70 | // General logging function. 71 | void Log(const char* fmt, ...); 72 | 73 | // Debug logging function. Can make things very slow (only enabled on Debug builds). 74 | void DebugLog(const char* fmt, ...); 75 | 76 | } // namespace toolkit::log 77 | -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/pch.cpp: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright(c) 2021 Matthieu Bucchianeri 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this softwareand 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 noticeand 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. 22 | 23 | #include "pch.h" 24 | -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/pch.h: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright(c) 2021-2022 Matthieu Bucchianeri 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this softwareand 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 noticeand 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. 22 | 23 | #pragma once 24 | 25 | // Standard library. 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #define _USE_MATH_DEFINES 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | using namespace std::chrono_literals; 51 | 52 | // Windows header files. 53 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 54 | #define NOMINMAX 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | 62 | using Microsoft::WRL::ComPtr; 63 | 64 | // Helpers for ComPtr manipulation. 65 | 66 | template 67 | inline T* get(const ComPtr& object) { 68 | return object.Get(); 69 | } 70 | 71 | template 72 | inline T** set(ComPtr& object) { 73 | return object.ReleaseAndGetAddressOf(); 74 | } 75 | 76 | template 77 | void attach(ComPtr& object, T* value) { 78 | object.Attach(value); 79 | } 80 | 81 | template 82 | T* detach(ComPtr& object) { 83 | return object.Detach(); 84 | } 85 | 86 | template 87 | constexpr inline T alignTo(T value, uint32_t pad) noexcept { 88 | //assert(pad && !(pad & (pad - 1))); 89 | return (value + (pad - 1)) & ~static_cast(pad - 1); 90 | } 91 | 92 | template 93 | constexpr inline T roundUp(T value, uint32_t pad) noexcept { 94 | return ((value + (pad - 1)) / pad) * pad; 95 | } 96 | 97 | template 98 | constexpr inline T roundDown(T value, uint32_t pad) noexcept { 99 | return (value / pad) * pad; 100 | } 101 | 102 | // ETL tracing 103 | #include 104 | #include 105 | 106 | // Direct3D. 107 | #include 108 | #include 109 | #include 110 | #include 111 | #include 112 | #include 113 | 114 | // OpenXR + Windows-specific definitions. 115 | #define XR_NO_PROTOTYPES 116 | #define XR_USE_PLATFORM_WIN32 117 | #define XR_USE_GRAPHICS_API_D3D11 118 | #define XR_USE_GRAPHICS_API_D3D12 119 | #include 120 | #include 121 | 122 | // Oculus definitions. 123 | #include 124 | 125 | // OpenXR loader interfaces. 126 | #include 127 | 128 | // OpenXR utilities. 129 | #include 130 | #include 131 | #define xrStringToPath(...) XR_SUCCESS 132 | #define xrPathToString(...) XR_SUCCESS 133 | #include 134 | #undef xrStringToPath 135 | #undef xrPathToString 136 | 137 | // FW1FontWrapper. 138 | #include 139 | 140 | // FMT formatter. 141 | #include 142 | 143 | // Detours 144 | #include 145 | #include "detours_helpers.h" 146 | 147 | // NVAPI SDK. 148 | #include 149 | 150 | // Omnicept SDK. 151 | #include 152 | 153 | // Pimax eye tracker SDK. 154 | #include 155 | #include 156 | #include 157 | -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/resource.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/XR_APILAYER_MBUCCHIA_toolkit/resource.aps -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by resource.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/resource.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 2 resource. 9 | // 10 | #include "winres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (United States) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 20 | #pragma code_page(1252) 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Version 51 | // 52 | 53 | VS_VERSION_INFO VERSIONINFO 54 | FILEVERSION 1,0,0,0 55 | PRODUCTVERSION 1,0,0,0 56 | FILEFLAGSMASK 0x3fL 57 | #ifdef _DEBUG 58 | FILEFLAGS 0x1L 59 | #else 60 | FILEFLAGS 0x0L 61 | #endif 62 | FILEOS 0x40004L 63 | FILETYPE 0x2L 64 | FILESUBTYPE 0x0L 65 | BEGIN 66 | BLOCK "StringFileInfo" 67 | BEGIN 68 | BLOCK "040904b0" 69 | BEGIN 70 | VALUE "FileVersion", "1.0.0.0" 71 | VALUE "InternalName", "XR_APILAYER_MBUCCHIA_toolkit.dll" 72 | VALUE "LegalCopyright", "Copyright �2021-2022 Matthieu Bucchianeri, Jean-Luc Dupiot" 73 | VALUE "OriginalFilename", "XR_APILAYER_MBUCCHIA_toolkit.dll" 74 | VALUE "ProductName", "OpenXR-Toolkit" 75 | VALUE "ProductVersion", "1.0.0.0" 76 | END 77 | END 78 | BLOCK "VarFileInfo" 79 | BEGIN 80 | VALUE "Translation", 0x409, 1200 81 | END 82 | END 83 | 84 | #endif // English (United States) resources 85 | ///////////////////////////////////////////////////////////////////////////// 86 | 87 | 88 | 89 | #ifndef APSTUDIO_INVOKED 90 | ///////////////////////////////////////////////////////////////////////////// 91 | // 92 | // Generated from the TEXTINCLUDE 3 resource. 93 | // 94 | 95 | 96 | ///////////////////////////////////////////////////////////////////////////// 97 | #endif // not APSTUDIO_INVOKED 98 | 99 | -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/shader_utilities.h: -------------------------------------------------------------------------------- 1 | // From https://github.com/NVIDIAGameWorks/NVIDIAImageScaling/blob/main/samples/DX11/include/DXUtilities.h 2 | 3 | // The MIT License(MIT) 4 | // 5 | // Copyright(c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files(the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions : 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | #pragma once 25 | 26 | #include "log.h" 27 | 28 | namespace toolkit::utilities::shader { 29 | 30 | using namespace toolkit::log; 31 | 32 | void CompileShader(const std::filesystem::path& shaderFile, 33 | const char* entryPoint, 34 | ID3DBlob** blob, 35 | const D3D_SHADER_MACRO* defines = nullptr, 36 | ID3DInclude* includes = nullptr, 37 | const char* target = "cs_5_0"); 38 | 39 | void CompileShader(const void* data, 40 | size_t size, 41 | const char* entryPoint, 42 | ID3DBlob** blob, 43 | const D3D_SHADER_MACRO* defines = nullptr, 44 | ID3DInclude* includes = nullptr, 45 | const char* target = "cs_5_0"); 46 | 47 | inline void CompileShader(std::string_view code, const char* entryPoint, ID3DBlob** blob, const char* target) { 48 | CompileShader(code.data(), code.size(), entryPoint, blob, nullptr, nullptr, target); 49 | } 50 | 51 | struct IncludeHeader : ID3DInclude { 52 | IncludeHeader(std::vector includePaths) : m_includePaths(std::move(includePaths)) { 53 | } 54 | 55 | HRESULT 56 | Open(D3D_INCLUDE_TYPE includeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID* ppData, UINT* pBytes); 57 | HRESULT Close(LPCVOID pData); 58 | 59 | std::vector> m_data; 60 | std::vector m_includePaths; 61 | }; 62 | 63 | namespace { 64 | template 65 | inline std::string toStr(T value) { 66 | return std::to_string(value); 67 | } 68 | 69 | template <> 70 | inline std::string toStr(bool value) { 71 | return value ? "1" : "0"; 72 | } 73 | 74 | template <> 75 | inline std::string toStr(std::string value) { 76 | return value; 77 | } 78 | 79 | template <> 80 | inline std::string toStr(const char* value) { 81 | return value; 82 | } 83 | } // namespace 84 | 85 | class Defines { 86 | public: 87 | template 88 | void add(const std::string& define, const T& val) { 89 | m_definesVector.push_back({define, toStr(val)}); 90 | } 91 | template 92 | void set(const std::string& define, const T& val) { 93 | auto it = std::find_if(m_definesVector.begin(), m_definesVector.end(), [&](const auto& entry) { 94 | return entry.first == define; 95 | }); 96 | if (it != m_definesVector.end()) 97 | it->second = toStr(val); 98 | } 99 | const D3D_SHADER_MACRO* get() const; 100 | 101 | private: 102 | std::vector> m_definesVector; 103 | mutable std::unique_ptr m_defines; 104 | }; 105 | 106 | } // namespace toolkit::utilities::shader 107 | -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/utils/ScreenGrab11.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: ScreenGrab11.h 3 | // 4 | // Function for capturing a 2D texture and saving it to a file (aka a 'screenshot' 5 | // when used on a Direct3D 11 Render Target). 6 | // 7 | // Note these functions are useful as a light-weight runtime screen grabber. For 8 | // full-featured texture capture, DDS writer, and texture processing pipeline, 9 | // see the 'Texconv' sample and the 'DirectXTex' library. 10 | // 11 | // Copyright (c) Microsoft Corporation. 12 | // Licensed under the MIT License. 13 | // 14 | // http://go.microsoft.com/fwlink/?LinkId=248926 15 | // http://go.microsoft.com/fwlink/?LinkId=248929 16 | //-------------------------------------------------------------------------------------- 17 | 18 | #pragma once 19 | 20 | #include 21 | 22 | #ifdef NTDDI_WIN10_FE 23 | #include 24 | #else 25 | #include 26 | #endif 27 | 28 | #include 29 | 30 | 31 | namespace DirectX 32 | { 33 | HRESULT __cdecl SaveDDSTextureToFile( 34 | _In_ ID3D11DeviceContext* pContext, 35 | _In_ ID3D11Resource* pSource, 36 | _In_z_ const wchar_t* fileName) noexcept; 37 | 38 | HRESULT __cdecl SaveWICTextureToFile( 39 | _In_ ID3D11DeviceContext* pContext, 40 | _In_ ID3D11Resource* pSource, 41 | _In_ REFGUID guidContainerFormat, 42 | _In_z_ const wchar_t* fileName, 43 | _In_opt_ const GUID* targetFormat = nullptr, 44 | _In_opt_ std::function setCustomProps = nullptr, 45 | _In_ bool forceSRGB = false); 46 | } 47 | -------------------------------------------------------------------------------- /XR_APILAYER_MBUCCHIA_toolkit/utils/ScreenGrab12.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: ScreenGrab12.h 3 | // 4 | // Function for capturing a 2D texture and saving it to a file (aka a 'screenshot' 5 | // when used on a Direct3D 12 Render Target). 6 | // 7 | // Note these functions are useful as a light-weight runtime screen grabber. For 8 | // full-featured texture capture, DDS writer, and texture processing pipeline, 9 | // see the 'Texconv' sample and the 'DirectXTex' library. 10 | // 11 | // Copyright (c) Microsoft Corporation. 12 | // Licensed under the MIT License. 13 | // 14 | // http://go.microsoft.com/fwlink/?LinkId=248926 15 | // http://go.microsoft.com/fwlink/?LinkID=615561 16 | //-------------------------------------------------------------------------------------- 17 | 18 | #pragma once 19 | 20 | #ifdef WIN32 21 | #include 22 | 23 | #ifdef NTDDI_WIN10_FE 24 | #include 25 | #else 26 | #include 27 | #endif 28 | 29 | #include 30 | #else 31 | #include 32 | #include 33 | #include 34 | #endif 35 | 36 | 37 | namespace DirectX 38 | { 39 | HRESULT __cdecl SaveDDSTextureToFile( 40 | _In_ ID3D12CommandQueue* pCommandQueue, 41 | _In_ ID3D12Resource* pSource, 42 | _In_z_ const wchar_t* fileName, 43 | D3D12_RESOURCE_STATES beforeState = D3D12_RESOURCE_STATE_RENDER_TARGET, 44 | D3D12_RESOURCE_STATES afterState = D3D12_RESOURCE_STATE_RENDER_TARGET) noexcept; 45 | 46 | #ifdef WIN32 47 | HRESULT __cdecl SaveWICTextureToFile( 48 | _In_ ID3D12CommandQueue* pCommandQ, 49 | _In_ ID3D12Resource* pSource, 50 | REFGUID guidContainerFormat, 51 | _In_z_ const wchar_t* fileName, 52 | D3D12_RESOURCE_STATES beforeState = D3D12_RESOURCE_STATE_RENDER_TARGET, 53 | D3D12_RESOURCE_STATES afterState = D3D12_RESOURCE_STATE_RENDER_TARGET, 54 | _In_opt_ const GUID* targetFormat = nullptr, 55 | _In_opt_ std::function setCustomProps = nullptr, 56 | bool forceSRGB = false); 57 | #endif 58 | } 59 | -------------------------------------------------------------------------------- /companion/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /companion/CustomSetupActions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Configuration; 6 | using System.IO; 7 | using System.Windows.Forms; 8 | 9 | // Reference: https://www.c-sharpcorner.com/article/how-to-perform-custom-actions-and-upgrade-using-visual-studio-installer/ 10 | namespace SetupCustomActions 11 | { 12 | [RunInstaller(true)] 13 | public partial class CustomActions : System.Configuration.Install.Installer 14 | { 15 | public CustomActions() 16 | { 17 | } 18 | 19 | protected override void OnAfterInstall(IDictionary savedState) 20 | { 21 | var installPath = Path.GetDirectoryName(base.Context.Parameters["AssemblyPath"]); 22 | var jsonName = "XR_APILAYER_MBUCCHIA_toolkit.json"; 23 | var jsonPath = installPath + "\\" + jsonName; 24 | 25 | // We want to add our layer at the very beginning, so that any other layer like the Ultraleap layer is following us. 26 | // We delete all entries, create our own, and recreate all entries. 27 | 28 | Microsoft.Win32.RegistryKey key; 29 | key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("SOFTWARE\\Khronos\\OpenXR\\1\\ApiLayers\\Implicit"); 30 | var existingValues = key.GetValueNames(); 31 | var entriesValues = new Dictionary(); 32 | foreach (var value in existingValues) 33 | { 34 | // Leave the layers that we want to be upstream of us. 35 | if (value.EndsWith("\\XR_APILAYER_MBUCCHIA_vulkan_d3d12_interop.json") || 36 | value.EndsWith("\\XR_APILAYER_NOVENDOR_vulkan_d3d12_interop.json") || 37 | value.EndsWith("OpenXR-Meta-Foveated\\openxr-api-layer.json") || 38 | value.EndsWith("OpenXR-Quad-Views-Foveated\\openxr-api-layer.json")) 39 | { 40 | continue; 41 | } 42 | 43 | var keyValue = key.GetValue(value); 44 | var valueKind = key.GetValueKind(value); 45 | key.DeleteValue(value); 46 | 47 | // Some installers might have created bogus keys: https://github.com/KhronosGroup/OpenXR-SDK-Source/issues/335. 48 | // Make sure we don't re-create them. 49 | if (valueKind != Microsoft.Win32.RegistryValueKind.DWord) 50 | { 51 | continue; 52 | } 53 | 54 | entriesValues.Add(value, keyValue); 55 | } 56 | 57 | bool detectedOldSoftware = false; 58 | key.SetValue(jsonPath, 0); 59 | foreach (var value in existingValues) 60 | { 61 | // Do not re-create keys for previous versions of our layer. 62 | if (value.EndsWith("\\XR_APILAYER_NOVENDOR_nis_scaler.json") || 63 | value.EndsWith("\\XR_APILAYER_NOVENDOR_hand_to_controller.json")) 64 | { 65 | detectedOldSoftware = true; 66 | continue; 67 | } 68 | 69 | // Do not re-create our own key. We did it before this loop. 70 | if (value.EndsWith("\\" + jsonName) || 71 | value.EndsWith("\\XR_APILAYER_NOVENDOR_toolkit.json")) 72 | { 73 | continue; 74 | } 75 | 76 | // Skip keys that we did not delete. 77 | if (!entriesValues.ContainsKey(value)) 78 | { 79 | continue; 80 | } 81 | 82 | key.SetValue(value, entriesValues[value]); 83 | } 84 | 85 | key.Close(); 86 | 87 | try 88 | { 89 | key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("SOFTWARE\\OpenXR_Toolkit"); 90 | 91 | // Force showing the splash again after re-install. 92 | var gen = key.GetValue("key_menu_gen", null); 93 | if (gen != null) 94 | { 95 | key.SetValue("key_menu_gen", (int)gen + 1); 96 | } 97 | } 98 | catch (Exception) 99 | { 100 | } 101 | finally 102 | { 103 | key.Close(); 104 | } 105 | 106 | if (detectedOldSoftware) 107 | { 108 | MessageBox.Show("An older version of this software was detected (OpenXR-NIS-Scaler or OpenXR-Hand-To-Controller). " + 109 | "It was deactivated, however please uninstall it through 'Add or remove programs' to free up disk space.", 110 | "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); 111 | } 112 | 113 | base.OnAfterInstall(savedState); 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /companion/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("OpenXR Toolkit Companion app")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("OpenXR-Toolkit")] 13 | [assembly: AssemblyCopyright("Copyright ©2021-2022 Matthieu Bucchianeri")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("69c43742-d646-44b8-a869-3d8016d525ce")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /companion/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace companion.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("companion.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized resource of type System.Drawing.Bitmap. 65 | /// 66 | internal static System.Drawing.Bitmap banner { 67 | get { 68 | object obj = ResourceManager.GetObject("banner", resourceCulture); 69 | return ((System.Drawing.Bitmap)(obj)); 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /companion/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | 12 | namespace companion.Properties 13 | { 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 17 | { 18 | 19 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 20 | 21 | public static Settings Default 22 | { 23 | get 24 | { 25 | return defaultInstance; 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /companion/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /companion/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/companion/banner.png -------------------------------------------------------------------------------- /companion/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/companion/icon.ico -------------------------------------------------------------------------------- /companion/openxr_loader.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/companion/openxr_loader.dll -------------------------------------------------------------------------------- /companion/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /external/FB/openxr/fb_eye_tracking_social.h: -------------------------------------------------------------------------------- 1 | // (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. 2 | 3 | /************************************************************************************ 4 | Filename : fb_eye_tracking.h 5 | Content : Eye tracking APIs. 6 | Language : C99 7 | *************************************************************************************/ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | /* 15 | 203 XR_FB_eye_tracking_social 16 | */ 17 | 18 | #if defined(__cplusplus) 19 | extern "C" { 20 | #endif 21 | 22 | #ifndef XR_FB_eye_tracking_social 23 | #define XR_FB_eye_tracking_social 1 24 | 25 | #define XR_FB_eye_tracking_social_SPEC_VERSION 1 26 | #define XR_FB_EYE_TRACKING_SOCIAL_EXTENSION_NAME "XR_FB_eye_tracking_social" 27 | 28 | XR_DEFINE_HANDLE(XrEyeTrackerFB) 29 | XR_STRUCT_ENUM(XR_TYPE_EYE_TRACKER_CREATE_INFO_FB, 1000202001); 30 | XR_STRUCT_ENUM(XR_TYPE_EYE_GAZES_INFO_FB, 1000202002); 31 | XR_STRUCT_ENUM(XR_TYPE_EYE_GAZES_FB, 1000202003); 32 | 33 | XR_STRUCT_ENUM(XR_TYPE_SYSTEM_EYE_TRACKING_PROPERTIES_FB, 1000202004); 34 | 35 | typedef struct XrSystemEyeTrackingPropertiesFB { 36 | XrStructureType type; 37 | void* XR_MAY_ALIAS next; 38 | XrBool32 supportsEyeTracking; 39 | } XrSystemEyeTrackingPropertiesFB; 40 | 41 | typedef struct XrEyeTrackerCreateInfoFB { 42 | XrStructureType type; 43 | const void* XR_MAY_ALIAS next; 44 | } XrEyeTrackerCreateInfoFB; 45 | 46 | typedef struct XrEyeGazesInfoFB { 47 | XrStructureType type; 48 | const void* XR_MAY_ALIAS next; 49 | XrSpace baseSpace; 50 | XrTime time; 51 | } XrEyeGazesInfoFB; 52 | 53 | typedef struct XrEyeGazeFB { 54 | XrBool32 isValid; 55 | XrPosef gazePose; 56 | float gazeConfidence; 57 | } XrEyeGazeFB; 58 | #define XrEyeGazeV2FB XrEyeGazeFB 59 | 60 | typedef enum XrEyePositionFB { 61 | XR_EYE_POSITION_LEFT_FB = 0, 62 | XR_EYE_POSITION_RIGHT_FB = 1, 63 | XR_EYE_POSITION_COUNT_FB = 2, 64 | XR_EYE_POSITION_MAX_ENUM_FB = 0x7FFFFFFF 65 | } XrEyePositionFB; 66 | 67 | typedef struct XrEyeGazesFB { 68 | XrStructureType type; 69 | void* XR_MAY_ALIAS next; 70 | XrEyeGazeFB gaze[2]; 71 | XrTime time; 72 | } XrEyeGazesFB; 73 | 74 | typedef XrResult(XRAPI_PTR* PFN_xrCreateEyeTrackerFB)( 75 | XrSession session, 76 | const XrEyeTrackerCreateInfoFB* createInfo, 77 | XrEyeTrackerFB* eyeTracker); 78 | typedef XrResult(XRAPI_PTR* PFN_xrDestroyEyeTrackerFB)(XrEyeTrackerFB eyeTracker); 79 | typedef XrResult(XRAPI_PTR* PFN_xrGetEyeGazesFB)( 80 | XrEyeTrackerFB eyeTracker, 81 | const XrEyeGazesInfoFB* gazeInfo, 82 | XrEyeGazesFB* eyeGazes); 83 | 84 | #endif // XR_FB_eye_tracking 85 | 86 | // ============================================================================ 87 | // Begin Backwards Compatibility (DEPRECATED) 88 | // ============================================================================ 89 | 90 | #ifndef XR_FBX_eye_tracking 91 | #define XR_FBX_eye_tracking 1 92 | 93 | #if defined(XR_FB_eye_tracking_EXPERIMENTAL_VERSION) 94 | #error "the XR_FB_eye_tracking_EXPERIMENTAL_VERSION is no more supported." 95 | #endif 96 | 97 | #if defined(XR_FB_eye_tracking_social_EXPERIMENTAL_VERSION) && \ 98 | (XR_FB_eye_tracking_social_EXPERIMENTAL_VERSION != 1) 99 | #error "unknown experimental version number for XR_FB_eye_tracking_social_EXPERIMENTAL_VERSION" 100 | #endif 101 | 102 | #define XR_FBX1_eye_tracking_SPEC_VERSION 1 103 | #define XR_FBX1_EYE_TRACKING_EXTENSION_NAME "XR_FBX1_eye_tracking" 104 | #define XR_FBX1_eye_tracking_social_SPEC_VERSION 1 105 | #define XR_FBX1_EYE_TRACKING_SOCIAL_EXTENSION_NAME "XR_FBX1_eye_tracking_social" 106 | 107 | #if defined(XR_FB_eye_tracking_social_EXPERIMENTAL_VERSION) && \ 108 | (XR_FB_eye_tracking_social_EXPERIMENTAL_VERSION == 1) 109 | #undef XR_FB_eye_tracking_social_SPEC_VERSION 110 | #undef XR_FB_EYE_TRACKING_SOCIAL_EXTENSION_NAME 111 | #define XR_FB_eye_tracking_social_SPEC_VERSION XR_FBX1_eye_tracking_social_SPEC_VERSION 112 | #define XR_FB_EYE_TRACKING_SOCIAL_EXTENSION_NAME XR_FBX1_EYE_TRACKING_SOCIAL_EXTENSION_NAME 113 | #endif // XR_FB_eye_tracking_social_EXPERIMENTAL_VERSION 114 | 115 | typedef XrFlags64 XrEyeInputFlagsFB; 116 | 117 | typedef struct XrEyeTrackerCreateInfoV1FB { 118 | XrStructureType type; 119 | const void* XR_MAY_ALIAS next; 120 | XrEyeInputFlagsFB flags; 121 | } XrEyeTrackerCreateInfoV1FB; 122 | 123 | #define XrEyeTrackerCreateInfoV2FB XrEyeTrackerCreateInfoFB 124 | 125 | typedef struct XrEyeGazeV1FB { 126 | XrBool32 isValid; 127 | XrPosef gazePose; 128 | float gazeConfidence; 129 | } XrEyeGazeV1FB; 130 | typedef XrEyeGazeFB XrEyeGazeV2FB; 131 | 132 | typedef struct XrEyeGazesV1FB { 133 | XrStructureType type; 134 | void* XR_MAY_ALIAS next; 135 | XrEyeGazeV1FB gaze[2]; 136 | } XrEyeGazesV1FB; 137 | 138 | #define XrEyeGazesV2FB XrEyeGazesFB 139 | 140 | #ifndef XR_NO_PROTOTYPES 141 | #ifdef XR_EXTENSION_PROTOTYPES 142 | XRAPI_ATTR XrResult XRAPI_CALL xrCreateEyeTrackerV1FB( 143 | XrSession session, 144 | const XrEyeTrackerCreateInfoV1FB* createInfo, 145 | XrEyeTrackerFB* eyeTracker); 146 | 147 | XRAPI_ATTR XrResult XRAPI_CALL xrCreateEyeTrackerV2FB( 148 | XrSession session, 149 | const XrEyeTrackerCreateInfoFB* createInfo, 150 | XrEyeTrackerFB* eyeTracker); 151 | 152 | XRAPI_ATTR XrResult XRAPI_CALL xrDestroyEyeTrackerFB(XrEyeTrackerFB eyeTracker); 153 | 154 | XRAPI_ATTR XrResult XRAPI_CALL xrGetEyeGazesV1FB( 155 | XrEyeTrackerFB eyeTracker, 156 | const XrEyeGazesInfoFB* gazeInfo, 157 | XrEyeGazesV1FB* eyeGazes); 158 | 159 | XRAPI_ATTR XrResult XRAPI_CALL xrGetEyeGazesV2FB( 160 | XrEyeTrackerFB eyeTracker, 161 | const XrEyeGazesInfoFB* gazeInfo, 162 | XrEyeGazesFB* eyeGazes); 163 | 164 | #endif /* XR_EXTENSION_PROTOTYPES */ 165 | #endif /* !XR_NO_PROTOTYPES */ 166 | 167 | #endif // XR_FBX_eye_tracking 168 | 169 | // ============================================================================ 170 | // End Backwards Compatibility (DEPRECATED) 171 | // ============================================================================ 172 | 173 | #ifdef __cplusplus 174 | } 175 | #endif 176 | -------------------------------------------------------------------------------- /external/FB/openxr/openxr_extension_helpers.h: -------------------------------------------------------------------------------- 1 | // (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. 2 | 3 | /************************************************************************************ 4 | 5 | Filename : openxr_extension_helpers.h 6 | Content : Helpers for private and experimental extension definition headers. 7 | Language : C99 8 | 9 | *************************************************************************************/ 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | #define XR_ENUM(type, enm, constant) static const type enm = (type)constant 16 | #define XR_STRUCT_ENUM(enm, constant) XR_ENUM(XrStructureType, enm, constant) 17 | #define XR_REFSPACE_ENUM(enm, constant) XR_ENUM(XrReferenceSpaceType, enm, constant) 18 | #define XR_RESULT_ENUM(enm, constant) XR_ENUM(XrResult, enm, constant) 19 | #define XR_COMPONENT_ENUM(enm, constant) XR_ENUM(XrComponentTypeFB, enm, constant) 20 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/FW1FontWrapper.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {76a87c04-8801-4479-974a-70dfbc8eeab9} 6 | 7 | 8 | {b9a7a8f7-55d0-4adc-b779-43c9018e7887} 9 | 10 | 11 | {6a111903-dbdb-4427-9f61-7b83490858ef} 12 | 13 | 14 | {615aae11-afe5-4f40-9f2d-19977ca2a0f6} 15 | 16 | 17 | 18 | 19 | Interface Implementations 20 | 21 | 22 | Interface Implementations 23 | 24 | 25 | Interface Implementations 26 | 27 | 28 | Interface Implementations 29 | 30 | 31 | Interface Implementations 32 | 33 | 34 | Interface Implementations 35 | 36 | 37 | Interface Implementations 38 | 39 | 40 | Interface Implementations 41 | 42 | 43 | Interface Implementations 44 | 45 | 46 | Interface Implementations 47 | 48 | 49 | Interface Implementations 50 | 51 | 52 | Precompiled Header 53 | 54 | 55 | FW1FontWrapper 56 | 57 | 58 | FW1FontWrapper 59 | 60 | 61 | Other 62 | 63 | 64 | Other 65 | 66 | 67 | 68 | 69 | Interface Implementations 70 | 71 | 72 | Interface Implementations 73 | 74 | 75 | Interface Implementations 76 | 77 | 78 | Interface Implementations 79 | 80 | 81 | Interface Implementations 82 | 83 | 84 | Interface Implementations 85 | 86 | 87 | Interface Implementations 88 | 89 | 90 | Interface Implementations 91 | 92 | 93 | Interface Implementations 94 | 95 | 96 | Interface Implementations 97 | 98 | 99 | Interface Implementations 100 | 101 | 102 | Interface Implementations 103 | 104 | 105 | Interface Implementations 106 | 107 | 108 | Interface Implementations 109 | 110 | 111 | Interface Implementations 112 | 113 | 114 | Interface Implementations 115 | 116 | 117 | Interface Implementations 118 | 119 | 120 | Interface Implementations 121 | 122 | 123 | Interface Implementations 124 | 125 | 126 | Interface Implementations 127 | 128 | 129 | Interface Implementations 130 | 131 | 132 | Interface Implementations 133 | 134 | 135 | Precompiled Header 136 | 137 | 138 | FW1FontWrapper 139 | 140 | 141 | Other 142 | 143 | 144 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/README.md: -------------------------------------------------------------------------------- 1 | # FW1FontWrapper 2 | FW1FontWrapper is a font wrapper library for drawing text using Direct3D 11. It uses DirectWrite for formatting, text layout, and glyph caching, exposing basic DirectWrite text functionality for use with a D3D11 render target. 3 | The library is written in C++, and either compiles to a DLL or can be statically included in a project directly. 4 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1ColorRGBA.cpp: -------------------------------------------------------------------------------- 1 | // CFW1ColorRGBA.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1ColorRGBA.h" 6 | 7 | 8 | namespace FW1FontWrapper { 9 | 10 | 11 | // Construct 12 | CFW1ColorRGBA::CFW1ColorRGBA() : 13 | m_color32(0xffffffff) 14 | { 15 | } 16 | 17 | 18 | // Destruct 19 | CFW1ColorRGBA::~CFW1ColorRGBA() { 20 | } 21 | 22 | 23 | // Init 24 | HRESULT CFW1ColorRGBA::initColor(IFW1Factory *pFW1Factory, UINT32 initialColor32) { 25 | HRESULT hResult = initBaseObject(pFW1Factory); 26 | if(FAILED(hResult)) 27 | return hResult; 28 | 29 | m_color32 = initialColor32; 30 | 31 | return S_OK; 32 | } 33 | 34 | 35 | }// namespace FW1FontWrapper 36 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1ColorRGBA.h: -------------------------------------------------------------------------------- 1 | // CFW1ColorRGBA.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1ColorRGBA 4 | #define IncludeGuard__FW1_CFW1ColorRGBA 5 | 6 | #include "CFW1Object.h" 7 | 8 | 9 | namespace FW1FontWrapper { 10 | 11 | 12 | // A color 13 | class CFW1ColorRGBA : public CFW1Object { 14 | public: 15 | // IUnknown 16 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 17 | 18 | // IFW1Color32 19 | virtual void STDMETHODCALLTYPE SetColor(UINT32 Color); 20 | virtual void STDMETHODCALLTYPE SetColor(FLOAT Red, FLOAT Green, FLOAT Blue, FLOAT Alpha); 21 | virtual void STDMETHODCALLTYPE SetColor(const FLOAT *pColor); 22 | virtual void STDMETHODCALLTYPE SetColor(const BYTE *pColor); 23 | 24 | virtual UINT32 STDMETHODCALLTYPE GetColor32(); 25 | 26 | // Public functions 27 | public: 28 | CFW1ColorRGBA(); 29 | 30 | HRESULT initColor(IFW1Factory *pFW1Factory, UINT32 initialColor32); 31 | 32 | // Internal functions 33 | private: 34 | virtual ~CFW1ColorRGBA(); 35 | 36 | // Internal data 37 | private: 38 | UINT32 m_color32; 39 | }; 40 | 41 | 42 | }// namespace FW1FontWrapper 43 | 44 | 45 | #endif// IncludeGuard__FW1_CFW1ColorRGBA 46 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1ColorRGBAInterface.cpp: -------------------------------------------------------------------------------- 1 | // CFW1ColorRGBAInterface.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1ColorRGBA.h" 6 | 7 | 8 | namespace FW1FontWrapper { 9 | 10 | 11 | // Query interface 12 | HRESULT STDMETHODCALLTYPE CFW1ColorRGBA::QueryInterface(REFIID riid, void **ppvObject) { 13 | if(ppvObject == NULL) 14 | return E_INVALIDARG; 15 | 16 | if(IsEqualIID(riid, __uuidof(IFW1ColorRGBA))) { 17 | *ppvObject = static_cast(this); 18 | AddRef(); 19 | return S_OK; 20 | } 21 | 22 | return CFW1Object::QueryInterface(riid, ppvObject); 23 | } 24 | 25 | 26 | // Set the color 27 | void STDMETHODCALLTYPE CFW1ColorRGBA::SetColor(UINT32 Color) { 28 | m_color32 = Color; 29 | } 30 | 31 | 32 | // Set the color 33 | void STDMETHODCALLTYPE CFW1ColorRGBA::SetColor(FLOAT Red, FLOAT Green, FLOAT Blue, FLOAT Alpha) { 34 | UINT32 color32; 35 | BYTE *colorBytes = reinterpret_cast(&color32); 36 | colorBytes[0] = static_cast(Red * 255.0f + 0.5f); 37 | colorBytes[1] = static_cast(Green * 255.0f + 0.5f); 38 | colorBytes[2] = static_cast(Blue * 255.0f + 0.5f); 39 | colorBytes[3] = static_cast(Alpha * 255.0f + 0.5f); 40 | 41 | m_color32 = color32; 42 | } 43 | 44 | 45 | // Set the color 46 | void STDMETHODCALLTYPE CFW1ColorRGBA::SetColor(const FLOAT *pColor) { 47 | SetColor(pColor[0], pColor[1], pColor[2], pColor[3]); 48 | } 49 | 50 | 51 | // Set the color 52 | void STDMETHODCALLTYPE CFW1ColorRGBA::SetColor(const BYTE *pColor) { 53 | UINT32 color32; 54 | BYTE *colorBytes = reinterpret_cast(&color32); 55 | for(int i=0; i < 4; ++i) 56 | colorBytes[i] = pColor[i]; 57 | 58 | m_color32 = color32; 59 | } 60 | 61 | 62 | // Get the color 63 | UINT32 STDMETHODCALLTYPE CFW1ColorRGBA::GetColor32() { 64 | return m_color32; 65 | } 66 | 67 | 68 | }// namespace FW1FontWrapper 69 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1DWriteRenderTarget.cpp: -------------------------------------------------------------------------------- 1 | // CFW1DWriteRenderTarget.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1DWriteRenderTarget.h" 6 | 7 | #define SAFE_RELEASE(pObject) { if(pObject) { (pObject)->Release(); (pObject) = NULL; } } 8 | 9 | 10 | namespace FW1FontWrapper { 11 | 12 | 13 | // Construct 14 | CFW1DWriteRenderTarget::CFW1DWriteRenderTarget() : 15 | m_pRenderTarget(NULL), 16 | m_hDC(NULL), 17 | m_hBlackBrush(NULL), 18 | m_bmWidthBytes(0), 19 | m_bmBytesPixel(0), 20 | m_renderTargetWidth(0), 21 | m_renderTargetHeight(0) 22 | { 23 | } 24 | 25 | 26 | // Destruct 27 | CFW1DWriteRenderTarget::~CFW1DWriteRenderTarget() { 28 | if(m_hBlackBrush != NULL) 29 | DeleteObject(m_hBlackBrush); 30 | 31 | SAFE_RELEASE(m_pRenderTarget); 32 | 33 | for(RenderingParamsMap::iterator it = m_renderingParams.begin(); it != m_renderingParams.end(); ++it) 34 | it->second->Release(); 35 | } 36 | 37 | 38 | // Init 39 | HRESULT CFW1DWriteRenderTarget::initRenderTarget( 40 | IFW1Factory *pFW1Factory, 41 | IDWriteFactory *pDWriteFactory, 42 | UINT renderTargetWidth, 43 | UINT renderTargetHeight 44 | ) { 45 | HRESULT hResult = initBaseObject(pFW1Factory); 46 | if(FAILED(hResult)) 47 | return hResult; 48 | 49 | if(pDWriteFactory == NULL) 50 | return E_INVALIDARG; 51 | 52 | m_renderTargetWidth = 384; 53 | if(renderTargetWidth > 0) 54 | m_renderTargetWidth = renderTargetWidth; 55 | 56 | m_renderTargetHeight = 384; 57 | if(renderTargetHeight > 0) 58 | m_renderTargetHeight = renderTargetHeight; 59 | 60 | // Create render target 61 | hResult = createRenderTarget(pDWriteFactory); 62 | 63 | if(SUCCEEDED(hResult)) 64 | hResult = S_OK; 65 | 66 | return hResult; 67 | } 68 | 69 | 70 | // Create render target 71 | HRESULT CFW1DWriteRenderTarget::createRenderTarget(IDWriteFactory *pDWriteFactory) { 72 | IDWriteGdiInterop *pGDIInterop; 73 | HRESULT hResult = pDWriteFactory->GetGdiInterop(&pGDIInterop); 74 | if(FAILED(hResult)) { 75 | m_lastError = L"Failed to get GDI interop"; 76 | } 77 | else { 78 | IDWriteBitmapRenderTarget *pRenderTarget; 79 | hResult = pGDIInterop->CreateBitmapRenderTarget( 80 | NULL, 81 | m_renderTargetWidth, 82 | m_renderTargetHeight, 83 | &pRenderTarget 84 | ); 85 | if(FAILED(hResult)) { 86 | m_lastError = L"Failed to create bitmap render target"; 87 | } 88 | else { 89 | hResult = pRenderTarget->SetPixelsPerDip(1.0f); 90 | hResult = S_OK; 91 | 92 | HDC hDC = pRenderTarget->GetMemoryDC(); 93 | if(hDC == NULL) { 94 | m_lastError = L"Failed to get render target DC"; 95 | hResult = E_FAIL; 96 | } 97 | else { 98 | HBRUSH hBrush = CreateSolidBrush(RGB(0, 0, 0)); 99 | if(hBrush == NULL) { 100 | m_lastError = L"Failed to create brush"; 101 | hResult = E_FAIL; 102 | } 103 | else { 104 | HBITMAP hBitmap = static_cast(GetCurrentObject(hDC, OBJ_BITMAP)); 105 | if(hBitmap == NULL) { 106 | m_lastError = L"GetCurrentObject failed"; 107 | hResult = E_FAIL; 108 | } 109 | else { 110 | DIBSECTION dib; 111 | int iResult = GetObject(hBitmap, sizeof(dib), &dib); 112 | if(iResult < sizeof(dib)) { 113 | m_lastError = L"GetObject failed"; 114 | hResult = E_FAIL; 115 | } 116 | else { 117 | // Store render target resources and info 118 | m_pRenderTarget = pRenderTarget; 119 | 120 | m_hDC = hDC; 121 | m_hBlackBrush = hBrush; 122 | 123 | m_bmBits = dib.dsBm.bmBits; 124 | m_bmWidthBytes = static_cast(dib.dsBm.bmWidthBytes); 125 | m_bmBytesPixel = static_cast(dib.dsBm.bmBitsPixel) / 8; 126 | 127 | hResult = S_OK; 128 | } 129 | } 130 | 131 | if(FAILED(hResult)) 132 | DeleteObject(hBrush); 133 | } 134 | } 135 | 136 | if(FAILED(hResult)) 137 | pRenderTarget->Release(); 138 | } 139 | 140 | pGDIInterop->Release(); 141 | } 142 | 143 | // Create rendering params for all accepted rendering modes 144 | if(SUCCEEDED(hResult)) { 145 | const UINT renderingModeCount = 2; 146 | DWRITE_RENDERING_MODE renderingModes[renderingModeCount] = { 147 | DWRITE_RENDERING_MODE_DEFAULT, 148 | DWRITE_RENDERING_MODE_ALIASED 149 | }; 150 | 151 | for(UINT i=0; i < renderingModeCount; ++i) { 152 | DWRITE_RENDERING_MODE renderingMode = renderingModes[i]; 153 | IDWriteRenderingParams *pRenderingParams; 154 | 155 | hResult = pDWriteFactory->CreateCustomRenderingParams( 156 | 1.0f, 157 | 0.0f, 158 | 0.0f, 159 | DWRITE_PIXEL_GEOMETRY_FLAT, 160 | renderingMode, 161 | &pRenderingParams 162 | ); 163 | if(SUCCEEDED(hResult)) 164 | m_renderingParams.insert(std::make_pair(renderingMode, pRenderingParams)); 165 | } 166 | 167 | if(m_renderingParams.empty()) { 168 | m_lastError = L"Failed to create rendering params"; 169 | hResult = E_FAIL; 170 | } 171 | else 172 | hResult = S_OK; 173 | } 174 | 175 | return hResult; 176 | } 177 | 178 | 179 | // Init glyph data 180 | void CFW1DWriteRenderTarget::initGlyphData( 181 | const DWRITE_FONT_METRICS *fontMetrics, 182 | const DWRITE_GLYPH_METRICS *glyphMetrics, 183 | FLOAT fontSize, 184 | DWGlyphData *outGlyphData 185 | ) { 186 | // Calculate pixel-space coordinates 187 | FLOAT fscale = fontSize / static_cast(fontMetrics->designUnitsPerEm); 188 | 189 | FLOAT l = static_cast(glyphMetrics->leftSideBearing) * fscale; 190 | FLOAT t = static_cast(glyphMetrics->topSideBearing) * fscale; 191 | 192 | FLOAT r = static_cast(glyphMetrics->rightSideBearing) * fscale; 193 | FLOAT b = static_cast(glyphMetrics->bottomSideBearing) * fscale; 194 | 195 | FLOAT v = static_cast(glyphMetrics->verticalOriginY) * fscale; 196 | 197 | FLOAT aw = static_cast(glyphMetrics->advanceWidth) * fscale; 198 | FLOAT ah = static_cast(glyphMetrics->advanceHeight) * fscale; 199 | 200 | // Set up glyph data 201 | outGlyphData->offsetX = floor(l); 202 | outGlyphData->offsetY = floor(t) - floor(v); 203 | outGlyphData->maxWidth = static_cast(aw - r - l + 2.0f); 204 | outGlyphData->maxHeight = static_cast(ah - b - t + 2.0f); 205 | } 206 | 207 | 208 | }// namespace FW1FontWrapper 209 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1DWriteRenderTarget.h: -------------------------------------------------------------------------------- 1 | // CFW1DWriteRenderTarget.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1DWriteRenderTarget 4 | #define IncludeGuard__FW1_CFW1DWriteRenderTarget 5 | 6 | #include "CFW1Object.h" 7 | 8 | 9 | namespace FW1FontWrapper { 10 | 11 | 12 | // Render target that provides pixels of one glyph-image at a time 13 | class CFW1DWriteRenderTarget : public CFW1Object { 14 | public: 15 | // IUnknown 16 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 17 | 18 | // IFW1DWriteRenderTarget 19 | virtual HRESULT STDMETHODCALLTYPE DrawGlyphTemp( 20 | IDWriteFontFace *pFontFace, 21 | UINT16 GlyphIndex, 22 | FLOAT FontSize, 23 | DWRITE_RENDERING_MODE RenderingMode, 24 | DWRITE_MEASURING_MODE MeasuringMode, 25 | FW1_GLYPHIMAGEDATA *pOutData 26 | ); 27 | 28 | // Public functions 29 | public: 30 | CFW1DWriteRenderTarget(); 31 | 32 | HRESULT initRenderTarget( 33 | IFW1Factory *pFW1Factory, 34 | IDWriteFactory *pDWriteFactory, 35 | UINT renderTargetWidth, 36 | UINT renderTargetHeight 37 | ); 38 | 39 | // Internal types 40 | private: 41 | struct DWGlyphData { 42 | FLOAT offsetX; 43 | FLOAT offsetY; 44 | LONG maxWidth; 45 | LONG maxHeight; 46 | }; 47 | 48 | typedef std::map RenderingParamsMap; 49 | 50 | // Internal functions 51 | private: 52 | virtual ~CFW1DWriteRenderTarget(); 53 | 54 | HRESULT createRenderTarget(IDWriteFactory *pDWriteFactory); 55 | 56 | void initGlyphData( 57 | const DWRITE_FONT_METRICS *fontMetrics, 58 | const DWRITE_GLYPH_METRICS *glyphMetrics, 59 | FLOAT fontSize, 60 | DWGlyphData *outGlyphData 61 | ); 62 | 63 | // Internal data 64 | private: 65 | std::wstring m_lastError; 66 | 67 | IDWriteBitmapRenderTarget *m_pRenderTarget; 68 | HDC m_hDC; 69 | HBRUSH m_hBlackBrush; 70 | LPVOID m_bmBits; 71 | UINT m_bmWidthBytes; 72 | UINT m_bmBytesPixel; 73 | UINT m_renderTargetWidth; 74 | UINT m_renderTargetHeight; 75 | RenderingParamsMap m_renderingParams; 76 | }; 77 | 78 | 79 | }// namespace FW1FontWrapper 80 | 81 | 82 | #endif// IncludeGuard__FW1_CFW1DWriteRenderTarget 83 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1DWriteRenderTargetInterface.cpp: -------------------------------------------------------------------------------- 1 | // CFW1DWriteRenderTargetInterface.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1DWriteRenderTarget.h" 6 | 7 | 8 | namespace FW1FontWrapper { 9 | 10 | 11 | // Query interface 12 | HRESULT STDMETHODCALLTYPE CFW1DWriteRenderTarget::QueryInterface(REFIID riid, void **ppvObject) { 13 | if(ppvObject == NULL) 14 | return E_INVALIDARG; 15 | 16 | if(IsEqualIID(riid, __uuidof(IFW1DWriteRenderTarget))) { 17 | *ppvObject = static_cast(this); 18 | AddRef(); 19 | return S_OK; 20 | } 21 | 22 | return CFW1Object::QueryInterface(riid, ppvObject); 23 | } 24 | 25 | 26 | // Draw glyph to temporary storage 27 | HRESULT STDMETHODCALLTYPE CFW1DWriteRenderTarget::DrawGlyphTemp( 28 | IDWriteFontFace *pFontFace, 29 | UINT16 GlyphIndex, 30 | FLOAT FontSize, 31 | DWRITE_RENDERING_MODE RenderingMode, 32 | DWRITE_MEASURING_MODE MeasuringMode, 33 | FW1_GLYPHIMAGEDATA *pOutData 34 | ) { 35 | // Font metrics 36 | DWRITE_FONT_METRICS fontMetrics; 37 | pFontFace->GetMetrics(&fontMetrics); 38 | 39 | // Glyph metrics 40 | DWRITE_GLYPH_METRICS glyphMetrics; 41 | HRESULT hResult = pFontFace->GetDesignGlyphMetrics(&GlyphIndex, 1, &glyphMetrics, FALSE); 42 | if(FAILED(hResult)) 43 | return hResult; 44 | 45 | // Calculate pixel measurements 46 | DWGlyphData dwGlyphData; 47 | initGlyphData(&fontMetrics, &glyphMetrics, FontSize, &dwGlyphData); 48 | 49 | // Set up drawing 50 | FLOAT glyphAdvance = 0.0f; 51 | DWRITE_GLYPH_OFFSET glyphOffset = {0.0f, 0.0f}; 52 | 53 | DWRITE_GLYPH_RUN glyphRun; 54 | ZeroMemory(&glyphRun, sizeof(glyphRun)); 55 | glyphRun.fontFace = pFontFace; 56 | glyphRun.fontEmSize = FontSize; 57 | glyphRun.glyphCount = 1; 58 | glyphRun.glyphIndices = &GlyphIndex; 59 | glyphRun.glyphAdvances = &glyphAdvance; 60 | glyphRun.glyphOffsets = &glyphOffset; 61 | 62 | // Clear background 63 | RECT rect; 64 | SetRect(&rect, 0, 0, 2+dwGlyphData.maxWidth+5, 2+dwGlyphData.maxHeight+5); 65 | int iRet = FillRect(m_hDC, &rect, m_hBlackBrush); 66 | if(iRet == 0) { 67 | } 68 | 69 | // Rendering mode 70 | IDWriteRenderingParams *pRenderingParams; 71 | 72 | RenderingParamsMap::iterator it = m_renderingParams.find(RenderingMode); 73 | if(it != m_renderingParams.end()) 74 | pRenderingParams = it->second; 75 | else 76 | pRenderingParams = m_renderingParams.begin()->second; 77 | 78 | // Draw 79 | hResult = m_pRenderTarget->DrawGlyphRun( 80 | 2.0f - dwGlyphData.offsetX, 81 | 2.0f - dwGlyphData.offsetY, 82 | MeasuringMode, 83 | &glyphRun, 84 | pRenderingParams, 85 | RGB(255, 255, 255), 86 | &rect 87 | ); 88 | if(FAILED(hResult)) 89 | return hResult; 90 | 91 | // Clip to valid render target to avoid buffer overruns in case the glyph was too large 92 | rect.left = std::max(rect.left, 0L); 93 | rect.top = std::max(rect.top, 0L); 94 | rect.right = std::min(static_cast(m_renderTargetWidth), rect.right); 95 | rect.bottom = std::min(static_cast(m_renderTargetHeight), rect.bottom); 96 | 97 | // Return glyph data 98 | pOutData->Metrics.OffsetX = dwGlyphData.offsetX + static_cast(rect.left) - 2.0f; 99 | pOutData->Metrics.OffsetY = dwGlyphData.offsetY + static_cast(rect.top) - 2.0f; 100 | pOutData->Metrics.Width = static_cast(rect.right - rect.left); 101 | pOutData->Metrics.Height = static_cast(rect.bottom - rect.top); 102 | pOutData->pGlyphPixels = 103 | static_cast(m_bmBits) 104 | + rect.top * m_bmWidthBytes 105 | + rect.left * m_bmBytesPixel; 106 | pOutData->RowPitch = m_bmWidthBytes; 107 | pOutData->PixelStride = m_bmBytesPixel; 108 | 109 | return S_OK; 110 | } 111 | 112 | 113 | }// namespace FW1FontWrapper 114 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1Factory.cpp: -------------------------------------------------------------------------------- 1 | // CFW1Factory.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1Factory.h" 6 | 7 | 8 | namespace FW1FontWrapper { 9 | 10 | 11 | // Construct 12 | CFW1Factory::CFW1Factory() : 13 | m_cRefCount(1) 14 | { 15 | InitializeCriticalSection(&m_errorStringCriticalSection); 16 | } 17 | 18 | 19 | // Destruct 20 | CFW1Factory::~CFW1Factory() { 21 | DeleteCriticalSection(&m_errorStringCriticalSection); 22 | } 23 | 24 | 25 | // Init 26 | HRESULT CFW1Factory::initFactory() { 27 | return S_OK; 28 | } 29 | 30 | 31 | // Create a DWrite factory 32 | HRESULT CFW1Factory::createDWriteFactory(IDWriteFactory **ppDWriteFactory) { 33 | HRESULT hResult = E_FAIL; 34 | 35 | typedef HRESULT (WINAPI * PFN_DWRITECREATEFACTORY)(__in DWRITE_FACTORY_TYPE factoryType, __in REFIID iid, __out IUnknown **factory); 36 | PFN_DWRITECREATEFACTORY pfnDWriteCreateFactory = NULL; 37 | 38 | #ifdef FW1_DELAYLOAD_DWRITE_DLL 39 | HMODULE hDWriteLib = LoadLibrary(TEXT("DWrite.dll")); 40 | if(hDWriteLib == NULL) { 41 | DWORD dwErr = GetLastError(); 42 | dwErr; 43 | setErrorString(L"Failed to load DWrite.dll"); 44 | } 45 | else { 46 | pfnDWriteCreateFactory = 47 | reinterpret_cast(GetProcAddress(hDWriteLib, "DWriteCreateFactory")); 48 | if(pfnDWriteCreateFactory == NULL) { 49 | DWORD dwErr = GetLastError(); 50 | dwErr; 51 | setErrorString(L"Failed to load DWriteCreateFactory"); 52 | } 53 | } 54 | #else 55 | pfnDWriteCreateFactory = DWriteCreateFactory; 56 | #endif 57 | 58 | if(pfnDWriteCreateFactory != NULL) { 59 | IDWriteFactory *pDWriteFactory; 60 | 61 | hResult = pfnDWriteCreateFactory( 62 | DWRITE_FACTORY_TYPE_SHARED, 63 | __uuidof(IDWriteFactory), 64 | reinterpret_cast(&pDWriteFactory) 65 | ); 66 | if(FAILED(hResult)) { 67 | setErrorString(L"DWriteCreateFactory failed"); 68 | } 69 | else { 70 | *ppDWriteFactory = pDWriteFactory; 71 | 72 | hResult = S_OK; 73 | } 74 | } 75 | 76 | return hResult; 77 | } 78 | 79 | 80 | // Set error string 81 | void CFW1Factory::setErrorString(const wchar_t *str) { 82 | EnterCriticalSection(&m_errorStringCriticalSection); 83 | m_lastError = str; 84 | LeaveCriticalSection(&m_errorStringCriticalSection); 85 | } 86 | 87 | 88 | }// namespace FW1FontWrapper 89 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1Factory.h: -------------------------------------------------------------------------------- 1 | // CFW1Factory.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1Factory 4 | #define IncludeGuard__FW1_CFW1Factory 5 | 6 | 7 | namespace FW1FontWrapper { 8 | 9 | 10 | // Factory that creates FW1 objects 11 | class CFW1Factory : public IFW1Factory { 12 | public: 13 | // IUnknown 14 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 15 | virtual ULONG STDMETHODCALLTYPE AddRef(); 16 | virtual ULONG STDMETHODCALLTYPE Release(); 17 | 18 | // IFW1Factory 19 | virtual HRESULT STDMETHODCALLTYPE CreateFontWrapper( 20 | ID3D11Device *pDevice, 21 | LPCWSTR pszFontFamily, 22 | IFW1FontWrapper **ppFontWrapper 23 | ); 24 | virtual HRESULT STDMETHODCALLTYPE CreateFontWrapper( 25 | ID3D11Device *pDevice, 26 | IDWriteFactory *pDWriteFactory, 27 | const FW1_FONTWRAPPERCREATEPARAMS *pCreateParams, 28 | IFW1FontWrapper **ppFontWrapper 29 | ); 30 | virtual HRESULT STDMETHODCALLTYPE CreateFontWrapper( 31 | ID3D11Device *pDevice, 32 | IFW1GlyphAtlas *pGlyphAtlas, 33 | IFW1GlyphProvider *pGlyphProvider, 34 | IFW1GlyphVertexDrawer *pGlyphVertexDrawer, 35 | IFW1GlyphRenderStates *pGlyphRenderStates, 36 | IDWriteFactory *pDWriteFactory, 37 | const FW1_DWRITEFONTPARAMS *pDefaultFontParams, 38 | IFW1FontWrapper **ppFontWrapper 39 | ); 40 | virtual HRESULT STDMETHODCALLTYPE CreateGlyphVertexDrawer( 41 | ID3D11Device *pDevice, 42 | UINT VertexBufferSize, 43 | IFW1GlyphVertexDrawer **ppGlyphVertexDrawer 44 | ); 45 | virtual HRESULT STDMETHODCALLTYPE CreateGlyphRenderStates( 46 | ID3D11Device *pDevice, 47 | BOOL DisableGeometryShader, 48 | BOOL AnisotropicFiltering, 49 | IFW1GlyphRenderStates **ppGlyphRenderStates 50 | ); 51 | virtual HRESULT STDMETHODCALLTYPE CreateTextRenderer( 52 | IFW1GlyphProvider *pGlyphProvider, 53 | IFW1TextRenderer **ppTextRenderer 54 | ); 55 | virtual HRESULT STDMETHODCALLTYPE CreateTextGeometry( 56 | IFW1TextGeometry **ppTextGeometry 57 | ); 58 | virtual HRESULT STDMETHODCALLTYPE CreateGlyphProvider( 59 | IFW1GlyphAtlas *pGlyphAtlas, 60 | IDWriteFactory *pDWriteFactory, 61 | IDWriteFontCollection *pFontCollection, 62 | UINT MaxGlyphWidth, 63 | UINT MaxGlyphHeight, 64 | IFW1GlyphProvider **ppGlyphProvider 65 | ); 66 | virtual HRESULT STDMETHODCALLTYPE CreateDWriteRenderTarget( 67 | IDWriteFactory *pDWriteFactory, 68 | UINT RenderTargetWidth, 69 | UINT RenderTargetHeight, 70 | IFW1DWriteRenderTarget **ppRenderTarget 71 | ); 72 | virtual HRESULT STDMETHODCALLTYPE CreateGlyphAtlas( 73 | ID3D11Device *pDevice, 74 | UINT GlyphSheetWidth, 75 | UINT GlyphSheetHeight, 76 | BOOL HardwareCoordBuffer, 77 | BOOL AllowOversizedGlyph, 78 | UINT MaxGlyphCountPerSheet, 79 | UINT MipLevels, 80 | UINT MaxGlyphSheetCount, 81 | IFW1GlyphAtlas **ppGlyphAtlas 82 | ); 83 | virtual HRESULT STDMETHODCALLTYPE CreateGlyphSheet( 84 | ID3D11Device *pDevice, 85 | UINT GlyphSheetWidth, 86 | UINT GlyphSheetHeight, 87 | BOOL HardwareCoordBuffer, 88 | BOOL AllowOversizedGlyph, 89 | UINT MaxGlyphCount, 90 | UINT MipLevels, 91 | IFW1GlyphSheet **ppGlyphSheet 92 | ); 93 | virtual HRESULT STDMETHODCALLTYPE CreateColor( 94 | UINT32 Color, 95 | IFW1ColorRGBA **ppColor 96 | ); 97 | 98 | // Public functions 99 | public: 100 | CFW1Factory(); 101 | 102 | HRESULT initFactory(); 103 | 104 | // Internal functions 105 | private: 106 | virtual ~CFW1Factory(); 107 | 108 | HRESULT createDWriteFactory(IDWriteFactory **ppDWriteFactory); 109 | 110 | void setErrorString(const wchar_t *str); 111 | 112 | // Internal data 113 | private: 114 | ULONG m_cRefCount; 115 | 116 | std::wstring m_lastError; 117 | CRITICAL_SECTION m_errorStringCriticalSection; 118 | 119 | private: 120 | CFW1Factory(const CFW1Factory&); 121 | CFW1Factory& operator=(const CFW1Factory&); 122 | }; 123 | 124 | 125 | }// namespace FW1FontWrapper 126 | 127 | 128 | #endif// IncludeGuard__FW1_CFW1Factory 129 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1FontWrapper.cpp: -------------------------------------------------------------------------------- 1 | // CFW1FontWrapper.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1FontWrapper.h" 6 | 7 | #define SAFE_RELEASE(pObject) { if(pObject) { (pObject)->Release(); (pObject) = NULL; } } 8 | 9 | 10 | namespace FW1FontWrapper { 11 | 12 | 13 | // Construct 14 | CFW1FontWrapper::CFW1FontWrapper() : 15 | m_pDevice(NULL), 16 | m_featureLevel(D3D_FEATURE_LEVEL_9_1), 17 | m_pDWriteFactory(NULL), 18 | 19 | m_pGlyphAtlas(NULL), 20 | m_pGlyphProvider(NULL), 21 | 22 | m_pGlyphRenderStates(NULL), 23 | m_pGlyphVertexDrawer(NULL), 24 | 25 | m_defaultTextInited(false), 26 | m_pDefaultTextFormat(NULL) 27 | { 28 | InitializeCriticalSection(&m_textRenderersCriticalSection); 29 | InitializeCriticalSection(&m_textGeometriesCriticalSection); 30 | } 31 | 32 | 33 | // Destruct 34 | CFW1FontWrapper::~CFW1FontWrapper() { 35 | SAFE_RELEASE(m_pFW1Factory); 36 | 37 | SAFE_RELEASE(m_pDevice); 38 | SAFE_RELEASE(m_pDWriteFactory); 39 | 40 | SAFE_RELEASE(m_pGlyphAtlas); 41 | SAFE_RELEASE(m_pGlyphProvider); 42 | 43 | SAFE_RELEASE(m_pGlyphRenderStates); 44 | SAFE_RELEASE(m_pGlyphVertexDrawer); 45 | 46 | while(!m_textRenderers.empty()) { 47 | m_textRenderers.top()->Release(); 48 | m_textRenderers.pop(); 49 | } 50 | 51 | while(!m_textGeometries.empty()) { 52 | m_textGeometries.top()->Release(); 53 | m_textGeometries.pop(); 54 | } 55 | 56 | SAFE_RELEASE(m_pDefaultTextFormat); 57 | 58 | DeleteCriticalSection(&m_textRenderersCriticalSection); 59 | DeleteCriticalSection(&m_textGeometriesCriticalSection); 60 | } 61 | 62 | 63 | // Init 64 | HRESULT CFW1FontWrapper::initFontWrapper( 65 | IFW1Factory *pFW1Factory, 66 | ID3D11Device *pDevice, 67 | IFW1GlyphAtlas *pGlyphAtlas, 68 | IFW1GlyphProvider *pGlyphProvider, 69 | IFW1GlyphVertexDrawer *pGlyphVertexDrawer, 70 | IFW1GlyphRenderStates *pGlyphRenderStates, 71 | IDWriteFactory *pDWriteFactory, 72 | const FW1_DWRITEFONTPARAMS *pDefaultFontParams 73 | ) { 74 | HRESULT hResult = initBaseObject(pFW1Factory); 75 | if(FAILED(hResult)) 76 | return hResult; 77 | 78 | if( 79 | pDevice == NULL || 80 | pGlyphAtlas == NULL || 81 | pGlyphProvider == NULL || 82 | pGlyphVertexDrawer == NULL || 83 | pGlyphRenderStates == NULL || 84 | pDWriteFactory == NULL 85 | ) 86 | return E_INVALIDARG; 87 | 88 | pDevice->AddRef(); 89 | m_pDevice = pDevice; 90 | m_featureLevel = m_pDevice->GetFeatureLevel(); 91 | 92 | pDWriteFactory->AddRef(); 93 | m_pDWriteFactory = pDWriteFactory; 94 | 95 | pGlyphAtlas->AddRef(); 96 | m_pGlyphAtlas = pGlyphAtlas; 97 | pGlyphProvider->AddRef(); 98 | m_pGlyphProvider = pGlyphProvider; 99 | 100 | pGlyphRenderStates->AddRef(); 101 | m_pGlyphRenderStates = pGlyphRenderStates; 102 | pGlyphVertexDrawer->AddRef(); 103 | m_pGlyphVertexDrawer = pGlyphVertexDrawer; 104 | 105 | // Create default text format for strings, if provided 106 | if(pDefaultFontParams->pszFontFamily != NULL && pDefaultFontParams->pszFontFamily[0] != 0) { 107 | IDWriteTextFormat *pTextFormat; 108 | hResult = m_pDWriteFactory->CreateTextFormat( 109 | pDefaultFontParams->pszFontFamily, 110 | NULL, 111 | pDefaultFontParams->FontWeight, 112 | pDefaultFontParams->FontStyle, 113 | pDefaultFontParams->FontStretch, 114 | 32.0f, 115 | (pDefaultFontParams->pszLocale != NULL) ? pDefaultFontParams->pszLocale : L"", 116 | &pTextFormat 117 | ); 118 | if(FAILED(hResult)) { 119 | m_lastError = L"Failed to create DWrite text format"; 120 | } 121 | else { 122 | m_pDefaultTextFormat = pTextFormat; 123 | m_defaultTextInited = true; 124 | 125 | hResult = S_OK; 126 | } 127 | } 128 | 129 | return hResult; 130 | } 131 | 132 | 133 | // Create text layout from string 134 | IDWriteTextLayout* CFW1FontWrapper::createTextLayout( 135 | const WCHAR *pszString, 136 | const WCHAR *pszFontFamily, 137 | FLOAT fontSize, 138 | const FW1_RECTF *pLayoutRect, 139 | UINT flags 140 | ) { 141 | if(m_defaultTextInited) { 142 | UINT32 stringLength = 0; 143 | while(pszString[stringLength] != 0) 144 | ++stringLength; 145 | 146 | // Create DWrite text layout for the string 147 | IDWriteTextLayout *pTextLayout; 148 | HRESULT hResult = m_pDWriteFactory->CreateTextLayout( 149 | pszString, 150 | stringLength, 151 | m_pDefaultTextFormat, 152 | pLayoutRect->Right - pLayoutRect->Left, 153 | pLayoutRect->Bottom - pLayoutRect->Top, 154 | &pTextLayout 155 | ); 156 | if(SUCCEEDED(hResult)) { 157 | // Layout settings 158 | DWRITE_TEXT_RANGE allText = {0, stringLength}; 159 | pTextLayout->SetFontSize(fontSize, allText); 160 | 161 | if(pszFontFamily != NULL) 162 | pTextLayout->SetFontFamilyName(pszFontFamily, allText); 163 | 164 | if((flags & FW1_NOWORDWRAP) != 0) 165 | pTextLayout->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP); 166 | 167 | if(flags & FW1_RIGHT) 168 | pTextLayout->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_TRAILING); 169 | else if(flags & FW1_CENTER) 170 | pTextLayout->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER); 171 | if(flags & FW1_BOTTOM) 172 | pTextLayout->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_FAR); 173 | else if(flags & FW1_VCENTER) 174 | pTextLayout->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER); 175 | 176 | return pTextLayout; 177 | } 178 | } 179 | 180 | return NULL; 181 | } 182 | 183 | 184 | }// namespace FW1FontWrapper 185 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1FontWrapper.h: -------------------------------------------------------------------------------- 1 | // CFW1FontWrapper.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1FontWrapper 4 | #define IncludeGuard__FW1_CFW1FontWrapper 5 | 6 | #include "CFW1Object.h" 7 | 8 | 9 | namespace FW1FontWrapper { 10 | 11 | 12 | // Font-wrapper simplifying drawing strings and text-layouts 13 | class CFW1FontWrapper : public CFW1Object { 14 | public: 15 | // IUnknown 16 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 17 | 18 | // IFW1FontWrapper 19 | virtual HRESULT STDMETHODCALLTYPE GetFactory(IFW1Factory **ppFactory); 20 | 21 | virtual HRESULT STDMETHODCALLTYPE GetDevice(ID3D11Device **ppDevice); 22 | virtual HRESULT STDMETHODCALLTYPE GetDWriteFactory(IDWriteFactory **ppDWriteFactory); 23 | virtual HRESULT STDMETHODCALLTYPE GetGlyphAtlas(IFW1GlyphAtlas **ppGlyphAtlas); 24 | virtual HRESULT STDMETHODCALLTYPE GetGlyphProvider(IFW1GlyphProvider **ppGlyphProvider); 25 | virtual HRESULT STDMETHODCALLTYPE GetRenderStates(IFW1GlyphRenderStates **ppRenderStates); 26 | virtual HRESULT STDMETHODCALLTYPE GetVertexDrawer(IFW1GlyphVertexDrawer **ppVertexDrawer); 27 | 28 | virtual void STDMETHODCALLTYPE DrawTextLayout( 29 | ID3D11DeviceContext *pContext, 30 | IDWriteTextLayout *pTextLayout, 31 | FLOAT OriginX, 32 | FLOAT OriginY, 33 | UINT32 Color, 34 | UINT Flags 35 | ); 36 | virtual void STDMETHODCALLTYPE DrawTextLayout( 37 | ID3D11DeviceContext *pContext, 38 | IDWriteTextLayout *pTextLayout, 39 | FLOAT OriginX, 40 | FLOAT OriginY, 41 | UINT32 Color, 42 | const FW1_RECTF *pClipRect, 43 | const FLOAT *pTransformMatrix, 44 | UINT Flags 45 | ); 46 | 47 | virtual void STDMETHODCALLTYPE DrawString( 48 | ID3D11DeviceContext *pContext, 49 | const WCHAR *pszString, 50 | FLOAT FontSize, 51 | FLOAT X, 52 | FLOAT Y, 53 | UINT32 Color, 54 | UINT Flags 55 | ); 56 | virtual void STDMETHODCALLTYPE DrawString( 57 | ID3D11DeviceContext *pContext, 58 | const WCHAR *pszString, 59 | const WCHAR *pszFontFamily, 60 | FLOAT FontSize, 61 | FLOAT X, 62 | FLOAT Y, 63 | UINT32 Color, 64 | UINT Flags 65 | ); 66 | virtual void STDMETHODCALLTYPE DrawString( 67 | ID3D11DeviceContext *pContext, 68 | const WCHAR *pszString, 69 | const WCHAR *pszFontFamily, 70 | FLOAT FontSize, 71 | const FW1_RECTF *pLayoutRect, 72 | UINT32 Color, 73 | const FW1_RECTF *pClipRect, 74 | const FLOAT *pTransformMatrix, 75 | UINT Flags 76 | ); 77 | 78 | virtual FW1_RECTF STDMETHODCALLTYPE MeasureString( 79 | const WCHAR *pszString, 80 | const WCHAR *pszFontFamily, 81 | FLOAT FontSize, 82 | const FW1_RECTF *pLayoutRect, 83 | UINT Flags 84 | ); 85 | 86 | virtual void STDMETHODCALLTYPE AnalyzeString( 87 | ID3D11DeviceContext *pContext, 88 | const WCHAR *pszString, 89 | const WCHAR *pszFontFamily, 90 | FLOAT FontSize, 91 | const FW1_RECTF *pLayoutRect, 92 | UINT32 Color, 93 | UINT Flags, 94 | IFW1TextGeometry *pTextGeometry 95 | ); 96 | 97 | virtual void STDMETHODCALLTYPE AnalyzeTextLayout( 98 | ID3D11DeviceContext *pContext, 99 | IDWriteTextLayout *pTextLayout, 100 | FLOAT OriginX, 101 | FLOAT OriginY, 102 | UINT32 Color, 103 | UINT Flags, 104 | IFW1TextGeometry *pTextGeometry 105 | ); 106 | 107 | virtual void STDMETHODCALLTYPE DrawGeometry( 108 | ID3D11DeviceContext *pContext, 109 | IFW1TextGeometry *pGeometry, 110 | const FW1_RECTF *pClipRect, 111 | const FLOAT *pTransformMatrix, 112 | UINT Flags 113 | ); 114 | 115 | virtual void STDMETHODCALLTYPE Flush(ID3D11DeviceContext *pContext); 116 | 117 | // Public functions 118 | public: 119 | CFW1FontWrapper(); 120 | 121 | HRESULT initFontWrapper( 122 | IFW1Factory *pFW1Factory, 123 | ID3D11Device *pDevice, 124 | IFW1GlyphAtlas *pGlyphAtlas, 125 | IFW1GlyphProvider *pGlyphProvider, 126 | IFW1GlyphVertexDrawer *pGlyphVertexDrawer, 127 | IFW1GlyphRenderStates *pGlyphRenderStates, 128 | IDWriteFactory *pDWriteFactory, 129 | const FW1_DWRITEFONTPARAMS *pDefaultFontParams 130 | ); 131 | 132 | // Internal functions 133 | private: 134 | virtual ~CFW1FontWrapper(); 135 | 136 | IDWriteTextLayout* createTextLayout( 137 | const WCHAR *pszString, 138 | const WCHAR *pszFontFamily, 139 | FLOAT fontSize, 140 | const FW1_RECTF *pLayoutRect, 141 | UINT flags 142 | ); 143 | 144 | // Internal data 145 | private: 146 | std::wstring m_lastError; 147 | 148 | ID3D11Device *m_pDevice; 149 | D3D_FEATURE_LEVEL m_featureLevel; 150 | IDWriteFactory *m_pDWriteFactory; 151 | 152 | IFW1GlyphAtlas *m_pGlyphAtlas; 153 | IFW1GlyphProvider *m_pGlyphProvider; 154 | 155 | IFW1GlyphRenderStates *m_pGlyphRenderStates; 156 | IFW1GlyphVertexDrawer *m_pGlyphVertexDrawer; 157 | 158 | CRITICAL_SECTION m_textRenderersCriticalSection; 159 | std::stack m_textRenderers; 160 | CRITICAL_SECTION m_textGeometriesCriticalSection; 161 | std::stack m_textGeometries; 162 | 163 | bool m_defaultTextInited; 164 | IDWriteTextFormat *m_pDefaultTextFormat; 165 | }; 166 | 167 | 168 | }// namespace FW1FontWrapper 169 | 170 | 171 | #endif// IncludeGuard__FW1_CFW1FontWrapper 172 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1GlyphAtlas.cpp: -------------------------------------------------------------------------------- 1 | // CFW1GlyphAtlas.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1GlyphAtlas.h" 6 | 7 | #define SAFE_RELEASE(pObject) { if(pObject) { (pObject)->Release(); (pObject) = NULL; } } 8 | 9 | 10 | namespace FW1FontWrapper { 11 | 12 | 13 | // Construct 14 | CFW1GlyphAtlas::CFW1GlyphAtlas() : 15 | m_pDevice(NULL), 16 | m_sheetWidth(0), 17 | m_sheetHeight(0), 18 | m_hardwareCoordBuffer(false), 19 | m_allowOversizedGlyph(false), 20 | m_maxGlyphCount(0), 21 | m_mipLevelCount(0), 22 | 23 | m_glyphSheets(0), 24 | m_sheetCount(0), 25 | m_maxSheetCount(0), 26 | m_currentSheetIndex(0), 27 | m_flushedSheetIndex(0) 28 | { 29 | InitializeCriticalSection(&m_glyphSheetsCriticalSection); 30 | } 31 | 32 | 33 | // Destruct 34 | CFW1GlyphAtlas::~CFW1GlyphAtlas() { 35 | SAFE_RELEASE(m_pDevice); 36 | 37 | for(UINT i=0; i < m_sheetCount; ++i) 38 | m_glyphSheets[i]->Release(); 39 | delete[] m_glyphSheets; 40 | 41 | DeleteCriticalSection(&m_glyphSheetsCriticalSection); 42 | } 43 | 44 | 45 | // Init 46 | HRESULT CFW1GlyphAtlas::initGlyphAtlas( 47 | IFW1Factory *pFW1Factory, 48 | ID3D11Device *pDevice, 49 | UINT sheetWidth, 50 | UINT sheetHeight, 51 | bool coordBuffer, 52 | bool allowOversizedGlyph, 53 | UINT maxGlyphCount, 54 | UINT mipLevelCount, 55 | UINT maxSheetCount 56 | ) { 57 | HRESULT hResult = initBaseObject(pFW1Factory); 58 | if(FAILED(hResult)) 59 | return hResult; 60 | 61 | if(pDevice == NULL) 62 | return E_INVALIDARG; 63 | 64 | pDevice->AddRef(); 65 | m_pDevice = pDevice; 66 | 67 | m_sheetWidth = sheetWidth; 68 | m_sheetHeight = sheetHeight; 69 | m_hardwareCoordBuffer = coordBuffer; 70 | m_allowOversizedGlyph = allowOversizedGlyph; 71 | m_mipLevelCount = mipLevelCount; 72 | m_maxGlyphCount = maxGlyphCount; 73 | 74 | m_maxSheetCount = 4096; 75 | if(maxSheetCount > 0 && maxSheetCount < 655536) 76 | m_maxSheetCount = maxSheetCount; 77 | m_glyphSheets = new IFW1GlyphSheet* [m_maxSheetCount]; 78 | 79 | // Default glyph 80 | BYTE glyph0Pixels[256]; 81 | FillMemory(glyph0Pixels, 256, 0xff); 82 | 83 | FW1_GLYPHMETRICS glyph0Metrics; 84 | glyph0Metrics.OffsetX = 0.0f; 85 | glyph0Metrics.OffsetY = 0.0f; 86 | glyph0Metrics.Width = 16; 87 | glyph0Metrics.Height = 16; 88 | 89 | UINT glyph0 = InsertGlyph(&glyph0Metrics, glyph0Pixels, 16, 1); 90 | if(glyph0 == 0xffffffff) 91 | return E_FAIL; 92 | else 93 | return S_OK; 94 | } 95 | 96 | 97 | // Create new glyph sheet 98 | HRESULT CFW1GlyphAtlas::createGlyphSheet(IFW1GlyphSheet **ppGlyphSheet) { 99 | IFW1GlyphSheet *pGlyphSheet; 100 | HRESULT hResult = m_pFW1Factory->CreateGlyphSheet( 101 | m_pDevice, 102 | m_sheetWidth, 103 | m_sheetHeight, 104 | m_hardwareCoordBuffer, 105 | m_allowOversizedGlyph, 106 | m_maxGlyphCount, 107 | m_mipLevelCount, 108 | &pGlyphSheet 109 | ); 110 | if(FAILED(hResult)) { 111 | } 112 | else { 113 | *ppGlyphSheet = pGlyphSheet; 114 | 115 | hResult = S_OK; 116 | } 117 | 118 | return hResult; 119 | } 120 | 121 | 122 | }// namespace FW1FontWrapper 123 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1GlyphAtlas.h: -------------------------------------------------------------------------------- 1 | // CFW1GlyphAtlas.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1GlyphAtlas 4 | #define IncludeGuard__FW1_CFW1GlyphAtlas 5 | 6 | #include "CFW1Object.h" 7 | 8 | 9 | namespace FW1FontWrapper { 10 | 11 | 12 | class CFW1GlyphAtlas : public CFW1Object { 13 | // Interface 14 | public: 15 | // IUnknown 16 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 17 | 18 | // IFW1GlyphAtlas 19 | virtual HRESULT STDMETHODCALLTYPE GetDevice(ID3D11Device **ppDevice); 20 | 21 | virtual UINT STDMETHODCALLTYPE GetTotalGlyphCount(); 22 | virtual UINT STDMETHODCALLTYPE GetSheetCount(); 23 | 24 | virtual HRESULT STDMETHODCALLTYPE GetSheet(UINT SheetIndex, IFW1GlyphSheet **ppGlyphSheet); 25 | 26 | virtual const FW1_GLYPHCOORDS* STDMETHODCALLTYPE GetGlyphCoords(UINT SheetIndex); 27 | virtual HRESULT STDMETHODCALLTYPE BindSheet(ID3D11DeviceContext *pContext, UINT SheetIndex, UINT Flags); 28 | 29 | virtual UINT STDMETHODCALLTYPE InsertGlyph( 30 | const FW1_GLYPHMETRICS *pGlyphMetrics, 31 | const void *pGlyphData, 32 | UINT RowPitch, 33 | UINT PixelStride 34 | ); 35 | virtual UINT STDMETHODCALLTYPE InsertSheet(IFW1GlyphSheet *pGlyphSheet); 36 | virtual void STDMETHODCALLTYPE Flush(ID3D11DeviceContext *pContext); 37 | 38 | // Public functions 39 | public: 40 | CFW1GlyphAtlas(); 41 | 42 | HRESULT initGlyphAtlas( 43 | IFW1Factory *pFW1Factory, 44 | ID3D11Device *pDevice, 45 | UINT sheetWidth, 46 | UINT sheetHeight, 47 | bool coordBuffer, 48 | bool allowOversizedTexture, 49 | UINT maxGlyphCountPerSheet, 50 | UINT mipLevelCount, 51 | UINT maxSheetCount 52 | ); 53 | 54 | // Internal functions 55 | private: 56 | virtual ~CFW1GlyphAtlas(); 57 | 58 | HRESULT createGlyphSheet(IFW1GlyphSheet **ppGlyphSheet); 59 | 60 | // Internal data 61 | private: 62 | ID3D11Device *m_pDevice; 63 | UINT m_sheetWidth; 64 | UINT m_sheetHeight; 65 | bool m_hardwareCoordBuffer; 66 | bool m_allowOversizedGlyph; 67 | UINT m_maxGlyphCount; 68 | UINT m_mipLevelCount; 69 | 70 | IFW1GlyphSheet **m_glyphSheets; 71 | UINT m_sheetCount; 72 | UINT m_maxSheetCount; 73 | UINT m_currentSheetIndex; 74 | UINT m_flushedSheetIndex; 75 | 76 | CRITICAL_SECTION m_glyphSheetsCriticalSection; 77 | }; 78 | 79 | 80 | }// namespace FW1FontWrapper 81 | 82 | 83 | #endif// IncludeGuard__FW1_CFW1GlyphAtlas 84 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1GlyphAtlasInterface.cpp: -------------------------------------------------------------------------------- 1 | // CFW1GlyphAtlasInterface.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1GlyphAtlas.h" 6 | 7 | 8 | namespace FW1FontWrapper { 9 | 10 | 11 | // Query interface 12 | HRESULT STDMETHODCALLTYPE CFW1GlyphAtlas::QueryInterface(REFIID riid, void **ppvObject) { 13 | if(ppvObject == NULL) 14 | return E_INVALIDARG; 15 | 16 | if(IsEqualIID(riid, __uuidof(IFW1GlyphAtlas))) { 17 | *ppvObject = static_cast(this); 18 | AddRef(); 19 | return S_OK; 20 | } 21 | 22 | return CFW1Object::QueryInterface(riid, ppvObject); 23 | } 24 | 25 | 26 | // Get the D3D11 device used by this atlas 27 | HRESULT STDMETHODCALLTYPE CFW1GlyphAtlas::GetDevice(ID3D11Device **ppDevice) { 28 | if(ppDevice == NULL) 29 | return E_INVALIDARG; 30 | 31 | m_pDevice->AddRef(); 32 | *ppDevice = m_pDevice; 33 | 34 | return S_OK; 35 | } 36 | 37 | 38 | // Get total glyph count in atlas 39 | UINT STDMETHODCALLTYPE CFW1GlyphAtlas::GetTotalGlyphCount() { 40 | UINT total = 0; 41 | 42 | for(UINT i=0; i < m_sheetCount; ++i) { 43 | FW1_GLYPHSHEETDESC desc; 44 | m_glyphSheets[i]->GetDesc(&desc); 45 | 46 | total += desc.GlyphCount; 47 | } 48 | 49 | return total; 50 | } 51 | 52 | 53 | // Get sheet count 54 | UINT STDMETHODCALLTYPE CFW1GlyphAtlas::GetSheetCount() { 55 | return m_sheetCount; 56 | } 57 | 58 | 59 | // Get sheet 60 | HRESULT STDMETHODCALLTYPE CFW1GlyphAtlas::GetSheet(UINT SheetIndex, IFW1GlyphSheet **ppGlyphSheet) { 61 | if(ppGlyphSheet == NULL) 62 | return E_INVALIDARG; 63 | 64 | if(SheetIndex < m_sheetCount) { 65 | *ppGlyphSheet = m_glyphSheets[SheetIndex]; 66 | 67 | return S_OK; 68 | } 69 | 70 | *ppGlyphSheet = NULL; 71 | 72 | return E_INVALIDARG; 73 | } 74 | 75 | // Get texture coordinates 76 | const FW1_GLYPHCOORDS* STDMETHODCALLTYPE CFW1GlyphAtlas::GetGlyphCoords(UINT SheetIndex) { 77 | if(SheetIndex < m_sheetCount) 78 | return m_glyphSheets[SheetIndex]->GetGlyphCoords(); 79 | 80 | return 0; 81 | } 82 | 83 | 84 | // Set sheet shader resources 85 | HRESULT STDMETHODCALLTYPE CFW1GlyphAtlas::BindSheet(ID3D11DeviceContext *pContext, UINT SheetIndex, UINT Flags) { 86 | if(SheetIndex < m_sheetCount) 87 | return m_glyphSheets[SheetIndex]->BindSheet(pContext, Flags); 88 | 89 | return E_INVALIDARG; 90 | } 91 | 92 | 93 | // Insert texture into atlas 94 | UINT STDMETHODCALLTYPE CFW1GlyphAtlas::InsertGlyph( 95 | const FW1_GLYPHMETRICS *pGlyphMetrics, 96 | const void *pGlyphData, 97 | UINT RowPitch, 98 | UINT PixelStride 99 | ) { 100 | UINT glyphIndex = 0xffffffff; 101 | UINT sheetIndex = 0; 102 | 103 | // Get open sheet range 104 | EnterCriticalSection(&m_glyphSheetsCriticalSection); 105 | UINT start = m_currentSheetIndex; 106 | UINT end = m_sheetCount; 107 | LeaveCriticalSection(&m_glyphSheetsCriticalSection); 108 | 109 | // Attempt to insert glyph 110 | for(UINT i=start; i < end; ++i) { 111 | IFW1GlyphSheet *pGlyphSheet = m_glyphSheets[i]; 112 | 113 | glyphIndex = pGlyphSheet->InsertGlyph(pGlyphMetrics, pGlyphData, RowPitch, PixelStride); 114 | if(glyphIndex != 0xffffffff) { 115 | sheetIndex = i; 116 | break; 117 | } 118 | } 119 | 120 | // Try to create a new glyph sheet on failure 121 | if(glyphIndex == 0xffffffff && m_sheetCount < m_maxSheetCount) { 122 | IFW1GlyphSheet *pGlyphSheet; 123 | if(SUCCEEDED(createGlyphSheet(&pGlyphSheet))) { 124 | glyphIndex = pGlyphSheet->InsertGlyph(pGlyphMetrics, pGlyphData, RowPitch, PixelStride); 125 | 126 | UINT newSheetIndex = InsertSheet(pGlyphSheet); 127 | if(newSheetIndex != 0xffffffff) 128 | sheetIndex = newSheetIndex; 129 | else 130 | glyphIndex = 0xffffffff; 131 | 132 | pGlyphSheet->Release(); 133 | } 134 | } 135 | 136 | if(glyphIndex == 0xffffffff) 137 | return 0xffffffff; 138 | 139 | return (sheetIndex << 16) | glyphIndex; 140 | } 141 | 142 | 143 | // Insert glyph sheets 144 | UINT STDMETHODCALLTYPE CFW1GlyphAtlas::InsertSheet(IFW1GlyphSheet *pGlyphSheet) { 145 | if(pGlyphSheet == NULL) 146 | return 0xffffffff; 147 | 148 | UINT sheetIndex = 0xffffffff; 149 | 150 | EnterCriticalSection(&m_glyphSheetsCriticalSection); 151 | if(m_sheetCount < m_maxSheetCount) { 152 | pGlyphSheet->AddRef(); 153 | 154 | sheetIndex = m_sheetCount; 155 | 156 | m_glyphSheets[sheetIndex] = pGlyphSheet; 157 | 158 | _WriteBarrier(); 159 | MemoryBarrier(); 160 | 161 | ++m_sheetCount; 162 | 163 | // Restrict the number of open sheets 164 | UINT numActiveSheets = 4; 165 | 166 | if(m_sheetCount > m_currentSheetIndex + numActiveSheets) { 167 | m_glyphSheets[m_currentSheetIndex]->CloseSheet(); 168 | 169 | ++m_currentSheetIndex; 170 | } 171 | } 172 | LeaveCriticalSection(&m_glyphSheetsCriticalSection); 173 | 174 | return sheetIndex; 175 | } 176 | 177 | 178 | // Flush all sheets with possible new glyphs 179 | void STDMETHODCALLTYPE CFW1GlyphAtlas::Flush(ID3D11DeviceContext *pContext) { 180 | UINT first = 0; 181 | UINT end = 0; 182 | 183 | EnterCriticalSection(&m_glyphSheetsCriticalSection); 184 | 185 | first = m_flushedSheetIndex; 186 | end = m_sheetCount; 187 | 188 | m_flushedSheetIndex = m_currentSheetIndex; 189 | 190 | LeaveCriticalSection(&m_glyphSheetsCriticalSection); 191 | 192 | for(UINT i=first; i < end; ++i) 193 | m_glyphSheets[i]->Flush(pContext); 194 | } 195 | 196 | 197 | }// namespace FW1FontWrapper 198 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1GlyphProvider.h: -------------------------------------------------------------------------------- 1 | // CFW1GlyphProvider.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1GlyphProvider 4 | #define IncludeGuard__FW1_CFW1GlyphProvider 5 | 6 | #include "CFW1Object.h" 7 | 8 | 9 | namespace FW1FontWrapper { 10 | 11 | 12 | // Fonts and glyphs-maps collection to match glyphs to images in a glyph-atlas 13 | class CFW1GlyphProvider : public CFW1Object { 14 | public: 15 | // IUnknown 16 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 17 | 18 | // IFW1GlyphProvider 19 | virtual HRESULT STDMETHODCALLTYPE GetGlyphAtlas(IFW1GlyphAtlas **ppGlyphAtlas); 20 | virtual HRESULT STDMETHODCALLTYPE GetDWriteFactory(IDWriteFactory **ppDWriteFactory); 21 | virtual HRESULT STDMETHODCALLTYPE GetDWriteFontCollection(IDWriteFontCollection **ppFontCollection); 22 | 23 | virtual const void* STDMETHODCALLTYPE GetGlyphMapFromFont( 24 | IDWriteFontFace *pFontFace, 25 | FLOAT FontSize, 26 | UINT FontFlags 27 | ); 28 | virtual UINT STDMETHODCALLTYPE GetAtlasIdFromGlyphIndex( 29 | const void* pGlyphMap, 30 | UINT16 GlyphIndex, 31 | IDWriteFontFace *pFontFace, 32 | UINT FontFlags 33 | ); 34 | 35 | // Public functions 36 | public: 37 | CFW1GlyphProvider(); 38 | 39 | HRESULT initGlyphProvider( 40 | IFW1Factory *pFW1Factory, 41 | IFW1GlyphAtlas *pGlyphAtlas, 42 | IDWriteFactory *pDWriteFactory, 43 | IDWriteFontCollection *pFontCollection, 44 | UINT maxGlyphWidth, 45 | UINT maxGlyphHeight 46 | ); 47 | 48 | // Internal types 49 | private: 50 | struct GlyphMap { 51 | FLOAT fontSize; 52 | UINT fontFlags; 53 | 54 | UINT *glyphs; 55 | UINT glyphCount; 56 | }; 57 | 58 | struct FontInfo { 59 | IDWriteFontFace *pFontFace; 60 | std::wstring uniqueName; 61 | }; 62 | 63 | typedef std::pair > FontId; 64 | typedef std::map FontMap; 65 | 66 | FontId makeFontId(UINT fontIndex, UINT fontFlags, FLOAT fontSize) { 67 | UINT relevantFlags = (fontFlags & (FW1_ALIASED)); 68 | return std::make_pair(fontIndex, std::make_pair(relevantFlags, fontSize)); 69 | } 70 | 71 | // Internal functions 72 | private: 73 | virtual ~CFW1GlyphProvider(); 74 | 75 | UINT getFontIndexFromFontFace(IDWriteFontFace *pFontFace); 76 | std::wstring getUniqueNameFromFontFace(IDWriteFontFace *pFontFace); 77 | 78 | UINT insertNewGlyph(GlyphMap *glyphMap, UINT16 glyphIndex, IDWriteFontFace *pFontFace); 79 | 80 | // Internal data 81 | private: 82 | IFW1GlyphAtlas *m_pGlyphAtlas; 83 | 84 | IDWriteFactory *m_pDWriteFactory; 85 | UINT m_maxGlyphWidth; 86 | UINT m_maxGlyphHeight; 87 | std::stack m_glyphRenderTargets; 88 | 89 | IDWriteFontCollection *m_pFontCollection; 90 | std::vector m_fonts; 91 | 92 | FontMap m_fontMap; 93 | 94 | CRITICAL_SECTION m_renderTargetsCriticalSection; 95 | CRITICAL_SECTION m_glyphMapsCriticalSection; 96 | CRITICAL_SECTION m_fontsCriticalSection; 97 | CRITICAL_SECTION m_insertGlyphCriticalSection; 98 | }; 99 | 100 | 101 | }// namespace FW1FontWrapper 102 | 103 | 104 | #endif// IncludeGuard__FW1_CFW1GlyphProvider 105 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1GlyphProviderInterface.cpp: -------------------------------------------------------------------------------- 1 | // CFW1GlyphProviderInterface.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1GlyphProvider.h" 6 | 7 | 8 | namespace FW1FontWrapper { 9 | 10 | 11 | // Query interface 12 | HRESULT STDMETHODCALLTYPE CFW1GlyphProvider::QueryInterface(REFIID riid, void **ppvObject) { 13 | if(ppvObject == NULL) 14 | return E_INVALIDARG; 15 | 16 | if(IsEqualIID(riid, __uuidof(IFW1GlyphProvider))) { 17 | *ppvObject = static_cast(this); 18 | AddRef(); 19 | return S_OK; 20 | } 21 | 22 | return CFW1Object::QueryInterface(riid, ppvObject); 23 | } 24 | 25 | 26 | // Get glyph atlas 27 | HRESULT STDMETHODCALLTYPE CFW1GlyphProvider::GetGlyphAtlas(IFW1GlyphAtlas **ppGlyphAtlas) { 28 | if(ppGlyphAtlas == NULL) 29 | return E_INVALIDARG; 30 | 31 | m_pGlyphAtlas->AddRef(); 32 | *ppGlyphAtlas = m_pGlyphAtlas; 33 | 34 | return S_OK; 35 | } 36 | 37 | 38 | // Get DWrite factory 39 | HRESULT STDMETHODCALLTYPE CFW1GlyphProvider::GetDWriteFactory(IDWriteFactory **ppDWriteFactory) { 40 | if(ppDWriteFactory == NULL) 41 | return E_INVALIDARG; 42 | 43 | m_pDWriteFactory->AddRef(); 44 | *ppDWriteFactory = m_pDWriteFactory; 45 | 46 | return S_OK; 47 | } 48 | 49 | 50 | // Get DWrite font collection 51 | HRESULT STDMETHODCALLTYPE CFW1GlyphProvider::GetDWriteFontCollection(IDWriteFontCollection **ppFontCollection) { 52 | if(ppFontCollection == NULL) 53 | return E_INVALIDARG; 54 | 55 | m_pFontCollection->AddRef(); 56 | *ppFontCollection = m_pFontCollection; 57 | 58 | return S_OK; 59 | } 60 | 61 | 62 | // Get glyph map 63 | const void* STDMETHODCALLTYPE CFW1GlyphProvider::GetGlyphMapFromFont( 64 | IDWriteFontFace *pFontFace, 65 | FLOAT FontSize, 66 | UINT FontFlags 67 | ) { 68 | // Get font id 69 | UINT fontIndex = getFontIndexFromFontFace(pFontFace); 70 | FontId fontId = makeFontId(fontIndex, FontFlags, FontSize); 71 | 72 | const void *glyphMap = 0; 73 | 74 | // Get the glyph-map 75 | EnterCriticalSection(&m_glyphMapsCriticalSection); 76 | FontMap::iterator it = m_fontMap.find(fontId); 77 | if(it != m_fontMap.end()) 78 | glyphMap = (*it).second; 79 | LeaveCriticalSection(&m_glyphMapsCriticalSection); 80 | 81 | if(glyphMap == 0 && (FontFlags & FW1_NONEWGLYPHS) == 0) { 82 | // Create a new glyph-map 83 | GlyphMap *newGlyphMap = new GlyphMap; 84 | newGlyphMap->fontSize = FontSize; 85 | newGlyphMap->fontFlags = FontFlags; 86 | newGlyphMap->glyphCount = pFontFace->GetGlyphCount(); 87 | newGlyphMap->glyphs = new UINT[newGlyphMap->glyphCount]; 88 | for(UINT i=0; i < newGlyphMap->glyphCount; ++i) 89 | newGlyphMap->glyphs[i] = 0xffffffff; 90 | 91 | bool needless = false; 92 | 93 | // Inert the new glyph-map and map the font-id to its index 94 | EnterCriticalSection(&m_glyphMapsCriticalSection); 95 | 96 | it = m_fontMap.find(fontId); 97 | if(it != m_fontMap.end()) { 98 | glyphMap = (*it).second; 99 | needless = true; 100 | } 101 | else { 102 | m_fontMap.insert(std::make_pair(fontId, newGlyphMap)); 103 | glyphMap = newGlyphMap; 104 | } 105 | 106 | LeaveCriticalSection(&m_glyphMapsCriticalSection); 107 | 108 | if(needless) {// Simultaneous creation on two threads 109 | delete[] newGlyphMap->glyphs; 110 | delete newGlyphMap; 111 | } 112 | else { 113 | UINT glyphAtlasId = insertNewGlyph(newGlyphMap, 0, pFontFace); 114 | glyphAtlasId; 115 | } 116 | } 117 | 118 | return glyphMap; 119 | } 120 | 121 | 122 | // Get atlas id of a glyph 123 | UINT STDMETHODCALLTYPE CFW1GlyphProvider::GetAtlasIdFromGlyphIndex( 124 | const void *pGlyphMap, 125 | UINT16 GlyphIndex, 126 | IDWriteFontFace *pFontFace, 127 | UINT FontFlags 128 | ) { 129 | GlyphMap *glyphMap = static_cast(const_cast(pGlyphMap)); 130 | 131 | if(glyphMap == 0) 132 | return 0; 133 | 134 | if(GlyphIndex >= glyphMap->glyphCount) 135 | return 0; 136 | 137 | // Get the atlas id for this glyph 138 | UINT glyphAtlasId = glyphMap->glyphs[GlyphIndex]; 139 | if(glyphAtlasId == 0xffffffff && (FontFlags & FW1_NONEWGLYPHS) == 0) 140 | glyphAtlasId = insertNewGlyph(glyphMap, GlyphIndex, pFontFace); 141 | 142 | // Fall back to the font default-glyph or the atlas default-glyph on failure 143 | if(glyphAtlasId == 0xffffffff) { 144 | glyphAtlasId = glyphMap->glyphs[0]; 145 | 146 | if((FontFlags & FW1_NONEWGLYPHS) == 0) { 147 | if(glyphAtlasId == 0xffffffff) { 148 | if(GlyphIndex == 0) 149 | glyphAtlasId = 0; 150 | else 151 | glyphAtlasId = GetAtlasIdFromGlyphIndex(pGlyphMap, 0, pFontFace, FontFlags); 152 | } 153 | 154 | EnterCriticalSection(&m_insertGlyphCriticalSection); 155 | if(glyphMap->glyphs[GlyphIndex] == 0xffffffff) 156 | glyphMap->glyphs[GlyphIndex] = glyphAtlasId; 157 | LeaveCriticalSection(&m_insertGlyphCriticalSection); 158 | } 159 | 160 | if(glyphAtlasId == 0xffffffff) 161 | glyphAtlasId = 0; 162 | } 163 | 164 | return glyphAtlasId; 165 | } 166 | 167 | 168 | }// namespace FW1FontWrapper 169 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1GlyphRenderStates.h: -------------------------------------------------------------------------------- 1 | // CFW1GlyphRenderStates.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1GlyphRenderStates 4 | #define IncludeGuard__FW1_CFW1GlyphRenderStates 5 | 6 | #include "CFW1Object.h" 7 | 8 | 9 | namespace FW1FontWrapper { 10 | 11 | 12 | // Shader etc. needed to draw glyphs 13 | class CFW1GlyphRenderStates : public CFW1Object { 14 | public: 15 | // IUnknown 16 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 17 | 18 | // IFW1GlyphRenderStates 19 | virtual HRESULT STDMETHODCALLTYPE GetDevice(ID3D11Device **ppDevice); 20 | 21 | virtual void STDMETHODCALLTYPE SetStates(ID3D11DeviceContext *pContext, UINT Flags); 22 | virtual void STDMETHODCALLTYPE UpdateShaderConstants( 23 | ID3D11DeviceContext *pContext, 24 | const FW1_RECTF *pClipRect, 25 | const FLOAT *pTransformMatrix 26 | ); 27 | virtual BOOL STDMETHODCALLTYPE HasGeometryShader(); 28 | 29 | // Public functions 30 | public: 31 | CFW1GlyphRenderStates(); 32 | 33 | HRESULT initRenderResources( 34 | IFW1Factory *pFW1Factory, 35 | ID3D11Device *pDevice, 36 | bool wantGeometryShader, 37 | bool anisotropicFiltering 38 | ); 39 | 40 | // Internal types 41 | private: 42 | struct ShaderConstants { 43 | FLOAT TransformMatrix[16]; 44 | FLOAT ClipRect[4]; 45 | }; 46 | 47 | // Internal functions 48 | private: 49 | virtual ~CFW1GlyphRenderStates(); 50 | 51 | HRESULT createQuadShaders(); 52 | HRESULT createGlyphShaders(); 53 | HRESULT createPixelShaders(); 54 | HRESULT createConstantBuffer(); 55 | HRESULT createRenderStates(bool anisotropicFiltering); 56 | 57 | // Internal data 58 | private: 59 | std::wstring m_lastError; 60 | 61 | pD3DCompile m_pfnD3DCompile; 62 | 63 | ID3D11Device *m_pDevice; 64 | D3D_FEATURE_LEVEL m_featureLevel; 65 | 66 | ID3D11VertexShader *m_pVertexShaderQuad; 67 | ID3D11VertexShader *m_pVertexShaderClipQuad; 68 | ID3D11InputLayout *m_pQuadInputLayout; 69 | 70 | ID3D11VertexShader *m_pVertexShaderPoint; 71 | ID3D11InputLayout *m_pPointInputLayout; 72 | ID3D11GeometryShader *m_pGeometryShaderPoint; 73 | ID3D11GeometryShader *m_pGeometryShaderClipPoint; 74 | bool m_hasGeometryShader; 75 | 76 | ID3D11PixelShader *m_pPixelShader; 77 | ID3D11PixelShader *m_pPixelShaderClip; 78 | 79 | ID3D11Buffer *m_pConstantBuffer; 80 | 81 | ID3D11BlendState *m_pBlendState; 82 | ID3D11SamplerState *m_pSamplerState; 83 | ID3D11RasterizerState *m_pRasterizerState; 84 | ID3D11DepthStencilState *m_pDepthStencilState; 85 | }; 86 | 87 | 88 | }// namespace FW1FontWrapper 89 | 90 | 91 | #endif// IncludeGuard__FW1_CFW1GlyphRenderStates 92 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1GlyphRenderStatesInterface.cpp: -------------------------------------------------------------------------------- 1 | // CFW1GlyphRenderStatesInterface.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1GlyphRenderStates.h" 6 | 7 | 8 | namespace FW1FontWrapper { 9 | 10 | 11 | // Query interface 12 | HRESULT STDMETHODCALLTYPE CFW1GlyphRenderStates::QueryInterface(REFIID riid, void **ppvObject) { 13 | if(ppvObject == NULL) 14 | return E_INVALIDARG; 15 | 16 | if(IsEqualIID(riid, __uuidof(IFW1GlyphRenderStates))) { 17 | *ppvObject = static_cast(this); 18 | AddRef(); 19 | return S_OK; 20 | } 21 | 22 | return CFW1Object::QueryInterface(riid, ppvObject); 23 | } 24 | 25 | 26 | // Get the D3D11 device used by the render states 27 | HRESULT STDMETHODCALLTYPE CFW1GlyphRenderStates::GetDevice(ID3D11Device **ppDevice) { 28 | if(ppDevice == NULL) 29 | return E_INVALIDARG; 30 | 31 | m_pDevice->AddRef(); 32 | *ppDevice = m_pDevice; 33 | 34 | return S_OK; 35 | } 36 | 37 | 38 | // Set render states for glyph drawing 39 | void STDMETHODCALLTYPE CFW1GlyphRenderStates::SetStates(ID3D11DeviceContext *pContext, UINT Flags) { 40 | if(m_hasGeometryShader && ((Flags & FW1_NOGEOMETRYSHADER) == 0)) { 41 | // Point vertices with geometry shader 42 | pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST); 43 | pContext->IASetInputLayout(m_pPointInputLayout); 44 | pContext->VSSetShader(m_pVertexShaderPoint, NULL, 0); 45 | if((Flags & FW1_CLIPRECT) != 0) 46 | pContext->GSSetShader(m_pGeometryShaderClipPoint, NULL, 0); 47 | else 48 | pContext->GSSetShader(m_pGeometryShaderPoint, NULL, 0); 49 | pContext->PSSetShader(m_pPixelShader, NULL, 0); 50 | pContext->GSSetConstantBuffers(0, 1, &m_pConstantBuffer); 51 | } 52 | else { 53 | // Quads constructed on the CPU 54 | pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); 55 | pContext->IASetInputLayout(m_pQuadInputLayout); 56 | if((Flags & FW1_CLIPRECT) != 0) { 57 | pContext->VSSetShader(m_pVertexShaderClipQuad, NULL, 0); 58 | pContext->PSSetShader(m_pPixelShaderClip, NULL, 0); 59 | } 60 | else { 61 | pContext->VSSetShader(m_pVertexShaderQuad, NULL, 0); 62 | pContext->PSSetShader(m_pPixelShader, NULL, 0); 63 | } 64 | pContext->VSSetConstantBuffers(0, 1, &m_pConstantBuffer); 65 | 66 | if(m_featureLevel >= D3D_FEATURE_LEVEL_10_0) 67 | pContext->GSSetShader(NULL, NULL, 0); 68 | } 69 | 70 | if(m_featureLevel >= D3D_FEATURE_LEVEL_11_0) { 71 | pContext->DSSetShader(NULL, NULL, 0); 72 | pContext->HSSetShader(NULL, NULL, 0); 73 | } 74 | 75 | pContext->OMSetBlendState(m_pBlendState, NULL, 0xffffffff); 76 | pContext->OMSetDepthStencilState(m_pDepthStencilState, 0); 77 | 78 | pContext->RSSetState(m_pRasterizerState); 79 | 80 | pContext->PSSetSamplers(0, 1, &m_pSamplerState); 81 | } 82 | 83 | 84 | // Update constant buffer 85 | void STDMETHODCALLTYPE CFW1GlyphRenderStates::UpdateShaderConstants( 86 | ID3D11DeviceContext *pContext, 87 | const FW1_RECTF *pClipRect, 88 | const FLOAT *pTransformMatrix 89 | ) { 90 | // Shader constants 91 | ShaderConstants constants; 92 | ZeroMemory(&constants, sizeof(constants)); 93 | 94 | // Transform matrix 95 | if(pTransformMatrix != NULL) 96 | CopyMemory(constants.TransformMatrix, pTransformMatrix, 16*sizeof(FLOAT)); 97 | else { 98 | // Get viewport size for orthographic transform 99 | FLOAT w = 512.0f; 100 | FLOAT h = 512.0f; 101 | 102 | D3D11_VIEWPORT vp; 103 | UINT nvp = 1; 104 | pContext->RSGetViewports(&nvp, &vp); 105 | if(nvp > 0) { 106 | if(vp.Width >= 1.0f && vp.Height >= 1.0f) { 107 | w = vp.Width; 108 | h = vp.Height; 109 | } 110 | } 111 | 112 | constants.TransformMatrix[0] = 2.0f / w; 113 | constants.TransformMatrix[12] = -1.0f; 114 | constants.TransformMatrix[5] = -2.0f / h; 115 | constants.TransformMatrix[13] = 1.0f; 116 | constants.TransformMatrix[10] = 1.0f; 117 | constants.TransformMatrix[15] = 1.0f; 118 | } 119 | 120 | // Clip rect 121 | if(pClipRect != NULL) { 122 | constants.ClipRect[0] = -pClipRect->Left; 123 | constants.ClipRect[1] = -pClipRect->Top; 124 | constants.ClipRect[2] = pClipRect->Right; 125 | constants.ClipRect[3] = pClipRect->Bottom; 126 | } 127 | else { 128 | constants.ClipRect[0] = FLT_MAX; 129 | constants.ClipRect[1] = FLT_MAX; 130 | constants.ClipRect[2] = FLT_MAX; 131 | constants.ClipRect[3] = FLT_MAX; 132 | } 133 | 134 | // Update constant buffer 135 | D3D11_MAPPED_SUBRESOURCE msr; 136 | HRESULT hResult = pContext->Map(m_pConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &msr); 137 | if(SUCCEEDED(hResult)) { 138 | CopyMemory(msr.pData, &constants, sizeof(constants)); 139 | 140 | pContext->Unmap(m_pConstantBuffer, 0); 141 | } 142 | } 143 | 144 | 145 | // Check for geometry shader 146 | BOOL STDMETHODCALLTYPE CFW1GlyphRenderStates::HasGeometryShader() { 147 | return (m_hasGeometryShader ? TRUE : FALSE); 148 | } 149 | 150 | 151 | }// namespace FW1FontWrapper 152 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1GlyphSheet.h: -------------------------------------------------------------------------------- 1 | // CFW1GlyphSheet.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1GlyphSheet 4 | #define IncludeGuard__FW1_CFW1GlyphSheet 5 | 6 | #include "CFW1Object.h" 7 | 8 | 9 | namespace FW1FontWrapper { 10 | 11 | 12 | // A texture containing multiple glyphimages 13 | class CFW1GlyphSheet : public CFW1Object { 14 | public: 15 | // IUnknown 16 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 17 | 18 | // IFW1GlyphSheet 19 | virtual HRESULT STDMETHODCALLTYPE GetDevice(ID3D11Device **ppDevice); 20 | virtual void STDMETHODCALLTYPE GetDesc(FW1_GLYPHSHEETDESC *pDesc); 21 | 22 | virtual HRESULT STDMETHODCALLTYPE GetSheetTexture(ID3D11ShaderResourceView **ppSheetTextureSRV); 23 | virtual HRESULT STDMETHODCALLTYPE GetCoordBuffer(ID3D11ShaderResourceView **ppCoordBufferSRV); 24 | 25 | virtual const FW1_GLYPHCOORDS* STDMETHODCALLTYPE GetGlyphCoords(); 26 | virtual HRESULT STDMETHODCALLTYPE BindSheet(ID3D11DeviceContext *pContext, UINT Flags); 27 | 28 | virtual UINT STDMETHODCALLTYPE InsertGlyph( 29 | const FW1_GLYPHMETRICS *pGlyphMetrics, 30 | const void *pGlyphData, 31 | UINT RowPitch, 32 | UINT PixelStride 33 | ); 34 | virtual void STDMETHODCALLTYPE CloseSheet(); 35 | virtual void STDMETHODCALLTYPE Flush(ID3D11DeviceContext *pContext); 36 | 37 | // Public functions 38 | public: 39 | CFW1GlyphSheet(); 40 | 41 | HRESULT initGlyphSheet( 42 | IFW1Factory *pFW1Factory, 43 | ID3D11Device *pDevice, 44 | UINT sheetWidth, 45 | UINT sheetHeight, 46 | bool coordBuffer, 47 | bool allowOversizedGlyph, 48 | UINT maxGlyphCount, 49 | UINT mipLevelCount 50 | ); 51 | 52 | // Internal types 53 | private: 54 | struct RectUI { 55 | UINT left; 56 | UINT top; 57 | UINT right; 58 | UINT bottom; 59 | }; 60 | 61 | class HeightRange { 62 | public: 63 | HeightRange(UINT totalWidth); 64 | ~HeightRange(); 65 | 66 | UINT findMin(UINT width, UINT *outMin); 67 | void update(UINT startX, UINT width, UINT newHeight); 68 | 69 | private: 70 | HeightRange(); 71 | HeightRange(const HeightRange&); 72 | HeightRange& operator=(const HeightRange&); 73 | 74 | UINT findMax(UINT startX, UINT width); 75 | 76 | UINT *m_heights; 77 | UINT m_totalWidth; 78 | }; 79 | 80 | class CriticalSectionLock { 81 | public: 82 | CriticalSectionLock(LPCRITICAL_SECTION pCriticalSection) : m_pCriticalSection(pCriticalSection) { 83 | EnterCriticalSection(m_pCriticalSection); 84 | } 85 | ~CriticalSectionLock() { 86 | LeaveCriticalSection(m_pCriticalSection); 87 | } 88 | 89 | private: 90 | CriticalSectionLock(); 91 | CriticalSectionLock(const CriticalSectionLock&); 92 | CriticalSectionLock& operator=(const CriticalSectionLock&); 93 | 94 | LPCRITICAL_SECTION m_pCriticalSection; 95 | }; 96 | 97 | // Internal functions 98 | private: 99 | virtual ~CFW1GlyphSheet(); 100 | 101 | HRESULT createDeviceResources(); 102 | 103 | // Internal data 104 | private: 105 | std::wstring m_lastError; 106 | 107 | UINT m_sheetWidth; 108 | UINT m_sheetHeight; 109 | bool m_hardwareCoordBuffer; 110 | bool m_allowOversizedGlyph; 111 | UINT m_mipLevelCount; 112 | UINT m_alignWidth; 113 | 114 | UINT8 *m_textureData; 115 | FW1_GLYPHCOORDS *m_glyphCoords; 116 | UINT m_maxGlyphCount; 117 | UINT m_glyphCount; 118 | 119 | ID3D11Device *m_pDevice; 120 | 121 | ID3D11Texture2D *m_pTexture; 122 | ID3D11ShaderResourceView *m_pTextureSRV; 123 | ID3D11Buffer *m_pCoordBuffer; 124 | ID3D11ShaderResourceView *m_pCoordBufferSRV; 125 | 126 | bool m_closed; 127 | bool m_static; 128 | 129 | HeightRange *m_heightRange; 130 | 131 | UINT m_updatedGlyphCount; 132 | RectUI m_dirtyRect; 133 | CRITICAL_SECTION m_sheetCriticalSection; 134 | CRITICAL_SECTION m_flushCriticalSection; 135 | }; 136 | 137 | 138 | }// namespace FW1FontWrapper 139 | 140 | 141 | #endif// IncludeGuard__FW1_CFW1GlyphSheet 142 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1GlyphVertexDrawer.h: -------------------------------------------------------------------------------- 1 | // CFW1GlyphVertexDrawer.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1GlyphVertexDrawer 4 | #define IncludeGuard__FW1_CFW1GlyphVertexDrawer 5 | 6 | #include "CFW1Object.h" 7 | 8 | 9 | namespace FW1FontWrapper { 10 | 11 | 12 | // Draws glyph-vertices from system memory using a dynamic vertex buffer 13 | class CFW1GlyphVertexDrawer : public CFW1Object { 14 | public: 15 | // IUnknown 16 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 17 | 18 | // IFW1GlyphVertexDrawer 19 | virtual HRESULT STDMETHODCALLTYPE GetDevice(ID3D11Device **ppDevice); 20 | 21 | virtual UINT STDMETHODCALLTYPE DrawVertices( 22 | ID3D11DeviceContext *pContext, 23 | IFW1GlyphAtlas *pGlyphAtlas, 24 | const FW1_VERTEXDATA *pVertexData, 25 | UINT Flags, 26 | UINT PreboundSheet 27 | ); 28 | 29 | // Public functions 30 | public: 31 | CFW1GlyphVertexDrawer(); 32 | 33 | HRESULT initVertexDrawer(IFW1Factory *pFW1Factory, ID3D11Device *pDevice, UINT vertexBufferSize); 34 | 35 | // Internal types 36 | private: 37 | struct QuadVertex { 38 | FLOAT positionX; 39 | FLOAT positionY; 40 | FLOAT texCoordX; 41 | FLOAT texCoordY; 42 | UINT32 color; 43 | }; 44 | 45 | // Internal functions 46 | private: 47 | virtual ~CFW1GlyphVertexDrawer(); 48 | 49 | HRESULT createBuffers(); 50 | 51 | UINT drawVertices( 52 | ID3D11DeviceContext *pContext, 53 | IFW1GlyphAtlas *pGlyphAtlas, 54 | const FW1_VERTEXDATA *vertexData, 55 | UINT preboundSheet 56 | ); 57 | UINT drawGlyphsAsQuads( 58 | ID3D11DeviceContext *pContext, 59 | IFW1GlyphAtlas *pGlyphAtlas, 60 | const FW1_VERTEXDATA *vertexData, 61 | UINT preboundSheet 62 | ); 63 | 64 | // Internal data 65 | private: 66 | std::wstring m_lastError; 67 | 68 | ID3D11Device *m_pDevice; 69 | 70 | ID3D11Buffer *m_pVertexBuffer; 71 | ID3D11Buffer *m_pIndexBuffer; 72 | UINT m_vertexBufferSize; 73 | UINT m_maxIndexCount; 74 | }; 75 | 76 | 77 | }// namespace FW1FontWrapper 78 | 79 | 80 | #endif// IncludeGuard__FW1_CFW1GlyphVertexDrawer 81 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1GlyphVertexDrawerInterface.cpp: -------------------------------------------------------------------------------- 1 | // CFW1GlyphVertexDrawerInterface.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1GlyphVertexDrawer.h" 6 | 7 | 8 | namespace FW1FontWrapper { 9 | 10 | 11 | // Query interface 12 | HRESULT STDMETHODCALLTYPE CFW1GlyphVertexDrawer::QueryInterface(REFIID riid, void **ppvObject) { 13 | if(ppvObject == NULL) 14 | return E_INVALIDARG; 15 | 16 | if(IsEqualIID(riid, __uuidof(IFW1GlyphVertexDrawer))) { 17 | *ppvObject = static_cast(this); 18 | AddRef(); 19 | return S_OK; 20 | } 21 | 22 | return CFW1Object::QueryInterface(riid, ppvObject); 23 | } 24 | 25 | 26 | // Get the D3D11 device used by this vetex drawer 27 | HRESULT STDMETHODCALLTYPE CFW1GlyphVertexDrawer::GetDevice(ID3D11Device **ppDevice) { 28 | if(ppDevice == NULL) 29 | return E_INVALIDARG; 30 | 31 | m_pDevice->AddRef(); 32 | *ppDevice = m_pDevice; 33 | 34 | return S_OK; 35 | } 36 | 37 | 38 | // Draw vertices 39 | UINT STDMETHODCALLTYPE CFW1GlyphVertexDrawer::DrawVertices( 40 | ID3D11DeviceContext *pContext, 41 | IFW1GlyphAtlas *pGlyphAtlas, 42 | const FW1_VERTEXDATA *pVertexData, 43 | UINT Flags, 44 | UINT PreboundSheet 45 | ) { 46 | UINT stride; 47 | UINT offset = 0; 48 | 49 | if((Flags & FW1_NOGEOMETRYSHADER) == 0) 50 | stride = sizeof(FW1_GLYPHVERTEX); 51 | else { 52 | stride = sizeof(QuadVertex); 53 | if((Flags & FW1_BUFFERSPREPARED) == 0) 54 | pContext->IASetIndexBuffer(m_pIndexBuffer, DXGI_FORMAT_R16_UINT, 0); 55 | } 56 | if((Flags & FW1_BUFFERSPREPARED) == 0) 57 | pContext->IASetVertexBuffers(0, 1, &m_pVertexBuffer, &stride, &offset); 58 | 59 | if((Flags & FW1_NOGEOMETRYSHADER) == 0) 60 | return drawVertices(pContext, pGlyphAtlas, pVertexData, PreboundSheet); 61 | else 62 | return drawGlyphsAsQuads(pContext, pGlyphAtlas, pVertexData, PreboundSheet); 63 | } 64 | 65 | 66 | }// namespace FW1FontWrapper 67 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1Object.h: -------------------------------------------------------------------------------- 1 | // CFW1Object.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1Object 4 | #define IncludeGuard__FW1_CFW1Object 5 | 6 | 7 | namespace FW1FontWrapper { 8 | 9 | 10 | // Helper baseclass to avoid writing IUnknown and IFW1Object implementations once per class 11 | template 12 | class CFW1Object : public IBase { 13 | public: 14 | // IUnknown 15 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) = 0 { 16 | if(ppvObject == NULL) 17 | return E_INVALIDARG; 18 | 19 | if(IsEqualIID(riid, __uuidof(IUnknown))) { 20 | *ppvObject = static_cast(this); 21 | AddRef(); 22 | return S_OK; 23 | } 24 | else if(IsEqualIID(riid, __uuidof(IFW1Object))) { 25 | *ppvObject = static_cast(this); 26 | AddRef(); 27 | return S_OK; 28 | } 29 | 30 | *ppvObject = NULL; 31 | return E_NOINTERFACE; 32 | } 33 | 34 | virtual ULONG STDMETHODCALLTYPE AddRef() { 35 | return static_cast(InterlockedIncrement(reinterpret_cast(&m_cRefCount))); 36 | } 37 | 38 | virtual ULONG STDMETHODCALLTYPE Release() { 39 | ULONG newCount = static_cast(InterlockedDecrement(reinterpret_cast(&m_cRefCount))); 40 | 41 | if(newCount == 0) 42 | delete this; 43 | 44 | return newCount; 45 | } 46 | 47 | // IFW1Object 48 | virtual HRESULT STDMETHODCALLTYPE GetFactory(IFW1Factory **ppFW1Factory) { 49 | if(ppFW1Factory == NULL) 50 | return E_INVALIDARG; 51 | 52 | m_pFW1Factory->AddRef(); 53 | *ppFW1Factory = m_pFW1Factory; 54 | 55 | return S_OK; 56 | } 57 | 58 | // Internal functions 59 | protected: 60 | CFW1Object() : 61 | m_cRefCount(1), 62 | 63 | m_pFW1Factory(NULL) 64 | { 65 | } 66 | 67 | virtual ~CFW1Object() { 68 | if(m_pFW1Factory != NULL) 69 | m_pFW1Factory->Release(); 70 | } 71 | 72 | HRESULT initBaseObject(IFW1Factory *pFW1Factory) { 73 | if(pFW1Factory == NULL) 74 | return E_INVALIDARG; 75 | 76 | pFW1Factory->AddRef(); 77 | m_pFW1Factory = pFW1Factory; 78 | 79 | return S_OK; 80 | } 81 | 82 | // Internal data 83 | protected: 84 | IFW1Factory *m_pFW1Factory; 85 | 86 | private: 87 | ULONG m_cRefCount; 88 | 89 | private: 90 | CFW1Object(const CFW1Object&); 91 | CFW1Object& operator=(const CFW1Object&); 92 | }; 93 | 94 | 95 | }// namespace FW1FontWrapper 96 | 97 | 98 | #endif// IncludeGuard__FW1_CFW1Object 99 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1StateSaver.h: -------------------------------------------------------------------------------- 1 | // CFW1StateSaver.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1StateSaver 4 | #define IncludeGuard__FW1_CFW1StateSaver 5 | 6 | 7 | namespace FW1FontWrapper { 8 | 9 | 10 | // Saves all the states that can be changed when drawing a string 11 | class CFW1StateSaver { 12 | // Public functions 13 | public: 14 | CFW1StateSaver(); 15 | ~CFW1StateSaver(); 16 | 17 | HRESULT saveCurrentState(ID3D11DeviceContext *pContext); 18 | HRESULT restoreSavedState(); 19 | void releaseSavedState(); 20 | 21 | // Internal data 22 | private: 23 | bool m_savedState; 24 | D3D_FEATURE_LEVEL m_featureLevel; 25 | ID3D11DeviceContext *m_pContext; 26 | D3D11_PRIMITIVE_TOPOLOGY m_primitiveTopology; 27 | ID3D11InputLayout *m_pInputLayout; 28 | ID3D11BlendState *m_pBlendState; 29 | FLOAT m_blendFactor[4]; 30 | UINT m_sampleMask; 31 | ID3D11DepthStencilState *m_pDepthStencilState; 32 | UINT m_stencilRef; 33 | ID3D11RasterizerState *m_pRasterizerState; 34 | ID3D11ShaderResourceView *m_pPSSRV; 35 | ID3D11SamplerState *m_pSamplerState; 36 | ID3D11VertexShader *m_pVS; 37 | ID3D11ClassInstance *m_pVSClassInstances[256]; 38 | UINT m_numVSClassInstances; 39 | ID3D11Buffer *m_pVSConstantBuffer; 40 | ID3D11GeometryShader *m_pGS; 41 | ID3D11ClassInstance *m_pGSClassInstances[256]; 42 | UINT m_numGSClassInstances; 43 | ID3D11Buffer *m_pGSConstantBuffer; 44 | ID3D11ShaderResourceView *m_pGSSRV; 45 | ID3D11PixelShader *m_pPS; 46 | ID3D11ClassInstance *m_pPSClassInstances[256]; 47 | UINT m_numPSClassInstances; 48 | ID3D11HullShader *m_pHS; 49 | ID3D11ClassInstance *m_pHSClassInstances[256]; 50 | UINT m_numHSClassInstances; 51 | ID3D11DomainShader *m_pDS; 52 | ID3D11ClassInstance *m_pDSClassInstances[256]; 53 | UINT m_numDSClassInstances; 54 | ID3D11Buffer *m_pVB; 55 | UINT m_vertexStride; 56 | UINT m_vertexOffset; 57 | ID3D11Buffer *m_pIndexBuffer; 58 | DXGI_FORMAT m_indexFormat; 59 | UINT m_indexOffset; 60 | 61 | private: 62 | CFW1StateSaver(const CFW1StateSaver&); 63 | CFW1StateSaver& operator=(const CFW1StateSaver&); 64 | }; 65 | 66 | 67 | }// namespace FW1FontWrapper 68 | 69 | 70 | #endif// IncludeGuard__FW1_CFW1StateSaver 71 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1TextGeometry.cpp: -------------------------------------------------------------------------------- 1 | // CFW1TextGeometry.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1TextGeometry.h" 6 | 7 | 8 | namespace FW1FontWrapper { 9 | 10 | 11 | // Construct 12 | CFW1TextGeometry::CFW1TextGeometry() : 13 | m_maxSheetIndex(0), 14 | m_sorted(false) 15 | { 16 | } 17 | 18 | 19 | // Destruct 20 | CFW1TextGeometry::~CFW1TextGeometry() { 21 | } 22 | 23 | 24 | // Init glyph provider 25 | HRESULT CFW1TextGeometry::initTextGeometry(IFW1Factory *pFW1Factory) { 26 | HRESULT hResult = initBaseObject(pFW1Factory); 27 | if(FAILED(hResult)) 28 | return hResult; 29 | 30 | return hResult; 31 | } 32 | 33 | 34 | }// namespace FW1FontWrapper 35 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1TextGeometry.h: -------------------------------------------------------------------------------- 1 | // CFW1TextGeometry.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1TextGeometry 4 | #define IncludeGuard__FW1_CFW1TextGeometry 5 | 6 | #include "CFW1Object.h" 7 | 8 | 9 | namespace FW1FontWrapper { 10 | 11 | 12 | // Vector of vertices with sorting per glyph sheet 13 | class CFW1TextGeometry : public CFW1Object { 14 | public: 15 | // IUnknown 16 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 17 | 18 | // IFW1TextGeometry 19 | virtual void STDMETHODCALLTYPE Clear(); 20 | virtual void STDMETHODCALLTYPE AddGlyphVertex(const FW1_GLYPHVERTEX *pVertex); 21 | 22 | virtual FW1_VERTEXDATA STDMETHODCALLTYPE GetGlyphVerticesTemp(); 23 | 24 | // Public functions 25 | public: 26 | CFW1TextGeometry(); 27 | 28 | HRESULT initTextGeometry(IFW1Factory *pFW1Factory); 29 | 30 | // Internal functions 31 | private: 32 | virtual ~CFW1TextGeometry(); 33 | 34 | // Internal data 35 | private: 36 | std::vector m_vertices; 37 | std::vector m_sortedVertices; 38 | 39 | UINT m_maxSheetIndex; 40 | std::vector m_vertexCounts; 41 | std::vector m_vertexStartIndices; 42 | bool m_sorted; 43 | }; 44 | 45 | 46 | }// namespace FW1FontWrapper 47 | 48 | 49 | #endif// IncludeGuard__FW1_CFW1TextGeometry 50 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1TextGeometryInterface.cpp: -------------------------------------------------------------------------------- 1 | // CFW1TextGeometryInterface.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1TextGeometry.h" 6 | 7 | 8 | namespace FW1FontWrapper { 9 | 10 | 11 | // Query interface 12 | HRESULT STDMETHODCALLTYPE CFW1TextGeometry::QueryInterface(REFIID riid, void **ppvObject) { 13 | if(ppvObject == NULL) 14 | return E_INVALIDARG; 15 | 16 | if(IsEqualIID(riid, __uuidof(IFW1TextGeometry))) { 17 | *ppvObject = static_cast(this); 18 | AddRef(); 19 | return S_OK; 20 | } 21 | 22 | return CFW1Object::QueryInterface(riid, ppvObject); 23 | } 24 | 25 | 26 | // Clear geometry 27 | void STDMETHODCALLTYPE CFW1TextGeometry::Clear() { 28 | m_vertices.clear(); 29 | m_maxSheetIndex = 0; 30 | 31 | m_sorted = false; 32 | } 33 | 34 | 35 | // Add a vertex 36 | void STDMETHODCALLTYPE CFW1TextGeometry::AddGlyphVertex(const FW1_GLYPHVERTEX *pVertex) { 37 | m_vertices.push_back(*pVertex); 38 | 39 | UINT sheetIndex = pVertex->GlyphIndex >> 16; 40 | m_maxSheetIndex = std::max(m_maxSheetIndex, sheetIndex); 41 | 42 | m_sorted = false; 43 | } 44 | 45 | 46 | // Get current glyph vertices 47 | FW1_VERTEXDATA STDMETHODCALLTYPE CFW1TextGeometry::GetGlyphVerticesTemp() { 48 | FW1_VERTEXDATA vertexData; 49 | 50 | if(!m_vertices.empty()) { 51 | UINT32 sheetCount = m_maxSheetIndex + 1; 52 | 53 | // Sort and prepare vertices 54 | if(!m_sorted) { 55 | m_sortedVertices.resize(m_vertices.size()); 56 | m_vertexCounts.resize(sheetCount); 57 | m_vertexStartIndices.resize(sheetCount); 58 | 59 | std::fill(m_vertexCounts.begin(), m_vertexCounts.end(), 0); 60 | 61 | UINT * const vertexCounts = &m_vertexCounts[0]; 62 | const FW1_GLYPHVERTEX * const vertices = &m_vertices[0]; 63 | const UINT32 vertexCount = static_cast(m_vertices.size()); 64 | 65 | for(UINT32 i=0; i < vertexCount; ++i) { 66 | UINT32 sheetIndex = vertices[i].GlyphIndex >> 16; 67 | 68 | ++vertexCounts[sheetIndex]; 69 | } 70 | 71 | UINT * const vertexStartIndices = &m_vertexStartIndices[0]; 72 | 73 | UINT currentStartIndex = 0; 74 | for(UINT32 i=0; i < sheetCount; ++i) { 75 | vertexStartIndices[i] = currentStartIndex; 76 | 77 | currentStartIndex += vertexCounts[i]; 78 | } 79 | 80 | FW1_GLYPHVERTEX * const sortedVertices = &m_sortedVertices[0]; 81 | 82 | for(UINT32 i=0; i < vertexCount; ++i) { 83 | const FW1_GLYPHVERTEX &vertex = vertices[i]; 84 | UINT32 sheetIndex = vertex.GlyphIndex >> 16; 85 | 86 | UINT &vertexIndex = vertexStartIndices[sheetIndex]; 87 | 88 | sortedVertices[vertexIndex] = vertex; 89 | sortedVertices[vertexIndex].GlyphIndex &= 0xffff; 90 | 91 | ++vertexIndex; 92 | } 93 | 94 | m_sorted = true; 95 | } 96 | 97 | vertexData.SheetCount = sheetCount; 98 | vertexData.pVertexCounts = &m_vertexCounts[0]; 99 | vertexData.TotalVertexCount = static_cast(m_vertices.size()); 100 | vertexData.pVertices = &m_sortedVertices[0]; 101 | } 102 | else { 103 | vertexData.SheetCount = 0; 104 | vertexData.pVertexCounts = 0; 105 | vertexData.TotalVertexCount = 0; 106 | vertexData.pVertices = 0; 107 | } 108 | 109 | return vertexData; 110 | } 111 | 112 | 113 | }// namespace FW1FontWrapper 114 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1TextRenderer.cpp: -------------------------------------------------------------------------------- 1 | // CFW1TextRenderer.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1TextRenderer.h" 6 | 7 | #define SAFE_RELEASE(pObject) { if(pObject) { (pObject)->Release(); (pObject) = NULL; } } 8 | 9 | 10 | namespace FW1FontWrapper { 11 | 12 | 13 | // Construct 14 | CFW1TextRenderer::CFW1TextRenderer() : 15 | m_pGlyphProvider(NULL), 16 | 17 | m_currentFlags(0), 18 | m_currentColor(0xff000000), 19 | 20 | m_cachedGlyphMap(0), 21 | m_pCachedGlyphMapFontFace(NULL), 22 | m_cachedGlyphMapFontSize(0), 23 | 24 | m_pDWriteTextRendererProxy(0) 25 | { 26 | } 27 | 28 | 29 | // Destruct 30 | CFW1TextRenderer::~CFW1TextRenderer() { 31 | SAFE_RELEASE(m_pGlyphProvider); 32 | 33 | delete m_pDWriteTextRendererProxy; 34 | } 35 | 36 | 37 | // Init 38 | HRESULT CFW1TextRenderer::initTextRenderer( 39 | IFW1Factory *pFW1Factory, 40 | IFW1GlyphProvider *pGlyphProvider 41 | ) { 42 | HRESULT hResult = initBaseObject(pFW1Factory); 43 | if(FAILED(hResult)) 44 | return hResult; 45 | 46 | if(pGlyphProvider == NULL) 47 | return E_INVALIDARG; 48 | 49 | pGlyphProvider->AddRef(); 50 | m_pGlyphProvider = pGlyphProvider; 51 | 52 | m_pDWriteTextRendererProxy = new CDWriteTextRendererProxy(this); 53 | 54 | return S_OK; 55 | } 56 | 57 | 58 | }// namespace FW1FontWrapper 59 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/CFW1TextRenderer.h: -------------------------------------------------------------------------------- 1 | // CFW1TextRenderer.h 2 | 3 | #ifndef IncludeGuard__FW1_CFW1TextRenderer 4 | #define IncludeGuard__FW1_CFW1TextRenderer 5 | 6 | #include "CFW1Object.h" 7 | 8 | 9 | namespace FW1FontWrapper { 10 | 11 | 12 | // Converts a DWrite text layout to vertices 13 | class CFW1TextRenderer : public CFW1Object { 14 | public: 15 | // IUnknown 16 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); 17 | 18 | // IFW1DWriteTextRenderer 19 | virtual HRESULT STDMETHODCALLTYPE GetGlyphProvider(IFW1GlyphProvider **ppGlyphProvider); 20 | 21 | virtual HRESULT STDMETHODCALLTYPE DrawTextLayout( 22 | IDWriteTextLayout *pTextLayout, 23 | FLOAT OriginX, 24 | FLOAT OriginY, 25 | UINT32 Color, 26 | UINT Flags, 27 | IFW1TextGeometry *pTextGeometry 28 | ); 29 | 30 | // Public functions 31 | public: 32 | CFW1TextRenderer(); 33 | 34 | HRESULT initTextRenderer( 35 | IFW1Factory *pFW1Factory, 36 | IFW1GlyphProvider *pGlyphProvider 37 | ); 38 | 39 | // Internal functions 40 | private: 41 | virtual ~CFW1TextRenderer(); 42 | 43 | // IDWritePixelSnapping interface (called via proxy) 44 | HRESULT IsPixelSnappingDisabled(void *clientDrawingContext, BOOL *isDisabled); 45 | HRESULT GetCurrentTransform(void *clientDrawingContext, DWRITE_MATRIX *transform); 46 | HRESULT GetPixelsPerDip(void *clientDrawingContext, FLOAT *pixelsPerDip); 47 | 48 | // IDWriteTextRenderer interface (called via proxy) 49 | HRESULT DrawGlyphRun( 50 | void *clientDrawingContext, 51 | FLOAT baselineOriginX, 52 | FLOAT baselineOriginY, 53 | DWRITE_MEASURING_MODE measuringMode, 54 | const DWRITE_GLYPH_RUN *glyphRun, 55 | const DWRITE_GLYPH_RUN_DESCRIPTION *glyphRunDescription, 56 | IUnknown *clientDrawingEffect 57 | ); 58 | HRESULT DrawUnderline( 59 | void *clientDrawingContext, 60 | FLOAT baselineOriginX, 61 | FLOAT baselineOriginY, 62 | const DWRITE_UNDERLINE *underline, 63 | IUnknown *clientDrawingEffect 64 | ); 65 | HRESULT DrawStrikethrough( 66 | void *clientDrawingContext, 67 | FLOAT baselineOriginX, 68 | FLOAT baselineOriginY, 69 | const DWRITE_STRIKETHROUGH *strikethrough, 70 | IUnknown *clientDrawingEffect 71 | ); 72 | HRESULT DrawInlineObject( 73 | void *clientDrawingContext, 74 | FLOAT originX, 75 | FLOAT originY, 76 | IDWriteInlineObject *inlineObject, 77 | BOOL isSideways, 78 | BOOL isRightToLeft, 79 | IUnknown *clientDrawingEffect 80 | ); 81 | 82 | // Internal data 83 | private: 84 | IFW1GlyphProvider *m_pGlyphProvider; 85 | 86 | UINT m_currentFlags; 87 | UINT32 m_currentColor; 88 | 89 | const void *m_cachedGlyphMap; 90 | IDWriteFontFace *m_pCachedGlyphMapFontFace; 91 | FLOAT m_cachedGlyphMapFontSize; 92 | 93 | 94 | // Proxy for IDWriteTextRenderer interface 95 | private: 96 | class CDWriteTextRendererProxy : public IDWriteTextRenderer { 97 | public: 98 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) { 99 | return m_realObject->QueryInterface(riid, ppvObject); 100 | } 101 | virtual ULONG STDMETHODCALLTYPE AddRef() { 102 | return m_realObject->AddRef(); 103 | } 104 | virtual ULONG STDMETHODCALLTYPE Release() { 105 | return m_realObject->Release(); 106 | } 107 | 108 | virtual HRESULT STDMETHODCALLTYPE IsPixelSnappingDisabled(void *clientDrawingContext, BOOL *isDisabled) { 109 | return m_realObject->IsPixelSnappingDisabled(clientDrawingContext, isDisabled); 110 | } 111 | virtual HRESULT STDMETHODCALLTYPE GetCurrentTransform(void *clientDrawingContext, DWRITE_MATRIX *transform) { 112 | return m_realObject->GetCurrentTransform(clientDrawingContext, transform); 113 | } 114 | virtual HRESULT STDMETHODCALLTYPE GetPixelsPerDip(void *clientDrawingContext, FLOAT *pixelsPerDip) { 115 | return m_realObject->GetPixelsPerDip(clientDrawingContext, pixelsPerDip); 116 | } 117 | 118 | virtual HRESULT STDMETHODCALLTYPE DrawGlyphRun(void *clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, DWRITE_MEASURING_MODE measuringMode, const DWRITE_GLYPH_RUN *glyphRun, const DWRITE_GLYPH_RUN_DESCRIPTION *glyphRunDescription, IUnknown *clientDrawingEffect) { 119 | return m_realObject->DrawGlyphRun(clientDrawingContext, baselineOriginX, baselineOriginY, measuringMode, glyphRun, glyphRunDescription, clientDrawingEffect); 120 | } 121 | virtual HRESULT STDMETHODCALLTYPE DrawUnderline(void *clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, const DWRITE_UNDERLINE *underline, IUnknown *clientDrawingEffect) { 122 | return m_realObject->DrawUnderline(clientDrawingContext, baselineOriginX, baselineOriginY, underline, clientDrawingEffect); 123 | } 124 | virtual HRESULT STDMETHODCALLTYPE DrawStrikethrough(void *clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, const DWRITE_STRIKETHROUGH *strikethrough, IUnknown *clientDrawingEffect) { 125 | return m_realObject->DrawStrikethrough(clientDrawingContext, baselineOriginX, baselineOriginY, strikethrough, clientDrawingEffect); 126 | } 127 | virtual HRESULT STDMETHODCALLTYPE DrawInlineObject(void *clientDrawingContext, FLOAT originX, FLOAT originY, IDWriteInlineObject *inlineObject, BOOL isSideways, BOOL isRightToLeft, IUnknown *clientDrawingEffect) { 128 | return m_realObject->DrawInlineObject(clientDrawingContext, originX, originY, inlineObject, isSideways, isRightToLeft, clientDrawingEffect); 129 | } 130 | 131 | public: 132 | CDWriteTextRendererProxy(CFW1TextRenderer *realObject) : m_realObject(realObject) {} 133 | 134 | private: 135 | CDWriteTextRendererProxy(const CDWriteTextRendererProxy&); 136 | CDWriteTextRendererProxy& operator=(const CDWriteTextRendererProxy&); 137 | 138 | private: 139 | CFW1TextRenderer *m_realObject; 140 | } *m_pDWriteTextRendererProxy; 141 | }; 142 | 143 | 144 | }// namespace FW1FontWrapper 145 | 146 | 147 | #endif// IncludeGuard__FW1_CFW1TextRenderer 148 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/FW1CompileSettings.h: -------------------------------------------------------------------------------- 1 | // FW1CompileSettings.h 2 | 3 | #ifndef IncludeGuard__FW1_FW1CompileSettings_h 4 | #define IncludeGuard__FW1_FW1CompileSettings_h 5 | 6 | 7 | // Define if building a DLL for the font-wrapper 8 | #define FW1_COMPILETODLL 9 | 10 | // Define to use LoadLibrary instead of linking to DLLs 11 | #define FW1_DELAYLOAD_DWRITE_DLL 12 | #define FW1_DELAYLOAD_D3DCOMPILER_XX_DLL 13 | 14 | 15 | #endif// IncludeGuard__FW1_FW1CompileSettings_h 16 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/FW1FontWrapper.cpp: -------------------------------------------------------------------------------- 1 | // FW1FontWrapper.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | #include "CFW1Factory.h" 6 | 7 | #ifndef FW1_DELAYLOAD_DWRITE_DLL 8 | #pragma comment (lib, "DWrite.lib") 9 | #endif 10 | 11 | #ifndef FW1_DELAYLOAD_D3DCOMPILER_XX_DLL 12 | #pragma comment (lib, "DWrite.lib") 13 | #endif 14 | 15 | #ifdef FW1_COMPILETODLL 16 | #ifndef _M_X64 17 | #pragma comment (linker, "/EXPORT:FW1CreateFactory=_FW1CreateFactory@8,@1") 18 | #endif 19 | #endif 20 | 21 | 22 | // Create FW1 factory 23 | extern "C" HRESULT STDMETHODCALLTYPE FW1CreateFactory(UINT32 Version, IFW1Factory **ppFactory) { 24 | if(Version != FW1_VERSION) 25 | return E_FAIL; 26 | 27 | if(ppFactory == NULL) 28 | return E_INVALIDARG; 29 | 30 | FW1FontWrapper::CFW1Factory *pFactory = new FW1FontWrapper::CFW1Factory; 31 | HRESULT hResult = pFactory->initFactory(); 32 | if(FAILED(hResult)) { 33 | pFactory->Release(); 34 | } 35 | else { 36 | *ppFactory = pFactory; 37 | 38 | hResult = S_OK; 39 | } 40 | 41 | return hResult; 42 | } 43 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/FW1Precompiled.cpp: -------------------------------------------------------------------------------- 1 | // FW1Precompiled.cpp 2 | 3 | #include "FW1Precompiled.h" 4 | 5 | -------------------------------------------------------------------------------- /external/FW1FontWrapper/Source/FW1Precompiled.h: -------------------------------------------------------------------------------- 1 | // FW1Precompiled.h 2 | 3 | #ifndef IncludeGuard__FW1_FW1Precompiled_h 4 | #define IncludeGuard__FW1_FW1Precompiled_h 5 | 6 | 7 | #define NOMINMAX 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "FW1CompileSettings.h" 21 | #include "FW1FontWrapper.h" 22 | 23 | 24 | #endif// IncludeGuard__FW1_FW1Precompiled_h 25 | -------------------------------------------------------------------------------- /external/aSeeVRClient/bin/aSeeVRClient.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/external/aSeeVRClient/bin/aSeeVRClient.dll -------------------------------------------------------------------------------- /external/aSeeVRClient/include/aSeeVRClient.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/external/aSeeVRClient/include/aSeeVRClient.h -------------------------------------------------------------------------------- /external/aSeeVRClient/include/aSeeVRTypes.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/external/aSeeVRClient/include/aSeeVRTypes.h -------------------------------------------------------------------------------- /external/aSeeVRClient/lib/aSeeVRClient.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/external/aSeeVRClient/lib/aSeeVRClient.lib -------------------------------------------------------------------------------- /installer/.gitignore: -------------------------------------------------------------------------------- 1 | Output/ -------------------------------------------------------------------------------- /installer/README.rtf: -------------------------------------------------------------------------------- 1 | {\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Tahoma;}} 2 | {\colortbl ;\red43\green145\blue175;\red163\green21\blue21;\red0\green0\blue0;\red0\green0\blue255;} 3 | {\*\generator Riched20 10.0.19041}\viewkind4\uc1 4 | \pard\sa200\sl240\slmult1\qj\cf1\f0\fs22\lang9 OpenXR Toolkit - \cf0 Development Build \fs16 (v0.0.0)\cf2\fs22\par 5 | \cf3\fs19 This software provides a collection of useful features to customize and improve existing OpenXR applications,\lang1033 \lang9 including render upscaling and sharpening, foveated rendering, hand tracking to controller input simulation, image adjustments\lang1033 \lang9 and other game-enhancing tweaks.\par 6 | Please visit the official page at {\cf0{\field{\*\fldinst{HYPERLINK https://mbucchia.github.io/OpenXR-Toolkit/ }}{\fldrslt{https://mbucchia.github.io/OpenXR-Toolkit/\ul0\cf0}}}}\f0\fs19 for detailed instructions on how to download,\lang1033 \lang9 install, and use this software.\par 7 | \b DISCLAIMER: This software is distributed as-is, without any warranties or conditions of any kind. Use at your own risks.\par 8 | \cf2 PRIVACY WARNING: Certain functionality of this software such as file logging and trace file logging may collect the following personal information: "Name of the computer", "Windows account name". By installing this software, you consent to have this information collected and potentially exposed online (if you share these logs online).\cf3\par 9 | \b0 This software was created by Matthieu Bucchianeri and Jean-Luc Dupiot.\par 10 | Logo and icons designed by RPthreenine.\par 11 | User Experience designed by Andrew Lilley (FarFutureFox).\par 12 | Additional contributions by James Lacey (Jabbah), Bernhard Berger, and Erik Uri.\par 13 | \par 14 | } 15 | -------------------------------------------------------------------------------- /installer/banner.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/installer/banner.bmp -------------------------------------------------------------------------------- /installer/comodo.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/installer/comodo.pfx -------------------------------------------------------------------------------- /installer/selfsigncert.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/installer/selfsigncert.pfx -------------------------------------------------------------------------------- /installer/signtool.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/installer/signtool.exe -------------------------------------------------------------------------------- /mappings/FS2020.cfg: -------------------------------------------------------------------------------- 1 | left.transform.vec=0.028 -0.054 -0.02 2 | left.transform.euler=-56 -5 16 3 | left.transform.quat=-0.4698203 0.0271368 0.1024868 0.8763726 4 | right.transform.vec=-0.028 -0.054 -0.02 5 | right.transform.euler=-56 5 -16 6 | right.transform.quat=-0.4698203 -0.0271368 -0.1024868 0.8763726 7 | left.enabled=true 8 | right.enabled=true 9 | grip_joint=0 10 | aim_joint=0 11 | left.pinch=/input/trigger/value 12 | left.thumb_press= 13 | left.index_bend= 14 | left.finger_gun= 15 | left.squeeze=/input/squeeze/value 16 | left.wrist_tap=/input/y/click 17 | left.palm_tap= 18 | left.index_tip_tap= 19 | left.custom1= 20 | right.pinch=/input/trigger/value 21 | right.thumb_press= 22 | right.index_bend= 23 | right.finger_gun= 24 | right.squeeze=/input/squeeze/value 25 | right.wrist_tap= 26 | right.palm_tap= 27 | right.index_tip_tap=/input/b/click 28 | right.custom1= 29 | interaction_profile=/interaction_profiles/hp/mixed_reality_controller 30 | pinch.near=0 31 | pinch.far=0.03 32 | thumb_press.near=0 33 | thumb_press.far=0.05 34 | index_bend.near=0.045 35 | index_bend.far=0.07 36 | finger_gun.near=0 37 | finger_gun.far=0.02 38 | squeeze.near=0.042 39 | squeeze.far=0.07 40 | wrist_tap.near=0.035 41 | wrist_tap.far=0.06 42 | palm_tap.near=0.02 43 | palm_tap.far=0.06 44 | index_tip_tap.near=0 45 | index_tip_tap.far=0.07 46 | click_threshold=0.75 47 | custom1_joint1=-1 48 | custom1_joint2=-1 49 | custom1.near=0 50 | custom1.far=0.1 51 | haptics_gesture=3 52 | haptics_action=/input/trigger/value 53 | haptics_frequency=0.5 54 | keepalive_action=/user/hand/left/input/thumbstick/click 55 | keepalive_interval=5 -------------------------------------------------------------------------------- /mappingstool/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /mappingstool/Program.cs: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright(c) 2022 Matthieu Bucchianeri 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this softwareand 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 noticeand 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. 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Linq; 26 | using System.Threading.Tasks; 27 | using System.Windows.Forms; 28 | 29 | namespace mappingtool 30 | { 31 | static class Program 32 | { 33 | /// 34 | /// The main entry point for the application. 35 | /// 36 | [STAThread] 37 | static void Main() 38 | { 39 | Application.EnableVisualStyles(); 40 | Application.SetCompatibleTextRenderingDefault(false); 41 | Application.Run(new Form1()); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /mappingstool/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("OpenXR Toolkit Hand-to-Controller Configuration tool")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("OpenXR-Toolkit")] 13 | [assembly: AssemblyCopyright("Copyright ©2021-2022 Matthieu Bucchianeri")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("f64486ba-421e-43a7-8e97-dc9981ea5c6f")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /mappingstool/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | 12 | namespace mappingtool.Properties 13 | { 14 | /// 15 | /// A strongly-typed resource class, for looking up localized strings, etc. 16 | /// 17 | // This class was auto-generated by the StronglyTypedResourceBuilder 18 | // class via a tool like ResGen or Visual Studio. 19 | // To add or remove a member, edit your .ResX file then rerun ResGen 20 | // with the /str option, or rebuild your VS project. 21 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 22 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 23 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 24 | internal class Resources 25 | { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() 33 | { 34 | } 35 | 36 | /// 37 | /// Returns the cached ResourceManager instance used by this class. 38 | /// 39 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 40 | internal static global::System.Resources.ResourceManager ResourceManager 41 | { 42 | get 43 | { 44 | if ((resourceMan == null)) 45 | { 46 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("mappingtool.Properties.Resources", typeof(Resources).Assembly); 47 | resourceMan = temp; 48 | } 49 | return resourceMan; 50 | } 51 | } 52 | 53 | /// 54 | /// Overrides the current thread's CurrentUICulture property for all 55 | /// resource lookups using this strongly typed resource class. 56 | /// 57 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 58 | internal static global::System.Globalization.CultureInfo Culture 59 | { 60 | get 61 | { 62 | return resourceCulture; 63 | } 64 | set 65 | { 66 | resourceCulture = value; 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /mappingstool/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /mappingstool/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | 12 | namespace mappingtool.Properties 13 | { 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 17 | { 18 | 19 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 20 | 21 | public static Settings Default 22 | { 23 | get 24 | { 25 | return defaultInstance; 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /mappingstool/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /mappingstool/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/mappingstool/icon.ico -------------------------------------------------------------------------------- /mappingstool/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /patches/FidelityFX-FSR/0000-conditionaly-compile-denoise-code-fsr-v1.20210629.patch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/patches/FidelityFX-FSR/0000-conditionaly-compile-denoise-code-fsr-v1.20210629.patch -------------------------------------------------------------------------------- /patches/NVIDIAImageScaling/0000-allow-compileshader-option-wx-nis-1-0-2.patch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/patches/NVIDIAImageScaling/0000-allow-compileshader-option-wx-nis-1-0-2.patch -------------------------------------------------------------------------------- /patches/msys-2.0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/patches/msys-2.0.dll -------------------------------------------------------------------------------- /patches/msys-iconv-2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/patches/msys-iconv-2.dll -------------------------------------------------------------------------------- /patches/msys-intl-8.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/patches/msys-intl-8.dll -------------------------------------------------------------------------------- /patches/patch.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/patches/patch.exe -------------------------------------------------------------------------------- /patches/sed.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/patches/sed.exe -------------------------------------------------------------------------------- /scripts/DisableDebugLayer.reg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/scripts/DisableDebugLayer.reg -------------------------------------------------------------------------------- /scripts/EnableDebugLayer.reg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbucchia/OpenXR-Toolkit/6b9ecb69a4b2dc714b14a86407868af315d02531/scripts/EnableDebugLayer.reg -------------------------------------------------------------------------------- /scripts/Install-Layer.ps1: -------------------------------------------------------------------------------- 1 | $RegistryPath = "HKLM:\Software\Khronos\OpenXR\1\ApiLayers\Implicit" 2 | $JsonPath = Join-Path "$PSScriptRoot" "XR_APILAYER_MBUCCHIA_toolkit.json" 3 | 4 | # Search for Ultraleap. 5 | $ultraleapPath = $null 6 | $layers = Get-Item $RegistryPath 2> $null | Select-Object -ExpandProperty property 7 | foreach ($entry in $layers) 8 | { 9 | if ($entry -match ".*\\UltraleapHandTracking.json") 10 | { 11 | $ultraleapPath = $entry 12 | break 13 | } 14 | } 15 | 16 | # To guarantee the loading order of the API layers, we remove Ultraleap, add our layer, then re-add Ultraleap. 17 | if ($ultraleapPath) 18 | { 19 | Start-Process -FilePath powershell.exe -Verb RunAs -Wait -ArgumentList @" 20 | & { 21 | Remove-ItemProperty -Path $RegistryPath -Name '$ultraleapPath' -Force | Out-Null 22 | New-ItemProperty -Path $RegistryPath -Name '$jsonPath' -PropertyType DWord -Value 0 -Force | Out-Null 23 | New-ItemProperty -Path $RegistryPath -Name '$ultraleapPath' -PropertyType DWord -Value 0 -Force | Out-Null 24 | } 25 | "@ 26 | } 27 | else 28 | { 29 | Start-Process -FilePath powershell.exe -Verb RunAs -Wait -ArgumentList @" 30 | & { 31 | If (-not (Test-Path $RegistryPath)) { 32 | New-Item -Path $RegistryPath -Force | Out-Null 33 | } 34 | New-ItemProperty -Path $RegistryPath -Name '$jsonPath' -PropertyType DWord -Value 0 -Force | Out-Null 35 | } 36 | "@ 37 | } 38 | -------------------------------------------------------------------------------- /scripts/OXRTK.wprp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /scripts/OXRTK_WMR.wprp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /scripts/Uninstall-Layer.ps1: -------------------------------------------------------------------------------- 1 | $JsonPath = Join-Path "$PSScriptRoot" "XR_APILAYER_MBUCCHIA_toolkit.json" 2 | Start-Process -FilePath powershell.exe -Verb RunAs -Wait -ArgumentList @" 3 | & { 4 | Remove-ItemProperty -Path HKLM:\Software\Khronos\OpenXR\1\ApiLayers\Implicit -Name '$jsonPath' -Force | Out-Null 5 | } 6 | "@ 7 | --------------------------------------------------------------------------------