pull main, refactor passthrough
This commit is contained in:
170
src/resources.rs
170
src/resources.rs
@@ -3,14 +3,20 @@ use std::sync::atomic::AtomicBool;
|
||||
use std::sync::Mutex;
|
||||
|
||||
use crate::input::XrInput;
|
||||
// use crate::passthrough::XrPassthroughLayer;
|
||||
use crate::passthrough::{CompositionLayerPassthrough, XrPassthroughLayer};
|
||||
use crate::resource_macros::*;
|
||||
use crate::xr::sys::CompositionLayerPassthroughFB;
|
||||
use crate::xr::{CompositionLayerBase, CompositionLayerFlags};
|
||||
use crate::{resource_macros::*, xr_resource_wrapper_copy};
|
||||
use bevy::prelude::*;
|
||||
use bevy::render::extract_resource::ExtractResourcePlugin;
|
||||
use bevy::prelude::*;
|
||||
use bevy::render::extract_component::ExtractComponent;
|
||||
use bevy::render::extract_resource::{ExtractResource, ExtractResourcePlugin};
|
||||
use core::ptr;
|
||||
use openxr as xr;
|
||||
|
||||
xr_resource_wrapper!(XrInstance, xr::Instance);
|
||||
xr_resource_wrapper!(XrSession, xr::Session<xr::AnyGraphics>);
|
||||
// xr_resource_wrapper!(XrSession, xr::Session<xr::AnyGraphics>);
|
||||
xr_resource_wrapper_copy!(XrEnvironmentBlendMode, xr::EnvironmentBlendMode);
|
||||
xr_resource_wrapper_copy!(XrResolution, UVec2);
|
||||
xr_resource_wrapper_copy!(XrFormat, wgpu::TextureFormat);
|
||||
@@ -20,6 +26,23 @@ xr_arc_resource_wrapper!(XrSessionRunning, AtomicBool);
|
||||
xr_arc_resource_wrapper!(XrSwapchain, Swapchain);
|
||||
xr_no_clone_resource_wrapper!(XrFrameWaiter, xr::FrameWaiter);
|
||||
|
||||
#[derive(Clone, Resource, ExtractResource)]
|
||||
pub enum XrSession {
|
||||
Vulkan(xr::Session<xr::Vulkan>),
|
||||
}
|
||||
|
||||
impl std::ops::Deref for XrSession {
|
||||
type Target = xr::Session<xr::AnyGraphics>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
// SAFTEY: should be fine i think -Schmarni
|
||||
unsafe {
|
||||
match self {
|
||||
XrSession::Vulkan(sess) => std::mem::transmute(sess),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct VulkanOXrSessionSetupInfo {
|
||||
pub(crate) device_ptr: *const c_void,
|
||||
@@ -91,7 +114,7 @@ impl Swapchain {
|
||||
stage: &xr::Space,
|
||||
resolution: UVec2,
|
||||
environment_blend_mode: xr::EnvironmentBlendMode,
|
||||
// passthrough_layer: Option<&XrPassthroughLayer>,
|
||||
passthrough_layer: Option<&XrPassthroughLayer>,
|
||||
) -> xr::Result<()> {
|
||||
match self {
|
||||
Swapchain::Vulkan(swapchain) => swapchain.end(
|
||||
@@ -100,7 +123,7 @@ impl Swapchain {
|
||||
stage,
|
||||
resolution,
|
||||
environment_blend_mode,
|
||||
// passthrough_layer,
|
||||
passthrough_layer,
|
||||
),
|
||||
}
|
||||
}
|
||||
@@ -160,7 +183,7 @@ impl<G: xr::Graphics> SwapchainInner<G> {
|
||||
stage: &xr::Space,
|
||||
resolution: UVec2,
|
||||
environment_blend_mode: xr::EnvironmentBlendMode,
|
||||
// passthrough_layer: Option<&XrPassthroughLayer>,
|
||||
passthrough_layer: Option<&XrPassthroughLayer>,
|
||||
) -> xr::Result<()> {
|
||||
let rect = xr::Rect2Di {
|
||||
offset: xr::Offset2Di { x: 0, y: 0 },
|
||||
@@ -174,76 +197,71 @@ impl<G: xr::Graphics> SwapchainInner<G> {
|
||||
warn!("views are len of 0");
|
||||
return Ok(());
|
||||
}
|
||||
// match passthrough_layer {
|
||||
// Some(pass) => {
|
||||
// // info!("Rendering with pass through");
|
||||
// let passthrough_layer = xr::sys::CompositionLayerPassthroughFB {
|
||||
// ty: CompositionLayerPassthroughFB::TYPE,
|
||||
// next: ptr::null(),
|
||||
// flags: CompositionLayerFlags::BLEND_TEXTURE_SOURCE_ALPHA,
|
||||
// space: xr::sys::Space::NULL,
|
||||
// layer_handle: pass.0,
|
||||
// };
|
||||
// self.stream.lock().unwrap().end(
|
||||
// predicted_display_time,
|
||||
// environment_blend_mode,
|
||||
// &[
|
||||
// &xr::CompositionLayerProjection::new()
|
||||
// .layer_flags(CompositionLayerFlags::UNPREMULTIPLIED_ALPHA)
|
||||
// .space(stage)
|
||||
// .views(&[
|
||||
// xr::CompositionLayerProjectionView::new()
|
||||
// .pose(views[0].pose)
|
||||
// .fov(views[0].fov)
|
||||
// .sub_image(
|
||||
// xr::SwapchainSubImage::new()
|
||||
// .swapchain(&swapchain)
|
||||
// .image_array_index(0)
|
||||
// .image_rect(rect),
|
||||
// ),
|
||||
// xr::CompositionLayerProjectionView::new()
|
||||
// .pose(views[1].pose)
|
||||
// .fov(views[1].fov)
|
||||
// .sub_image(
|
||||
// xr::SwapchainSubImage::new()
|
||||
// .swapchain(&swapchain)
|
||||
// .image_array_index(1)
|
||||
// .image_rect(rect),
|
||||
// ),
|
||||
// ]),
|
||||
// unsafe {
|
||||
// &*(&passthrough_layer as *const _ as *const CompositionLayerBase<G>)
|
||||
// },
|
||||
// ],
|
||||
// )
|
||||
// }
|
||||
match passthrough_layer {
|
||||
Some(pass) => {
|
||||
//bevy::log::info!("Rendering with pass through");
|
||||
|
||||
// None =>
|
||||
let r = self.stream.lock().unwrap().end(
|
||||
predicted_display_time,
|
||||
environment_blend_mode,
|
||||
&[&xr::CompositionLayerProjection::new().space(stage).views(&[
|
||||
xr::CompositionLayerProjectionView::new()
|
||||
.pose(views[0].pose)
|
||||
.fov(views[0].fov)
|
||||
.sub_image(
|
||||
xr::SwapchainSubImage::new()
|
||||
.swapchain(&swapchain)
|
||||
.image_array_index(0)
|
||||
.image_rect(rect),
|
||||
),
|
||||
xr::CompositionLayerProjectionView::new()
|
||||
.pose(views[1].pose)
|
||||
.fov(views[1].fov)
|
||||
.sub_image(
|
||||
xr::SwapchainSubImage::new()
|
||||
.swapchain(&swapchain)
|
||||
.image_array_index(1)
|
||||
.image_rect(rect),
|
||||
),
|
||||
])],
|
||||
);
|
||||
r
|
||||
// }
|
||||
self.stream.lock().unwrap().end(
|
||||
predicted_display_time,
|
||||
environment_blend_mode,
|
||||
&[
|
||||
&CompositionLayerPassthrough::from_xr_passthrough_layer(
|
||||
pass,
|
||||
),
|
||||
&xr::CompositionLayerProjection::new()
|
||||
.layer_flags(CompositionLayerFlags::BLEND_TEXTURE_SOURCE_ALPHA)
|
||||
.space(stage)
|
||||
.views(&[
|
||||
xr::CompositionLayerProjectionView::new()
|
||||
.pose(views[0].pose)
|
||||
.fov(views[0].fov)
|
||||
.sub_image(
|
||||
xr::SwapchainSubImage::new()
|
||||
.swapchain(&swapchain)
|
||||
.image_array_index(0)
|
||||
.image_rect(rect),
|
||||
),
|
||||
xr::CompositionLayerProjectionView::new()
|
||||
.pose(views[1].pose)
|
||||
.fov(views[1].fov)
|
||||
.sub_image(
|
||||
xr::SwapchainSubImage::new()
|
||||
.swapchain(&swapchain)
|
||||
.image_array_index(1)
|
||||
.image_rect(rect),
|
||||
),
|
||||
]),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
None => {
|
||||
bevy::log::info!("Rendering without pass through");
|
||||
self.stream.lock().unwrap().end(
|
||||
predicted_display_time,
|
||||
environment_blend_mode,
|
||||
&[&xr::CompositionLayerProjection::new().space(stage).views(&[
|
||||
xr::CompositionLayerProjectionView::new()
|
||||
.pose(views[0].pose)
|
||||
.fov(views[0].fov)
|
||||
.sub_image(
|
||||
xr::SwapchainSubImage::new()
|
||||
.swapchain(&swapchain)
|
||||
.image_array_index(0)
|
||||
.image_rect(rect),
|
||||
),
|
||||
xr::CompositionLayerProjectionView::new()
|
||||
.pose(views[1].pose)
|
||||
.fov(views[1].fov)
|
||||
.sub_image(
|
||||
xr::SwapchainSubImage::new()
|
||||
.swapchain(&swapchain)
|
||||
.image_array_index(1)
|
||||
.image_rect(rect),
|
||||
),
|
||||
])],
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user