Skip to content

Commit

Permalink
add headless graphics api
Browse files Browse the repository at this point in the history
  • Loading branch information
galister committed Aug 10, 2024
1 parent 2af2256 commit 1d31117
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
66 changes: 66 additions & 0 deletions openxr/src/graphics/headless.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use crate::*;

/// Used to create a session without graphics.
///
/// See [`XR_MND_headless`] for safety details.
///
/// [`XR_MND_headless`]: https://www.khronos.org/registry/OpenXR/specs/1.1/html/xrspec.html#XR_MND_headless
pub enum Headless {}

impl Graphics for Headless {
type Requirements = Requirements;
type SessionCreateInfo = SessionCreateInfo;
type SwapchainImage = HeadlessSwapchainImage;
type Format = HeadlessFormat;

fn raise_format(_: i64) -> Self::Format {
unreachable!()
}
fn lower_format(_: Self::Format) -> i64 {
unreachable!()
}

fn requirements(_instance: &Instance, _system: SystemId) -> Result<Requirements> {
Ok(Requirements {})
}

unsafe fn create_session(
instance: &Instance,
system: SystemId,
_info: &SessionCreateInfo,
) -> Result<sys::Session> {
let info = sys::SessionCreateInfo {
ty: sys::SessionCreateInfo::TYPE,
next: std::ptr::null(),
create_flags: Default::default(),
system_id: system,
};
let mut out = sys::Session::NULL;
cvt((instance.fp().create_session)(
instance.as_raw(),
&info,
&mut out,
))?;
Ok(out)
}

fn enumerate_swapchain_images(
_swapchain: &Swapchain<Self>,
) -> Result<Vec<Self::SwapchainImage>> {
// in a MND_headless session, xrEnumerateSwapchainFormats will always
// enumerate 0 formats, and so it's not possible to create a swapchain
unreachable!();
}
}

#[derive(Clone, Copy)]
pub struct Requirements {}

#[derive(Clone, Copy)]
pub struct SessionCreateInfo {}

#[derive(Clone, Copy)]
pub enum HeadlessSwapchainImage {}

#[derive(Clone, Copy)]
pub enum HeadlessFormat {}
3 changes: 3 additions & 0 deletions openxr/src/graphics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ pub use opengl::OpenGL;

pub mod opengles;
pub use opengles::OpenGlEs;

pub mod headless;
pub use headless::Headless;

0 comments on commit 1d31117

Please sign in to comment.