Skip to content

Commit

Permalink
Add GDExtension support for OpenXR extension wrappers
Browse files Browse the repository at this point in the history
This commit adds the classes OpenXRExtensionWrapperExtension and OpenXRAPIExtension
that can be used in GDExtensions to define OpenXR extension wrappers.
It modifies extension wrapper registration so that they can be registered
before OpenXRAPI instantiation (e.g. in core level initialization of GDExtensions).

Developed by Migeran (https://migeran.com)
  • Loading branch information
konczg committed Jul 26, 2023
1 parent c3b0a92 commit d600e6e
Show file tree
Hide file tree
Showing 11 changed files with 832 additions and 0 deletions.
114 changes: 114 additions & 0 deletions doc/classes/OpenXRAPIExtension.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="OpenXRAPIExtension" inherits="RefCounted" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
Makes the OpenXR API available for GDExtension.
</brief_description>
<description>
[OpenXRAPIExtension] makes OpenXR available for GDExtension. It provides the OpenXR API to GDExtension through the [method get_instance_proc_addr] method, and the OpenXR instance through [method get_instance].
It also provides methods for querying the status of OpenXR initialization, and helper methods for ease of use of the API with GDExtension.
</description>
<tutorials>
<link title="XrResult documentation">https://registry.khronos.org/OpenXR/specs/1.0/man/html/XrResult.html</link>
<link title="XrInstance documentation">https://registry.khronos.org/OpenXR/specs/1.0/man/html/XrInstance.html</link>
<link title="XrSpace documentation">https://registry.khronos.org/OpenXR/specs/1.0/man/html/XrSpace.html</link>
<link title="XrSession documentation">https://registry.khronos.org/OpenXR/specs/1.0/man/html/XrSession.html</link>
<link title="XrSystemId documentation">https://registry.khronos.org/OpenXR/specs/1.0/man/html/XrSystemId.html</link>
<link title="xrBeginSession documentation">https://registry.khronos.org/OpenXR/specs/1.0/man/html/xrBeginSession.html</link>
<link title="XrPosef documentation">https://registry.khronos.org/OpenXR/specs/1.0/man/html/XrPosef.html</link>
</tutorials>
<methods>
<method name="can_render">
<return type="bool" />
<description>
Returns [code]true[/code] if OpenXR is initialized for rendering with an XR viewport.
</description>
</method>
<method name="get_error_string">
<return type="String" />
<param index="0" name="result" type="int" />
<description>
Returns an error string for the given [url=https://registry.khronos.org/OpenXR/specs/1.0/man/html/XrResult.html]XrResult[/url].
</description>
</method>
<method name="get_instance">
<return type="int" />
<description>
Returns the [url=https://registry.khronos.org/OpenXR/specs/1.0/man/html/XrInstance.html]XrInstance[/url] created during the initialization of the OpenXR API.
</description>
</method>
<method name="get_instance_proc_addr">
<return type="int" />
<param index="0" name="name" type="String" />
<description>
Returns the function pointer of the OpenXR function with the specified name, cast to an integer. If the function with the given name does not exist, the method returns [code]0[/code].
[b]Note:[/b] [code]openxr/util.h[/code] contains utility macros for acquiring OpenXR functions, e.g. [code]GDEXTENSION_INIT_XR_FUNC_V(xrCreateAction)[/code].
</description>
</method>
<method name="get_next_frame_time">
<return type="int" />
<description>
Returns the timing for the next frame.
</description>
</method>
<method name="get_play_space">
<return type="int" />
<description>
Returns the play space, which is an [url=https://registry.khronos.org/OpenXR/specs/1.0/man/html/XrSpace.html]XrSpace[/url] cast to an integer.
</description>
</method>
<method name="get_session">
<return type="int" />
<description>
Returns the OpenXR session, which is an [url=https://registry.khronos.org/OpenXR/specs/1.0/man/html/XrSession.html]XrSession[/url] cast to an integer.
</description>
</method>
<method name="get_swapchain_format_name">
<return type="String" />
<param index="0" name="swapchain_format" type="int" />
<description>
Returns the name of the specified swapchain format.
</description>
</method>
<method name="get_system_id">
<return type="int" />
<description>
Returns the id of the system, which is a [url=https://registry.khronos.org/OpenXR/specs/1.0/man/html/XrSystemId.html]XrSystemId[/url] cast to an integer.
</description>
</method>
<method name="is_initialized">
<return type="bool" />
<description>
Returns [code]true[/code] if OpenXR is initialized.
</description>
</method>
<method name="is_running">
<return type="bool" />
<description>
Returns [code]true[/code] if OpenXR is running ([url=https://registry.khronos.org/OpenXR/specs/1.0/man/html/xrBeginSession.html]xrBeginSession[/url] was successfully called and the swapchains were created).
</description>
</method>
<method name="openxr_is_enabled" qualifiers="static">
<return type="bool" />
<param index="0" name="check_run_in_editor" type="bool" />
<description>
Returns [code]true[/code] if OpenXR is enabled.
</description>
</method>
<method name="transform_from_pose">
<return type="Transform3D" />
<param index="0" name="pose" type="const void*" />
<description>
Creates a [Transform3D] from an [url=https://registry.khronos.org/OpenXR/specs/1.0/man/html/XrPosef.html]XrPosef[/url].
</description>
</method>
<method name="xr_result">
<return type="bool" />
<param index="0" name="result" type="int" />
<param index="1" name="format" type="String" />
<param index="2" name="args" type="Array" />
<description>
Returns [code]true[/code] if the provided [url=https://registry.khronos.org/OpenXR/specs/1.0/man/html/XrResult.html]XrResult[/url] (cast to an integer) is successful. Otherwise returns [code]false[/code] and prints the [url=https://registry.khronos.org/OpenXR/specs/1.0/man/html/XrResult.html]XrResult[/url] converted to a string, with the specified additional information.
</description>
</method>
</methods>
</class>
167 changes: 167 additions & 0 deletions doc/classes/OpenXRExtensionWrapperExtension.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="OpenXRExtensionWrapperExtension" inherits="Object" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
Allows clients to implement OpenXR extensions with GDExtension.
</brief_description>
<description>
[OpenXRExtensionWrapperExtension] allows clients to implement OpenXR extensions with GDExtension. The extension should be registered with [method register_extension_wrapper].
</description>
<tutorials>
</tutorials>
<methods>
<method name="_get_requested_extensions" qualifiers="virtual">
<return type="Dictionary" />
<description>
Returns a [Dictionary] of OpenXR extensions related to this extension. The [Dictionary] should contain the name of the extension, mapped to a [code]bool *[/code] cast to an integer:
- If the [code]bool *[/code] is a [code]nullptr[/code] this extension is mandatory.
- If the [code]bool *[/code] points to a boolean, the boolean will be updated to [code]true[/code] if the extension is enabled.
</description>
</method>
<method name="_on_before_instance_created" qualifiers="virtual">
<return type="void" />
<description>
Called before the OpenXR instance is created.
</description>
</method>
<method name="_on_event_polled" qualifiers="virtual">
<return type="bool" />
<param index="0" name="event" type="const void*" />
<description>
Called when there is an OpenXR event to process. When implementing, return [code]true[/code] if the event was handled, return [code]false[/code] otherwise.
</description>
</method>
<method name="_on_instance_created" qualifiers="virtual">
<return type="void" />
<param index="0" name="instance" type="int" />
<description>
Called right after the OpenXR instance is created.
</description>
</method>
<method name="_on_instance_destroyed" qualifiers="virtual">
<return type="void" />
<description>
Called right before the OpenXR instance is destroyed.
</description>
</method>
<method name="_on_pre_render" qualifiers="virtual">
<return type="void" />
<description>
Called right before the XR viewports begin their rendering step.
</description>
</method>
<method name="_on_process" qualifiers="virtual">
<return type="void" />
<description>
Called as part of the OpenXR process handling. This happens right before general and physics processing steps of the main loop. During this step controller data is queried and made available to game logic.
</description>
</method>
<method name="_on_register_metadata" qualifiers="virtual">
<return type="void" />
<description>
Allows extensions to register additional controller metadata. This function is called even when the OpenXR API is not constructed as the metadata needs to be available to the editor.
Extensions should also provide metadata regardless of whether they are supported on the host system. The controller data is used to setup action maps for users who may have access to the relevant hardware.
</description>
</method>
<method name="_on_session_created" qualifiers="virtual">
<return type="void" />
<param index="0" name="session" type="int" />
<description>
Called right after the OpenXR session is created.
</description>
</method>
<method name="_on_session_destroyed" qualifiers="virtual">
<return type="void" />
<description>
Called right before the OpenXR session is destroyed.
</description>
</method>
<method name="_on_state_exiting" qualifiers="virtual">
<return type="void" />
<description>
Called when the OpenXR session state is changed to exiting.
</description>
</method>
<method name="_on_state_focused" qualifiers="virtual">
<return type="void" />
<description>
Called when the OpenXR session state is changed to focused. This state is the active state when the game runs.
</description>
</method>
<method name="_on_state_idle" qualifiers="virtual">
<return type="void" />
<description>
Called when the OpenXR session state is changed to idle.
</description>
</method>
<method name="_on_state_loss_pending" qualifiers="virtual">
<return type="void" />
<description>
Called when the OpenXR session state is changed to loss pending.
</description>
</method>
<method name="_on_state_ready" qualifiers="virtual">
<return type="void" />
<description>
Called when the OpenXR session state is changed to ready. This means OpenXR is ready to set up the session.
</description>
</method>
<method name="_on_state_stopping" qualifiers="virtual">
<return type="void" />
<description>
Called when the OpenXR session state is changed to stopping.
</description>
</method>
<method name="_on_state_synchronized" qualifiers="virtual">
<return type="void" />
<description>
Called when the OpenXR session state is changed to synchronized. OpenXR also returns to this state when the application loses focus.
</description>
</method>
<method name="_on_state_visible" qualifiers="virtual">
<return type="void" />
<description>
Called when the OpenXR session state is changed to visible. This means OpenXR is now ready to receive frames.
</description>
</method>
<method name="_set_instance_create_info_and_get_next_pointer" qualifiers="virtual">
<return type="int" />
<param index="0" name="next_pointer" type="void*" />
<description>
Adds additional data structures when the OpenXR instance is created.
</description>
</method>
<method name="_set_session_create_and_get_next_pointer" qualifiers="virtual">
<return type="int" />
<param index="0" name="next_pointer" type="void*" />
<description>
Adds additional data structures when the OpenXR session is created.
</description>
</method>
<method name="_set_swapchain_create_info_and_get_next_pointer" qualifiers="virtual">
<return type="int" />
<param index="0" name="next_pointer" type="void*" />
<description>
Adds additional data structures when creating OpenXR swapchains.
</description>
</method>
<method name="_set_system_properties_and_get_next_pointer" qualifiers="virtual">
<return type="int" />
<param index="0" name="next_pointer" type="void*" />
<description>
Adds additional data structures when interogating OpenXR system abilities.
</description>
</method>
<method name="get_openxr_api">
<return type="OpenXRAPIExtension" />
<description>
Returns the created [OpenXRAPIExtension], which can be used to access the OpenXR API.
</description>
</method>
<method name="register_extension_wrapper">
<return type="void" />
<description>
Registers the extension. This should happen at core module initialization level.
</description>
</method>
</methods>
</class>
2 changes: 2 additions & 0 deletions modules/openxr/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ env_openxr.add_source_files(module_obj, "extensions/openxr_fb_display_refresh_ra
env_openxr.add_source_files(module_obj, "extensions/openxr_pico_controller_extension.cpp")
env_openxr.add_source_files(module_obj, "extensions/openxr_wmr_controller_extension.cpp")
env_openxr.add_source_files(module_obj, "extensions/openxr_ml2_controller_extension.cpp")
env_openxr.add_source_files(module_obj, "extensions/openxr_extension_wrapper_extension.cpp")
env_openxr.add_source_files(module_obj, "extensions/openxr_api_extension.cpp")

env.modules_sources += module_obj

Expand Down
1 change: 1 addition & 0 deletions modules/openxr/extensions/openxr_android_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ OpenXRAndroidExtension::OpenXRAndroidExtension() {
HashMap<String, bool *> OpenXRAndroidExtension::get_requested_extensions() {
HashMap<String, bool *> request_extensions;

request_extensions[XR_KHR_LOADER_INIT_ANDROID_EXTENSION_NAME] = &loader_init_extension_available;
request_extensions[XR_KHR_ANDROID_CREATE_INSTANCE_EXTENSION_NAME] = &create_instance_extension_available;

return request_extensions;
Expand Down
Loading

0 comments on commit d600e6e

Please sign in to comment.