Ralith / openxrs

OpenXR bindings for Rust
Apache License 2.0
281 stars 59 forks source link

Adds support for structextends #136

Open artumino opened 1 year ago

artumino commented 1 year ago

Handles "structextends" similarly to how ash does it.

I identify a series of root structs, referenced by at least another one through their "structextends" attribute. Each root struct defines an extension trait and a generic push_next method over the extension trait that allows adding members to the pointer chain. Structs that have a "structextends" attribute implement the extension trait of the structure they are extending which allows them to be chained.

In the case of polymorphic structs, I use a similar approach by defining an extension trait that will be implemented by every extension struct and a push_next trait that will be implemented by each child.

This allows submitting an additional CompositionLayerDepthInfoKHR to composition layer views, or additional layer info like application space warp info.

Example code for depth submission:

let mut depth_info = openxr::CompositionLayerDepthInfoKHR::new()
        .sub_image(
            openxr::SwapchainSubImage::new()
                .swapchain(depth_swapchain.internal())
                .image_array_index(0)
                .image_rect(rect),
        )
        .max_depth(1.0)
        .min_depth(0.0)
        .far_z(cameras[0].far)
        .near_z(cameras[0].near);

openxr::CompositionLayerProjectionView::new()
        .push_next(&mut depth_info)
        .pose(views[0].pose)
        .fov(views[0].fov)
        .sub_image(
            openxr::SwapchainSubImage::new()
                .swapchain(color_swapchain.internal())
                .image_array_index(0)
                .image_rect(rect),
        )