TheButlah / ovr_overlay

Rust OpenVR bindings using an up-to-date OpenVR and autocxx
https://docs.rs/ovr_overlay
Other
7 stars 8 forks source link

Add Applications #14

Closed ShayBox closed 1 year ago

ShayBox commented 1 year ago

Related to #13

I'm not very experienced with C/C++, I'm not sure if you wanted the ovr_applications feature flag for the sys crate, the other flags appear to only be used for the library crate.

I did try but you can't put #[cfg(feature = "ovr_applications")] directly in the include_cpp! macro block without an error, and adding a second macro block also didn't work.

ShayBox commented 1 year ago

When building the docs locally it does seem to have worked, but in testing I don't know how to use this kind of code, not experienced in C/C++ or autocxx/bindgen/unsafe rust code, all I get from vr::VRApplications() is *mut ?

This pull request is probably useless unless someone contributes or helps but maybe it can get things started, I also found this project that has similar looking code for the parts I need, maybe it can help.
https://github.com/mdonoughe/vr-status/blob/e8873736c33c713f978dd8e8f01ab93049d75a46/src/openvr.rs

TheButlah commented 1 year ago

So in Rust FFI you generally have two crates, one low level -sys crate which is mostly just unsafe bindings to the foreign code, and one higher level library which wraps over the unsafe code and makes it safe.

Autocxx generates the ovr_overlay_sys crate for us, based on the macro. We then manually wrap that code with ovr_overlay, which makes the unsafe code safe to call. This is the crate with the feature flags (we don't make any attempt to modify the sys one).

I'll merge this PR since it adds the necessary functionality to the -sys crate, but if you want to easily call this functionality from rust you will probably need to actually crate a new manager type like the others in the rust wrappers, and implement functions on those types that call the unsafe rust.