diff options
-rw-r--r-- | doc/classes/XRInterface.xml | 37 | ||||
-rw-r--r-- | modules/openxr/openxr_api.cpp | 62 | ||||
-rw-r--r-- | modules/openxr/openxr_api.h | 11 | ||||
-rw-r--r-- | modules/openxr/openxr_interface.cpp | 54 | ||||
-rw-r--r-- | modules/openxr/openxr_interface.h | 4 | ||||
-rw-r--r-- | modules/openxr/openxr_util.cpp | 271 | ||||
-rw-r--r-- | modules/openxr/openxr_util.h | 1 | ||||
-rw-r--r-- | servers/xr/xr_interface.cpp | 14 | ||||
-rw-r--r-- | servers/xr/xr_interface.h | 11 |
9 files changed, 212 insertions, 253 deletions
diff --git a/doc/classes/XRInterface.xml b/doc/classes/XRInterface.xml index 05d5eb6673..db65ce62f2 100644 --- a/doc/classes/XRInterface.xml +++ b/doc/classes/XRInterface.xml @@ -51,6 +51,12 @@ Returns the resolution at which we should render our intermediate results before things like lens distortion are applied by the VR platform. </description> </method> + <method name="get_supported_environment_blend_modes"> + <return type="Array" /> + <description> + Returns the an array of supported environment blend modes, see [enum XRInterface.EnvironmentBlendMode]. + </description> + </method> <method name="get_tracking_status" qualifiers="const"> <return type="int" enum="XRInterface.TrackingStatus" /> <description> @@ -101,6 +107,28 @@ Is [code]true[/code] if this interface supports passthrough. </description> </method> + <method name="set_environment_blend_mode"> + <return type="bool" /> + <param index="0" name="mode" type="int" enum="XRInterface.EnvironmentBlendMode" /> + <description> + Sets the active environment blend mode. + [param mode] is the [enum XRInterface.EnvironmentBlendMode] starting with the next frame. + [b]Note:[/b] Not all runtimes support all environment blend modes, so it is important to check this at startup. For example: + [codeblock] + func _ready(): + var xr_interface : XRInterface = XRServer.find_interface("OpenXR") + if xr_interface and xr_interface.is_initialized(): + var vp : Viewport = get_viewport() + vp.use_xr = true + var acceptable_modes = [ XRInterface.XR_ENV_BLEND_MODE_OPAQUE, XRInterface.XR_ENV_BLEND_MODE_ADDITIVE ] + var modes = xr_interface.get_supported_environment_blend_modes() + for mode in acceptable_modes: + if mode in modes: + xr_interface.set_environment_blend_mode(mode) + break + [/codeblock] + </description> + </method> <method name="set_play_area_mode"> <return type="bool" /> <param index="0" name="mode" type="int" enum="XRInterface.PlayAreaMode" /> @@ -220,5 +248,14 @@ <constant name="XR_PLAY_AREA_STAGE" value="4" enum="PlayAreaMode"> Same as roomscale but origin point is fixed to the center of the physical space, XRServer.center_on_hmd disabled. </constant> + <constant name="XR_ENV_BLEND_MODE_OPAQUE" value="0" enum="EnvironmentBlendMode"> + Opaque blend mode. This is typically used for VR devices. + </constant> + <constant name="XR_ENV_BLEND_MODE_ADDITIVE" value="1" enum="EnvironmentBlendMode"> + Additive blend mode. This is typically used for AR devices or VR devices with passthrough. + </constant> + <constant name="XR_ENV_BLEND_MODE_ALPHA_BLEND" value="2" enum="EnvironmentBlendMode"> + Alpha blend mode. This is typically used for AR or VR devices with passthrough capabilities. The alpha channel controls how much of the passthrough is visible. Alpha of 0.0 means the passthrough is visible and this pixel works in ADDITIVE mode. Alpha of 1.0 means that the passthrough is not visible and this pixel works in OPAQUE mode. + </constant> </constants> </class> diff --git a/modules/openxr/openxr_api.cpp b/modules/openxr/openxr_api.cpp index 0a25cd68b7..ddb3114b59 100644 --- a/modules/openxr/openxr_api.cpp +++ b/modules/openxr/openxr_api.cpp @@ -483,6 +483,37 @@ bool OpenXRAPI::load_supported_view_configuration_types() { return true; } +bool OpenXRAPI::load_supported_environmental_blend_modes() { + // This queries the supported environmental blend modes. + + ERR_FAIL_COND_V(instance == XR_NULL_HANDLE, false); + + if (supported_environment_blend_modes != nullptr) { + // free previous results + memfree(supported_environment_blend_modes); + supported_environment_blend_modes = nullptr; + num_supported_environment_blend_modes = 0; + } + + XrResult result = xrEnumerateEnvironmentBlendModes(instance, system_id, view_configuration, 0, &num_supported_environment_blend_modes, nullptr); + if (XR_FAILED(result)) { + print_line("OpenXR: Failed to get supported environmental blend mode count [", get_error_string(result), "]"); + return false; + } + + supported_environment_blend_modes = (XrEnvironmentBlendMode *)memalloc(sizeof(XrEnvironmentBlendMode) * num_supported_environment_blend_modes); + ERR_FAIL_NULL_V(supported_environment_blend_modes, false); + + result = xrEnumerateEnvironmentBlendModes(instance, system_id, view_configuration, num_supported_environment_blend_modes, &num_supported_environment_blend_modes, supported_environment_blend_modes); + ERR_FAIL_COND_V_MSG(XR_FAILED(result), false, "OpenXR: Failed to enumerate environmental blend modes"); + + for (uint32_t i = 0; i < num_supported_environment_blend_modes; i++) { + print_verbose(String("OpenXR: Found environmental blend mode ") + OpenXRUtil::get_environment_blend_mode_name(supported_environment_blend_modes[i])); + } + + return true; +} + bool OpenXRAPI::is_view_configuration_supported(XrViewConfigurationType p_configuration_type) const { ERR_FAIL_NULL_V(supported_view_configuration_types, false); @@ -551,6 +582,12 @@ void OpenXRAPI::destroy_instance() { supported_view_configuration_types = nullptr; } + if (supported_environment_blend_modes != nullptr) { + memfree(supported_environment_blend_modes); + supported_environment_blend_modes = nullptr; + num_supported_environment_blend_modes = 0; + } + if (instance != XR_NULL_HANDLE) { for (OpenXRExtensionWrapper *wrapper : registered_extension_wrappers) { wrapper->on_instance_destroyed(); @@ -1205,6 +1242,7 @@ bool OpenXRAPI::resolve_instance_openxr_symbols() { OPENXR_API_INIT_XR_FUNC_V(xrDestroySwapchain); OPENXR_API_INIT_XR_FUNC_V(xrEndFrame); OPENXR_API_INIT_XR_FUNC_V(xrEndSession); + OPENXR_API_INIT_XR_FUNC_V(xrEnumerateEnvironmentBlendModes); OPENXR_API_INIT_XR_FUNC_V(xrEnumerateReferenceSpaces); OPENXR_API_INIT_XR_FUNC_V(xrEnumerateSwapchainFormats); OPENXR_API_INIT_XR_FUNC_V(xrEnumerateViewConfigurations); @@ -1312,6 +1350,11 @@ bool OpenXRAPI::initialize(const String &p_rendering_driver) { return false; } + if (!load_supported_environmental_blend_modes()) { + destroy_instance(); + return false; + } + return true; } @@ -1822,7 +1865,7 @@ void OpenXRAPI::end_frame() { XR_TYPE_FRAME_END_INFO, // type nullptr, // next frame_state.predictedDisplayTime, // displayTime - XR_ENVIRONMENT_BLEND_MODE_OPAQUE, // environmentBlendMode + environment_blend_mode, // environmentBlendMode 0, // layerCount nullptr // layers }; @@ -1874,7 +1917,7 @@ void OpenXRAPI::end_frame() { XR_TYPE_FRAME_END_INFO, // type nullptr, // next frame_state.predictedDisplayTime, // displayTime - XR_ENVIRONMENT_BLEND_MODE_OPAQUE, // environmentBlendMode + environment_blend_mode, // environmentBlendMode static_cast<uint32_t>(layers_list.size()), // layerCount layers_list.ptr() // layers }; @@ -2777,3 +2820,18 @@ void OpenXRAPI::register_composition_layer_provider(OpenXRCompositionLayerProvid void OpenXRAPI::unregister_composition_layer_provider(OpenXRCompositionLayerProvider *provider) { composition_layer_providers.erase(provider); } + +const XrEnvironmentBlendMode *OpenXRAPI::get_supported_environment_blend_modes(uint32_t &count) { + count = num_supported_environment_blend_modes; + return supported_environment_blend_modes; +} + +bool OpenXRAPI::set_environment_blend_mode(XrEnvironmentBlendMode mode) { + for (uint32_t i = 0; i < num_supported_environment_blend_modes; i++) { + if (supported_environment_blend_modes[i] == mode) { + environment_blend_mode = mode; + return true; + } + } + return false; +} diff --git a/modules/openxr/openxr_api.h b/modules/openxr/openxr_api.h index e1787c6da0..8c642c4ff4 100644 --- a/modules/openxr/openxr_api.h +++ b/modules/openxr/openxr_api.h @@ -99,9 +99,13 @@ private: XrFormFactor form_factor = XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY; XrViewConfigurationType view_configuration = XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO; XrReferenceSpaceType reference_space = XR_REFERENCE_SPACE_TYPE_STAGE; - // XrEnvironmentBlendMode environment_blend_mode = XR_ENVIRONMENT_BLEND_MODE_OPAQUE; bool submit_depth_buffer = false; // if set to true we submit depth buffers to OpenXR if a suitable extension is enabled. + // blend mode + XrEnvironmentBlendMode environment_blend_mode = XR_ENVIRONMENT_BLEND_MODE_OPAQUE; + uint32_t num_supported_environment_blend_modes = 0; + XrEnvironmentBlendMode *supported_environment_blend_modes = nullptr; + // state XrInstance instance = XR_NULL_HANDLE; XrSystemId system_id = 0; @@ -182,6 +186,7 @@ private: EXT_PROTO_XRRESULT_FUNC2(xrEndFrame, (XrSession), session, (const XrFrameEndInfo *), frameEndInfo) EXT_PROTO_XRRESULT_FUNC1(xrEndSession, (XrSession), session) EXT_PROTO_XRRESULT_FUNC3(xrEnumerateApiLayerProperties, (uint32_t), propertyCapacityInput, (uint32_t *), propertyCountOutput, (XrApiLayerProperties *), properties) + EXT_PROTO_XRRESULT_FUNC6(xrEnumerateEnvironmentBlendModes, (XrInstance), instance, (XrSystemId), systemId, (XrViewConfigurationType), viewConfigurationType, (uint32_t), environmentBlendModeCapacityInput, (uint32_t *), environmentBlendModeCountOutput, (XrEnvironmentBlendMode *), environmentBlendModes) EXT_PROTO_XRRESULT_FUNC4(xrEnumerateInstanceExtensionProperties, (const char *), layerName, (uint32_t), propertyCapacityInput, (uint32_t *), propertyCountOutput, (XrExtensionProperties *), properties) EXT_PROTO_XRRESULT_FUNC4(xrEnumerateReferenceSpaces, (XrSession), session, (uint32_t), spaceCapacityInput, (uint32_t *), spaceCountOutput, (XrReferenceSpaceType *), spaces) EXT_PROTO_XRRESULT_FUNC4(xrEnumerateSwapchainFormats, (XrSession), session, (uint32_t), formatCapacityInput, (uint32_t *), formatCountOutput, (int64_t *), formats) @@ -210,6 +215,7 @@ private: bool create_instance(); bool get_system_info(); bool load_supported_view_configuration_types(); + bool load_supported_environmental_blend_modes(); bool is_view_configuration_supported(XrViewConfigurationType p_configuration_type) const; bool load_supported_view_configuration_views(XrViewConfigurationType p_configuration_type); void destroy_instance(); @@ -390,6 +396,9 @@ public: void register_composition_layer_provider(OpenXRCompositionLayerProvider *provider); void unregister_composition_layer_provider(OpenXRCompositionLayerProvider *provider); + const XrEnvironmentBlendMode *get_supported_environment_blend_modes(uint32_t &count); + bool set_environment_blend_mode(XrEnvironmentBlendMode mode); + OpenXRAPI(); ~OpenXRAPI(); }; diff --git a/modules/openxr/openxr_interface.cpp b/modules/openxr/openxr_interface.cpp index 702e56b410..51de9b913a 100644 --- a/modules/openxr/openxr_interface.cpp +++ b/modules/openxr/openxr_interface.cpp @@ -870,6 +870,60 @@ void OpenXRInterface::stop_passthrough() { } } +Array OpenXRInterface::get_supported_environment_blend_modes() { + Array modes; + + if (!openxr_api) { + return modes; + } + + uint32_t count = 0; + const XrEnvironmentBlendMode *env_blend_modes = openxr_api->get_supported_environment_blend_modes(count); + + if (!env_blend_modes) { + return modes; + } + + for (uint32_t i = 0; i < count; i++) { + switch (env_blend_modes[i]) { + case XR_ENVIRONMENT_BLEND_MODE_OPAQUE: + modes.push_back(XR_ENV_BLEND_MODE_OPAQUE); + break; + case XR_ENVIRONMENT_BLEND_MODE_ADDITIVE: + modes.push_back(XR_ENV_BLEND_MODE_ADDITIVE); + break; + case XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND: + modes.push_back(XR_ENV_BLEND_MODE_ALPHA_BLEND); + break; + default: + WARN_PRINT("Unsupported blend mode found: " + String::num_int64(int64_t(env_blend_modes[i]))); + } + } + return modes; +} + +bool OpenXRInterface::set_environment_blend_mode(XRInterface::EnvironmentBlendMode mode) { + if (openxr_api) { + XrEnvironmentBlendMode oxr_blend_mode; + switch (mode) { + case XR_ENV_BLEND_MODE_OPAQUE: + oxr_blend_mode = XR_ENVIRONMENT_BLEND_MODE_OPAQUE; + break; + case XR_ENV_BLEND_MODE_ADDITIVE: + oxr_blend_mode = XR_ENVIRONMENT_BLEND_MODE_ADDITIVE; + break; + case XR_ENV_BLEND_MODE_ALPHA_BLEND: + oxr_blend_mode = XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND; + break; + default: + WARN_PRINT("Unknown blend mode requested: " + String::num_int64(int64_t(mode))); + oxr_blend_mode = XR_ENVIRONMENT_BLEND_MODE_OPAQUE; + } + return openxr_api->set_environment_blend_mode(oxr_blend_mode); + } + return false; +} + void OpenXRInterface::on_state_ready() { emit_signal(SNAME("session_begun")); } diff --git a/modules/openxr/openxr_interface.h b/modules/openxr/openxr_interface.h index cce329d8e6..40ee95f02f 100644 --- a/modules/openxr/openxr_interface.h +++ b/modules/openxr/openxr_interface.h @@ -147,6 +147,10 @@ public: virtual bool start_passthrough() override; virtual void stop_passthrough() override; + /** environment blend mode. */ + virtual Array get_supported_environment_blend_modes() override; + virtual bool set_environment_blend_mode(XRInterface::EnvironmentBlendMode mode) override; + void on_state_ready(); void on_state_visible(); void on_state_focused(); diff --git a/modules/openxr/openxr_util.cpp b/modules/openxr/openxr_util.cpp index 50ebf468b9..926e918390 100644 --- a/modules/openxr/openxr_util.cpp +++ b/modules/openxr/openxr_util.cpp @@ -29,267 +29,38 @@ /**************************************************************************/ #include "openxr_util.h" +#include <openxr/openxr_reflection.h> -#define ENUM_TO_STRING_CASE(e) \ - case e: { \ - return String(#e); \ - } break; +#define XR_ENUM_CASE_STR(name, val) \ + case name: \ + return #name; +#define XR_ENUM_SWITCH(enumType, var) \ + switch (var) { \ + XR_LIST_ENUM_##enumType(XR_ENUM_CASE_STR) default : return "Unknown " #enumType ": " + String::num_int64(int64_t(var)); \ + } -// TODO see if we can generate this code further using the xml file with meta data supplied by OpenXR +String OpenXRUtil::get_view_configuration_name(XrViewConfigurationType p_view_configuration){ + XR_ENUM_SWITCH(XrViewConfigurationType, p_view_configuration) +} -String OpenXRUtil::get_view_configuration_name(XrViewConfigurationType p_view_configuration) { - switch (p_view_configuration) { - ENUM_TO_STRING_CASE(XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO) - ENUM_TO_STRING_CASE(XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO) - ENUM_TO_STRING_CASE(XR_VIEW_CONFIGURATION_TYPE_PRIMARY_QUAD_VARJO) - ENUM_TO_STRING_CASE(XR_VIEW_CONFIGURATION_TYPE_SECONDARY_MONO_FIRST_PERSON_OBSERVER_MSFT) - ENUM_TO_STRING_CASE(XR_VIEW_CONFIGURATION_TYPE_MAX_ENUM) - default: { - return String("View Configuration ") + String::num_int64(int64_t(p_view_configuration)); - } break; - } +String OpenXRUtil::get_reference_space_name(XrReferenceSpaceType p_reference_space){ + XR_ENUM_SWITCH(XrReferenceSpaceType, p_reference_space) } -String OpenXRUtil::get_reference_space_name(XrReferenceSpaceType p_reference_space) { - switch (p_reference_space) { - ENUM_TO_STRING_CASE(XR_REFERENCE_SPACE_TYPE_VIEW) - ENUM_TO_STRING_CASE(XR_REFERENCE_SPACE_TYPE_LOCAL) - ENUM_TO_STRING_CASE(XR_REFERENCE_SPACE_TYPE_STAGE) - ENUM_TO_STRING_CASE(XR_REFERENCE_SPACE_TYPE_UNBOUNDED_MSFT) - ENUM_TO_STRING_CASE(XR_REFERENCE_SPACE_TYPE_COMBINED_EYE_VARJO) - ENUM_TO_STRING_CASE(XR_REFERENCE_SPACE_TYPE_MAX_ENUM) - default: { - return String("Reference space ") + String::num_int64(int64_t(p_reference_space)); - } break; - } +String OpenXRUtil::get_structure_type_name(XrStructureType p_structure_type){ + XR_ENUM_SWITCH(XrStructureType, p_structure_type) } -String OpenXRUtil::get_structure_type_name(XrStructureType p_structure_type) { - switch (p_structure_type) { - ENUM_TO_STRING_CASE(XR_TYPE_UNKNOWN) - ENUM_TO_STRING_CASE(XR_TYPE_API_LAYER_PROPERTIES) - ENUM_TO_STRING_CASE(XR_TYPE_EXTENSION_PROPERTIES) - ENUM_TO_STRING_CASE(XR_TYPE_INSTANCE_CREATE_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_SYSTEM_GET_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_SYSTEM_PROPERTIES) - ENUM_TO_STRING_CASE(XR_TYPE_VIEW_LOCATE_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_VIEW) - ENUM_TO_STRING_CASE(XR_TYPE_SESSION_CREATE_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_SWAPCHAIN_CREATE_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_SESSION_BEGIN_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_VIEW_STATE) - ENUM_TO_STRING_CASE(XR_TYPE_FRAME_END_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_HAPTIC_VIBRATION) - ENUM_TO_STRING_CASE(XR_TYPE_EVENT_DATA_BUFFER) - ENUM_TO_STRING_CASE(XR_TYPE_EVENT_DATA_INSTANCE_LOSS_PENDING) - ENUM_TO_STRING_CASE(XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED) - ENUM_TO_STRING_CASE(XR_TYPE_ACTION_STATE_BOOLEAN) - ENUM_TO_STRING_CASE(XR_TYPE_ACTION_STATE_FLOAT) - ENUM_TO_STRING_CASE(XR_TYPE_ACTION_STATE_VECTOR2F) - ENUM_TO_STRING_CASE(XR_TYPE_ACTION_STATE_POSE) - ENUM_TO_STRING_CASE(XR_TYPE_ACTION_SET_CREATE_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_ACTION_CREATE_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_INSTANCE_PROPERTIES) - ENUM_TO_STRING_CASE(XR_TYPE_FRAME_WAIT_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_COMPOSITION_LAYER_PROJECTION) - ENUM_TO_STRING_CASE(XR_TYPE_COMPOSITION_LAYER_QUAD) - ENUM_TO_STRING_CASE(XR_TYPE_REFERENCE_SPACE_CREATE_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_ACTION_SPACE_CREATE_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_EVENT_DATA_REFERENCE_SPACE_CHANGE_PENDING) - ENUM_TO_STRING_CASE(XR_TYPE_VIEW_CONFIGURATION_VIEW) - ENUM_TO_STRING_CASE(XR_TYPE_SPACE_LOCATION) - ENUM_TO_STRING_CASE(XR_TYPE_SPACE_VELOCITY) - ENUM_TO_STRING_CASE(XR_TYPE_FRAME_STATE) - ENUM_TO_STRING_CASE(XR_TYPE_VIEW_CONFIGURATION_PROPERTIES) - ENUM_TO_STRING_CASE(XR_TYPE_FRAME_BEGIN_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW) - ENUM_TO_STRING_CASE(XR_TYPE_EVENT_DATA_EVENTS_LOST) - ENUM_TO_STRING_CASE(XR_TYPE_INTERACTION_PROFILE_SUGGESTED_BINDING) - ENUM_TO_STRING_CASE(XR_TYPE_EVENT_DATA_INTERACTION_PROFILE_CHANGED) - ENUM_TO_STRING_CASE(XR_TYPE_INTERACTION_PROFILE_STATE) - ENUM_TO_STRING_CASE(XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_SWAPCHAIN_IMAGE_WAIT_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_SWAPCHAIN_IMAGE_RELEASE_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_ACTION_STATE_GET_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_HAPTIC_ACTION_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_SESSION_ACTION_SETS_ATTACH_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_ACTIONS_SYNC_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_BOUND_SOURCES_FOR_ACTION_ENUMERATE_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_INPUT_SOURCE_LOCALIZED_NAME_GET_INFO) - ENUM_TO_STRING_CASE(XR_TYPE_COMPOSITION_LAYER_CUBE_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_INSTANCE_CREATE_INFO_ANDROID_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_COMPOSITION_LAYER_DEPTH_INFO_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_VULKAN_SWAPCHAIN_FORMAT_LIST_CREATE_INFO_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_EVENT_DATA_PERF_SETTINGS_EXT) - ENUM_TO_STRING_CASE(XR_TYPE_COMPOSITION_LAYER_CYLINDER_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_COMPOSITION_LAYER_EQUIRECT_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT) - ENUM_TO_STRING_CASE(XR_TYPE_DEBUG_UTILS_MESSENGER_CALLBACK_DATA_EXT) - ENUM_TO_STRING_CASE(XR_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT) - ENUM_TO_STRING_CASE(XR_TYPE_DEBUG_UTILS_LABEL_EXT) - ENUM_TO_STRING_CASE(XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_GRAPHICS_BINDING_OPENGL_XCB_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_GRAPHICS_BINDING_OPENGL_WAYLAND_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_GRAPHICS_REQUIREMENTS_OPENGL_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_GRAPHICS_BINDING_OPENGL_ES_ANDROID_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_ES_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_GRAPHICS_REQUIREMENTS_OPENGL_ES_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_GRAPHICS_BINDING_VULKAN_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_SWAPCHAIN_IMAGE_VULKAN_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_GRAPHICS_REQUIREMENTS_VULKAN_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_GRAPHICS_BINDING_D3D11_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_SWAPCHAIN_IMAGE_D3D11_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_GRAPHICS_REQUIREMENTS_D3D11_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_GRAPHICS_BINDING_D3D12_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_SWAPCHAIN_IMAGE_D3D12_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_GRAPHICS_REQUIREMENTS_D3D12_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_SYSTEM_EYE_GAZE_INTERACTION_PROPERTIES_EXT) - ENUM_TO_STRING_CASE(XR_TYPE_EYE_GAZE_SAMPLE_TIME_EXT) - ENUM_TO_STRING_CASE(XR_TYPE_VISIBILITY_MASK_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_EVENT_DATA_VISIBILITY_MASK_CHANGED_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_SESSION_CREATE_INFO_OVERLAY_EXTX) - ENUM_TO_STRING_CASE(XR_TYPE_EVENT_DATA_MAIN_SESSION_VISIBILITY_CHANGED_EXTX) - ENUM_TO_STRING_CASE(XR_TYPE_COMPOSITION_LAYER_COLOR_SCALE_BIAS_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_SPATIAL_ANCHOR_CREATE_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SPATIAL_ANCHOR_SPACE_CREATE_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_COMPOSITION_LAYER_IMAGE_LAYOUT_FB) - ENUM_TO_STRING_CASE(XR_TYPE_COMPOSITION_LAYER_ALPHA_BLEND_FB) - ENUM_TO_STRING_CASE(XR_TYPE_VIEW_CONFIGURATION_DEPTH_RANGE_EXT) - ENUM_TO_STRING_CASE(XR_TYPE_GRAPHICS_BINDING_EGL_MNDX) - ENUM_TO_STRING_CASE(XR_TYPE_SPATIAL_GRAPH_NODE_SPACE_CREATE_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SYSTEM_HAND_TRACKING_PROPERTIES_EXT) - ENUM_TO_STRING_CASE(XR_TYPE_HAND_TRACKER_CREATE_INFO_EXT) - ENUM_TO_STRING_CASE(XR_TYPE_HAND_JOINTS_LOCATE_INFO_EXT) - ENUM_TO_STRING_CASE(XR_TYPE_HAND_JOINT_LOCATIONS_EXT) - ENUM_TO_STRING_CASE(XR_TYPE_HAND_JOINT_VELOCITIES_EXT) - ENUM_TO_STRING_CASE(XR_TYPE_SYSTEM_HAND_TRACKING_MESH_PROPERTIES_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_HAND_MESH_SPACE_CREATE_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_HAND_MESH_UPDATE_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_HAND_MESH_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_HAND_POSE_TYPE_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SECONDARY_VIEW_CONFIGURATION_SESSION_BEGIN_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SECONDARY_VIEW_CONFIGURATION_STATE_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SECONDARY_VIEW_CONFIGURATION_FRAME_STATE_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SECONDARY_VIEW_CONFIGURATION_FRAME_END_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SECONDARY_VIEW_CONFIGURATION_LAYER_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SECONDARY_VIEW_CONFIGURATION_SWAPCHAIN_CREATE_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_CONTROLLER_MODEL_KEY_STATE_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_CONTROLLER_MODEL_NODE_PROPERTIES_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_CONTROLLER_MODEL_PROPERTIES_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_CONTROLLER_MODEL_NODE_STATE_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_CONTROLLER_MODEL_STATE_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_VIEW_CONFIGURATION_VIEW_FOV_EPIC) - ENUM_TO_STRING_CASE(XR_TYPE_HOLOGRAPHIC_WINDOW_ATTACHMENT_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_COMPOSITION_LAYER_REPROJECTION_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_COMPOSITION_LAYER_REPROJECTION_PLANE_OVERRIDE_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_ANDROID_SURFACE_SWAPCHAIN_CREATE_INFO_FB) - ENUM_TO_STRING_CASE(XR_TYPE_COMPOSITION_LAYER_SECURE_CONTENT_FB) - ENUM_TO_STRING_CASE(XR_TYPE_INTERACTION_PROFILE_ANALOG_THRESHOLD_VALVE) - ENUM_TO_STRING_CASE(XR_TYPE_HAND_JOINTS_MOTION_RANGE_INFO_EXT) - ENUM_TO_STRING_CASE(XR_TYPE_LOADER_INIT_INFO_ANDROID_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_VULKAN_INSTANCE_CREATE_INFO_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_VULKAN_DEVICE_CREATE_INFO_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_VULKAN_GRAPHICS_DEVICE_GET_INFO_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_COMPOSITION_LAYER_EQUIRECT2_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_SCENE_OBSERVER_CREATE_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SCENE_CREATE_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_NEW_SCENE_COMPUTE_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_VISUAL_MESH_COMPUTE_LOD_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SCENE_COMPONENTS_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SCENE_COMPONENTS_GET_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SCENE_COMPONENT_LOCATIONS_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SCENE_COMPONENTS_LOCATE_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SCENE_OBJECTS_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SCENE_COMPONENT_PARENT_FILTER_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SCENE_OBJECT_TYPES_FILTER_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SCENE_PLANES_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SCENE_PLANE_ALIGNMENT_FILTER_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SCENE_MESHES_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SCENE_MESH_BUFFERS_GET_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SCENE_MESH_BUFFERS_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SCENE_MESH_VERTEX_BUFFER_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SCENE_MESH_INDICES_UINT32_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SCENE_MESH_INDICES_UINT16_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SERIALIZED_SCENE_FRAGMENT_DATA_GET_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SCENE_DESERIALIZE_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_EVENT_DATA_DISPLAY_REFRESH_RATE_CHANGED_FB) - ENUM_TO_STRING_CASE(XR_TYPE_VIVE_TRACKER_PATHS_HTCX) - ENUM_TO_STRING_CASE(XR_TYPE_EVENT_DATA_VIVE_TRACKER_CONNECTED_HTCX) - ENUM_TO_STRING_CASE(XR_TYPE_SYSTEM_COLOR_SPACE_PROPERTIES_FB) - ENUM_TO_STRING_CASE(XR_TYPE_HAND_TRACKING_MESH_FB) - ENUM_TO_STRING_CASE(XR_TYPE_HAND_TRACKING_SCALE_FB) - ENUM_TO_STRING_CASE(XR_TYPE_HAND_TRACKING_AIM_STATE_FB) - ENUM_TO_STRING_CASE(XR_TYPE_HAND_TRACKING_CAPSULES_STATE_FB) - ENUM_TO_STRING_CASE(XR_TYPE_FOVEATION_PROFILE_CREATE_INFO_FB) - ENUM_TO_STRING_CASE(XR_TYPE_SWAPCHAIN_CREATE_INFO_FOVEATION_FB) - ENUM_TO_STRING_CASE(XR_TYPE_SWAPCHAIN_STATE_FOVEATION_FB) - ENUM_TO_STRING_CASE(XR_TYPE_FOVEATION_LEVEL_PROFILE_CREATE_INFO_FB) - ENUM_TO_STRING_CASE(XR_TYPE_TRIANGLE_MESH_CREATE_INFO_FB) - ENUM_TO_STRING_CASE(XR_TYPE_SYSTEM_PASSTHROUGH_PROPERTIES_FB) - ENUM_TO_STRING_CASE(XR_TYPE_PASSTHROUGH_CREATE_INFO_FB) - ENUM_TO_STRING_CASE(XR_TYPE_PASSTHROUGH_LAYER_CREATE_INFO_FB) - ENUM_TO_STRING_CASE(XR_TYPE_COMPOSITION_LAYER_PASSTHROUGH_FB) - ENUM_TO_STRING_CASE(XR_TYPE_GEOMETRY_INSTANCE_CREATE_INFO_FB) - ENUM_TO_STRING_CASE(XR_TYPE_GEOMETRY_INSTANCE_TRANSFORM_FB) - ENUM_TO_STRING_CASE(XR_TYPE_PASSTHROUGH_STYLE_FB) - ENUM_TO_STRING_CASE(XR_TYPE_PASSTHROUGH_COLOR_MAP_MONO_TO_RGBA_FB) - ENUM_TO_STRING_CASE(XR_TYPE_PASSTHROUGH_COLOR_MAP_MONO_TO_MONO_FB) - ENUM_TO_STRING_CASE(XR_TYPE_EVENT_DATA_PASSTHROUGH_STATE_CHANGED_FB) - ENUM_TO_STRING_CASE(XR_TYPE_BINDING_MODIFICATIONS_KHR) - ENUM_TO_STRING_CASE(XR_TYPE_VIEW_LOCATE_FOVEATED_RENDERING_VARJO) - ENUM_TO_STRING_CASE(XR_TYPE_FOVEATED_VIEW_CONFIGURATION_VIEW_VARJO) - ENUM_TO_STRING_CASE(XR_TYPE_SYSTEM_FOVEATED_RENDERING_PROPERTIES_VARJO) - ENUM_TO_STRING_CASE(XR_TYPE_COMPOSITION_LAYER_DEPTH_TEST_VARJO) - ENUM_TO_STRING_CASE(XR_TYPE_SYSTEM_MARKER_TRACKING_PROPERTIES_VARJO) - ENUM_TO_STRING_CASE(XR_TYPE_EVENT_DATA_MARKER_TRACKING_UPDATE_VARJO) - ENUM_TO_STRING_CASE(XR_TYPE_MARKER_SPACE_CREATE_INFO_VARJO) - ENUM_TO_STRING_CASE(XR_TYPE_SPATIAL_ANCHOR_PERSISTENCE_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SPATIAL_ANCHOR_FROM_PERSISTED_ANCHOR_CREATE_INFO_MSFT) - ENUM_TO_STRING_CASE(XR_TYPE_SWAPCHAIN_IMAGE_FOVEATION_VULKAN_FB) - ENUM_TO_STRING_CASE(XR_TYPE_SWAPCHAIN_STATE_ANDROID_SURFACE_DIMENSIONS_FB) - ENUM_TO_STRING_CASE(XR_TYPE_SWAPCHAIN_STATE_SAMPLER_OPENGL_ES_FB) - ENUM_TO_STRING_CASE(XR_TYPE_SWAPCHAIN_STATE_SAMPLER_VULKAN_FB) - ENUM_TO_STRING_CASE(XR_TYPE_COMPOSITION_LAYER_SPACE_WARP_INFO_FB) - ENUM_TO_STRING_CASE(XR_TYPE_SYSTEM_SPACE_WARP_PROPERTIES_FB) - ENUM_TO_STRING_CASE(XR_STRUCTURE_TYPE_MAX_ENUM) - default: { - return String("Structure type ") + String::num_int64(int64_t(p_structure_type)); - } break; - } +String OpenXRUtil::get_session_state_name(XrSessionState p_session_state){ + XR_ENUM_SWITCH(XrSessionState, p_session_state) } -String OpenXRUtil::get_session_state_name(XrSessionState p_session_state) { - switch (p_session_state) { - ENUM_TO_STRING_CASE(XR_SESSION_STATE_UNKNOWN) - ENUM_TO_STRING_CASE(XR_SESSION_STATE_IDLE) - ENUM_TO_STRING_CASE(XR_SESSION_STATE_READY) - ENUM_TO_STRING_CASE(XR_SESSION_STATE_SYNCHRONIZED) - ENUM_TO_STRING_CASE(XR_SESSION_STATE_VISIBLE) - ENUM_TO_STRING_CASE(XR_SESSION_STATE_FOCUSED) - ENUM_TO_STRING_CASE(XR_SESSION_STATE_STOPPING) - ENUM_TO_STRING_CASE(XR_SESSION_STATE_LOSS_PENDING) - ENUM_TO_STRING_CASE(XR_SESSION_STATE_EXITING) - ENUM_TO_STRING_CASE(XR_SESSION_STATE_MAX_ENUM) - default: { - return String("Session state ") + String::num_int64(int64_t(p_session_state)); - } break; - } +String OpenXRUtil::get_action_type_name(XrActionType p_action_type){ + XR_ENUM_SWITCH(XrActionType, p_action_type) } -String OpenXRUtil::get_action_type_name(XrActionType p_action_type) { - switch (p_action_type) { - ENUM_TO_STRING_CASE(XR_ACTION_TYPE_BOOLEAN_INPUT) - ENUM_TO_STRING_CASE(XR_ACTION_TYPE_FLOAT_INPUT) - ENUM_TO_STRING_CASE(XR_ACTION_TYPE_VECTOR2F_INPUT) - ENUM_TO_STRING_CASE(XR_ACTION_TYPE_POSE_INPUT) - ENUM_TO_STRING_CASE(XR_ACTION_TYPE_VIBRATION_OUTPUT) - ENUM_TO_STRING_CASE(XR_ACTION_TYPE_MAX_ENUM) - default: { - return String("Action type ") + String::num_int64(int64_t(p_action_type)); - } break; - } +String OpenXRUtil::get_environment_blend_mode_name(XrEnvironmentBlendMode p_blend_mode) { + XR_ENUM_SWITCH(XrEnvironmentBlendMode, p_blend_mode); } String OpenXRUtil::make_xr_version_string(XrVersion p_version) { diff --git a/modules/openxr/openxr_util.h b/modules/openxr/openxr_util.h index dfda537474..7e7a6a1880 100644 --- a/modules/openxr/openxr_util.h +++ b/modules/openxr/openxr_util.h @@ -41,6 +41,7 @@ public: static String get_structure_type_name(XrStructureType p_structure_type); static String get_session_state_name(XrSessionState p_session_state); static String get_action_type_name(XrActionType p_action_type); + static String get_environment_blend_mode_name(XrEnvironmentBlendMode p_blend_mode); static String make_xr_version_string(XrVersion p_version); }; diff --git a/servers/xr/xr_interface.cpp b/servers/xr/xr_interface.cpp index 9968a47b0c..7f3d8668a4 100644 --- a/servers/xr/xr_interface.cpp +++ b/servers/xr/xr_interface.cpp @@ -75,6 +75,10 @@ void XRInterface::_bind_methods() { ClassDB::bind_method(D_METHOD("get_transform_for_view", "view", "cam_transform"), &XRInterface::get_transform_for_view); ClassDB::bind_method(D_METHOD("get_projection_for_view", "view", "aspect", "near", "far"), &XRInterface::get_projection_for_view); + /** environment blend mode. */ + ClassDB::bind_method(D_METHOD("get_supported_environment_blend_modes"), &XRInterface::get_supported_environment_blend_modes); + ClassDB::bind_method(D_METHOD("set_environment_blend_mode", "mode"), &XRInterface::set_environment_blend_mode); + ADD_GROUP("AR", "ar_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ar_is_anchor_detection_enabled"), "set_anchor_detection_is_enabled", "get_anchor_detection_is_enabled"); @@ -97,6 +101,10 @@ void XRInterface::_bind_methods() { BIND_ENUM_CONSTANT(XR_PLAY_AREA_SITTING); BIND_ENUM_CONSTANT(XR_PLAY_AREA_ROOMSCALE); BIND_ENUM_CONSTANT(XR_PLAY_AREA_STAGE); + + BIND_ENUM_CONSTANT(XR_ENV_BLEND_MODE_OPAQUE); + BIND_ENUM_CONSTANT(XR_ENV_BLEND_MODE_ADDITIVE); + BIND_ENUM_CONSTANT(XR_ENV_BLEND_MODE_ALPHA_BLEND); }; bool XRInterface::is_primary() { @@ -273,3 +281,9 @@ XRInterface::TrackingStatus XRInterface::get_tracking_status() const { void XRInterface::trigger_haptic_pulse(const String &p_action_name, const StringName &p_tracker_name, double p_frequency, double p_amplitude, double p_duration_sec, double p_delay_sec) { } + +Array XRInterface::get_supported_environment_blend_modes() { + Array default_blend_modes; + default_blend_modes.push_back(XR_ENV_BLEND_MODE_OPAQUE); + return default_blend_modes; +} diff --git a/servers/xr/xr_interface.h b/servers/xr/xr_interface.h index 6f70f75772..c32455f466 100644 --- a/servers/xr/xr_interface.h +++ b/servers/xr/xr_interface.h @@ -78,6 +78,12 @@ public: XR_PLAY_AREA_STAGE, /* Same as roomscale but origin point is fixed to the center of the physical space, XRServer.center_on_hmd disabled */ }; + enum EnvironmentBlendMode { + XR_ENV_BLEND_MODE_OPAQUE, /* You cannot see the real world, VR like */ + XR_ENV_BLEND_MODE_ADDITIVE, /* You can see the real world, AR like */ + XR_ENV_BLEND_MODE_ALPHA_BLEND, /* Real world is passed through where alpha channel is 0.0 and gradually blends to opaque for value 1.0. */ + }; + protected: _THREAD_SAFE_CLASS_ @@ -138,6 +144,10 @@ public: virtual bool start_passthrough() { return false; } virtual void stop_passthrough() {} + /** environment blend mode. */ + virtual Array get_supported_environment_blend_modes(); + virtual bool set_environment_blend_mode(EnvironmentBlendMode mode) { return false; } + XRInterface(); ~XRInterface(); @@ -151,5 +161,6 @@ private: VARIANT_ENUM_CAST(XRInterface::Capabilities); VARIANT_ENUM_CAST(XRInterface::TrackingStatus); VARIANT_ENUM_CAST(XRInterface::PlayAreaMode); +VARIANT_ENUM_CAST(XRInterface::EnvironmentBlendMode); #endif // XR_INTERFACE_H |