Skip to content

Commit

Permalink
Merge pull request #87630 from dsnopek/openxr-passthrough-from-gdexte…
Browse files Browse the repository at this point in the history
…nsion

OpenXR: Allow moving vendor passthrough extensions to GDExtension
  • Loading branch information
akien-mga committed Feb 3, 2024
2 parents 0465027 + e74a0f4 commit 673f161
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 497 deletions.
12 changes: 8 additions & 4 deletions doc/classes/XRInterface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,18 @@
Is [code]true[/code] if this interface has been initialized.
</description>
</method>
<method name="is_passthrough_enabled">
<method name="is_passthrough_enabled" is_deprecated="true">
<return type="bool" />
<description>
Is [code]true[/code] if passthrough is enabled.
[i]Deprecated.[/i] Check if [member environment_blend_mode] is [constant XRInterface.XR_ENV_BLEND_MODE_ALPHA_BLEND], instead.
</description>
</method>
<method name="is_passthrough_supported">
<method name="is_passthrough_supported" is_deprecated="true">
<return type="bool" />
<description>
Is [code]true[/code] if this interface supports passthrough.
[i]Deprecated.[/i] Check that [constant XRInterface.XR_ENV_BLEND_MODE_ALPHA_BLEND] is supported using [method get_supported_environment_blend_modes], instead.
</description>
</method>
<method name="set_environment_blend_mode">
Expand Down Expand Up @@ -144,17 +146,19 @@
[b]Note:[/b] Changing this after the interface has already been initialized can be jarring for the player, so it's recommended to recenter on the HMD with [method XRServer.center_on_hmd] (if switching to [constant XRInterface.XR_PLAY_AREA_STAGE]) or make the switch during a scene change.
</description>
</method>
<method name="start_passthrough">
<method name="start_passthrough" is_deprecated="true">
<return type="bool" />
<description>
Starts passthrough, will return [code]false[/code] if passthrough couldn't be started.
[b]Note:[/b] The viewport used for XR must have a transparent background, otherwise passthrough may not properly render.
[i]Deprecated.[/i] Set the [member environment_blend_mode] to [constant XRInterface.XR_ENV_BLEND_MODE_ALPHA_BLEND], instead.
</description>
</method>
<method name="stop_passthrough">
<method name="stop_passthrough" is_deprecated="true">
<return type="void" />
<description>
Stops passthrough.
[i]Deprecated.[/i] Set the [member environment_blend_mode] to [constant XRInterface.XR_ENV_BLEND_MODE_OPAQUE], instead.
</description>
</method>
<method name="supports_play_area_mode">
Expand Down
38 changes: 38 additions & 0 deletions modules/openxr/doc_classes/OpenXRAPIExtension.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
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_environment_blend_mode_alpha_supported">
<return type="int" enum="OpenXRAPIExtension.OpenXRAlphaBlendModeSupport" />
<description>
Returns [enum OpenXRAPIExtension.OpenXRAlphaBlendModeSupport] denoting if [constant XRInterface.XR_ENV_BLEND_MODE_ALPHA_BLEND] is really support, emulated or not supported at all.
</description>
</method>
<method name="is_initialized">
<return type="bool" />
<description>
Expand All @@ -94,13 +100,34 @@
Returns [code]true[/code] if OpenXR is enabled.
</description>
</method>
<method name="register_composition_layer_provider">
<return type="void" />
<param index="0" name="extension" type="OpenXRExtensionWrapperExtension" />
<description>
Registers the given extension as a composition layer provider.
</description>
</method>
<method name="set_emulate_environment_blend_mode_alpha_blend">
<return type="void" />
<param index="0" name="enabled" type="bool" />
<description>
If set to [code]true[/code], an OpenXR extension is loaded which is capable of emulating the [constant XRInterface.XR_ENV_BLEND_MODE_ALPHA_BLEND] blend mode.
</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="unregister_composition_layer_provider">
<return type="void" />
<param index="0" name="extension" type="OpenXRExtensionWrapperExtension" />
<description>
Unregisters the given extension as a composition layer provider.
</description>
</method>
<method name="xr_result">
<return type="bool" />
<param index="0" name="result" type="int" />
Expand All @@ -111,4 +138,15 @@
</description>
</method>
</methods>
<constants>
<constant name="OPENXR_ALPHA_BLEND_MODE_SUPPORT_NONE" value="0" enum="OpenXRAlphaBlendModeSupport">
Means that [constant XRInterface.XR_ENV_BLEND_MODE_ALPHA_BLEND] isn't supported at all.
</constant>
<constant name="OPENXR_ALPHA_BLEND_MODE_SUPPORT_REAL" value="1" enum="OpenXRAlphaBlendModeSupport">
Means that [constant XRInterface.XR_ENV_BLEND_MODE_ALPHA_BLEND] is really supported.
</constant>
<constant name="OPENXR_ALPHA_BLEND_MODE_SUPPORT_EMULATING" value="2" enum="OpenXRAlphaBlendModeSupport">
Means that [constant XRInterface.XR_ENV_BLEND_MODE_ALPHA_BLEND] is emulated.
</constant>
</constants>
</class>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
<tutorials>
</tutorials>
<methods>
<method name="_get_composition_layer" qualifiers="virtual">
<return type="int" />
<description>
Returns a pointer to a [code]XrCompositionLayerBaseHeader[/code] struct to provide a 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_requested_extensions" qualifiers="virtual">
<return type="Dictionary" />
<description>
Expand Down
11 changes: 11 additions & 0 deletions modules/openxr/extensions/openxr_extension_wrapper_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void OpenXRExtensionWrapperExtension::_bind_methods() {
GDVIRTUAL_BIND(_set_session_create_and_get_next_pointer, "next_pointer");
GDVIRTUAL_BIND(_set_swapchain_create_info_and_get_next_pointer, "next_pointer");
GDVIRTUAL_BIND(_set_hand_joint_locations_and_get_next_pointer, "hand_index", "next_pointer");
GDVIRTUAL_BIND(_get_composition_layer);
GDVIRTUAL_BIND(_on_register_metadata);
GDVIRTUAL_BIND(_on_before_instance_created);
GDVIRTUAL_BIND(_on_instance_created, "instance");
Expand Down Expand Up @@ -128,6 +129,16 @@ void *OpenXRExtensionWrapperExtension::set_hand_joint_locations_and_get_next_poi
return nullptr;
}

XrCompositionLayerBaseHeader *OpenXRExtensionWrapperExtension::get_composition_layer() {
uint64_t pointer;

if (GDVIRTUAL_CALL(_get_composition_layer, pointer)) {
return reinterpret_cast<XrCompositionLayerBaseHeader *>(pointer);
}

return nullptr;
}

void OpenXRExtensionWrapperExtension::on_register_metadata() {
GDVIRTUAL_CALL(_on_register_metadata);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "core/os/thread_safe.h"
#include "core/variant/native_ptr.h"

class OpenXRExtensionWrapperExtension : public Object, OpenXRExtensionWrapper {
class OpenXRExtensionWrapperExtension : public Object, public OpenXRExtensionWrapper, public OpenXRCompositionLayerProvider {
GDCLASS(OpenXRExtensionWrapperExtension, Object);

protected:
Expand All @@ -59,13 +59,15 @@ class OpenXRExtensionWrapperExtension : public Object, OpenXRExtensionWrapper {
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 XrCompositionLayerBaseHeader *get_composition_layer() 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>);
GDVIRTUAL0R(uint64_t, _get_composition_layer);

virtual void on_register_metadata() override;
virtual void on_before_instance_created() override;
Expand Down
Loading

0 comments on commit 673f161

Please sign in to comment.