From 21e18c1c418d614b44d015cca429b9509c00a376 Mon Sep 17 00:00:00 2001 From: Fredia Huya-Kouadio Date: Mon, 6 Feb 2023 10:09:25 -0800 Subject: Improve logic to detect whether vulkan is used for rendering --- platform/android/export/export_plugin.cpp | 15 +++++++++------ platform/android/export/export_plugin.h | 2 ++ platform/android/export/gradle_export_util.cpp | 6 ++---- platform/android/export/gradle_export_util.h | 2 +- .../java/lib/src/org/godotengine/godot/Godot.java | 17 +++++++++++++---- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/platform/android/export/export_plugin.cpp b/platform/android/export/export_plugin.cpp index 8cc2b1eb97..0b66654617 100644 --- a/platform/android/export/export_plugin.cpp +++ b/platform/android/export/export_plugin.cpp @@ -800,6 +800,12 @@ bool EditorExportPlatformAndroid::_has_manage_external_storage_permission(const return p_permissions.find("android.permission.MANAGE_EXTERNAL_STORAGE") != -1; } +bool EditorExportPlatformAndroid::_uses_vulkan() { + String current_renderer = GLOBAL_GET("rendering/renderer/rendering_method.mobile"); + bool uses_vulkan = (current_renderer == "forward_plus" || current_renderer == "mobile") && GLOBAL_GET("rendering/rendering_device/driver.android") == "vulkan"; + return uses_vulkan; +} + void EditorExportPlatformAndroid::_get_permissions(const Ref &p_preset, bool p_give_internet, Vector &r_permissions) { const char **aperms = android_perms; while (*aperms) { @@ -854,7 +860,7 @@ void EditorExportPlatformAndroid::_write_tmp_manifest(const Ref &p Vector feature_required_list; Vector feature_versions; - String current_renderer = GLOBAL_GET("rendering/renderer/rendering_method.mobile"); - bool has_vulkan = current_renderer == "forward_plus" || current_renderer == "mobile"; - if (has_vulkan) { + if (_uses_vulkan()) { // Require vulkan hardware level 1 support feature_names.push_back("android.hardware.vulkan.level"); feature_required_list.push_back(true); @@ -2384,13 +2388,12 @@ bool EditorExportPlatformAndroid::has_valid_project_configuration(const Ref get_enabled_abis(const Ref &p_preset); + static bool _uses_vulkan(); + public: typedef Error (*EditorExportSaveFunction)(void *p_userdata, const String &p_path, const Vector &p_data, int p_file, int p_total, const Vector &p_enc_in_filters, const Vector &p_enc_ex_filters, const Vector &p_key); diff --git a/platform/android/export/gradle_export_util.cpp b/platform/android/export/gradle_export_util.cpp index 7eb595f48d..671df89608 100644 --- a/platform/android/export/gradle_export_util.cpp +++ b/platform/android/export/gradle_export_util.cpp @@ -254,7 +254,7 @@ String _get_screen_sizes_tag(const Ref &p_preset) { return manifest_screen_sizes; } -String _get_xr_features_tag(const Ref &p_preset) { +String _get_xr_features_tag(const Ref &p_preset, bool p_uses_vulkan) { String manifest_xr_features; int xr_mode_index = (int)(p_preset->get("xr_features/xr_mode")); bool uses_xr = xr_mode_index == XR_MODE_OPENXR; @@ -274,9 +274,7 @@ String _get_xr_features_tag(const Ref &p_preset) { } } - String current_renderer = GLOBAL_GET("rendering/renderer/rendering_method.mobile"); - bool has_vulkan = current_renderer == "forward_plus" || current_renderer == "mobile"; - if (has_vulkan) { + if (p_uses_vulkan) { manifest_xr_features += " \n"; } return manifest_xr_features; diff --git a/platform/android/export/gradle_export_util.h b/platform/android/export/gradle_export_util.h index fe5888e11c..da6d1170bd 100644 --- a/platform/android/export/gradle_export_util.h +++ b/platform/android/export/gradle_export_util.h @@ -116,7 +116,7 @@ String _get_gles_tag(); String _get_screen_sizes_tag(const Ref &p_preset); -String _get_xr_features_tag(const Ref &p_preset); +String _get_xr_features_tag(const Ref &p_preset, bool p_uses_vulkan); String _get_activity_tag(const Ref &p_preset, bool p_uses_xr); diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.java b/platform/android/java/lib/src/org/godotengine/godot/Godot.java index 6296ee2c22..307fa7bae1 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/Godot.java +++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.java @@ -275,16 +275,16 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC return false; } - final String renderer = GodotLib.getGlobal("rendering/renderer/rendering_method"); - if (renderer.equals("gl_compatibility")) { - mRenderView = new GodotGLRenderView(activity, this, xrMode, use_debug_opengl); - } else { + if (usesVulkan()) { if (!meetsVulkanRequirements(activity.getPackageManager())) { Log.e(TAG, "Missing requirements for vulkan support! Aborting..."); alert(R.string.error_missing_vulkan_requirements_message, R.string.text_error_title, this::forceQuit); return false; } mRenderView = new GodotVulkanRenderView(activity, this); + } else { + // Fallback to openGl + mRenderView = new GodotGLRenderView(activity, this, xrMode, use_debug_opengl); } View view = mRenderView.getView(); @@ -322,6 +322,15 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC return true; } + /** + * Returns true if `Vulkan` is used for rendering. + */ + private boolean usesVulkan() { + final String renderer = GodotLib.getGlobal("rendering/renderer/rendering_method"); + final String renderingDevice = GodotLib.getGlobal("rendering/rendering_device/driver"); + return ("forward_plus".equals(renderer) || "mobile".equals(renderer)) && "vulkan".equals(renderingDevice); + } + /** * Returns true if the device meets the base requirements for Vulkan support, false otherwise. */ -- cgit v1.2.3