Skip to content

Commit

Permalink
Improve support for XR projects
Browse files Browse the repository at this point in the history
  • Loading branch information
m4gr3d committed Sep 5, 2024
1 parent b6223c0 commit 59a68c2
Show file tree
Hide file tree
Showing 21 changed files with 565 additions and 91 deletions.
3 changes: 2 additions & 1 deletion main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
if (arg == "--audio-driver" ||
arg == "--display-driver" ||
arg == "--rendering-method" ||
arg == "--rendering-driver") {
arg == "--rendering-driver" ||
arg == "--xr-mode") {
if (N) {
forwardable_cli_arguments[CLI_SCOPE_TOOL].push_back(arg);
forwardable_cli_arguments[CLI_SCOPE_TOOL].push_back(N->get());
Expand Down
22 changes: 10 additions & 12 deletions modules/openxr/openxr_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,14 @@ OpenXRAPI *OpenXRAPI::singleton = nullptr;
Vector<OpenXRExtensionWrapper *> OpenXRAPI::registered_extension_wrappers;

bool OpenXRAPI::openxr_is_enabled(bool p_check_run_in_editor) {
// @TODO we need an overrule switch so we can force enable openxr, i.e run "godot --openxr_enabled"

if (Engine::get_singleton()->is_editor_hint() && p_check_run_in_editor) {
// Disabled for now, using XR inside of the editor we'll be working on during the coming months.
return false;
} else {
if (XRServer::get_xr_mode() == XRServer::XRMODE_DEFAULT) {
return GLOBAL_GET("xr/openxr/enabled");
if (XRServer::get_xr_mode() == XRServer::XRMODE_DEFAULT) {
if (Engine::get_singleton()->is_editor_hint() && p_check_run_in_editor) {
return GLOBAL_GET("xr/openxr/enabled.editor");
} else {
return XRServer::get_xr_mode() == XRServer::XRMODE_ON;
return GLOBAL_GET("xr/openxr/enabled");
}
} else {
return XRServer::get_xr_mode() == XRServer::XRMODE_ON;
}
}

Expand Down Expand Up @@ -562,7 +559,7 @@ bool OpenXRAPI::create_instance() {

// Create our OpenXR instance
XrApplicationInfo application_info{
"", // applicationName, we'll set this down below
"Godot Game Engine", // applicationName, if we're running a game we'll update this down below.
1, // applicationVersion, we don't currently have this
"Godot Game Engine", // engineName
VERSION_MAJOR * 10000 + VERSION_MINOR * 100 + VERSION_PATCH, // engineVersion 4.0 -> 40000, 4.0.1 -> 40001, 4.1 -> 40100, etc.
Expand All @@ -588,7 +585,9 @@ bool OpenXRAPI::create_instance() {
extension_ptrs.ptr() // enabledExtensionNames
};

copy_string_to_char_buffer(project_name, instance_create_info.applicationInfo.applicationName, XR_MAX_APPLICATION_NAME_SIZE);
if (project_name != "") {
copy_string_to_char_buffer(project_name, instance_create_info.applicationInfo.applicationName, XR_MAX_APPLICATION_NAME_SIZE);
}

XrResult result = xrCreateInstance(&instance_create_info, &instance);
ERR_FAIL_COND_V_MSG(XR_FAILED(result), false, "Failed to create XR instance.");
Expand Down Expand Up @@ -2583,7 +2582,6 @@ OpenXRAPI::OpenXRAPI() {

if (Engine::get_singleton()->is_editor_hint()) {
// Enabled OpenXR in the editor? Adjust our settings for the editor

} else {
// Load settings from project settings
int form_factor_setting = GLOBAL_GET("xr/openxr/form_factor");
Expand Down
1 change: 1 addition & 0 deletions platform/android/java/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ allprojects {
mavenCentral()
gradlePluginPortal()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots/"}

// Godot user plugins custom maven repos
String[] mavenRepos = getGodotPluginsMavenRepos()
Expand Down
1 change: 1 addition & 0 deletions platform/android/java/app/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pluginManagement {
mavenCentral()
gradlePluginPortal()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots/"}
}
}

Expand Down
39 changes: 29 additions & 10 deletions platform/android/java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ allprojects {
mavenCentral()
gradlePluginPortal()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots/"}
}
}

ext {
supportedAbis = ["arm32", "arm64", "x86_32", "x86_64"]
supportedFlavors = ["editor", "template"]
supportedEditorVendors = ["google", "meta"]
supportedFlavorsBuildTypes = [
"editor": ["dev", "debug", "release"],
"template": ["dev", "debug", "release"]
Expand Down Expand Up @@ -92,12 +94,17 @@ def templateExcludedBuildTask() {
/**
* Generates the build tasks for the given flavor
* @param flavor Must be one of the supported flavors ('template' / 'editor')
* @param editorVendor Must be one of the supported editor vendors ('google' / 'meta')
*/
def generateBuildTasks(String flavor = "template") {
def generateBuildTasks(String flavor = "template", String editorVendor = "google") {
if (!supportedFlavors.contains(flavor)) {
throw new GradleException("Invalid build flavor: $flavor")
}
if (!supportedEditorVendors.contains(editorVendor)) {
throw new GradleException("Invalid editor vendor: $editorVendor")
}

String capitalizedEditorVendor = editorVendor.capitalize()
def buildTasks = []

// Only build the apks and aar files for which we have native shared libraries unless we intend
Expand Down Expand Up @@ -163,28 +170,28 @@ def generateBuildTasks(String flavor = "template") {
}
} else {
// Copy the generated editor apk to the bin directory.
String copyEditorApkTaskName = "copyEditor${capitalizedTarget}ApkToBin"
String copyEditorApkTaskName = "copyEditor${capitalizedEditorVendor}${capitalizedTarget}ApkToBin"
if (tasks.findByName(copyEditorApkTaskName) != null) {
buildTasks += tasks.getByName(copyEditorApkTaskName)
} else {
buildTasks += tasks.create(name: copyEditorApkTaskName, type: Copy) {
dependsOn ":editor:assemble${capitalizedTarget}"
from("editor/build/outputs/apk/${target}")
dependsOn ":editor:assemble${capitalizedEditorVendor}${capitalizedTarget}"
from("editor/build/outputs/apk/${editorVendor}/${target}")
into(androidEditorBuildsDir)
include("android_editor-${target}*.apk")
include("android_editor-${editorVendor}-${target}*.apk")
}
}

// Copy the generated editor aab to the bin directory.
String copyEditorAabTaskName = "copyEditor${capitalizedTarget}AabToBin"
String copyEditorAabTaskName = "copyEditor${capitalizedEditorVendor}${capitalizedTarget}AabToBin"
if (tasks.findByName(copyEditorAabTaskName) != null) {
buildTasks += tasks.getByName(copyEditorAabTaskName)
} else {
buildTasks += tasks.create(name: copyEditorAabTaskName, type: Copy) {
dependsOn ":editor:bundle${capitalizedTarget}"
from("editor/build/outputs/bundle/${target}")
dependsOn ":editor:bundle${capitalizedEditorVendor}${capitalizedTarget}"
from("editor/build/outputs/bundle/${editorVendor}${capitalizedTarget}")
into(androidEditorBuildsDir)
include("android_editor-${target}*.aab")
include("android_editor-${editorVendor}-${target}*.aab")
}
}
}
Expand All @@ -205,7 +212,19 @@ def generateBuildTasks(String flavor = "template") {
*/
task generateGodotEditor {
gradle.startParameter.excludedTaskNames += templateExcludedBuildTask()
dependsOn = generateBuildTasks("editor")
dependsOn = generateBuildTasks("editor", "google")
}

/**
* Generate the Godot Meta Editor Android apk.
*
* Note: Unless the 'generateNativeLibs` argument is specified, the Godot 'tools' shared libraries
* must have been generated (via scons) prior to running this gradle task.
* The task will only build the apk(s) for which the shared libraries is available.
*/
task generateGodotMetaEditor {
gradle.startParameter.excludedTaskNames += templateExcludedBuildTask()
dependsOn = generateBuildTasks("editor", "meta")
}

/**
Expand Down
43 changes: 33 additions & 10 deletions platform/android/java/editor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ plugins {
id 'base'
}

dependencies {
implementation "androidx.fragment:fragment:$versions.fragmentVersion"
implementation project(":lib")

implementation "androidx.window:window:1.3.0"
implementation "androidx.core:core-splashscreen:$versions.splashscreenVersion"
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
implementation "org.bouncycastle:bcprov-jdk15to18:1.77"
}

ext {
// Retrieve the build number from the environment variable; default to 0 if none is specified.
// The build number is added as a suffix to the version code for upload to the Google Play store.
Expand Down Expand Up @@ -154,4 +144,37 @@ android {
doNotStrip '**/*.so'
}
}

flavorDimensions = ["vendor"]
productFlavors {
google {
dimension "vendor"
missingDimensionStrategy 'products', 'editor'
}
meta {
dimension "vendor"
missingDimensionStrategy 'products', 'editor'
ndk {
//noinspection ChromeOsAbiSupport
abiFilters "arm64-v8a"
}
applicationIdSuffix ".meta"
versionNameSuffix "-meta"
minSdkVersion 23
targetSdkVersion 32
}
}
}

dependencies {
implementation "androidx.fragment:fragment:$versions.fragmentVersion"
implementation project(":lib")

implementation "androidx.window:window:1.3.0"
implementation "androidx.core:core-splashscreen:$versions.splashscreenVersion"
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
implementation "org.bouncycastle:bcprov-jdk15to18:1.77"

// Meta dependencies
metaImplementation "org.godotengine:godot-openxr-vendors-meta:3.0.0-stable"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**************************************************************************/
/* GodotEditor.kt */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

package org.godotengine.editor

/**
* Primary window of the Godot Editor.
*
* This is the implementation of the editor used when running on regular Android devices.
*/
open class GodotEditor : BaseGodotEditor() {
}
Loading

0 comments on commit 59a68c2

Please sign in to comment.