Path: blob/master/modules/openxr/extensions/openxr_extension_wrapper.cpp
21209 views
/**************************************************************************/1/* openxr_extension_wrapper.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "openxr_extension_wrapper.h"3132#include "../openxr_api.h"33#include "../openxr_api_extension.h"3435void OpenXRExtensionWrapper::_bind_methods() {36GDVIRTUAL_BIND(_get_requested_extensions, "xr_version");37GDVIRTUAL_BIND(_set_system_properties_and_get_next_pointer, "next_pointer");38GDVIRTUAL_BIND(_set_instance_create_info_and_get_next_pointer, "xr_version", "next_pointer");39GDVIRTUAL_BIND(_set_session_create_and_get_next_pointer, "next_pointer");40GDVIRTUAL_BIND(_set_swapchain_create_info_and_get_next_pointer, "next_pointer");41GDVIRTUAL_BIND(_set_hand_joint_locations_and_get_next_pointer, "hand_index", "next_pointer");42GDVIRTUAL_BIND(_set_projection_views_and_get_next_pointer, "view_index", "next_pointer");43GDVIRTUAL_BIND(_set_frame_wait_info_and_get_next_pointer, "next_pointer");44GDVIRTUAL_BIND(_set_frame_end_info_and_get_next_pointer, "next_pointer");45GDVIRTUAL_BIND(_set_view_locate_info_and_get_next_pointer, "next_pointer");46GDVIRTUAL_BIND(_set_reference_space_create_info_and_get_next_pointer, "reference_space_type", "next_pointer");47GDVIRTUAL_BIND(_prepare_view_configuration, "view_count");48GDVIRTUAL_BIND(_set_view_configuration_and_get_next_pointer, "view", "next_pointer");49GDVIRTUAL_BIND(_print_view_configuration_info, "view");50GDVIRTUAL_BIND(_get_composition_layer_count);51GDVIRTUAL_BIND(_get_composition_layer, "index");52GDVIRTUAL_BIND(_get_composition_layer_order, "index");53GDVIRTUAL_BIND(_get_suggested_tracker_names);54GDVIRTUAL_BIND(_on_register_metadata);55GDVIRTUAL_BIND(_on_before_instance_created);56GDVIRTUAL_BIND(_on_instance_created, "instance");57GDVIRTUAL_BIND(_on_instance_destroyed);58GDVIRTUAL_BIND(_on_session_created, "session");59GDVIRTUAL_BIND(_on_process);60GDVIRTUAL_BIND(_on_sync_actions);61GDVIRTUAL_BIND(_on_pre_render);62GDVIRTUAL_BIND(_on_main_swapchains_created);63GDVIRTUAL_BIND(_on_pre_draw_viewport, "viewport");64GDVIRTUAL_BIND(_on_post_draw_viewport, "viewport");65GDVIRTUAL_BIND(_on_session_destroyed);66GDVIRTUAL_BIND(_on_state_idle);67GDVIRTUAL_BIND(_on_state_ready);68GDVIRTUAL_BIND(_on_state_synchronized);69GDVIRTUAL_BIND(_on_state_visible);70GDVIRTUAL_BIND(_on_state_focused);71GDVIRTUAL_BIND(_on_state_stopping);72GDVIRTUAL_BIND(_on_state_loss_pending);73GDVIRTUAL_BIND(_on_state_exiting);74GDVIRTUAL_BIND(_on_event_polled, "event");75GDVIRTUAL_BIND(_set_viewport_composition_layer_and_get_next_pointer, "layer", "property_values", "next_pointer");76GDVIRTUAL_BIND(_get_viewport_composition_layer_extension_properties);77GDVIRTUAL_BIND(_get_viewport_composition_layer_extension_property_defaults);78GDVIRTUAL_BIND(_on_viewport_composition_layer_destroyed, "layer");79GDVIRTUAL_BIND(_set_android_surface_swapchain_create_info_and_get_next_pointer, "property_values", "next_pointer");8081#ifndef DISABLE_DEPRECATED82GDVIRTUAL_BIND_COMPAT(_get_requested_extensions_bind_compat_109302);83GDVIRTUAL_BIND_COMPAT(_set_instance_create_info_and_get_next_pointer_bind_compat_109302, "next_pointer");84#endif8586ClassDB::bind_method(D_METHOD("get_openxr_api"), &OpenXRExtensionWrapper::_gdextension_get_openxr_api);87ClassDB::bind_method(D_METHOD("register_extension_wrapper"), &OpenXRExtensionWrapper::_gdextension_register_extension_wrapper);88}8990HashMap<String, bool *> OpenXRExtensionWrapper::get_requested_extensions(XrVersion p_xr_version) {91Dictionary request_extension;9293if (GDVIRTUAL_CALL(_get_requested_extensions, (uint64_t)p_xr_version, request_extension)) {94HashMap<String, bool *> result;95for (const KeyValue<Variant, Variant> &kv : request_extension) {96GDExtensionPtr<bool> value = VariantCaster<GDExtensionPtr<bool>>::cast(kv.value);97result.insert(kv.key, value);98}99return result;100}101102#ifndef DISABLE_DEPRECATED103if (GDVIRTUAL_CALL(_get_requested_extensions_bind_compat_109302, request_extension)) {104HashMap<String, bool *> result;105for (const KeyValue<Variant, Variant> &kv : request_extension) {106GDExtensionPtr<bool> value = VariantCaster<GDExtensionPtr<bool>>::cast(kv.value);107result.insert(kv.key, value);108}109return result;110}111#endif112113return HashMap<String, bool *>();114}115116void *OpenXRExtensionWrapper::set_system_properties_and_get_next_pointer(void *p_next_pointer) {117uint64_t pointer;118119if (GDVIRTUAL_CALL(_set_system_properties_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {120return reinterpret_cast<void *>(pointer);121}122123return nullptr;124}125126void *OpenXRExtensionWrapper::set_instance_create_info_and_get_next_pointer(XrVersion p_xr_version, void *p_next_pointer) {127uint64_t pointer;128129if (GDVIRTUAL_CALL(_set_instance_create_info_and_get_next_pointer, (uint64_t)p_xr_version, GDExtensionPtr<void>(p_next_pointer), pointer)) {130return reinterpret_cast<void *>(pointer);131}132133#ifndef DISABLE_DEPRECATED134if (GDVIRTUAL_CALL(_set_instance_create_info_and_get_next_pointer_bind_compat_109302, GDExtensionPtr<void>(p_next_pointer), pointer)) {135return reinterpret_cast<void *>(pointer);136}137#endif138139return nullptr;140}141142void *OpenXRExtensionWrapper::set_session_create_and_get_next_pointer(void *p_next_pointer) {143uint64_t pointer;144145if (GDVIRTUAL_CALL(_set_session_create_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {146return reinterpret_cast<void *>(pointer);147}148149return nullptr;150}151152void *OpenXRExtensionWrapper::set_swapchain_create_info_and_get_next_pointer(void *p_next_pointer) {153uint64_t pointer;154155if (GDVIRTUAL_CALL(_set_swapchain_create_info_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {156return reinterpret_cast<void *>(pointer);157}158159return nullptr;160}161162void *OpenXRExtensionWrapper::set_hand_joint_locations_and_get_next_pointer(int p_hand_index, void *p_next_pointer) {163uint64_t pointer;164165if (GDVIRTUAL_CALL(_set_hand_joint_locations_and_get_next_pointer, p_hand_index, GDExtensionPtr<void>(p_next_pointer), pointer)) {166return reinterpret_cast<void *>(pointer);167}168169return nullptr;170}171172void *OpenXRExtensionWrapper::set_projection_views_and_get_next_pointer(int p_view_index, void *p_next_pointer) {173uint64_t pointer = 0;174175if (GDVIRTUAL_CALL(_set_projection_views_and_get_next_pointer, p_view_index, GDExtensionPtr<void>(p_next_pointer), pointer)) {176return reinterpret_cast<void *>(pointer);177}178179return nullptr;180}181182void *OpenXRExtensionWrapper::set_reference_space_create_info_and_get_next_pointer(int p_reference_space_type, void *p_next_pointer) {183uint64_t pointer = 0;184185if (GDVIRTUAL_CALL(_set_reference_space_create_info_and_get_next_pointer, p_reference_space_type, GDExtensionPtr<void>(p_next_pointer), pointer)) {186return reinterpret_cast<void *>(pointer);187}188189return nullptr;190}191192void *OpenXRExtensionWrapper::set_frame_wait_info_and_get_next_pointer(void *p_next_pointer) {193uint64_t pointer = 0;194195if (GDVIRTUAL_CALL(_set_frame_wait_info_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {196return reinterpret_cast<void *>(pointer);197}198199return nullptr;200}201202void *OpenXRExtensionWrapper::set_frame_end_info_and_get_next_pointer(void *p_next_pointer) {203uint64_t pointer = 0;204205if (GDVIRTUAL_CALL(_set_frame_end_info_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {206return reinterpret_cast<void *>(pointer);207}208209return nullptr;210}211212void OpenXRExtensionWrapper::prepare_view_configuration(uint32_t p_view_count) {213GDVIRTUAL_CALL(_prepare_view_configuration, p_view_count);214}215216void *OpenXRExtensionWrapper::set_view_configuration_and_get_next_pointer(uint32_t p_view, void *p_next_pointer) {217uint64_t pointer = 0;218219if (GDVIRTUAL_CALL(_set_view_configuration_and_get_next_pointer, p_view, GDExtensionPtr<void>(p_next_pointer), pointer)) {220return reinterpret_cast<void *>(pointer);221}222223return nullptr;224}225226void OpenXRExtensionWrapper::print_view_configuration_info(uint32_t p_view) const {227GDVIRTUAL_CALL(_print_view_configuration_info, p_view);228}229230void *OpenXRExtensionWrapper::set_view_locate_info_and_get_next_pointer(void *p_next_pointer) {231uint64_t pointer = 0;232233if (GDVIRTUAL_CALL(_set_view_locate_info_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {234return reinterpret_cast<void *>(pointer);235}236237return nullptr;238}239240PackedStringArray OpenXRExtensionWrapper::get_suggested_tracker_names() {241PackedStringArray ret;242243if (GDVIRTUAL_CALL(_get_suggested_tracker_names, ret)) {244return ret;245}246247return PackedStringArray();248}249250int OpenXRExtensionWrapper::get_composition_layer_count() {251int count = 0;252GDVIRTUAL_CALL(_get_composition_layer_count, count);253return count;254}255256XrCompositionLayerBaseHeader *OpenXRExtensionWrapper::get_composition_layer(int p_index) {257uint64_t pointer;258259if (GDVIRTUAL_CALL(_get_composition_layer, p_index, pointer)) {260return reinterpret_cast<XrCompositionLayerBaseHeader *>(pointer);261}262263return nullptr;264}265266int OpenXRExtensionWrapper::get_composition_layer_order(int p_index) {267int order = 0;268GDVIRTUAL_CALL(_get_composition_layer_order, p_index, order);269return order;270}271272void OpenXRExtensionWrapper::on_register_metadata() {273GDVIRTUAL_CALL(_on_register_metadata);274}275276void OpenXRExtensionWrapper::on_before_instance_created() {277GDVIRTUAL_CALL(_on_before_instance_created);278}279280void OpenXRExtensionWrapper::on_instance_created(const XrInstance p_instance) {281uint64_t instance = (uint64_t)p_instance;282GDVIRTUAL_CALL(_on_instance_created, instance);283}284285void OpenXRExtensionWrapper::on_instance_destroyed() {286GDVIRTUAL_CALL(_on_instance_destroyed);287}288289void OpenXRExtensionWrapper::on_session_created(const XrSession p_session) {290uint64_t session = (uint64_t)p_session;291GDVIRTUAL_CALL(_on_session_created, session);292}293294void OpenXRExtensionWrapper::on_process() {295GDVIRTUAL_CALL(_on_process);296}297298void OpenXRExtensionWrapper::on_sync_actions() {299GDVIRTUAL_CALL(_on_sync_actions);300}301302void OpenXRExtensionWrapper::on_pre_render() {303GDVIRTUAL_CALL(_on_pre_render);304}305306void OpenXRExtensionWrapper::on_main_swapchains_created() {307GDVIRTUAL_CALL(_on_main_swapchains_created);308}309310void OpenXRExtensionWrapper::on_session_destroyed() {311GDVIRTUAL_CALL(_on_session_destroyed);312}313314void OpenXRExtensionWrapper::on_pre_draw_viewport(RID p_render_target) {315GDVIRTUAL_CALL(_on_pre_draw_viewport, p_render_target);316}317318void OpenXRExtensionWrapper::on_post_draw_viewport(RID p_render_target) {319GDVIRTUAL_CALL(_on_post_draw_viewport, p_render_target);320}321322void OpenXRExtensionWrapper::on_state_idle() {323GDVIRTUAL_CALL(_on_state_idle);324}325326void OpenXRExtensionWrapper::on_state_ready() {327GDVIRTUAL_CALL(_on_state_ready);328}329330void OpenXRExtensionWrapper::on_state_synchronized() {331GDVIRTUAL_CALL(_on_state_synchronized);332}333334void OpenXRExtensionWrapper::on_state_visible() {335GDVIRTUAL_CALL(_on_state_visible);336}337338void OpenXRExtensionWrapper::on_state_focused() {339GDVIRTUAL_CALL(_on_state_focused);340}341342void OpenXRExtensionWrapper::on_state_stopping() {343GDVIRTUAL_CALL(_on_state_stopping);344}345346void OpenXRExtensionWrapper::on_state_loss_pending() {347GDVIRTUAL_CALL(_on_state_loss_pending);348}349350void OpenXRExtensionWrapper::on_state_exiting() {351GDVIRTUAL_CALL(_on_state_exiting);352}353354bool OpenXRExtensionWrapper::on_event_polled(const XrEventDataBuffer &p_event) {355bool event_polled;356357if (GDVIRTUAL_CALL(_on_event_polled, GDExtensionConstPtr<void>(&p_event), event_polled)) {358return event_polled;359}360361return false;362}363364void *OpenXRExtensionWrapper::set_viewport_composition_layer_and_get_next_pointer(const XrCompositionLayerBaseHeader *p_layer, const Dictionary &p_property_values, void *p_next_pointer) {365uint64_t pointer = 0;366367if (GDVIRTUAL_CALL(_set_viewport_composition_layer_and_get_next_pointer, GDExtensionConstPtr<void>(p_layer), p_property_values, GDExtensionPtr<void>(p_next_pointer), pointer)) {368return reinterpret_cast<void *>(pointer);369}370371return p_next_pointer;372}373374void OpenXRExtensionWrapper::on_viewport_composition_layer_destroyed(const XrCompositionLayerBaseHeader *p_layer) {375GDVIRTUAL_CALL(_on_viewport_composition_layer_destroyed, GDExtensionConstPtr<void>(p_layer));376}377378void OpenXRExtensionWrapper::get_viewport_composition_layer_extension_properties(List<PropertyInfo> *p_property_list) {379TypedArray<Dictionary> properties;380381if (GDVIRTUAL_CALL(_get_viewport_composition_layer_extension_properties, properties)) {382for (int i = 0; i < properties.size(); i++) {383p_property_list->push_back(PropertyInfo::from_dict(properties[i]));384}385}386}387388Dictionary OpenXRExtensionWrapper::get_viewport_composition_layer_extension_property_defaults() {389Dictionary property_defaults;390GDVIRTUAL_CALL(_get_viewport_composition_layer_extension_property_defaults, property_defaults);391return property_defaults;392}393394void *OpenXRExtensionWrapper::set_android_surface_swapchain_create_info_and_get_next_pointer(const Dictionary &p_property_values, void *p_next_pointer) {395uint64_t pointer = 0;396397if (GDVIRTUAL_CALL(_set_android_surface_swapchain_create_info_and_get_next_pointer, p_property_values, GDExtensionPtr<void>(p_next_pointer), pointer)) {398return reinterpret_cast<void *>(pointer);399}400401return p_next_pointer;402}403404Ref<OpenXRAPIExtension> OpenXRExtensionWrapper::_gdextension_get_openxr_api() {405return openxr_api_extension;406}407408void OpenXRExtensionWrapper::_gdextension_register_extension_wrapper() {409OpenXRAPI::register_extension_wrapper(this);410}411412OpenXRExtensionWrapper::OpenXRExtensionWrapper() {413openxr_api_extension.instantiate();414}415416OpenXRExtensionWrapper::~OpenXRExtensionWrapper() {417}418419420