Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add headless graphics api #167

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions openxr/src/graphics/headless.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use crate::*;

/// Used to create a session without graphics.
///
/// See [`XR_MND_headless`] for 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 {
// used by enumerate_swapchain_formats, which returns empty
unreachable!()
Ralith marked this conversation as resolved.
Show resolved Hide resolved
}
fn lower_format(f: Self::Format) -> i64 {
// used by create_swapchain, which is not available in headless
match f {}
}

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;
Loading