OpenXR: Clean-up OpenXRExtensionWrapper by removing multiple inheritance and deprecating OpenXRExtensionWrapperExtension

This commit is contained in:
David Snopek 2025-03-13 16:39:17 -05:00
parent 3d9b05ad4a
commit 9d3c950b5d
15 changed files with 492 additions and 513 deletions

View File

@ -14,3 +14,13 @@ Validate extension JSON: Error: Field 'classes/DisplayServer/methods/file_dialog
Validate extension JSON: Error: Field 'classes/DisplayServer/methods/file_dialog_with_options_show/arguments': size changed value in new API, from 9 to 10.
Optional argument added. Compatibility methods registered.
GH-104087
---------
Validate extension JSON: Error: Field 'classes/OpenXRAPIExtension/methods/register_composition_layer_provider/arguments/0': type changed value in new API, from "OpenXRExtensionWrapperExtension" to "OpenXRExtensionWrapper".
Validate extension JSON: Error: Field 'classes/OpenXRAPIExtension/methods/unregister_composition_layer_provider/arguments/0': type changed value in new API, from "OpenXRExtensionWrapperExtension" to "OpenXRExtensionWrapper".
Validate extension JSON: Error: Field 'classes/OpenXRAPIExtension/methods/register_projection_views_extension/arguments/0': type changed value in new API, from "OpenXRExtensionWrapperExtension" to "OpenXRExtensionWrapper".
Validate extension JSON: Error: Field 'classes/OpenXRAPIExtension/methods/unregister_projection_views_extension/arguments/0': type changed value in new API, from "OpenXRExtensionWrapperExtension" to "OpenXRExtensionWrapper".
Switched from `OpenXRExtensionWrapperExtension` to parent `OpenXRExtensionWrapper`. Compatibility methods registered.

View File

@ -225,14 +225,14 @@
</method>
<method name="register_composition_layer_provider">
<return type="void" />
<param index="0" name="extension" type="OpenXRExtensionWrapperExtension" />
<param index="0" name="extension" type="OpenXRExtensionWrapper" />
<description>
Registers the given extension as a composition layer provider.
</description>
</method>
<method name="register_projection_views_extension">
<return type="void" />
<param index="0" name="extension" type="OpenXRExtensionWrapperExtension" />
<param index="0" name="extension" type="OpenXRExtensionWrapper" />
<description>
Registers the given extension as a provider of additional data structures to projections views.
</description>
@ -290,14 +290,14 @@
</method>
<method name="unregister_composition_layer_provider">
<return type="void" />
<param index="0" name="extension" type="OpenXRExtensionWrapperExtension" />
<param index="0" name="extension" type="OpenXRExtensionWrapper" />
<description>
Unregisters the given extension as a composition layer provider.
</description>
</method>
<method name="unregister_projection_views_extension">
<return type="void" />
<param index="0" name="extension" type="OpenXRExtensionWrapperExtension" />
<param index="0" name="extension" type="OpenXRExtensionWrapper" />
<description>
Unregisters the given extension as a provider of additional data structures to projections views.
</description>

View File

@ -1,11 +1,273 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="OpenXRExtensionWrapper" inherits="Object" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Abstract wrapper class for OpenXR extension classes.
Allows implementing OpenXR extensions with GDExtension.
</brief_description>
<description>
This abstract wrapper class is used for all wrapper classes that implement the various OpenXR extensions.
[OpenXRExtensionWrapper] allows implementing OpenXR extensions with GDExtension. The extension should be registered with [method register_extension_wrapper].
</description>
<tutorials>
</tutorials>
<methods>
<method name="_get_composition_layer" qualifiers="virtual">
<return type="int" />
<param index="0" name="index" type="int" />
<description>
Returns a pointer to an [code]XrCompositionLayerBaseHeader[/code] struct to provide the given composition layer.
This will only be called if the extension previously registered itself with [method OpenXRAPIExtension.register_composition_layer_provider].
</description>
</method>
<method name="_get_composition_layer_count" qualifiers="virtual">
<return type="int" />
<description>
Returns the number of composition layers this extension wrapper provides via [method _get_composition_layer].
This will only be called if the extension previously registered itself with [method OpenXRAPIExtension.register_composition_layer_provider].
</description>
</method>
<method name="_get_composition_layer_order" qualifiers="virtual">
<return type="int" />
<param index="0" name="index" type="int" />
<description>
Returns an integer that will be used to sort the given composition layer provided via [method _get_composition_layer]. Lower numbers will move the layer to the front of the list, and higher numbers to the end. The default projection layer has an order of [code]0[/code], so layers provided by this method should probably be above or below (but not exactly) [code]0[/code].
This will only be called if the extension previously registered itself with [method OpenXRAPIExtension.register_composition_layer_provider].
</description>
</method>
<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="_get_suggested_tracker_names" qualifiers="virtual">
<return type="PackedStringArray" />
<description>
Returns a [PackedStringArray] of positional tracker names that are used within the extension wrapper.
</description>
</method>
<method name="_get_viewport_composition_layer_extension_properties" qualifiers="virtual">
<return type="Dictionary[]" />
<description>
Gets an array of [Dictionary]s that represent properties, just like [method Object._get_property_list], that will be added to [OpenXRCompositionLayer] nodes.
</description>
</method>
<method name="_get_viewport_composition_layer_extension_property_defaults" qualifiers="virtual">
<return type="Dictionary" />
<description>
Gets a [Dictionary] containing the default values for the properties returned by [method _get_viewport_composition_layer_extension_properties].
</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_main_swapchains_created" qualifiers="virtual">
<return type="void" />
<description>
Called right after the main swapchains are (re)created.
</description>
</method>
<method name="_on_post_draw_viewport" qualifiers="virtual">
<return type="void" />
<param index="0" name="viewport" type="RID" />
<description>
Called right after the given viewport is rendered.
[b]Note:[/b] The draw commands might only be queued at this point, not executed.
</description>
</method>
<method name="_on_pre_draw_viewport" qualifiers="virtual">
<return type="void" />
<param index="0" name="viewport" type="RID" />
<description>
Called right before the given viewport is rendered.
</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="_on_viewport_composition_layer_destroyed" qualifiers="virtual">
<return type="void" />
<param index="0" name="layer" type="const void*" />
<description>
Called when a composition layer created via [OpenXRCompositionLayer] is destroyed.
[param layer] is a pointer to an [code]XrCompositionLayerBaseHeader[/code] struct.
</description>
</method>
<method name="_set_android_surface_swapchain_create_info_and_get_next_pointer" qualifiers="virtual">
<return type="int" />
<param index="0" name="property_values" type="Dictionary" />
<param index="1" name="next_pointer" type="void*" />
<description>
Adds additional data structures to Android surface swapchains created by [OpenXRCompositionLayer].
[param property_values] contains the values of the properties returned by [method _get_viewport_composition_layer_extension_properties].
</description>
</method>
<method name="_set_hand_joint_locations_and_get_next_pointer" qualifiers="virtual">
<return type="int" />
<param index="0" name="hand_index" type="int" />
<param index="1" name="next_pointer" type="void*" />
<description>
Adds additional data structures when each hand tracker is created.
</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_projection_views_and_get_next_pointer" qualifiers="virtual">
<return type="int" />
<param index="0" name="view_index" type="int" />
<param index="1" name="next_pointer" type="void*" />
<description>
Adds additional data structures to the projection view of the given [param view_index].
</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 querying OpenXR system abilities.
</description>
</method>
<method name="_set_viewport_composition_layer_and_get_next_pointer" qualifiers="virtual">
<return type="int" />
<param index="0" name="layer" type="const void*" />
<param index="1" name="property_values" type="Dictionary" />
<param index="2" name="next_pointer" type="void*" />
<description>
Adds additional data structures to composition layers created by [OpenXRCompositionLayer].
[param property_values] contains the values of the properties returned by [method _get_viewport_composition_layer_extension_properties].
[param layer] is a pointer to an [code]XrCompositionLayerBaseHeader[/code] struct.
</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>

