Skip to content

Commit

Permalink
Add support for XR_FB_android_surface_swapchain_create
Browse files Browse the repository at this point in the history
  • Loading branch information
dsnopek committed Dec 9, 2024
1 parent cdedfcb commit 0177dfc
Show file tree
Hide file tree
Showing 8 changed files with 12,734 additions and 762 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-addon-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ jobs:
needs: build

env:
GODOT_VERSION: "4.3-stable"
GODOT_VERSION: "4.4-dev6"
XRSIM_VERSION: "65.0.0"

steps:
Expand Down
2 changes: 1 addition & 1 deletion demo/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ config_version=5

config/name="OpenXR Demo"
run/main_scene="res://main.tscn"
config/features=PackedStringArray("4.3", "GL Compatibility")
config/features=PackedStringArray("4.4", "GL Compatibility")
config/icon="res://icon.svg"

[debug]
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)


add_definitions(-DANDROID)
add_definitions(-DANDROID_ENABLED)

set(GODOT_COMPILE_FLAGS)
set(GODOT_LINKER_FLAGS)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/**************************************************************************/
/* openxr_fb_android_surface_swapchain_create_extension_wrapper.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT XR */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2022-present Godot XR contributors (see CONTRIBUTORS.md) */
/* */
/* 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. */
/**************************************************************************/

#include "extensions/openxr_fb_android_surface_swapchain_create_extension_wrapper.h"

#include <godot_cpp/classes/object.hpp>
#include <godot_cpp/classes/open_xrapi_extension.hpp>

using namespace godot;

static const char *SYNCHRONOUS_PROPERTY_NAME = "XR_FB_android_surface_swapchain_create/synchronous";
static const char *USE_TIMESTAMPS_PROPERTY_NAME = "XR_FB_android_surface_swapchain_create/use_timestamps";

OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper *OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper::singleton = nullptr;

OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper *OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper::get_singleton() {
if (singleton == nullptr) {
singleton = memnew(OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper());
}
return singleton;
}

OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper::OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper() :
OpenXRExtensionWrapperExtension() {
ERR_FAIL_COND_MSG(singleton != nullptr, "An OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper singleton already exists.");

#ifdef ANDROID_ENABLED
request_extensions[XR_FB_ANDROID_SURFACE_SWAPCHAIN_CREATE_EXTENSION_NAME] = &fb_android_surface_swapchain_create_ext;
#endif
singleton = this;
}

OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper::~OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper() {
}

void OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_enabled"), &OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper::is_enabled);
}

Dictionary OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper::_get_requested_extensions() {
Dictionary result;
for (auto ext : request_extensions) {
uint64_t value = reinterpret_cast<uint64_t>(ext.value);
result[ext.key] = (Variant)value;
}
return result;
}

TypedArray<Dictionary> OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper::_get_viewport_composition_layer_extension_properties() {
TypedArray<Dictionary> properties;

{
Dictionary synchronous;
synchronous["name"] = SYNCHRONOUS_PROPERTY_NAME;
synchronous["type"] = Variant::BOOL;
synchronous["hint"] = PROPERTY_HINT_NONE;
synchronous["hint_string"] = "";
properties.push_back(synchronous);
}

{
Dictionary use_timestamps;
use_timestamps["name"] = USE_TIMESTAMPS_PROPERTY_NAME;
use_timestamps["type"] = Variant::BOOL;
use_timestamps["hint"] = PROPERTY_HINT_NONE;
use_timestamps["hint_string"] = "";
properties.push_back(use_timestamps);
}

return properties;
}

Dictionary OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper::_get_viewport_composition_layer_extension_property_defaults() {
Dictionary defaults;
defaults[SYNCHRONOUS_PROPERTY_NAME] = false;
defaults[USE_TIMESTAMPS_PROPERTY_NAME] = false;
return defaults;
}

