The open source OpenXR runtime
1# Implementing OpenXR extensions {#implementing-extension}
2
3<!--
4Copyright 2021, Collabora, Ltd. and the Monado contributors
5SPDX-License-Identifier: BSL-1.0
6-->
7
8Khronos often adds new functionality to the OpenXR specification as extensions.
9
10The general steps to implement an OpenXR extension in Monado are as follows.
11
12* Edit scripts/generate_oxr_ext_support.py. Usually you only need to add an
13 entry to the `EXTENSIONS` list at the top.
14* Run the script `python scripts/generate_oxr_ext_support.py`.
15* Format the regenerated file with
16 `clang-format -i src/xrt/state_trackers/oxr/oxr_extension_support.h`.
17* Add entry points for each new function in
18 `src/xrt/state_trackers/oxr/oxr_api_negotiate.c`.
19* Add Monado internal prototypes for the new functions in
20 `src/xrt/state_trackers/oxr/oxr_api_funcs.h`. The Monado implementations of
21 OpenXR functions are prefixed with `oxr_` and use the `XRAPI_ATTR` and
22 `XRAPI_CALL` macros to satisfy calling conventions for all platforms.
23* Implement the `oxr_` Monado internal functions in an appropriate source file
24 `src/state_trackers/oxr/oxr_api_*.c`. Trivial functions can be implemented
25 right there along with the usual parameter checks. More complex functions that
26 use more internal Monado state should call functions implemented in the
27 relevant `oxr_*.c` file (without `_api_`). The definitions for those functions
28 go into `src/xrt/state_trackers/oxr/oxr_objects.h`.
29* Monado internal implementations of "objects" (think XrSession or
30 XrHandTracker) go into `src/xrt/state_trackers/oxr/oxr_objects.h`.
31* Enums, defines and types go into `src/xrt/include/xrt/xrt_defines.h`. OpenXR
32 types are typically not used outside of the `oxr_api_*` files, instead
33 equivalents with the prefix `XRT_` are defined here.