1 | /**************************************************************************/ |
2 | /* openxr_api_extension.cpp */ |
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 | #include "openxr_api_extension.h" |
32 | |
33 | void OpenXRAPIExtension::_bind_methods() { |
34 | ClassDB::bind_method(D_METHOD("get_instance" ), &OpenXRAPIExtension::get_instance); |
35 | ClassDB::bind_method(D_METHOD("get_system_id" ), &OpenXRAPIExtension::get_system_id); |
36 | ClassDB::bind_method(D_METHOD("get_session" ), &OpenXRAPIExtension::get_session); |
37 | |
38 | ClassDB::bind_method(D_METHOD("transform_from_pose" , "pose" ), &OpenXRAPIExtension::transform_from_pose); |
39 | ClassDB::bind_method(D_METHOD("xr_result" , "result" , "format" , "args" ), &OpenXRAPIExtension::xr_result); |
40 | ClassDB::bind_static_method("OpenXRAPIExtension" , D_METHOD("openxr_is_enabled" , "check_run_in_editor" ), &OpenXRAPIExtension::openxr_is_enabled); |
41 | ClassDB::bind_method(D_METHOD("get_instance_proc_addr" , "name" ), &OpenXRAPIExtension::get_instance_proc_addr); |
42 | ClassDB::bind_method(D_METHOD("get_error_string" , "result" ), &OpenXRAPIExtension::get_error_string); |
43 | ClassDB::bind_method(D_METHOD("get_swapchain_format_name" , "swapchain_format" ), &OpenXRAPIExtension::get_swapchain_format_name); |
44 | |
45 | ClassDB::bind_method(D_METHOD("is_initialized" ), &OpenXRAPIExtension::is_initialized); |
46 | ClassDB::bind_method(D_METHOD("is_running" ), &OpenXRAPIExtension::is_running); |
47 | |
48 | ClassDB::bind_method(D_METHOD("get_play_space" ), &OpenXRAPIExtension::get_play_space); |
49 | ClassDB::bind_method(D_METHOD("get_next_frame_time" ), &OpenXRAPIExtension::get_next_frame_time); |
50 | ClassDB::bind_method(D_METHOD("can_render" ), &OpenXRAPIExtension::can_render); |
51 | } |
52 | |
53 | uint64_t OpenXRAPIExtension::get_instance() { |
54 | ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), 0); |
55 | return (uint64_t)OpenXRAPI::get_singleton()->get_instance(); |
56 | } |
57 | |
58 | uint64_t OpenXRAPIExtension::get_system_id() { |
59 | ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), 0); |
60 | return (uint64_t)OpenXRAPI::get_singleton()->get_system_id(); |
61 | } |
62 | |
63 | uint64_t OpenXRAPIExtension::get_session() { |
64 | ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), 0); |
65 | return (uint64_t)OpenXRAPI::get_singleton()->get_session(); |
66 | } |
67 | |
68 | Transform3D OpenXRAPIExtension::transform_from_pose(GDExtensionConstPtr<const void> p_pose) { |
69 | ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), Transform3D()); |
70 | return OpenXRAPI::get_singleton()->transform_from_pose(*(XrPosef *)p_pose.data); |
71 | } |
72 | |
73 | bool OpenXRAPIExtension::xr_result(uint64_t result, String format, Array args) { |
74 | ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), false); |
75 | return OpenXRAPI::get_singleton()->xr_result((XrResult)result, format.utf8().get_data(), args); |
76 | } |
77 | |
78 | bool OpenXRAPIExtension::openxr_is_enabled(bool p_check_run_in_editor) { |
79 | ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), false); |
80 | return OpenXRAPI::openxr_is_enabled(p_check_run_in_editor); |
81 | } |
82 | |
83 | uint64_t OpenXRAPIExtension::get_instance_proc_addr(String p_name) { |
84 | ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), 0); |
85 | CharString str = p_name.utf8(); |
86 | PFN_xrVoidFunction addr = nullptr; |
87 | XrResult result = OpenXRAPI::get_singleton()->get_instance_proc_addr(str.get_data(), &addr); |
88 | if (result != XR_SUCCESS) { |
89 | return 0; |
90 | } |
91 | return reinterpret_cast<uint64_t>(addr); |
92 | } |
93 | |
94 | String OpenXRAPIExtension::get_error_string(uint64_t result) { |
95 | ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), String()); |
96 | return OpenXRAPI::get_singleton()->get_error_string((XrResult)result); |
97 | } |
98 | |
99 | String OpenXRAPIExtension::get_swapchain_format_name(int64_t p_swapchain_format) { |
100 | ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), String()); |
101 | return OpenXRAPI::get_singleton()->get_swapchain_format_name(p_swapchain_format); |
102 | } |
103 | |
104 | bool OpenXRAPIExtension::is_initialized() { |
105 | ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), false); |
106 | return OpenXRAPI::get_singleton()->is_initialized(); |
107 | } |
108 | |
109 | bool OpenXRAPIExtension::is_running() { |
110 | ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), false); |
111 | return OpenXRAPI::get_singleton()->is_running(); |
112 | } |
113 | |
114 | uint64_t OpenXRAPIExtension::get_play_space() { |
115 | ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), 0); |
116 | return (uint64_t)OpenXRAPI::get_singleton()->get_play_space(); |
117 | } |
118 | |
119 | int64_t OpenXRAPIExtension::get_next_frame_time() { |
120 | ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), 0); |
121 | return (XrTime)OpenXRAPI::get_singleton()->get_next_frame_time(); |
122 | } |
123 | |
124 | bool OpenXRAPIExtension::can_render() { |
125 | ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), false); |
126 | return OpenXRAPI::get_singleton()->can_render(); |
127 | } |
128 | |
129 | OpenXRAPIExtension::OpenXRAPIExtension() { |
130 | } |
131 | |