Skip to content

losttech/OpenXR.PInvoke

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Getting started on Windows

  1. Create a new .NET Core WPF or Windows Forms project
  2. Add a reference to OpenXR.PInvoke package
  3. Allow unsafe code:
<PropertyGroup>
  <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
  1. Reference OpenXR.Loader package
  2. Modify .csproj file to have these (works on Windows only)
<ItemGroup>
  <PackageReference Include="OpenXR.Loader" Version="1.0.6.2" GeneratePathProperty="true" />
</ItemGroup>

<ItemGroup>
  <OpenXRBinaries Include="$(PkgOpenXR_Loader)/native/**/bin/openxr_loader.*" />
</ItemGroup>

<Target Name="CopyOpenXRLoaderFiles" AfterTargets="Build">
  <Copy SourceFiles="@(OpenXRBinaries)" DestinationFiles="@(OpenXRBinaries->'$(OutDir)native\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
  1. Add a custom native library resolver (works as is on Windows only):
NativeLibrary.SetDllImportResolver(typeof(OpenXR.PInvoke.XR).Assembly, Resolver);

static IntPtr Resolver(string libraryname, Assembly assembly, DllImportSearchPath? searchpath) {
    if (libraryname != "openxr_loader") return IntPtr.Zero;

    string installDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
    if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
        throw new PlatformNotSupportedException();

    string bitness = IntPtr.Size switch {
        4 => "Win32",
        8 => "x64",
        _ => throw new PlatformNotSupportedException(),
    };

    string path = Path.Combine(new[] {
        installDir, "native", bitness, "release", "bin",
        Path.ChangeExtension(libraryname, ".dll"),
    });

    return NativeLibrary.Load(path);
}

About

Raw PInvoke bindings for OpenXR

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages