diff --git a/crates/bevy_openxr/examples/android/src/lib.rs b/crates/bevy_openxr/examples/android/src/lib.rs index ad5ac98..9866566 100644 --- a/crates/bevy_openxr/examples/android/src/lib.rs +++ b/crates/bevy_openxr/examples/android/src/lib.rs @@ -37,17 +37,21 @@ fn setup( mut meshes: ResMut>, mut materials: ResMut>, ) { + let mut white: StandardMaterial = Color::WHITE.into(); + white.unlit = true; // circular base commands.spawn(PbrBundle { mesh: meshes.add(Circle::new(4.0)), - material: materials.add(Color::WHITE), + material: materials.add(white), transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)), ..default() }); + let mut cube_mat: StandardMaterial = Color::rgb_u8(124, 144, 255).into(); + cube_mat.unlit = true; // cube commands.spawn(PbrBundle { mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)), - material: materials.add(Color::rgb_u8(124, 144, 255)), + material: materials.add(cube_mat), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }); diff --git a/crates/bevy_openxr/examples/sessions.rs b/crates/bevy_openxr/examples/sessions.rs index 353293f..3404eec 100644 --- a/crates/bevy_openxr/examples/sessions.rs +++ b/crates/bevy_openxr/examples/sessions.rs @@ -17,8 +17,8 @@ fn main() { fn handle_input( keys: Res>, mut end: EventWriter, - mut destroy: EventWriter, - mut begin: EventWriter, + mut _destroy: EventWriter, + mut _begin: EventWriter, mut create: EventWriter, state: Res, ) { @@ -26,14 +26,6 @@ fn handle_input( info!("sending end"); end.send_default(); } - if keys.just_pressed(KeyCode::KeyD) { - info!("sending destroy"); - destroy.send_default(); - } - if keys.just_pressed(KeyCode::KeyB) { - info!("sending begin"); - begin.send_default(); - } if keys.just_pressed(KeyCode::KeyC) { info!("sending create"); create.send_default(); diff --git a/crates/bevy_openxr/src/openxr/features/handtracking.rs b/crates/bevy_openxr/src/openxr/features/handtracking.rs index 6232ab1..c60750c 100644 --- a/crates/bevy_openxr/src/openxr/features/handtracking.rs +++ b/crates/bevy_openxr/src/openxr/features/handtracking.rs @@ -40,7 +40,7 @@ fn spawn_default_hands( session: Res, root: Query>, ) { - dbg!("spawning default hands"); + debug!("spawning default hands"); let Ok(root) = root.get_single() else { error!("unable to get tracking root, skipping hand creation"); return; @@ -118,7 +118,7 @@ fn clean_up_default_hands( query: Query, With)>>, ) { for e in &query { - dbg!("removing default hand entity"); + debug!("removing default hand entity"); cmds.entity(e).despawn_recursive(); } } diff --git a/crates/bevy_openxr/src/openxr/init.rs b/crates/bevy_openxr/src/openxr/init.rs index b22a2c1..8fada5f 100644 --- a/crates/bevy_openxr/src/openxr/init.rs +++ b/crates/bevy_openxr/src/openxr/init.rs @@ -511,7 +511,6 @@ pub fn poll_events( SessionState::IDLE => { if *status == XrStatus::Available { session_status_events.send(OxrSessionStatusEvent::Created); - info!("sending create info"); } XrStatus::Idle } @@ -522,7 +521,6 @@ pub fn poll_events( SessionState::STOPPING => XrStatus::Stopping, SessionState::EXITING | SessionState::LOSS_PENDING => { session_status_events.send(OxrSessionStatusEvent::AboutToBeDestroyed); - info!("sending destroy info"); XrStatus::Exiting } _ => unreachable!(), @@ -557,5 +555,4 @@ pub fn destroy_xr_session_render(world: &mut World) { world.run_system_once(apply_deferred); world.remove_resource::(); world.insert_resource(OxrSessionStarted(false)); - info!("Render App destroy"); } diff --git a/crates/bevy_openxr/src/openxr/render.rs b/crates/bevy_openxr/src/openxr/render.rs index 0fd0a20..89dd188 100644 --- a/crates/bevy_openxr/src/openxr/render.rs +++ b/crates/bevy_openxr/src/openxr/render.rs @@ -1,13 +1,15 @@ use bevy::{ - ecs::query::QuerySingleError, + app::{MainScheduleOrder, SubApp}, + ecs::{query::QuerySingleError, schedule::MainThreadExecutor}, prelude::*, render::{ camera::{ManualTextureView, ManualTextureViewHandle, ManualTextureViews, RenderTarget}, extract_resource::ExtractResourcePlugin, - pipelined_rendering::PipelinedRenderingPlugin, + pipelined_rendering::{PipelinedRenderingPlugin, RenderAppChannels, RenderExtractApp}, view::ExtractedView, Render, RenderApp, RenderSet, }, + tasks::ComputeTaskPool, transform::TransformSystem, }; use bevy_xr::{ @@ -35,6 +37,20 @@ impl Plugin for OxrRenderPlugin { fn build(&self, app: &mut App) { if app.is_plugin_added::() { app.init_resource::(); + + let mut schedule_order = app.world.resource_mut::(); + + if let Some(pos) = schedule_order + .labels + .iter() + .position(|label| (**label).eq(&OxrLast)) + { + schedule_order.labels.remove(pos); + } + + if let Some(sub_app) = app.remove_sub_app(RenderExtractApp) { + app.insert_sub_app(RenderExtractApp, SubApp::new(sub_app.app, update_rendering)); + } } app.add_plugins(( @@ -82,11 +98,6 @@ impl Plugin for OxrRenderPlugin { ) .add_systems(Last, wait_frame.run_if(session_started)); app.sub_app_mut(RenderApp) - .add_systems( - Render, - (|q: Query<&XrCamera>| info!("cams render: {}", q.iter().len())) - .in_set(OxrRenderBegin), - ) .add_systems( Render, ( @@ -108,13 +119,13 @@ impl Plugin for OxrRenderPlugin { .in_set(OxrRenderEnd), ) .insert_resource(OxrRenderLayers(vec![Box::new(ProjectionLayer)])); - // .add_systems( - // XrSessionExiting, - // ( - // |mut cmds: Commands| cmds.remove_resource::(), - // clean_views, - // ), - // ); + // .add_systems( + // XrSessionExiting, + // ( + // |mut cmds: Commands| cmds.remove_resource::(), + // clean_views, + // ), + // ); // app.add_systems( // PreUpdate, @@ -158,6 +169,31 @@ impl Plugin for OxrRenderPlugin { } } +// This function waits for the rendering world to be received, +// runs extract, and then sends the rendering world back to the render thread. +// +// modified pipelined rendering extract function +fn update_rendering(app_world: &mut World, _sub_app: &mut App) { + app_world.resource_scope(|world, main_thread_executor: Mut| { + world.resource_scope(|world, mut render_channels: Mut| { + // we use a scope here to run any main thread tasks that the render world still needs to run + // while we wait for the render world to be received. + let mut render_app = ComputeTaskPool::get() + .scope_with_executor(true, Some(&*main_thread_executor.0), |s| { + s.spawn(async { render_channels.recv().await }); + }) + .pop() + .unwrap(); + + world.run_schedule(OxrLast); + + render_app.extract(world); + + render_channels.send_blocking(render_app); + }); + }); +} + pub const XR_TEXTURE_INDEX: u32 = 3383858418; pub fn clean_views( @@ -168,7 +204,6 @@ pub fn clean_views( for (e, cam) in &cam_query { manual_texture_views.remove(&ManualTextureViewHandle(XR_TEXTURE_INDEX + cam.0)); commands.entity(e).despawn_recursive(); - info!("removing cam") } } diff --git a/crates/bevy_openxr/src/openxr/session.rs b/crates/bevy_openxr/src/openxr/session.rs index bb5dd55..522e552 100644 --- a/crates/bevy_openxr/src/openxr/session.rs +++ b/crates/bevy_openxr/src/openxr/session.rs @@ -74,7 +74,6 @@ fn run_session_status_schedules(world: &mut World) { world.run_schedule(XrSessionExiting); world.run_system_once(apply_deferred); world.remove_resource::(); - info!("Main App destroy"); } } }