Giter Club home page Giter Club logo

openxr.pinvoke's Introduction

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);
}

openxr.pinvoke's People

Contributors

lostmsu avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

openxr.pinvoke's Issues

appInfo.applicationName is not a variable, property, or indexer?

Hello,

in trying to set the applicationName in a XrApplicationInfo struct with the following code

//C#
...   
XrApplicationInfo appInfo = new XrApplicationInfo();
appInfo.applicationName = (sbyte*)myFoo;
...

I get the error message "left hand side must be variable, property, or indexer"

intellisense in VS2019 recognizes it as a field, and I don't quite understand the implications of the following:

public struct XrApplicationInfo
...
[CompilerGenerated]
[UnsafeValueType]
public struct <applicationName>e__FixedBuffer
{
    public sbyte FixedElementField;
}
...

is there some particular idiom for working with these types of values? should I be trying to set e__FixedBuffer? or perhaps is the problem that I'm accidentally trying to set that value?

any assistance would be appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.