View File

@ -1,273 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="OpenXRExtensionWrapperExtension" inherits="OpenXRExtensionWrapper" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<class name="OpenXRExtensionWrapperExtension" inherits="OpenXRExtensionWrapper" deprecated="Use [OpenXRExtensionWrapper] instead." xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Allows clients to implement OpenXR extensions with GDExtension.
Allows implementing 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].
[OpenXRExtensionWrapperExtension] allows implementing OpenXR extensions with GDExtension. The extension should be registered with [method OpenXRExtensionWrapper.register_extension_wrapper].
</description>
<tutorials>
</tutorials>
<methods>
<method name="_get_composition_layer" qualifiers="virtual">
<return type="int" />
<param index="0" name="index" type="int" />
<description>
Returns a pointer to an [code]XrCompositionLayerBaseHeader[/code] struct to provide the given composition layer.
This will only be called if the extension previously registered itself with [method OpenXRAPIExtension.register_composition_layer_provider].
</description>
</method>
<method name="_get_composition_layer_count" qualifiers="virtual">
<return type="int" />
<description>
Returns the number of composition layers this extension wrapper provides via [method _get_composition_layer].
This will only be called if the extension previously registered itself with [method OpenXRAPIExtension.register_composition_layer_provider].
</description>
</method>
<method name="_get_composition_layer_order" qualifiers="virtual">
<return type="int" />
<param index="0" name="index" type="int" />
<description>
Returns an integer that will be used to sort the given composition layer provided via [method _get_composition_layer]. Lower numbers will move the layer to the front of the list, and higher numbers to the end. The default projection layer has an order of [code]0[/code], so layers provided by this method should probably be above or below (but not exactly) [code]0[/code].
This will only be called if the extension previously registered itself with [method OpenXRAPIExtension.register_composition_layer_provider].
</description>
</method>
<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="_get_suggested_tracker_names" qualifiers="virtual">
<return type="PackedStringArray" />
<description>
Returns a [PackedStringArray] of positional tracker names that are used within the extension wrapper.
</description>
</method>
<method name="_get_viewport_composition_layer_extension_properties" qualifiers="virtual">
<return type="Dictionary[]" />
<description>
Gets an array of [Dictionary]s that represent properties, just like [method Object._get_property_list], that will be added to [OpenXRCompositionLayer] nodes.
</description>
</method>
<method name="_get_viewport_composition_layer_extension_property_defaults" qualifiers="virtual">
<return type="Dictionary" />
<description>
Gets a [Dictionary] containing the default values for the properties returned by [method _get_viewport_composition_layer_extension_properties].
</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_main_swapchains_created" qualifiers="virtual">
<return type="void" />
<description>
Called right after the main swapchains are (re)created.
</description>
</method>
<method name="_on_post_draw_viewport" qualifiers="virtual">
<return type="void" />
<param index="0" name="viewport" type="RID" />
<description>
Called right after the given viewport is rendered.
[b]Note:[/b] The draw commands might only be queued at this point, not executed.
</description>
</method>
<method name="_on_pre_draw_viewport" qualifiers="virtual">
<return type="void" />
<param index="0" name="viewport" type="RID" />
<description>
Called right before the given viewport is rendered.
</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="_on_viewport_composition_layer_destroyed" qualifiers="virtual">
<return type="void" />
<param index="0" name="layer" type="const void*" />
<description>
Called when a composition layer created via [OpenXRCompositionLayer] is destroyed.
[param layer] is a pointer to an [code]XrCompositionLayerBaseHeader[/code] struct.
</description>
</method>
<method name="_set_android_surface_swapchain_create_info_and_get_next_pointer" qualifiers="virtual">
<return type="int" />
<param index="0" name="property_values" type="Dictionary" />
<param index="1" name="next_pointer" type="void*" />
<description>
Adds additional data structures to Android surface swapchains created by [OpenXRCompositionLayer].
[param property_values] contains the values of the properties returned by [method _get_viewport_composition_layer_extension_properties].
</description>
</method>
<method name="_set_hand_joint_locations_and_get_next_pointer" qualifiers="virtual">
<return type="int" />
<param index="0" name="hand_index" type="int" />
<param index="1" name="next_pointer" type="void*" />
<description>
Adds additional data structures when each hand tracker is created.
</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_projection_views_and_get_next_pointer" qualifiers="virtual">
<return type="int" />
<param index="0" name="view_index" type="int" />
<param index="1" name="next_pointer" type="void*" />
<description>
Adds additional data structures to the projection view of the given [param view_index].
</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 querying OpenXR system abilities.
</description>
</method>
<method name="_set_viewport_composition_layer_and_get_next_pointer" qualifiers="virtual">
<return type="int" />
<param index="0" name="layer" type="const void*" />
<param index="1" name="property_values" type="Dictionary" />
<param index="2" name="next_pointer" type="void*" />
<description>
Adds additional data structures to composition layers created by [OpenXRCompositionLayer].
[param property_values] contains the values of the properties returned by [method _get_viewport_composition_layer_extension_properties].
[param layer] is a pointer to an [code]XrCompositionLayerBaseHeader[/code] struct.
</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>

View File

