working pipelined rendering

This commit is contained in:
awtterpip
2024-06-02 05:23:02 -05:00
parent e17262ab46
commit a0099bc4a7
4 changed files with 24 additions and 29 deletions

View File

@@ -6,6 +6,7 @@ use bevy_xr::{
};
use openxr::SpaceLocationFlags;
use crate::resources::Pipelined;
use crate::{
init::OxrTrackingRoot,
reference_space::{OxrPrimaryReferenceSpace, OxrReferenceSpace},
@@ -139,12 +140,22 @@ fn locate_hands(
&OxrHandBoneEntities,
)>,
mut bone_query: Query<(&HandBone, &mut HandBoneRadius, &mut Transform)>,
pipelined: Option<Res<Pipelined>>,
) {
for (tracker, ref_space, hand_entities) in &tracker_query {
let ref_space = ref_space.map(|v| &v.0).unwrap_or(&default_ref_space.0);
// relate_hand_joints also provides velocities
let joints = match ref_space.locate_hand_joints(tracker, frame_state.predicted_display_time)
{
let joints = match ref_space.locate_hand_joints(
tracker,
if pipelined.is_some() {
openxr::Time::from_nanos(
frame_state.predicted_display_time.as_nanos()
+ frame_state.predicted_display_period.as_nanos(),
)
} else {
frame_state.predicted_display_time
},
) {
Ok(Some(v)) => v,
Ok(None) => continue,
Err(openxr::sys::Result::ERROR_EXTENSION_NOT_PRESENT) => {

View File

@@ -31,7 +31,7 @@ use crate::resources::*;
use crate::types::*;
pub fn session_started(started: Option<Res<OxrSessionStarted>>) -> bool {
started.is_some_and(|started| started.get())
started.is_some_and(|started| started.0)
}
pub fn should_render(frame_state: Option<Res<OxrFrameState>>) -> bool {
@@ -109,6 +109,7 @@ impl Plugin for OxrInitPlugin {
},
ExtractResourcePlugin::<OxrCleanupSession>::default(),
ExtractResourcePlugin::<XrStatus>::default(),
ExtractResourcePlugin::<OxrSessionStarted>::default(),
))
.init_schedule(OxrLast)
.init_schedule(OxrSessionCreated)
@@ -180,13 +181,7 @@ impl Plugin for OxrInitPlugin {
}
};
let session_started = OxrSessionStarted::default();
app.insert_resource(session_started.clone());
let render_app = app.sub_app_mut(RenderApp);
render_app.insert_resource(session_started);
app.insert_resource(OxrSessionStarted(false));
}
}
@@ -489,18 +484,18 @@ pub fn create_xr_session(world: &mut World) {
}
}
pub fn begin_xr_session(session: Res<OxrSession>, session_started: Res<OxrSessionStarted>) {
pub fn begin_xr_session(session: Res<OxrSession>, mut session_started: ResMut<OxrSessionStarted>) {
let _span = info_span!("xr_begin_session");
session
.begin(openxr::ViewConfigurationType::PRIMARY_STEREO)
.expect("Failed to begin session");
session_started.set(true);
session_started.0 = true;
}
pub fn end_xr_session(session: Res<OxrSession>, session_started: Res<OxrSessionStarted>) {
pub fn end_xr_session(session: Res<OxrSession>, mut session_started: ResMut<OxrSessionStarted>) {
let _span = info_span!("xr_end_session");
session.end().expect("Failed to end session");
session_started.set(false);
session_started.0 = false;
}
/// This is used solely to transport resources from the main world to the render world.

View File

@@ -1,7 +1,7 @@
// use actions::XrActionPlugin;
use bevy::{
app::{PluginGroup, PluginGroupBuilder},
render::{pipelined_rendering::PipelinedRenderingPlugin, RenderPlugin},
render::RenderPlugin,
utils::default,
window::{PresentMode, Window, WindowPlugin},
};
@@ -34,7 +34,7 @@ pub fn add_xr_plugins<G: PluginGroup>(plugins: G) -> PluginGroupBuilder {
plugins
.build()
.disable::<RenderPlugin>()
.disable::<PipelinedRenderingPlugin>()
// .disable::<PipelinedRenderingPlugin>()
.add_before::<RenderPlugin, _>(XrSessionPlugin)
.add_before::<RenderPlugin, _>(OxrInitPlugin::default())
.add(OxrReferenceSpacePlugin::default())

View File

@@ -1,4 +1,3 @@
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use bevy::prelude::*;
@@ -440,18 +439,8 @@ pub struct SessionConfigInfo {
pub graphics_info: SessionCreateInfo,
}
#[derive(Resource, Clone, Default)]
pub struct OxrSessionStarted(Arc<AtomicBool>);
impl OxrSessionStarted {
pub fn set(&self, val: bool) {
self.0.store(val, Ordering::SeqCst);
}
pub fn get(&self) -> bool {
self.0.load(Ordering::SeqCst)
}
}
#[derive(ExtractResource, Resource, Clone, Default)]
pub struct OxrSessionStarted(pub bool);
/// The frame state returned from [FrameWaiter::wait_frame](openxr::FrameWaiter::wait)
#[derive(Clone, Deref, DerefMut, Resource, ExtractResource)]