Skip to content

Quick OpenXR overview(Without rendering)

TheHellBox edited this page Apr 29, 2019 · 1 revision

Probably totaly wrong explanation, but it can be useful for new users

Fo first of all, OpenXR is an lib that provides you ability to render picture into headset and get some input/tracking data from it. To start working with OpenXR, we have to create entry. Example:

let entry = xr::Entry::linked();

OpenXR has extensions, that's some kind of a list of abilities your runtime can handle, to enumerate them use the following code:

let extensions = entry.enumerate_extensions().expect("Cannot enumerate extensions");

To prove that extension you need exists, you can use code like this

if !extensions.khr_opengl_enable {
    panic!("XR: OpenGL extension unsupported");
}

The next step is creating instance. According to OpenXR specification: An OpenXR instance is an object that allows an OpenXR application to communicate with an OpenXR runtime.

To create instance, you have to know which extensions you are going to use. For example, if you are creating a game, you probably need khr_opengl_enable extension for OpenGL rendering. Or, if you are creating monitoring app that does not require rendering, you probably need khr_headless extension.

For creating a set of extensions, we want to use ExtensionSet type. To build one, you write this code

let extension_set = xr::ExtensionSet {
    khr_opengl_enable: true,
    ..Default::default()
};

And now we can create instance

let instance = entry.create_instance(app_info, &extension_set,).unwrap();

The first step is made! Now, you can get some information from runtime. For example, we can run this code

let instance_props = instance.properties().expect("Cannot load instance props");
println!("loaded instance: {} v{}", instance_props.runtime_name, instance_props.runtime_version);

Now we need session, you need an SessionCreateInfo type. I don't want to cover how to create SessionCreateInfo, as we are not talking about rendering right now. But for initializing session you can do following code

let (session, frame_stream) = unsafe{
    instance.create_session(system, &info).unwrap()
};
session.begin(xr::ViewConfigurationType::PRIMARY_STEREO).unwrap();

Now, when we initialized OpenXR session, we can do whatever we want.

Clone this wiki locally