You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-25 15:37:42 +00:00
OpenXR add core support for Khronos loader
This commit is contained in:
@@ -35,6 +35,119 @@
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/gui/editor_bottom_panel.h"
|
||||
#include "editor/settings/editor_command_palette.h"
|
||||
#include "platform/android/export/export_plugin.h"
|
||||
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// OpenXRExportPlugin
|
||||
|
||||
bool OpenXRExportPlugin::supports_platform(const Ref<EditorExportPlatform> &p_export_platform) const {
|
||||
return p_export_platform->is_class(EditorExportPlatformAndroid::get_class_static());
|
||||
}
|
||||
|
||||
bool OpenXRExportPlugin::is_openxr_mode() const {
|
||||
int xr_mode_index = get_option("xr_features/xr_mode");
|
||||
|
||||
return xr_mode_index == XR_MODE_OPENXR;
|
||||
}
|
||||
|
||||
String OpenXRExportPlugin::_get_export_option_warning(const Ref<EditorExportPlatform> &p_export_platform, const String &p_option_name) const {
|
||||
if (!supports_platform(p_export_platform)) {
|
||||
return String();
|
||||
}
|
||||
|
||||
bool gradle_build = get_option("gradle_build/use_gradle_build");
|
||||
if (is_openxr_mode() && !gradle_build) {
|
||||
return "\"Use Gradle Build\" must be enabled when xr_mode is set to \"OpenXR\".";
|
||||
}
|
||||
|
||||
return String();
|
||||
}
|
||||
|
||||
PackedStringArray OpenXRExportPlugin::get_android_dependencies(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
|
||||
PackedStringArray ret;
|
||||
|
||||
if (!supports_platform(p_export_platform)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (is_openxr_mode()) {
|
||||
// Loader is always identified by the full API version even if we're initializing for OpenXR 1.0.
|
||||
int major = XR_VERSION_MAJOR(XR_CURRENT_API_VERSION);
|
||||
int minor = XR_VERSION_MINOR(XR_CURRENT_API_VERSION);
|
||||
int patch = XR_VERSION_PATCH(XR_CURRENT_API_VERSION);
|
||||
String openxr_loader = "org.khronos.openxr:openxr_loader_for_android:" + String::num_int64(major) + "." + String::num_int64(minor) + "." + String::num_int64(patch);
|
||||
|
||||
ret.push_back(openxr_loader);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
PackedStringArray OpenXRExportPlugin::_get_export_features(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
|
||||
PackedStringArray features;
|
||||
|
||||
if (!supports_platform(p_export_platform) || !is_openxr_mode()) {
|
||||
return features;
|
||||
}
|
||||
|
||||
// Placeholder for now
|
||||
|
||||
return features;
|
||||
}
|
||||
|
||||
String OpenXRExportPlugin::get_android_manifest_element_contents(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
|
||||
String contents;
|
||||
|
||||
if (!supports_platform(p_export_platform) || !is_openxr_mode()) {
|
||||
return contents;
|
||||
}
|
||||
|
||||
contents += R"n(
|
||||
<uses-permission android:name="org.khronos.openxr.permission.OPENXR" />
|
||||
<uses-permission android:name="org.khronos.openxr.permission.OPENXR_SYSTEM" />
|
||||
|
||||
<queries>
|
||||
<provider android:authorities="org.khronos.openxr.runtime_broker;org.khronos.openxr.system_runtime_broker" />
|
||||
|
||||
<intent>
|
||||
<action android:name="org.khronos.openxr.OpenXRRuntimeService" />
|
||||
</intent>
|
||||
<intent>
|
||||
<action android:name="org.khronos.openxr.OpenXRApiLayerService" />
|
||||
</intent>
|
||||
|
||||
</queries>
|
||||
|
||||
<uses-feature android:name="android.hardware.vr.headtracking" android:required="false" android:version="1" />
|
||||
)n";
|
||||
|
||||
return contents;
|
||||
}
|
||||
|
||||
String OpenXRExportPlugin::get_android_manifest_activity_element_contents(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
|
||||
String contents;
|
||||
|
||||
if (!supports_platform(p_export_platform) || !is_openxr_mode()) {
|
||||
return contents;
|
||||
}
|
||||
|
||||
contents += R"n(
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
||||
<category android:name="org.khronos.openxr.intent.category.IMMERSIVE_HMD" />
|
||||
</intent-filter>
|
||||
)n";
|
||||
|
||||
return contents;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// OpenXREditorPlugin
|
||||
|
||||
void OpenXREditorPlugin::edit(Object *p_node) {
|
||||
if (Object::cast_to<OpenXRActionMap>(p_node)) {
|
||||
@@ -64,3 +177,19 @@ OpenXREditorPlugin::OpenXREditorPlugin() {
|
||||
add_control_to_container(CONTAINER_TOOLBAR, select_runtime);
|
||||
#endif
|
||||
}
|
||||
|
||||
void OpenXREditorPlugin::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
// Initialize our export plugin
|
||||
openxr_export_plugin.instantiate();
|
||||
add_export_plugin(openxr_export_plugin);
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
// Clean up our export plugin
|
||||
remove_export_plugin(openxr_export_plugin);
|
||||
|
||||
openxr_export_plugin.unref();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user