working pipelined rendering
This commit is contained in:
@@ -6,6 +6,7 @@ use bevy_xr::{
|
|||||||
};
|
};
|
||||||
use openxr::SpaceLocationFlags;
|
use openxr::SpaceLocationFlags;
|
||||||
|
|
||||||
|
use crate::resources::Pipelined;
|
||||||
use crate::{
|
use crate::{
|
||||||
init::OxrTrackingRoot,
|
init::OxrTrackingRoot,
|
||||||
reference_space::{OxrPrimaryReferenceSpace, OxrReferenceSpace},
|
reference_space::{OxrPrimaryReferenceSpace, OxrReferenceSpace},
|
||||||
@@ -139,12 +140,22 @@ fn locate_hands(
|
|||||||
&OxrHandBoneEntities,
|
&OxrHandBoneEntities,
|
||||||
)>,
|
)>,
|
||||||
mut bone_query: Query<(&HandBone, &mut HandBoneRadius, &mut Transform)>,
|
mut bone_query: Query<(&HandBone, &mut HandBoneRadius, &mut Transform)>,
|
||||||
|
pipelined: Option<Res<Pipelined>>,
|
||||||
) {
|
) {
|
||||||
for (tracker, ref_space, hand_entities) in &tracker_query {
|
for (tracker, ref_space, hand_entities) in &tracker_query {
|
||||||
let ref_space = ref_space.map(|v| &v.0).unwrap_or(&default_ref_space.0);
|
let ref_space = ref_space.map(|v| &v.0).unwrap_or(&default_ref_space.0);
|
||||||
// relate_hand_joints also provides velocities
|
// 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(Some(v)) => v,
|
||||||
Ok(None) => continue,
|
Ok(None) => continue,
|
||||||
Err(openxr::sys::Result::ERROR_EXTENSION_NOT_PRESENT) => {
|
Err(openxr::sys::Result::ERROR_EXTENSION_NOT_PRESENT) => {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ use crate::resources::*;
|
|||||||
use crate::types::*;
|
use crate::types::*;
|
||||||
|
|
||||||
pub fn session_started(started: Option<Res<OxrSessionStarted>>) -> bool {
|
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 {
|
pub fn should_render(frame_state: Option<Res<OxrFrameState>>) -> bool {
|
||||||
@@ -109,6 +109,7 @@ impl Plugin for OxrInitPlugin {
|
|||||||
},
|
},
|
||||||
ExtractResourcePlugin::<OxrCleanupSession>::default(),
|
ExtractResourcePlugin::<OxrCleanupSession>::default(),
|
||||||
ExtractResourcePlugin::<XrStatus>::default(),
|
ExtractResourcePlugin::<XrStatus>::default(),
|
||||||
|
ExtractResourcePlugin::<OxrSessionStarted>::default(),
|
||||||
))
|
))
|
||||||
.init_schedule(OxrLast)
|
.init_schedule(OxrLast)
|
||||||
.init_schedule(OxrSessionCreated)
|
.init_schedule(OxrSessionCreated)
|
||||||
@@ -180,13 +181,7 @@ impl Plugin for OxrInitPlugin {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let session_started = OxrSessionStarted::default();
|
app.insert_resource(OxrSessionStarted(false));
|
||||||
|
|
||||||
app.insert_resource(session_started.clone());
|
|
||||||
|
|
||||||
let render_app = app.sub_app_mut(RenderApp);
|
|
||||||
|
|
||||||
render_app.insert_resource(session_started);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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");
|
let _span = info_span!("xr_begin_session");
|
||||||
session
|
session
|
||||||
.begin(openxr::ViewConfigurationType::PRIMARY_STEREO)
|
.begin(openxr::ViewConfigurationType::PRIMARY_STEREO)
|
||||||
.expect("Failed to begin session");
|
.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");
|
let _span = info_span!("xr_end_session");
|
||||||
session.end().expect("Failed to 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.
|
/// This is used solely to transport resources from the main world to the render world.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// use actions::XrActionPlugin;
|
// use actions::XrActionPlugin;
|
||||||
use bevy::{
|
use bevy::{
|
||||||
app::{PluginGroup, PluginGroupBuilder},
|
app::{PluginGroup, PluginGroupBuilder},
|
||||||
render::{pipelined_rendering::PipelinedRenderingPlugin, RenderPlugin},
|
render::RenderPlugin,
|
||||||
utils::default,
|
utils::default,
|
||||||
window::{PresentMode, Window, WindowPlugin},
|
window::{PresentMode, Window, WindowPlugin},
|
||||||
};
|
};
|
||||||
@@ -34,7 +34,7 @@ pub fn add_xr_plugins<G: PluginGroup>(plugins: G) -> PluginGroupBuilder {
|
|||||||
plugins
|
plugins
|
||||||
.build()
|
.build()
|
||||||
.disable::<RenderPlugin>()
|
.disable::<RenderPlugin>()
|
||||||
.disable::<PipelinedRenderingPlugin>()
|
// .disable::<PipelinedRenderingPlugin>()
|
||||||
.add_before::<RenderPlugin, _>(XrSessionPlugin)
|
.add_before::<RenderPlugin, _>(XrSessionPlugin)
|
||||||
.add_before::<RenderPlugin, _>(OxrInitPlugin::default())
|
.add_before::<RenderPlugin, _>(OxrInitPlugin::default())
|
||||||
.add(OxrReferenceSpacePlugin::default())
|
.add(OxrReferenceSpacePlugin::default())
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
@@ -440,18 +439,8 @@ pub struct SessionConfigInfo {
|
|||||||
pub graphics_info: SessionCreateInfo,
|
pub graphics_info: SessionCreateInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Resource, Clone, Default)]
|
#[derive(ExtractResource, Resource, Clone, Default)]
|
||||||
pub struct OxrSessionStarted(Arc<AtomicBool>);
|
pub struct OxrSessionStarted(pub bool);
|
||||||
|
|
||||||
impl OxrSessionStarted {
|
|
||||||
pub fn set(&self, val: bool) {
|
|
||||||
self.0.store(val, Ordering::SeqCst);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get(&self) -> bool {
|
|
||||||
self.0.load(Ordering::SeqCst)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The frame state returned from [FrameWaiter::wait_frame](openxr::FrameWaiter::wait)
|
/// The frame state returned from [FrameWaiter::wait_frame](openxr::FrameWaiter::wait)
|
||||||
#[derive(Clone, Deref, DerefMut, Resource, ExtractResource)]
|
#[derive(Clone, Deref, DerefMut, Resource, ExtractResource)]
|
||||||
|
|||||||
Reference in New Issue
Block a user