oxr backend progress
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
mod graphics;
|
||||
mod utils;
|
||||
|
||||
use std::sync::Mutex;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
pub struct OXrEntry(openxr::Entry);
|
||||
@@ -11,6 +16,14 @@ impl OXrEntry {
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<openxr::ExtensionSet> for ExtensionSet {
|
||||
fn into(self) -> openxr::ExtensionSet {
|
||||
let mut set = openxr::ExtensionSet::default();
|
||||
set.khr_vulkan_enable2 = self.vulkan;
|
||||
set
|
||||
}
|
||||
}
|
||||
|
||||
impl EntryTrait for OXrEntry {
|
||||
fn available_extensions(&self) -> Result<ExtensionSet> {
|
||||
// self.0.enumerate_extensions();
|
||||
@@ -18,11 +31,25 @@ impl EntryTrait for OXrEntry {
|
||||
}
|
||||
|
||||
fn create_instance(&self, exts: ExtensionSet) -> Result<Instance> {
|
||||
todo!()
|
||||
#[allow(unused_mut)]
|
||||
let mut enabled_extensions: openxr::ExtensionSet = exts.into();
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
enabled_extensions.khr_android_create_instance = true;
|
||||
}
|
||||
let xr_instance = self.0.create_instance(
|
||||
&openxr::ApplicationInfo {
|
||||
application_name: "bevy",
|
||||
..Default::default()
|
||||
},
|
||||
&enabled_extensions,
|
||||
&[],
|
||||
)?;
|
||||
Ok(OXrInstance(xr_instance, exts).into())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OXrInstance(openxr::Instance);
|
||||
pub struct OXrInstance(openxr::Instance, ExtensionSet);
|
||||
|
||||
impl InstanceTrait for OXrInstance {
|
||||
fn entry(&self) -> Entry {
|
||||
@@ -30,10 +57,54 @@ impl InstanceTrait for OXrInstance {
|
||||
}
|
||||
|
||||
fn enabled_extensions(&self) -> ExtensionSet {
|
||||
todo!()
|
||||
self.1
|
||||
}
|
||||
|
||||
fn create_session(&self, info: SessionCreateInfo) -> Result<Session> {
|
||||
graphics::init_oxr_graphics(self.0.clone(), self.1, info.texture_format).map(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OXrSession {
|
||||
pub(crate) instance: Instance,
|
||||
pub(crate) session: openxr::Session<openxr::AnyGraphics>,
|
||||
pub(crate) render_resources: Mutex<
|
||||
Option<(
|
||||
wgpu::Device,
|
||||
wgpu::Queue,
|
||||
wgpu::AdapterInfo,
|
||||
wgpu::Adapter,
|
||||
wgpu::Instance,
|
||||
)>,
|
||||
>,
|
||||
}
|
||||
|
||||
impl SessionTrait for OXrSession {
|
||||
fn instance(&self) -> &Instance {
|
||||
&self.instance
|
||||
}
|
||||
|
||||
fn get_render_resources(
|
||||
&self,
|
||||
) -> Option<(
|
||||
wgpu::Device,
|
||||
wgpu::Queue,
|
||||
wgpu::AdapterInfo,
|
||||
wgpu::Adapter,
|
||||
wgpu::Instance,
|
||||
)> {
|
||||
std::mem::take(&mut self.render_resources.lock().unwrap())
|
||||
}
|
||||
|
||||
fn create_input(&self, bindings: Bindings) -> Result<Input> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn begin_frame(&self) -> Result<(View, View)> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn end_frame(&self) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
17
xr_api/src/backend/oxr/graphics.rs
Normal file
17
xr_api/src/backend/oxr/graphics.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
mod vulkan;
|
||||
|
||||
use super::OXrSession;
|
||||
use crate::error::{Result, XrError};
|
||||
use crate::types::ExtensionSet;
|
||||
|
||||
pub fn init_oxr_graphics(
|
||||
instance: openxr::Instance,
|
||||
extensions: ExtensionSet,
|
||||
format: wgpu::TextureFormat,
|
||||
) -> Result<OXrSession> {
|
||||
if extensions.vulkan {
|
||||
return vulkan::init_oxr_graphics(instance, format);
|
||||
}
|
||||
|
||||
Err(XrError::Placeholder)
|
||||
}
|
||||
9
xr_api/src/backend/oxr/graphics/vulkan.rs
Normal file
9
xr_api/src/backend/oxr/graphics/vulkan.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
use crate::backend::oxr::OXrSession;
|
||||
use crate::error::Result;
|
||||
|
||||
pub fn init_oxr_graphics(
|
||||
instance: openxr::Instance,
|
||||
format: wgpu::TextureFormat,
|
||||
) -> Result<OXrSession> {
|
||||
todo!()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
use crate::error::XrError;
|
||||
|
||||
impl From<openxr::sys::Result> for XrError {
|
||||
fn from(value: openxr::sys::Result) -> Self {
|
||||
XrError::Placeholder
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,14 @@ use crate::api_traits::{ActionInputTrait, HapticTrait, InputTrait};
|
||||
use crate::error::Result;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub struct ExtensionSet {}
|
||||
pub struct ExtensionSet {
|
||||
pub vulkan: bool,
|
||||
}
|
||||
|
||||
pub enum SessionCreateInfo {}
|
||||
pub struct SessionCreateInfo {
|
||||
/// preferred texture format
|
||||
pub texture_format: wgpu::TextureFormat,
|
||||
}
|
||||
|
||||
pub struct Bindings {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user