uint64_t OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper::_set_android_surface_swapchain_create_info_and_get_next_pointer(const Dictionary &p_property_values, void *p_next_pointer) {
#ifdef ANDROID_ENABLED
if (fb_android_surface_swapchain_create_ext) {
create_info.next = p_next_pointer;
create_info.createFlags = 0;

if ((bool)p_property_values.get(SYNCHRONOUS_PROPERTY_NAME, false)) {
create_info.createFlags |= XR_ANDROID_SURFACE_SWAPCHAIN_SYNCHRONOUS_BIT_FB;
}
if ((bool)p_property_values.get(USE_TIMESTAMPS_PROPERTY_NAME, false)) {
create_info.createFlags |= XR_ANDROID_SURFACE_SWAPCHAIN_USE_TIMESTAMPS_BIT_FB;
}

if (create_info.createFlags != 0) {
return reinterpret_cast<uint64_t>(&create_info);
}
}
#endif

return reinterpret_cast<uint64_t>(p_next_pointer);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**************************************************************************/
/* openxr_fb_android_surface_swapchain_create_extension_wrapper.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT XR */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2022-present Godot XR contributors (see CONTRIBUTORS.md) */
/* */
/* 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. */
/**************************************************************************/

#pragma once

#include <openxr/openxr.h>
#include <godot_cpp/classes/open_xr_extension_wrapper_extension.hpp>
#include <godot_cpp/templates/hash_map.hpp>

#ifdef ANDROID_ENABLED
#define XR_USE_PLATFORM_ANDROID
#include <jni.h>
#include <openxr/openxr_platform.h>
#endif

using namespace godot;

// Wrapper for the XR_FB_android_surface_swapchain_create extension.
class OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper : public OpenXRExtensionWrapperExtension {
GDCLASS(OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper, OpenXRExtensionWrapperExtension);

public:
Dictionary _get_requested_extensions() override;

bool is_enabled() const {
return fb_android_surface_swapchain_create_ext;
}

virtual TypedArray<Dictionary> _get_viewport_composition_layer_extension_properties() override;
virtual Dictionary _get_viewport_composition_layer_extension_property_defaults() override;
virtual uint64_t _set_android_surface_swapchain_create_info_and_get_next_pointer(const Dictionary &p_property_values, void *p_next_pointer) override;

static OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper *get_singleton();

OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper();
~OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper();

protected:
static void _bind_methods();

private:
HashMap<String, bool *> request_extensions;

static OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper *singleton;

bool fb_android_surface_swapchain_create_ext = false;

#ifdef ANDROID_ENABLED
XrAndroidSurfaceSwapchainCreateInfoFB create_info = {
XR_TYPE_ANDROID_SURFACE_SWAPCHAIN_CREATE_INFO_FB, // type
nullptr, // next
0, // createFlags
};
#endif
};
4 changes: 4 additions & 0 deletions plugin/src/main/cpp/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "export/pico_export_plugin.h"
#include "export/magicleap_export_plugin.h"

#include "extensions/openxr_fb_android_surface_swapchain_create_extension_wrapper.h"
#include "extensions/openxr_fb_body_tracking_extension_wrapper.h"
#include "extensions/openxr_fb_composition_layer_alpha_blend_extension_wrapper.h"
#include "extensions/openxr_fb_composition_layer_secure_content_extension_wrapper.h"
Expand Down Expand Up @@ -144,6 +145,9 @@ void initialize_plugin_module(ModuleInitializationLevel p_level) {
ClassDB::register_class<OpenXRFbCompositionLayerSettingsExtensionWrapper>();
OpenXRFbCompositionLayerSettingsExtensionWrapper::get_singleton()->register_extension_wrapper();

ClassDB::register_class<OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper>();
OpenXRFbAndroidSurfaceSwapchainCreateExtensionWrapper::get_singleton()->register_extension_wrapper();

ClassDB::register_class<OpenXRHtcFacialTrackingExtensionWrapper>();
OpenXRHtcFacialTrackingExtensionWrapper::get_singleton()->register_extension_wrapper();

Expand Down
2 changes: 1 addition & 1 deletion thirdparty/godot-cpp
Submodule godot-cpp updated 59 files
+14 −11 .github/actions/godot-cache-restore/action.yml
+6 −5 .github/actions/godot-cache-save/action.yml
+62 −0 .github/actions/setup-godot-cpp/action.yml
+27 −77 .github/workflows/ci.yml
+21 −0 .github/workflows/runner.yml
+3 −2 .github/workflows/static_checks.yml
+7 −0 .gitignore
+56 −227 CMakeLists.txt
+225 −70 binding_generator.py
+0 −94 cmake/GodotCompilerWarnings.cmake
+41 −0 cmake/android.cmake
+175 −0 cmake/common_compiler_flags.cmake
+40 −0 cmake/emsdkHack.cmake
+330 −0 cmake/godotcpp.cmake
+22 −0 cmake/ios.cmake
+22 −0 cmake/linux.cmake
+59 −0 cmake/macos.cmake
+42 −0 cmake/web.cmake
+100 −0 cmake/windows.cmake
+345 −0 doc/cmake.rst
+3,940 −275 gdextension/extension_api.json
+124 −6 gdextension/gdextension_interface.h
+6 −2 include/godot_cpp/classes/ref.hpp
+22 −18 include/godot_cpp/classes/wrapped.hpp
+13 −7 include/godot_cpp/core/class_db.hpp
+8 −0 include/godot_cpp/core/defs.hpp
+75 −0 include/godot_cpp/core/print_string.hpp
+213 −11 include/godot_cpp/core/type_info.hpp
+5 −2 include/godot_cpp/godot.hpp
+1 −1 include/godot_cpp/templates/safe_refcount.hpp
+1 −1 include/godot_cpp/variant/basis.hpp
+42 −44 include/godot_cpp/variant/quaternion.hpp
+238 −0 include/godot_cpp/variant/typed_dictionary.hpp
+3 −2 include/godot_cpp/variant/variant.hpp
+510 −0 include/godot_cpp/variant/variant_internal.hpp
+4 −3 include/godot_cpp/variant/vector4.hpp
+25 −23 src/classes/wrapped.cpp
+6 −1 src/core/class_db.cpp
+39 −0 src/core/print_string.cpp
+10 −4 src/godot.cpp
+5 −2 src/variant/basis.cpp
+6 −0 src/variant/packed_arrays.cpp
+28 −40 src/variant/quaternion.cpp
+7 −6 src/variant/variant.cpp
+43 −0 src/variant/variant_internal.cpp
+54 −129 test/CMakeLists.txt
+1 −0 test/SConstruct
+24 −2 test/project/main.gd
+64 −0 test/src/example.cpp
+19 −0 test/src/example.h
+1 −0 test/src/register_types.cpp
+5 −0 tools/android.py
+31 −1 tools/common_compiler_flags.py
+9 −0 tools/godotcpp.py
+5 −0 tools/ios.py
+4 −0 tools/linux.py
+5 −0 tools/macos.py
+9 −1 tools/web.py
+64 −12 tools/windows.py
Loading

0 comments on commit 0177dfc

Please sign in to comment.