add enabled extension and implement overlay plugin

Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
Schmarni
2024-06-25 19:15:27 +02:00
parent 0a7f692a35
commit cde28677a0
4 changed files with 33 additions and 4 deletions

View File

@@ -1,6 +1,9 @@
use bevy::prelude::{Deref, DerefMut};
use bevy::{ecs::system::Resource, prelude::{Deref, DerefMut}};
use openxr::ExtensionSet;
#[derive(Clone, Debug, Eq, PartialEq, Deref, DerefMut, Resource)]
pub struct OxrEnabledExtensions(pub OxrExtensions);
#[derive(Clone, Debug, Eq, PartialEq, Deref, DerefMut)]
pub struct OxrExtensions(ExtensionSet);
impl OxrExtensions {

View File

@@ -1,3 +1,4 @@
pub mod handtracking;
#[cfg(feature = "passthrough")]
pub mod passthrough;
pub mod overlay;

View File

@@ -28,7 +28,9 @@ use bevy_xr::session::XrStatus;
use bevy_xr::session::XrStatusChanged;
use crate::error::OxrError;
use crate::features::overlay::OxrOverlaySessionEvent;
use crate::graphics::*;
use crate::openxr::exts::OxrEnabledExtensions;
use crate::resources::*;
use crate::session::OxrSession;
use crate::session::OxrSessionCreateNextChain;
@@ -97,7 +99,9 @@ impl Plugin for OxrInitPlugin {
system_id,
WgpuGraphics(device, queue, adapter_info, adapter, wgpu_instance),
session_create_info,
enabled_exts,
)) => {
app.insert_resource(enabled_exts);
app.add_plugins((
RenderPlugin {
render_creation: RenderCreation::manual(
@@ -197,7 +201,15 @@ pub fn update_root_transform(
}
impl OxrInitPlugin {
fn init_xr(&self) -> Result<(OxrInstance, OxrSystemId, WgpuGraphics, SessionConfigInfo)> {
fn init_xr(
&self,
) -> Result<(
OxrInstance,
OxrSystemId,
WgpuGraphics,
SessionConfigInfo,
OxrEnabledExtensions,
)> {
#[cfg(windows)]
let entry = OxrEntry(openxr::Entry::linked());
#[cfg(not(windows))]
@@ -236,7 +248,7 @@ impl OxrInitPlugin {
let instance = entry.create_instance(
self.app_info.clone(),
exts,
exts.clone(),
// &["XR_APILAYER_LUNARG_api_dump"],
&[],
backend,
@@ -274,6 +286,7 @@ impl OxrInitPlugin {
OxrSystemId(system_id),
graphics,
session_create_info,
OxrEnabledExtensions(exts),
))
}
}
@@ -495,6 +508,7 @@ pub fn poll_events(
mut status: ResMut<XrStatus>,
mut changed_event: EventWriter<XrStatusChanged>,
mut session_status_events: EventWriter<OxrSessionStatusEvent>,
mut overlay_writer: Option<ResMut<Events<OxrOverlaySessionEvent>>>,
) {
let _span = info_span!("xr_poll_events");
let mut buffer = Default::default();
@@ -534,6 +548,16 @@ pub fn poll_events(
}
InstanceLossPending(_) => {}
EventsLost(e) => warn!("lost {} XR events", e.lost_event_count()),
MainSessionVisibilityChangedEXTX(d) => {
if let Some(writer) = overlay_writer.as_mut() {
writer.send(OxrOverlaySessionEvent::MainSessionVisibilityChanged {
visible: d.visible(),
flags: d.flags(),
});
} else {
warn!("Overlay Event Recieved without the OverlayPlugin being added!");
}
}
_ => {}
}
}

View File

@@ -26,12 +26,12 @@ pub mod graphics;
pub mod helper_traits;
pub mod init;
pub mod layer_builder;
pub mod next_chain;
pub mod reference_space;
pub mod render;
pub mod resources;
pub mod session;
pub mod types;
pub mod next_chain;
pub fn add_xr_plugins<G: PluginGroup>(plugins: G) -> PluginGroupBuilder {
plugins
@@ -49,6 +49,7 @@ pub fn add_xr_plugins<G: PluginGroup>(plugins: G) -> PluginGroupBuilder {
.add(action_set_attaching::OxrActionAttachingPlugin)
.add(action_binding::OxrActionBindingPlugin)
.add(action_set_syncing::OxrActionSyncingPlugin)
.add(features::overlay::OxrOverlayPlugin)
// .add(XrActionPlugin)
// we should probably handle the exiting ourselfs so that we can correctly end the
// session and instance