@ -30,10 +30,9 @@
#pragma once
#include "openxr_composition_layer_provider.h"
#include "openxr_extension_wrapper.h"
class OpenXRCompositionLayerDepthExtension : public OpenXRExtensionWrapper, public OpenXRCompositionLayerProvider {
class OpenXRCompositionLayerDepthExtension : public OpenXRExtensionWrapper {
GDCLASS(OpenXRCompositionLayerDepthExtension, OpenXRExtensionWrapper);
protected:

View File

@ -30,7 +30,6 @@
#pragma once
#include "openxr_composition_layer_provider.h"
#include "openxr_extension_wrapper.h"
#include "../openxr_api.h"
@ -49,7 +48,7 @@ class OpenXRViewportCompositionLayerProvider;
// This extension provides access to composition layers for displaying 2D content through the XR compositor.
// OpenXRCompositionLayerExtension enables the extensions related to this functionality
class OpenXRCompositionLayerExtension : public OpenXRExtensionWrapper, public OpenXRCompositionLayerProvider {
class OpenXRCompositionLayerExtension : public OpenXRExtensionWrapper {
GDCLASS(OpenXRCompositionLayerExtension, OpenXRExtensionWrapper);
protected:

View File

@ -1,5 +1,5 @@
/**************************************************************************/
/* openxr_extension_wrapper_extension.cpp */
/* openxr_extension_wrapper.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -28,11 +28,12 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "openxr_extension_wrapper_extension.h"
#include "openxr_extension_wrapper.h"
#include "../openxr_api.h"
#include "../openxr_api_extension.h"
void OpenXRExtensionWrapperExtension::_bind_methods() {
void OpenXRExtensionWrapper::_bind_methods() {
GDVIRTUAL_BIND(_get_requested_extensions);
GDVIRTUAL_BIND(_set_system_properties_and_get_next_pointer, "next_pointer");
GDVIRTUAL_BIND(_set_instance_create_info_and_get_next_pointer, "next_pointer");
@ -70,11 +71,11 @@ void OpenXRExtensionWrapperExtension::_bind_methods() {
GDVIRTUAL_BIND(_on_viewport_composition_layer_destroyed, "layer");
GDVIRTUAL_BIND(_set_android_surface_swapchain_create_info_and_get_next_pointer, "property_values", "next_pointer");
ClassDB::bind_method(D_METHOD("get_openxr_api"), &OpenXRExtensionWrapperExtension::get_openxr_api);
ClassDB::bind_method(D_METHOD("register_extension_wrapper"), &OpenXRExtensionWrapperExtension::register_extension_wrapper);
ClassDB::bind_method(D_METHOD("get_openxr_api"), &OpenXRExtensionWrapper::_gdextension_get_openxr_api);
ClassDB::bind_method(D_METHOD("register_extension_wrapper"), &OpenXRExtensionWrapper::_gdextension_register_extension_wrapper);
}
HashMap<String, bool *> OpenXRExtensionWrapperExtension::get_requested_extensions() {
HashMap<String, bool *> OpenXRExtensionWrapper::get_requested_extensions() {
Dictionary request_extension;
if (GDVIRTUAL_CALL(_get_requested_extensions, request_extension)) {
@ -91,7 +92,7 @@ HashMap<String, bool *> OpenXRExtensionWrapperExtension::get_requested_extension
return HashMap<String, bool *>();
}
void *OpenXRExtensionWrapperExtension::set_system_properties_and_get_next_pointer(void *p_next_pointer) {
void *OpenXRExtensionWrapper::set_system_properties_and_get_next_pointer(void *p_next_pointer) {
uint64_t pointer;
if (GDVIRTUAL_CALL(_set_system_properties_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
@ -101,7 +102,7 @@ void *OpenXRExtensionWrapperExtension::set_system_properties_and_get_next_pointe
return nullptr;
}
void *OpenXRExtensionWrapperExtension::set_instance_create_info_and_get_next_pointer(void *p_next_pointer) {
void *OpenXRExtensionWrapper::set_instance_create_info_and_get_next_pointer(void *p_next_pointer) {
uint64_t pointer;
if (GDVIRTUAL_CALL(_set_instance_create_info_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
@ -111,7 +112,7 @@ void *OpenXRExtensionWrapperExtension::set_instance_create_info_and_get_next_poi
return nullptr;
}
void *OpenXRExtensionWrapperExtension::set_session_create_and_get_next_pointer(void *p_next_pointer) {
void *OpenXRExtensionWrapper::set_session_create_and_get_next_pointer(void *p_next_pointer) {
uint64_t pointer;
if (GDVIRTUAL_CALL(_set_session_create_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
@ -121,7 +122,7 @@ void *OpenXRExtensionWrapperExtension::set_session_create_and_get_next_pointer(v
return nullptr;
}
void *OpenXRExtensionWrapperExtension::set_swapchain_create_info_and_get_next_pointer(void *p_next_pointer) {
void *OpenXRExtensionWrapper::set_swapchain_create_info_and_get_next_pointer(void *p_next_pointer) {
uint64_t pointer;
if (GDVIRTUAL_CALL(_set_swapchain_create_info_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
@ -131,7 +132,7 @@ void *OpenXRExtensionWrapperExtension::set_swapchain_create_info_and_get_next_po
return nullptr;
}
void *OpenXRExtensionWrapperExtension::set_hand_joint_locations_and_get_next_pointer(int p_hand_index, void *p_next_pointer) {
void *OpenXRExtensionWrapper::set_hand_joint_locations_and_get_next_pointer(int p_hand_index, void *p_next_pointer) {
uint64_t pointer;
if (GDVIRTUAL_CALL(_set_hand_joint_locations_and_get_next_pointer, p_hand_index, GDExtensionPtr<void>(p_next_pointer), pointer)) {
@ -141,7 +142,7 @@ void *OpenXRExtensionWrapperExtension::set_hand_joint_locations_and_get_next_poi
return nullptr;
}
void *OpenXRExtensionWrapperExtension::set_projection_views_and_get_next_pointer(int p_view_index, void *p_next_pointer) {
void *OpenXRExtensionWrapper::set_projection_views_and_get_next_pointer(int p_view_index, void *p_next_pointer) {
uint64_t pointer = 0;
if (GDVIRTUAL_CALL(_set_projection_views_and_get_next_pointer, p_view_index, GDExtensionPtr<void>(p_next_pointer), pointer)) {
@ -151,7 +152,7 @@ void *OpenXRExtensionWrapperExtension::set_projection_views_and_get_next_pointer
return nullptr;
}
PackedStringArray OpenXRExtensionWrapperExtension::get_suggested_tracker_names() {
PackedStringArray OpenXRExtensionWrapper::get_suggested_tracker_names() {
PackedStringArray ret;
if (GDVIRTUAL_CALL(_get_suggested_tracker_names, ret)) {
@ -161,13 +162,13 @@ PackedStringArray OpenXRExtensionWrapperExtension::get_suggested_tracker_names()
return PackedStringArray();
}
int OpenXRExtensionWrapperExtension::get_composition_layer_count() {
int OpenXRExtensionWrapper::get_composition_layer_count() {
int count = 0;
GDVIRTUAL_CALL(_get_composition_layer_count, count);
return count;
}
XrCompositionLayerBaseHeader *OpenXRExtensionWrapperExtension::get_composition_layer(int p_index) {
XrCompositionLayerBaseHeader *OpenXRExtensionWrapper::get_composition_layer(int p_index) {
uint64_t pointer;
if (GDVIRTUAL_CALL(_get_composition_layer, p_index, pointer)) {
@ -177,91 +178,91 @@ XrCompositionLayerBaseHeader *OpenXRExtensionWrapperExtension::get_composition_l
return nullptr;
}
int OpenXRExtensionWrapperExtension::get_composition_layer_order(int p_index) {
int OpenXRExtensionWrapper::get_composition_layer_order(int p_index) {
int order = 0;
GDVIRTUAL_CALL(_get_composition_layer_order, p_index, order);
return order;
}
void OpenXRExtensionWrapperExtension::on_register_metadata() {
void OpenXRExtensionWrapper::on_register_metadata() {
GDVIRTUAL_CALL(_on_register_metadata);
}
void OpenXRExtensionWrapperExtension::on_before_instance_created() {
void OpenXRExtensionWrapper::on_before_instance_created() {
GDVIRTUAL_CALL(_on_before_instance_created);
}
void OpenXRExtensionWrapperExtension::on_instance_created(const XrInstance p_instance) {
void OpenXRExtensionWrapper::on_instance_created(const XrInstance p_instance) {
uint64_t instance = (uint64_t)p_instance;
GDVIRTUAL_CALL(_on_instance_created, instance);
}
void OpenXRExtensionWrapperExtension::on_instance_destroyed() {
void OpenXRExtensionWrapper::on_instance_destroyed() {
GDVIRTUAL_CALL(_on_instance_destroyed);
}
void OpenXRExtensionWrapperExtension::on_session_created(const XrSession p_session) {
void OpenXRExtensionWrapper::on_session_created(const XrSession p_session) {
uint64_t session = (uint64_t)p_session;
GDVIRTUAL_CALL(_on_session_created, session);
}
void OpenXRExtensionWrapperExtension::on_process() {
void OpenXRExtensionWrapper::on_process() {
GDVIRTUAL_CALL(_on_process);
}
void OpenXRExtensionWrapperExtension::on_pre_render() {
void OpenXRExtensionWrapper::on_pre_render() {
GDVIRTUAL_CALL(_on_pre_render);
}
void OpenXRExtensionWrapperExtension::on_main_swapchains_created() {
void OpenXRExtensionWrapper::on_main_swapchains_created() {
GDVIRTUAL_CALL(_on_main_swapchains_created);
}
void OpenXRExtensionWrapperExtension::on_session_destroyed() {
void OpenXRExtensionWrapper::on_session_destroyed() {
GDVIRTUAL_CALL(_on_session_destroyed);
}
void OpenXRExtensionWrapperExtension::on_pre_draw_viewport(RID p_render_target) {
void OpenXRExtensionWrapper::on_pre_draw_viewport(RID p_render_target) {
GDVIRTUAL_CALL(_on_pre_draw_viewport, p_render_target);
}
void OpenXRExtensionWrapperExtension::on_post_draw_viewport(RID p_render_target) {
void OpenXRExtensionWrapper::on_post_draw_viewport(RID p_render_target) {
GDVIRTUAL_CALL(_on_post_draw_viewport, p_render_target);
}
void OpenXRExtensionWrapperExtension::on_state_idle() {
void OpenXRExtensionWrapper::on_state_idle() {
GDVIRTUAL_CALL(_on_state_idle);
}
void OpenXRExtensionWrapperExtension::on_state_ready() {
void OpenXRExtensionWrapper::on_state_ready() {
GDVIRTUAL_CALL(_on_state_ready);
}
void OpenXRExtensionWrapperExtension::on_state_synchronized() {
void OpenXRExtensionWrapper::on_state_synchronized() {
GDVIRTUAL_CALL(_on_state_synchronized);
}
void OpenXRExtensionWrapperExtension::on_state_visible() {
void OpenXRExtensionWrapper::on_state_visible() {
GDVIRTUAL_CALL(_on_state_visible);
}
void OpenXRExtensionWrapperExtension::on_state_focused() {
void OpenXRExtensionWrapper::on_state_focused() {
GDVIRTUAL_CALL(_on_state_focused);
}
void OpenXRExtensionWrapperExtension::on_state_stopping() {
void OpenXRExtensionWrapper::on_state_stopping() {
GDVIRTUAL_CALL(_on_state_stopping);
}
void OpenXRExtensionWrapperExtension::on_state_loss_pending() {
void OpenXRExtensionWrapper::on_state_loss_pending() {
GDVIRTUAL_CALL(_on_state_loss_pending);
}
void OpenXRExtensionWrapperExtension::on_state_exiting() {
void OpenXRExtensionWrapper::on_state_exiting() {
GDVIRTUAL_CALL(_on_state_exiting);
}
bool OpenXRExtensionWrapperExtension::on_event_polled(const XrEventDataBuffer &p_event) {
bool OpenXRExtensionWrapper::on_event_polled(const XrEventDataBuffer &p_event) {
bool event_polled;
if (GDVIRTUAL_CALL(_on_event_polled, GDExtensionConstPtr<void>(&p_event), event_polled)) {
@ -271,7 +272,7 @@ bool OpenXRExtensionWrapperExtension::on_event_polled(const XrEventDataBuffer &p
return false;
}
void *OpenXRExtensionWrapperExtension::set_viewport_composition_layer_and_get_next_pointer(const XrCompositionLayerBaseHeader *p_layer, const Dictionary &p_property_values, void *p_next_pointer) {
void *OpenXRExtensionWrapper::set_viewport_composition_layer_and_get_next_pointer(const XrCompositionLayerBaseHeader *p_layer, const Dictionary &p_property_values, void *p_next_pointer) {
uint64_t pointer = 0;
if (GDVIRTUAL_CALL(_set_viewport_composition_layer_and_get_next_pointer, GDExtensionConstPtr<void>(p_layer), p_property_values, GDExtensionPtr<void>(p_next_pointer), pointer)) {
@ -281,11 +282,11 @@ void *OpenXRExtensionWrapperExtension::set_viewport_composition_layer_and_get_ne
return p_next_pointer;
}
void OpenXRExtensionWrapperExtension::on_viewport_composition_layer_destroyed(const XrCompositionLayerBaseHeader *p_layer) {
void OpenXRExtensionWrapper::on_viewport_composition_layer_destroyed(const XrCompositionLayerBaseHeader *p_layer) {
GDVIRTUAL_CALL(_on_viewport_composition_layer_destroyed, GDExtensionConstPtr<void>(p_layer));
}
void OpenXRExtensionWrapperExtension::get_viewport_composition_layer_extension_properties(List<PropertyInfo> *p_property_list) {
void OpenXRExtensionWrapper::get_viewport_composition_layer_extension_properties(List<PropertyInfo> *p_property_list) {
TypedArray<Dictionary> properties;
if (GDVIRTUAL_CALL(_get_viewport_composition_layer_extension_properties, properties)) {
@ -295,13 +296,13 @@ void OpenXRExtensionWrapperExtension::get_viewport_composition_layer_extension_p
}
}
Dictionary OpenXRExtensionWrapperExtension::get_viewport_composition_layer_extension_property_defaults() {
Dictionary OpenXRExtensionWrapper::get_viewport_composition_layer_extension_property_defaults() {
Dictionary property_defaults;
GDVIRTUAL_CALL(_get_viewport_composition_layer_extension_property_defaults, property_defaults);
return property_defaults;
}
void *OpenXRExtensionWrapperExtension::set_android_surface_swapchain_create_info_and_get_next_pointer(const Dictionary &p_property_values, void *p_next_pointer) {
void *OpenXRExtensionWrapper::set_android_surface_swapchain_create_info_and_get_next_pointer(const Dictionary &p_property_values, void *p_next_pointer) {
uint64_t pointer = 0;
if (GDVIRTUAL_CALL(_set_android_surface_swapchain_create_info_and_get_next_pointer, p_property_values, GDExtensionPtr<void>(p_next_pointer), pointer)) {
@ -311,17 +312,14 @@ void *OpenXRExtensionWrapperExtension::set_android_surface_swapchain_create_info
return p_next_pointer;
}
Ref<OpenXRAPIExtension> OpenXRExtensionWrapperExtension::get_openxr_api() {
return openxr_api;
Ref<OpenXRAPIExtension> OpenXRExtensionWrapper::_gdextension_get_openxr_api() {
static Ref<OpenXRAPIExtension> openxr_api_extension;
if (unlikely(openxr_api_extension.is_null())) {
openxr_api_extension.instantiate();
}
return openxr_api_extension;
}
void OpenXRExtensionWrapperExtension::register_extension_wrapper() {
void OpenXRExtensionWrapper::_gdextension_register_extension_wrapper() {
OpenXRAPI::register_extension_wrapper(this);
}
OpenXRExtensionWrapperExtension::OpenXRExtensionWrapperExtension() {
openxr_api.instantiate();
}
OpenXRExtensionWrapperExtension::~OpenXRExtensionWrapperExtension() {
}

View File

@ -33,28 +33,37 @@
#include "core/error/error_macros.h"
#include "core/math/projection.h"
#include "core/object/class_db.h"
#include "core/object/gdvirtual.gen.inc"
#include "core/templates/hash_map.h"
#include "core/templates/rid.h"
#include "core/variant/native_ptr.h"
#include "core/variant/typed_array.h"
#include "core/variant/variant.h"
#include <openxr/openxr.h>
class OpenXRAPI;
class OpenXRAPIExtension;
class OpenXRActionMap;
// `OpenXRExtensionWrapper` allows us to implement OpenXR extensions.
class OpenXRExtensionWrapper : public Object {
GDCLASS(OpenXRExtensionWrapper, Object);
Ref<OpenXRAPIExtension> _gdextension_get_openxr_api();
void _gdextension_register_extension_wrapper();
protected:
static void _bind_methods() {}
static void _bind_methods();
public:
// `get_requested_extensions` should return a list of OpenXR extensions related to this extension.
// If the bool * is a nullptr this extension is mandatory
// If the bool * points to a boolean, the boolean will be updated
// to true if the extension is enabled.
virtual HashMap<String, bool *> get_requested_extensions() = 0;
virtual HashMap<String, bool *> get_requested_extensions();
GDVIRTUAL0R(Dictionary, _get_requested_extensions);
// These functions allow an extension to add entries to a struct chain.
// `p_next_pointer` points to the last struct that was created for this chain
@ -62,14 +71,27 @@ public:
// You should return the pointer to the last struct you define as your result.
// If you are not adding any structs, just return `p_next_pointer`.
// See existing extensions for examples of this implementation.
virtual void *set_system_properties_and_get_next_pointer(void *p_next_pointer) { return p_next_pointer; } // Add additional data structures when we interrogate OpenXRS system abilities.
virtual void *set_instance_create_info_and_get_next_pointer(void *p_next_pointer) { return p_next_pointer; } // Add additional data structures when we create our OpenXR instance.
virtual void *set_session_create_and_get_next_pointer(void *p_next_pointer) { return p_next_pointer; } // Add additional data structures when we create our OpenXR session.
virtual void *set_swapchain_create_info_and_get_next_pointer(void *p_next_pointer) { return p_next_pointer; } // Add additional data structures when creating OpenXR swap chains.
virtual void *set_hand_joint_locations_and_get_next_pointer(int p_hand_index, void *p_next_pointer) { return p_next_pointer; }
virtual void *set_projection_views_and_get_next_pointer(int p_view_index, void *p_next_pointer) { return p_next_pointer; }
virtual void *set_system_properties_and_get_next_pointer(void *p_next_pointer); // Add additional data structures when we interrogate OpenXRS system abilities.
virtual void *set_instance_create_info_and_get_next_pointer(void *p_next_pointer); // Add additional data structures when we create our OpenXR instance.
virtual void *set_session_create_and_get_next_pointer(void *p_next_pointer); // Add additional data structures when we create our OpenXR session.
virtual void *set_swapchain_create_info_and_get_next_pointer(void *p_next_pointer); // Add additional data structures when creating OpenXR swap chains.
virtual void *set_hand_joint_locations_and_get_next_pointer(int p_hand_index, void *p_next_pointer);
virtual void *set_projection_views_and_get_next_pointer(int p_view_index, void *p_next_pointer);
virtual PackedStringArray get_suggested_tracker_names() { return PackedStringArray(); }
//TODO workaround as GDExtensionPtr<void> return type results in build error in godot-cpp
GDVIRTUAL1R(uint64_t, _set_system_properties_and_get_next_pointer, GDExtensionPtr<void>);
GDVIRTUAL1R(uint64_t, _set_instance_create_info_and_get_next_pointer, GDExtensionPtr<void>);
GDVIRTUAL1R(uint64_t, _set_session_create_and_get_next_pointer, GDExtensionPtr<void>);
GDVIRTUAL1R(uint64_t, _set_swapchain_create_info_and_get_next_pointer, GDExtensionPtr<void>);
GDVIRTUAL2R(uint64_t, _set_hand_joint_locations_and_get_next_pointer, int, GDExtensionPtr<void>);
GDVIRTUAL2R(uint64_t, _set_projection_views_and_get_next_pointer, int, GDExtensionPtr<void>);
GDVIRTUAL0R(int, _get_composition_layer_count);
GDVIRTUAL1R(uint64_t, _get_composition_layer, int);
GDVIRTUAL1R(int, _get_composition_layer_order, int);
virtual PackedStringArray get_suggested_tracker_names();
GDVIRTUAL0R(PackedStringArray, _get_suggested_tracker_names);
// `on_register_metadata` allows extensions to register additional controller metadata.
// This function is called even when OpenXRApi is not constructured as the metadata
@ -77,43 +99,75 @@ public:
// Also extensions should provide metadata regardless of whether they are supported
// on the host system as the controller data is used to setup action maps for users
// who may have access to the relevant hardware.
virtual void on_register_metadata() {}
virtual void on_register_metadata();
virtual void on_before_instance_created() {} // `on_before_instance_created` is called before we create our OpenXR instance.
virtual void on_instance_created(const XrInstance p_instance) {} // `on_instance_created` is called right after we've successfully created our OpenXR instance.
virtual void on_instance_destroyed() {} // `on_instance_destroyed` is called right before we destroy our OpenXR instance.
virtual void on_session_created(const XrSession p_session) {} // `on_session_created` is called right after we've successfully created our OpenXR session.
virtual void on_session_destroyed() {} // `on_session_destroyed` is called right before we destroy our OpenXR session.
virtual void on_before_instance_created(); // `on_before_instance_created` is called before we create our OpenXR instance.
virtual void on_instance_created(const XrInstance p_instance); // `on_instance_created` is called right after we've successfully created our OpenXR instance.
virtual void on_instance_destroyed(); // `on_instance_destroyed` is called right before we destroy our OpenXR instance.
virtual void on_session_created(const XrSession p_session); // `on_session_created` is called right after we've successfully created our OpenXR session.
virtual void on_session_destroyed(); // `on_session_destroyed` is called right before we destroy our OpenXR session.
// `on_process` is called as part of our OpenXR process handling,
// this happens right before physics process and normal processing is run.
// This is when controller data is queried and made available to game logic.
virtual void on_process() {}
virtual void on_pre_render() {} // `on_pre_render` is called right before we start rendering our XR viewports.
virtual void on_main_swapchains_created() {} // `on_main_swapchains_created` is called right after our main swapchains are (re)created.
virtual void on_pre_draw_viewport(RID p_render_target) {} // `on_pre_draw_viewport` is called right before we start rendering this viewport
virtual void on_post_draw_viewport(RID p_render_target) {} // `on_port_draw_viewport` is called right after we start rendering this viewport (note that on Vulkan draw commands may only be queued)
virtual void on_process();
virtual void on_pre_render(); // `on_pre_render` is called right before we start rendering our XR viewports.
virtual void on_main_swapchains_created(); // `on_main_swapchains_created` is called right after our main swapchains are (re)created.
virtual void on_pre_draw_viewport(RID p_render_target); // `on_pre_draw_viewport` is called right before we start rendering this viewport
virtual void on_post_draw_viewport(RID p_render_target); // `on_port_draw_viewport` is called right after we start rendering this viewport (note that on Vulkan draw commands may only be queued)
virtual void on_state_idle() {} // `on_state_idle` is called when the OpenXR session state is changed to idle.
virtual void on_state_ready() {} // `on_state_ready` is called when the OpenXR session state is changed to ready, this means OpenXR is ready to setup our session.
virtual void on_state_synchronized() {} // `on_state_synchronized` is called when the OpenXR session state is changed to synchronized, note that OpenXR also returns to this state when our application looses focus.
virtual void on_state_visible() {} // `on_state_visible` is called when the OpenXR session state is changed to visible, OpenXR is now ready to receive frames.
virtual void on_state_focused() {} // `on_state_focused` is called when the OpenXR session state is changed to focused, this state is the active state when our game runs.
virtual void on_state_stopping() {} // `on_state_stopping` is called when the OpenXR session state is changed to stopping.
virtual void on_state_loss_pending() {} // `on_state_loss_pending` is called when the OpenXR session state is changed to loss pending.
virtual void on_state_exiting() {} // `on_state_exiting` is called when the OpenXR session state is changed to exiting.
GDVIRTUAL0(_on_register_metadata);
GDVIRTUAL0(_on_before_instance_created);
GDVIRTUAL1(_on_instance_created, uint64_t);
GDVIRTUAL0(_on_instance_destroyed);
GDVIRTUAL1(_on_session_created, uint64_t);
GDVIRTUAL0(_on_process);
GDVIRTUAL0(_on_pre_render);
GDVIRTUAL0(_on_main_swapchains_created);
GDVIRTUAL0(_on_session_destroyed);
GDVIRTUAL1(_on_pre_draw_viewport, RID);
GDVIRTUAL1(_on_post_draw_viewport, RID);
virtual void *set_viewport_composition_layer_and_get_next_pointer(const XrCompositionLayerBaseHeader *p_layer, const Dictionary &p_property_values, void *p_next_pointer) { return p_next_pointer; } // Add additional data structures to composition layers created via OpenXRCompositionLayer.
virtual void on_viewport_composition_layer_destroyed(const XrCompositionLayerBaseHeader *p_layer) {} // `on_viewport_composition_layer_destroyed` is called when a composition layer created via OpenXRCompositionLayer is destroyed.
virtual void get_viewport_composition_layer_extension_properties(List<PropertyInfo> *p_property_list) {} // Get additional property definitions for OpenXRCompositionLayer.
virtual Dictionary get_viewport_composition_layer_extension_property_defaults() { return Dictionary(); } // Get the default values for the additional property definitions for OpenXRCompositionLayer.
virtual void *set_android_surface_swapchain_create_info_and_get_next_pointer(const Dictionary &p_property_values, void *p_next_pointer) { return p_next_pointer; }
virtual void on_state_idle(); // `on_state_idle` is called when the OpenXR session state is changed to idle.
virtual void on_state_ready(); // `on_state_ready` is called when the OpenXR session state is changed to ready, this means OpenXR is ready to setup our session.
virtual void on_state_synchronized(); // `on_state_synchronized` is called when the OpenXR session state is changed to synchronized, note that OpenXR also returns to this state when our application looses focus.
virtual void on_state_visible(); // `on_state_visible` is called when the OpenXR session state is changed to visible, OpenXR is now ready to receive frames.
virtual void on_state_focused(); // `on_state_focused` is called when the OpenXR session state is changed to focused, this state is the active state when our game runs.
virtual void on_state_stopping(); // `on_state_stopping` is called when the OpenXR session state is changed to stopping.
virtual void on_state_loss_pending(); // `on_state_loss_pending` is called when the OpenXR session state is changed to loss pending.
virtual void on_state_exiting(); // `on_state_exiting` is called when the OpenXR session state is changed to exiting.
GDVIRTUAL0(_on_state_idle);
GDVIRTUAL0(_on_state_ready);
GDVIRTUAL0(_on_state_synchronized);
GDVIRTUAL0(_on_state_visible);
GDVIRTUAL0(_on_state_focused);
GDVIRTUAL0(_on_state_stopping);
GDVIRTUAL0(_on_state_loss_pending);
GDVIRTUAL0(_on_state_exiting);
// These will only be called on extensions registered via OpenXRAPI::register_composition_layer_provider().
virtual int get_composition_layer_count();
virtual XrCompositionLayerBaseHeader *get_composition_layer(int p_index);
virtual int get_composition_layer_order(int p_index);
virtual void *set_viewport_composition_layer_and_get_next_pointer(const XrCompositionLayerBaseHeader *p_layer, const Dictionary &p_property_values, void *p_next_pointer); // Add additional data structures to composition layers created via OpenXRCompositionLayer.
virtual void on_viewport_composition_layer_destroyed(const XrCompositionLayerBaseHeader *p_layer); // `on_viewport_composition_layer_destroyed` is called when a composition layer created via OpenXRCompositionLayer is destroyed.
virtual void get_viewport_composition_layer_extension_properties(List<PropertyInfo> *p_property_list); // Get additional property definitions for OpenXRCompositionLayer.
virtual Dictionary get_viewport_composition_layer_extension_property_defaults(); // Get the default values for the additional property definitions for OpenXRCompositionLayer.
virtual void *set_android_surface_swapchain_create_info_and_get_next_pointer(const Dictionary &p_property_values, void *p_next_pointer);
GDVIRTUAL3R(uint64_t, _set_viewport_composition_layer_and_get_next_pointer, GDExtensionConstPtr<void>, Dictionary, GDExtensionPtr<void>);
GDVIRTUAL1(_on_viewport_composition_layer_destroyed, GDExtensionConstPtr<void>);
GDVIRTUAL0R(TypedArray<Dictionary>, _get_viewport_composition_layer_extension_properties);
GDVIRTUAL0R(Dictionary, _get_viewport_composition_layer_extension_property_defaults);
GDVIRTUAL2R(uint64_t, _set_android_surface_swapchain_create_info_and_get_next_pointer, Dictionary, GDExtensionPtr<void>);
// `on_event_polled` is called when there is an OpenXR event to process.
// Should return true if the event was handled, false otherwise.
virtual bool on_event_polled(const XrEventDataBuffer &event) {
return false;
}
virtual bool on_event_polled(const XrEventDataBuffer &event);
GDVIRTUAL1R(bool, _on_event_polled, GDExtensionConstPtr<void>);
OpenXRExtensionWrapper() = default;
virtual ~OpenXRExtensionWrapper() = default;

View File

@ -30,117 +30,8 @@
#pragma once
#include "../openxr_api_extension.h"
#include "openxr_extension_wrapper.h"
#include "core/object/ref_counted.h"
#include "core/os/thread_safe.h"
#include "core/variant/native_ptr.h"
#include "core/variant/typed_array.h"
class OpenXRExtensionWrapperExtension : public OpenXRExtensionWrapper, public OpenXRCompositionLayerProvider {
class OpenXRExtensionWrapperExtension : public OpenXRExtensionWrapper {
GDCLASS(OpenXRExtensionWrapperExtension, OpenXRExtensionWrapper);
protected:
_THREAD_SAFE_CLASS_
static void _bind_methods();
Ref<OpenXRAPIExtension> openxr_api;
public:
virtual HashMap<String, bool *> get_requested_extensions() override;
GDVIRTUAL0R(Dictionary, _get_requested_extensions);
virtual void *set_system_properties_and_get_next_pointer(void *p_next_pointer) override;
virtual void *set_instance_create_info_and_get_next_pointer(void *p_next_pointer) override;
virtual void *set_session_create_and_get_next_pointer(void *p_next_pointer) override;
virtual void *set_swapchain_create_info_and_get_next_pointer(void *p_next_pointer) override;
virtual void *set_hand_joint_locations_and_get_next_pointer(int p_hand_index, void *p_next_pointer) override;
virtual void *set_projection_views_and_get_next_pointer(int p_view_index, void *p_next_pointer) override;
virtual int get_composition_layer_count() override;
virtual XrCompositionLayerBaseHeader *get_composition_layer(int p_index) override;
virtual int get_composition_layer_order(int p_index) override;
//TODO workaround as GDExtensionPtr<void> return type results in build error in godot-cpp
GDVIRTUAL1R(uint64_t, _set_system_properties_and_get_next_pointer, GDExtensionPtr<void>);
GDVIRTUAL1R(uint64_t, _set_instance_create_info_and_get_next_pointer, GDExtensionPtr<void>);
GDVIRTUAL1R(uint64_t, _set_session_create_and_get_next_pointer, GDExtensionPtr<void>);
GDVIRTUAL1R(uint64_t, _set_swapchain_create_info_and_get_next_pointer, GDExtensionPtr<void>);
GDVIRTUAL2R(uint64_t, _set_hand_joint_locations_and_get_next_pointer, int, GDExtensionPtr<void>);
GDVIRTUAL2R(uint64_t, _set_projection_views_and_get_next_pointer, int, GDExtensionPtr<void>);
GDVIRTUAL0R(int, _get_composition_layer_count);
GDVIRTUAL1R(uint64_t, _get_composition_layer, int);
GDVIRTUAL1R(int, _get_composition_layer_order, int);
virtual PackedStringArray get_suggested_tracker_names() override;
GDVIRTUAL0R(PackedStringArray, _get_suggested_tracker_names);
virtual void on_register_metadata() override;
virtual void on_before_instance_created() override;
virtual void on_instance_created(const XrInstance p_instance) override;
virtual void on_instance_destroyed() override;
virtual void on_session_created(const XrSession p_session) override;
virtual void on_process() override;
virtual void on_pre_render() override;
virtual void on_main_swapchains_created() override;
virtual void on_session_destroyed() override;
virtual void on_pre_draw_viewport(RID p_render_target) override;
virtual void on_post_draw_viewport(RID p_render_target) override;
GDVIRTUAL0(_on_register_metadata);
GDVIRTUAL0(_on_before_instance_created);
GDVIRTUAL1(_on_instance_created, uint64_t);
GDVIRTUAL0(_on_instance_destroyed);
GDVIRTUAL1(_on_session_created, uint64_t);
GDVIRTUAL0(_on_process);
GDVIRTUAL0(_on_pre_render);
GDVIRTUAL0(_on_main_swapchains_created);
GDVIRTUAL0(_on_session_destroyed);
GDVIRTUAL1(_on_pre_draw_viewport, RID);
GDVIRTUAL1(_on_post_draw_viewport, RID);
virtual void on_state_idle() override;
virtual void on_state_ready() override;
virtual void on_state_synchronized() override;
virtual void on_state_visible() override;
virtual void on_state_focused() override;
virtual void on_state_stopping() override;
virtual void on_state_loss_pending() override;
virtual void on_state_exiting() override;
GDVIRTUAL0(_on_state_idle);
GDVIRTUAL0(_on_state_ready);
GDVIRTUAL0(_on_state_synchronized);
GDVIRTUAL0(_on_state_visible);
GDVIRTUAL0(_on_state_focused);
GDVIRTUAL0(_on_state_stopping);
GDVIRTUAL0(_on_state_loss_pending);
GDVIRTUAL0(_on_state_exiting);
virtual bool on_event_polled(const XrEventDataBuffer &p_event) override;
GDVIRTUAL1R(bool, _on_event_polled, GDExtensionConstPtr<void>);
virtual void *set_viewport_composition_layer_and_get_next_pointer(const XrCompositionLayerBaseHeader *p_layer, const Dictionary &p_property_values, void *p_next_pointer) override;
virtual void on_viewport_composition_layer_destroyed(const XrCompositionLayerBaseHeader *p_layer) override;
virtual void get_viewport_composition_layer_extension_properties(List<PropertyInfo> *p_property_list) override;
virtual Dictionary get_viewport_composition_layer_extension_property_defaults() override;
virtual void *set_android_surface_swapchain_create_info_and_get_next_pointer(const Dictionary &p_property_values, void *p_next_pointer) override;
GDVIRTUAL3R(uint64_t, _set_viewport_composition_layer_and_get_next_pointer, GDExtensionConstPtr<void>, Dictionary, GDExtensionPtr<void>);
GDVIRTUAL1(_on_viewport_composition_layer_destroyed, GDExtensionConstPtr<void>);
GDVIRTUAL0R(TypedArray<Dictionary>, _get_viewport_composition_layer_extension_properties);
GDVIRTUAL0R(Dictionary, _get_viewport_composition_layer_extension_property_defaults);
GDVIRTUAL2R(uint64_t, _set_android_surface_swapchain_create_info_and_get_next_pointer, Dictionary, GDExtensionPtr<void>);
Ref<OpenXRAPIExtension> get_openxr_api();
void register_extension_wrapper();
OpenXRExtensionWrapperExtension();
virtual ~OpenXRExtensionWrapperExtension() override;
};

View File

@ -30,7 +30,6 @@
#include "openxr_api.h"
#include "extensions/openxr_extension_wrapper_extension.h"
#include "openxr_interface.h"
#include "openxr_util.h"
@ -61,6 +60,10 @@
#include "extensions/openxr_fb_update_swapchain_extension.h"
#include "extensions/openxr_hand_tracking_extension.h"
#ifndef DISABLE_DEPRECATED
#include "extensions/openxr_extension_wrapper_extension.h"
#endif // DISABLE_DEPRECATED
#ifdef ANDROID_ENABLED
#define OPENXR_LOADER_NAME "libopenxr_loader.so"
#endif
@ -1740,11 +1743,14 @@ void OpenXRAPI::register_extension_metadata() {
void OpenXRAPI::cleanup_extension_wrappers() {
for (OpenXRExtensionWrapper *extension_wrapper : registered_extension_wrappers) {
#ifndef DISABLE_DEPRECATED
// Fix crash when the extension wrapper comes from GDExtension.
OpenXRExtensionWrapperExtension *gdextension_extension_wrapper = dynamic_cast<OpenXRExtensionWrapperExtension *>(extension_wrapper);
if (gdextension_extension_wrapper) {
memdelete(gdextension_extension_wrapper);
} else {
} else
#endif
{
memdelete(extension_wrapper);
}
}
@ -2425,11 +2431,11 @@ void OpenXRAPI::end_frame() {
bool projection_layer_is_first = true;
// Add composition layers from providers
for (OpenXRCompositionLayerProvider *provider : composition_layer_providers) {
for (int i = 0; i < provider->get_composition_layer_count(); i++) {
for (OpenXRExtensionWrapper *extension : composition_layer_providers) {
for (int i = 0; i < extension->get_composition_layer_count(); i++) {
OrderedCompositionLayer layer = {
provider->get_composition_layer(i),
provider->get_composition_layer_order(i),
extension->get_composition_layer(i),
extension->get_composition_layer_order(i),
};
if (layer.composition_layer) {
ordered_layers_list.push_back(layer);
@ -2683,12 +2689,7 @@ OpenXRAPI::OpenXRAPI() {
}
OpenXRAPI::~OpenXRAPI() {
// cleanup our composition layer providers
for (OpenXRCompositionLayerProvider *provider : composition_layer_providers) {
memdelete(provider);
}
composition_layer_providers.clear();
supported_extensions.clear();
layer_properties.clear();
@ -3594,12 +3595,12 @@ bool OpenXRAPI::trigger_haptic_pulse(RID p_action, RID p_tracker, float p_freque
return true;
}
void OpenXRAPI::register_composition_layer_provider(OpenXRCompositionLayerProvider *provider) {
composition_layer_providers.append(provider);
void OpenXRAPI::register_composition_layer_provider(OpenXRExtensionWrapper *p_extension) {
composition_layer_providers.append(p_extension);
}
void OpenXRAPI::unregister_composition_layer_provider(OpenXRCompositionLayerProvider *provider) {
composition_layer_providers.erase(provider);
void OpenXRAPI::unregister_composition_layer_provider(OpenXRExtensionWrapper *p_extension) {
composition_layer_providers.erase(p_extension);
}
void OpenXRAPI::register_projection_views_extension(OpenXRExtensionWrapper *p_extension) {

View File

@ -31,7 +31,6 @@
#pragma once
#include "action_map/openxr_action.h"
#include "extensions/openxr_composition_layer_provider.h"
#include "extensions/openxr_extension_wrapper.h"
#include "util.h"
@ -94,7 +93,7 @@ private:
Vector<CharString> enabled_extensions;
// composition layer providers
Vector<OpenXRCompositionLayerProvider *> composition_layer_providers;
Vector<OpenXRExtensionWrapper *> composition_layer_providers;
// projection views extensions
Vector<OpenXRExtensionWrapper *> projection_views_extensions;
@ -577,8 +576,8 @@ public:
XRPose::TrackingConfidence get_action_pose(RID p_action, RID p_tracker, Transform3D &r_transform, Vector3 &r_linear_velocity, Vector3 &r_angular_velocity);
bool trigger_haptic_pulse(RID p_action, RID p_tracker, float p_frequency, float p_amplitude, XrDuration p_duration_ns);
void register_composition_layer_provider(OpenXRCompositionLayerProvider *provider);
void unregister_composition_layer_provider(OpenXRCompositionLayerProvider *provider);
void register_composition_layer_provider(OpenXRExtensionWrapper *p_extension);
void unregister_composition_layer_provider(OpenXRExtensionWrapper *p_extension);
void register_projection_views_extension(OpenXRExtensionWrapper *p_extension);
void unregister_projection_views_extension(OpenXRExtensionWrapper *p_extension);

View File

@ -1,5 +1,5 @@
/**************************************************************************/
/* openxr_composition_layer_provider.h */
/* openxr_api_extension.compat.inc */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -28,18 +28,31 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#pragma once
#ifndef DISABLE_DEPRECATED
#include "openxr_extension_wrapper.h"
#include "extensions/openxr_extension_wrapper_extension.h"
#include <openxr/openxr.h>
void OpenXRAPIExtension::_register_composition_layer_provider_bind_compat_104087(OpenXRExtensionWrapperExtension *p_extension) {
register_composition_layer_provider(p_extension);
}
// Interface for OpenXR extensions that provide a composition layer.
class OpenXRCompositionLayerProvider {
public:
virtual int get_composition_layer_count() = 0;
virtual XrCompositionLayerBaseHeader *get_composition_layer(int p_index) = 0;
virtual int get_composition_layer_order(int p_index) = 0;
void OpenXRAPIExtension::_unregister_composition_layer_provider_bind_compat_104087(OpenXRExtensionWrapperExtension *p_extension) {
unregister_composition_layer_provider(p_extension);
}
virtual ~OpenXRCompositionLayerProvider() {}
};
void OpenXRAPIExtension::_register_projection_views_extension_bind_compat_104087(OpenXRExtensionWrapperExtension *p_extension) {
register_projection_views_extension(p_extension);
}
void OpenXRAPIExtension::_unregister_projection_views_extension_bind_compat_104087(OpenXRExtensionWrapperExtension *p_extension) {
unregister_projection_views_extension(p_extension);
}
void OpenXRAPIExtension::_bind_compatibility_methods() {
ClassDB::bind_compatibility_method(D_METHOD("register_composition_layer_provider", "extension"), &OpenXRAPIExtension::_register_composition_layer_provider_bind_compat_104087);
ClassDB::bind_compatibility_method(D_METHOD("unregister_composition_layer_provider", "extension"), &OpenXRAPIExtension::_unregister_composition_layer_provider_bind_compat_104087);
ClassDB::bind_compatibility_method(D_METHOD("register_projection_views_extension", "extension"), &OpenXRAPIExtension::_register_projection_views_extension_bind_compat_104087);
ClassDB::bind_compatibility_method(D_METHOD("unregister_projection_views_extension", "extension"), &OpenXRAPIExtension::_unregister_projection_views_extension_bind_compat_104087);
}
#endif // DISABLE_DEPRECATED

View File

@ -30,7 +30,8 @@
#include "openxr_api_extension.h"
#include "extensions/openxr_extension_wrapper_extension.h"
#include "extensions/openxr_extension_wrapper.h"
#include "openxr_api_extension.compat.inc"
void OpenXRAPIExtension::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_instance"), &OpenXRAPIExtension::get_instance);
@ -220,22 +221,22 @@ uint64_t OpenXRAPIExtension::get_hand_tracker(int p_hand_index) {
return (uint64_t)OpenXRAPI::get_singleton()->get_hand_tracker(p_hand_index);
}
void OpenXRAPIExtension::register_composition_layer_provider(OpenXRExtensionWrapperExtension *p_extension) {
void OpenXRAPIExtension::register_composition_layer_provider(OpenXRExtensionWrapper *p_extension) {
ERR_FAIL_NULL(OpenXRAPI::get_singleton());
OpenXRAPI::get_singleton()->register_composition_layer_provider(p_extension);
}
void OpenXRAPIExtension::unregister_composition_layer_provider(OpenXRExtensionWrapperExtension *p_extension) {
void OpenXRAPIExtension::unregister_composition_layer_provider(OpenXRExtensionWrapper *p_extension) {
ERR_FAIL_NULL(OpenXRAPI::get_singleton());
OpenXRAPI::get_singleton()->unregister_composition_layer_provider(p_extension);
}
void OpenXRAPIExtension::register_projection_views_extension(OpenXRExtensionWrapperExtension *p_extension) {
void OpenXRAPIExtension::register_projection_views_extension(OpenXRExtensionWrapper *p_extension) {
ERR_FAIL_NULL(OpenXRAPI::get_singleton());
OpenXRAPI::get_singleton()->register_projection_views_extension(p_extension);
}
void OpenXRAPIExtension::unregister_projection_views_extension(OpenXRExtensionWrapperExtension *p_extension) {
void OpenXRAPIExtension::unregister_projection_views_extension(OpenXRExtensionWrapper *p_extension) {
ERR_FAIL_NULL(OpenXRAPI::get_singleton());
OpenXRAPI::get_singleton()->unregister_projection_views_extension(p_extension);
}

View File

@ -36,6 +36,7 @@
#include "core/os/thread_safe.h"
#include "core/variant/native_ptr.h"
class OpenXRExtensionWrapper;
class OpenXRExtensionWrapperExtension;
class OpenXRAPIExtension : public RefCounted {
@ -46,6 +47,14 @@ protected:
static void _bind_methods();
#ifndef DISABLE_DEPRECATED
static void _bind_compatibility_methods();
void _register_composition_layer_provider_bind_compat_104087(OpenXRExtensionWrapperExtension *p_extension);
void _unregister_composition_layer_provider_bind_compat_104087(OpenXRExtensionWrapperExtension *p_extension);
void _register_projection_views_extension_bind_compat_104087(OpenXRExtensionWrapperExtension *p_extension);
void _unregister_projection_views_extension_bind_compat_104087(OpenXRExtensionWrapperExtension *p_extension);
#endif
public:
uint64_t get_instance();
uint64_t get_system_id();
@ -80,11 +89,11 @@ public:
uint64_t get_hand_tracker(int p_hand_index);
void register_composition_layer_provider(OpenXRExtensionWrapperExtension *p_extension);
void unregister_composition_layer_provider(OpenXRExtensionWrapperExtension *p_extension);
void register_composition_layer_provider(OpenXRExtensionWrapper *p_extension);
void unregister_composition_layer_provider(OpenXRExtensionWrapper *p_extension);
void register_projection_views_extension(OpenXRExtensionWrapperExtension *p_extension);
void unregister_projection_views_extension(OpenXRExtensionWrapperExtension *p_extension);
void register_projection_views_extension(OpenXRExtensionWrapper *p_extension);
void unregister_projection_views_extension(OpenXRExtensionWrapper *p_extension);
double get_render_state_z_near();
double get_render_state_z_far();

View File

@ -36,9 +36,12 @@
#include "action_map/openxr_haptic_feedback.h"
#include "action_map/openxr_interaction_profile.h"
#include "action_map/openxr_interaction_profile_metadata.h"
#include "openxr_api_extension.h"
#include "openxr_interface.h"
#ifndef DISABLE_DEPRECATED
#include "extensions/openxr_extension_wrapper_extension.h"
#endif // DISABLE_DEPRECATED
#include "scene/openxr_composition_layer.h"
#include "scene/openxr_composition_layer_cylinder.h"
@ -112,8 +115,10 @@ static void _editor_init() {
void initialize_openxr_module(ModuleInitializationLevel p_level) {
if (p_level == MODULE_INITIALIZATION_LEVEL_CORE) {
GDREGISTER_ABSTRACT_CLASS(OpenXRExtensionWrapper);
GDREGISTER_VIRTUAL_CLASS(OpenXRExtensionWrapper);
#ifndef DISABLE_DEPRECATED
GDREGISTER_VIRTUAL_CLASS(OpenXRExtensionWrapperExtension);
#endif // DISABLE_DEPRECATED
GDREGISTER_ABSTRACT_CLASS(OpenXRFutureResult); // Declared abstract, should never be instantiated by a user (Q or should this be internal?)
GDREGISTER_CLASS(OpenXRFutureExtension);
GDREGISTER_CLASS(OpenXRAPIExtension);