0.2.0-dev Download ZIP
144 lines ·6.4 KB Raw
| 1 | /**************************************************************************/ |
| 2 | /* openxr_api_extension.h */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #pragma once |
| 32 | |
| 33 | #include "core/object/ref_counted.h" |
| 34 | #include "core/os/thread_safe.h" |
| 35 | #include "core/variant/native_ptr.h" |
| 36 | |
| 37 | #include <openxr/openxr.h> |
| 38 | |
| 39 | class OpenXRExtensionWrapper; |
| 40 | class OpenXRExtensionWrapperExtension; |
| 41 | |
| 42 | class OpenXRAPIExtension : public RefCounted { |
| 43 | GDCLASS(OpenXRAPIExtension, RefCounted); |
| 44 | |
| 45 | protected: |
| 46 | _THREAD_SAFE_CLASS_ |
| 47 | |
| 48 | static void _bind_methods(); |
| 49 | |
| 50 | #ifndef DISABLE_DEPRECATED |
| 51 | static void _bind_compatibility_methods(); |
| 52 | void _register_composition_layer_provider_bind_compat_104087(OpenXRExtensionWrapperExtension *p_extension); |
| 53 | void _unregister_composition_layer_provider_bind_compat_104087(OpenXRExtensionWrapperExtension *p_extension); |
| 54 | void _register_projection_views_extension_bind_compat_104087(OpenXRExtensionWrapperExtension *p_extension); |
| 55 | void _unregister_projection_views_extension_bind_compat_104087(OpenXRExtensionWrapperExtension *p_extension); |
| 56 | #endif |
| 57 | |
| 58 | public: |
| 59 | uint64_t get_openxr_version(); |
| 60 | uint64_t get_instance(); |
| 61 | uint64_t get_system_id(); |
| 62 | uint64_t get_session(); |
| 63 | |
| 64 | // Helper method to convert an XrPosef to a Transform3D. |
| 65 | Transform3D transform_from_pose(GDExtensionPtr<const void> p_pose); |
| 66 | |
| 67 | bool xr_result(uint64_t p_result, const String &p_format, const Array &p_args = Array()); |
| 68 | |
| 69 | static bool openxr_is_enabled(bool p_check_run_in_editor = true); |
| 70 | |
| 71 | //TODO workaround as GDExtensionPtr<void> return type results in build error in godot-cpp |
| 72 | uint64_t get_instance_proc_addr(const String &p_name); |
| 73 | String get_error_string(uint64_t result); |
| 74 | String get_swapchain_format_name(int64_t p_swapchain_format); |
| 75 | void set_object_name(int64_t p_object_type, uint64_t p_object_handle, const String &p_object_name); |
| 76 | void begin_debug_label_region(const String &p_label_name); |
| 77 | void end_debug_label_region(); |
| 78 | void insert_debug_label(const String &p_label_name); |
| 79 | |
| 80 | uint32_t get_view_count() const; |
| 81 | uint32_t get_primary_view_count() const; |
| 82 | uint64_t get_view_configuration() const; |
| 83 | |
| 84 | bool is_initialized(); |
| 85 | bool is_running(); |
| 86 | |
| 87 | void set_custom_play_space(GDExtensionPtr<const void> p_custom_space); |
| 88 | uint64_t get_play_space(); |
| 89 | int64_t get_predicted_display_time(); |
| 90 | int64_t get_next_frame_time(); |
| 91 | bool can_render(); |
| 92 | |
| 93 | RID find_action(const String &p_name, const RID &p_action_set = RID()); |
| 94 | uint64_t action_get_handle(RID p_action); |
| 95 | |
| 96 | uint64_t get_hand_tracker(int p_hand_index); |
| 97 | |
| 98 | void register_composition_layer_provider(OpenXRExtensionWrapper *p_extension); |
| 99 | void unregister_composition_layer_provider(OpenXRExtensionWrapper *p_extension); |
| 100 | |
| 101 | void register_projection_views_extension(OpenXRExtensionWrapper *p_extension); |
| 102 | void unregister_projection_views_extension(OpenXRExtensionWrapper *p_extension); |
| 103 | |
| 104 | void register_frame_info_extension(OpenXRExtensionWrapper *p_extension); |
| 105 | void unregister_frame_info_extension(OpenXRExtensionWrapper *p_extension); |
| 106 | |
| 107 | void register_projection_layer_extension(OpenXRExtensionWrapper *p_extension); |
| 108 | void unregister_projection_layer_extension(OpenXRExtensionWrapper *p_extension); |
| 109 | |
| 110 | double get_render_state_z_near(); |
| 111 | double get_render_state_z_far(); |
| 112 | |
| 113 | void set_velocity_texture(RID p_render_target); |
| 114 | void set_velocity_depth_texture(RID p_render_target); |
| 115 | void set_velocity_target_size(const Size2i &p_target_size); |
| 116 | |
| 117 | PackedInt64Array get_supported_swapchain_formats(); |
| 118 | |
| 119 | uint64_t openxr_swapchain_create(XrSwapchainCreateFlags p_create_flags, XrSwapchainUsageFlags p_usage_flags, int64_t p_swapchain_format, uint32_t p_width, uint32_t p_height, uint32_t p_sample_count, uint32_t p_array_size); |
| 120 | void openxr_swapchain_free(uint64_t p_swapchain_info); |
| 121 | uint64_t openxr_swapchain_get_swapchain(uint64_t p_swapchain_info); |
| 122 | void openxr_swapchain_acquire(uint64_t p_swapchain_info); |
| 123 | RID openxr_swapchain_get_image(uint64_t p_swapchain_info); |
| 124 | void openxr_swapchain_release(uint64_t p_swapchain_info); |
| 125 | |
| 126 | uint64_t get_projection_layer(); |
| 127 | |
| 128 | void set_render_region(const Rect2i &p_render_region); |
| 129 | |
| 130 | void update_main_swapchain_size(); |
| 131 | |
| 132 | enum OpenXRAlphaBlendModeSupport { |
| 133 | OPENXR_ALPHA_BLEND_MODE_SUPPORT_NONE = 0, |
| 134 | OPENXR_ALPHA_BLEND_MODE_SUPPORT_REAL = 1, |
| 135 | OPENXR_ALPHA_BLEND_MODE_SUPPORT_EMULATING = 2, |
| 136 | }; |
| 137 | |
| 138 | void set_emulate_environment_blend_mode_alpha_blend(bool p_enabled); |
| 139 | OpenXRAlphaBlendModeSupport is_environment_blend_mode_alpha_blend_supported(); |
| 140 | |
| 141 | OpenXRAPIExtension(); |
| 142 | }; |
| 143 | |
| 144 | VARIANT_ENUM_CAST(OpenXRAPIExtension::OpenXRAlphaBlendModeSupport); |