forked from GodotVR/godot_openxr_vendors
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Android Surface swapchain support
- Loading branch information
Showing
3 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
124 changes: 124 additions & 0 deletions
124
common/src/main/cpp/extensions/openxr_khr_android_surface_swapchain_extension_wrapper.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/**************************************************************************/ | ||
/* openxr_khr_android_surface_swapchain_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. */ | ||
/**************************************************************************/ | ||
|
||
#ifdef ANDROID | ||
|
||
#include "extensions/openxr_khr_android_surface_swapchain_extension_wrapper.h" | ||
#include <godot_cpp/classes/open_xrapi_extension.hpp> | ||
|
||
using namespace godot; | ||
|
||
OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper *OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper::singleton = nullptr; | ||
|
||
OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper *OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper::get_singleton() { | ||
if (singleton == nullptr) { | ||
singleton = memnew(OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper()); | ||
} | ||
return singleton; | ||
} | ||
|
||
OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper::OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper() : | ||
OpenXRExtensionWrapperExtension() { | ||
ERR_FAIL_COND_MSG(singleton != nullptr, "An OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper singleton already exists."); | ||
|
||
request_extensions[XR_KHR_ANDROID_SURFACE_SWAPCHAIN_EXTENSION_NAME] = &khr_android_surface_swapchain_ext; | ||
request_extensions[XR_FB_ANDROID_SURFACE_SWAPCHAIN_CREATE_EXTENSION_NAME] = &fb_android_surface_swapchain_create_ext; | ||
singleton = this; | ||
} | ||
|
||
OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper::~OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper() { | ||
cleanup(); | ||
} | ||
|
||
void OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper::_bind_methods() { | ||
// ClassDB::bind_method(D_METHOD("is_spatial_entity_query_supported"), &OpenXRFbSpatialEntityQueryExtensionWrapper::is_spatial_entity_query_supported); | ||
// ClassDB::bind_method(D_METHOD("query_persisted_anchors"), &OpenXRFbSpatialEntityQueryExtensionWrapper::query_persisted_anchors); | ||
// ADD_SIGNAL(MethodInfo("persisted_anchors_found", PropertyInfo(Variant::PACKED_STRING_ARRAY, "name"))); | ||
} | ||
|
||
void OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper::cleanup() { | ||
khr_android_surface_swapchain_ext = false; | ||
fb_android_surface_swapchain_create_ext = false; | ||
} | ||
|
||
Dictionary OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper::_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; | ||
} | ||
|
||
void OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper::_on_instance_created(uint64_t instance) { | ||
if (khr_android_surface_swapchain_ext && fb_android_surface_swapchain_create_ext) { | ||
bool result = initialize_khr_android_surface_swapchain_extension((XrInstance)instance); | ||
if (!result) { | ||
UtilityFunctions::print("Failed to initialize khr_android_surface_swapchain_ext extension"); | ||
khr_android_surface_swapchain_ext = false; | ||
fb_android_surface_swapchain_create_ext = false; | ||
} | ||
} | ||
} | ||
|
||
void OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper::_on_session_created(uint64_t p_session) { | ||
if (khr_android_surface_swapchain_ext && fb_android_surface_swapchain_create_ext) { | ||
get_openxr_api()->register_composition_layer_provider(this); | ||
} | ||
}; | ||
|
||
void OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper::_on_session_destroyed() { | ||
if (khr_android_surface_swapchain_ext && fb_android_surface_swapchain_create_ext) { | ||
get_openxr_api()->unregister_composition_layer_provider(this); | ||
} | ||
}; | ||
|
||
void OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper::_on_instance_destroyed() { | ||
cleanup(); | ||
} | ||
|
||
int OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper::_get_composition_layer_count() { | ||
return 0; | ||
}; | ||
|
||
uint64_t OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper::_get_composition_layer(int p_index) { | ||
return 0; | ||
}; | ||
|
||
int OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper::_get_composition_layer_order(int p_index) { | ||
return 0; | ||
}; | ||
|
||
bool OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper::initialize_khr_android_surface_swapchain_extension(const XrInstance &p_instance) { | ||
GDEXTENSION_INIT_XR_FUNC_V(xrCreateSwapchainAndroidSurfaceKHR); | ||
|
||
return true; | ||
} | ||
|
||
#endif // ANDROID |
87 changes: 87 additions & 0 deletions
87
.../src/main/cpp/include/extensions/openxr_khr_android_surface_swapchain_extension_wrapper.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/**************************************************************************/ | ||
/* openxr_khr_android_surface_swapchain_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 | ||
|
||
#define XR_USE_PLATFORM_ANDROID | ||
#include <jni.h> | ||
#include <openxr/openxr.h> | ||
#include <openxr/openxr_platform.h> | ||
|
||
#include <godot_cpp/classes/open_xr_extension_wrapper_extension.hpp> | ||
#include <godot_cpp/templates/hash_map.hpp> | ||
#include <godot_cpp/variant/utility_functions.hpp> | ||
|
||
#include "util.h" | ||
|
||
using namespace godot; | ||
|
||
class OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper : public OpenXRExtensionWrapperExtension { | ||
GDCLASS(OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper, OpenXRExtensionWrapperExtension); | ||
|
||
public: | ||
Dictionary _get_requested_extensions() override; | ||
|
||
void _on_instance_created(uint64_t p_instance) override; | ||
void _on_session_created(uint64_t p_session) override; | ||
void _on_session_destroyed() override; | ||
void _on_instance_destroyed() override; | ||
|
||
int _get_composition_layer_count() override; | ||
uint64_t _get_composition_layer(int p_index) override; | ||
int _get_composition_layer_order(int p_index) override; | ||
|
||
bool is_android_surface_swapchain_supported() { | ||
return khr_android_surface_swapchain_ext && fb_android_surface_swapchain_create_ext; | ||
} | ||
|
||
static OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper *get_singleton(); | ||
|
||
OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper(); | ||
~OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper(); | ||
|
||
protected: | ||
static void _bind_methods(); | ||
|
||
private: | ||
EXT_PROTO_XRRESULT_FUNC4(xrCreateSwapchainAndroidSurfaceKHR, | ||
(XrSession), session, | ||
(const XrSwapchainCreateInfo *), info, | ||
(XrSwapchain *), swapchain, | ||
(jobject *), surface); | ||
|
||
bool initialize_khr_android_surface_swapchain_extension(const XrInstance &instance); | ||
void cleanup(); | ||
|
||
static OpenXRKhrAndroidSurfaceSwapchainExtensionWrapper *singleton; | ||
|
||
HashMap<String, bool *> request_extensions; | ||
bool khr_android_surface_swapchain_ext = false; | ||
bool fb_android_surface_swapchain_create_ext = false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters