From afc8c6391ccc2d3d69dcad0d93b2639bfe77dc55 Mon Sep 17 00:00:00 2001 From: Bastiaan Olij Date: Thu, 9 Apr 2020 00:47:36 +1000 Subject: Renaming all ARVR nodes to XR --- modules/gdnative/SCsub | 2 +- modules/gdnative/arvr/SCsub | 6 - modules/gdnative/arvr/arvr_interface_gdnative.cpp | 439 --------------------- modules/gdnative/arvr/arvr_interface_gdnative.h | 91 ----- modules/gdnative/arvr/config.py | 6 - modules/gdnative/arvr/register_types.cpp | 39 -- modules/gdnative/arvr/register_types.h | 37 -- modules/gdnative/config.py | 2 +- .../gdnative/doc_classes/ARVRInterfaceGDNative.xml | 15 - modules/gdnative/doc_classes/GDNativeLibrary.xml | 2 +- .../gdnative/doc_classes/XRInterfaceGDNative.xml | 15 + modules/gdnative/gdnative_api.json | 28 +- modules/gdnative/gdnative_builders.py | 2 +- modules/gdnative/include/arvr/godot_arvr.h | 92 ----- modules/gdnative/include/xr/godot_xr.h | 91 +++++ modules/gdnative/register_types.cpp | 6 +- modules/gdnative/xr/SCsub | 6 + modules/gdnative/xr/config.py | 6 + modules/gdnative/xr/register_types.cpp | 40 ++ modules/gdnative/xr/register_types.h | 37 ++ modules/gdnative/xr/xr_interface_gdnative.cpp | 428 ++++++++++++++++++++ modules/gdnative/xr/xr_interface_gdnative.h | 91 +++++ 22 files changed, 735 insertions(+), 746 deletions(-) delete mode 100644 modules/gdnative/arvr/SCsub delete mode 100644 modules/gdnative/arvr/arvr_interface_gdnative.cpp delete mode 100644 modules/gdnative/arvr/arvr_interface_gdnative.h delete mode 100644 modules/gdnative/arvr/config.py delete mode 100644 modules/gdnative/arvr/register_types.cpp delete mode 100644 modules/gdnative/arvr/register_types.h delete mode 100644 modules/gdnative/doc_classes/ARVRInterfaceGDNative.xml create mode 100644 modules/gdnative/doc_classes/XRInterfaceGDNative.xml delete mode 100644 modules/gdnative/include/arvr/godot_arvr.h create mode 100644 modules/gdnative/include/xr/godot_xr.h create mode 100644 modules/gdnative/xr/SCsub create mode 100644 modules/gdnative/xr/config.py create mode 100644 modules/gdnative/xr/register_types.cpp create mode 100644 modules/gdnative/xr/register_types.h create mode 100644 modules/gdnative/xr/xr_interface_gdnative.cpp create mode 100644 modules/gdnative/xr/xr_interface_gdnative.h (limited to 'modules/gdnative') diff --git a/modules/gdnative/SCsub b/modules/gdnative/SCsub index a788175b07..cab05549d2 100644 --- a/modules/gdnative/SCsub +++ b/modules/gdnative/SCsub @@ -17,7 +17,7 @@ env_gdnative.Prepend(CPPPATH=["#modules/gdnative/include/"]) Export("env_gdnative") SConscript("net/SCsub") -SConscript("arvr/SCsub") +SConscript("xr/SCsub") SConscript("pluginscript/SCsub") SConscript("videodecoder/SCsub") diff --git a/modules/gdnative/arvr/SCsub b/modules/gdnative/arvr/SCsub deleted file mode 100644 index 0b2db3b504..0000000000 --- a/modules/gdnative/arvr/SCsub +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env python - -Import("env") -Import("env_gdnative") - -env_gdnative.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/gdnative/arvr/arvr_interface_gdnative.cpp b/modules/gdnative/arvr/arvr_interface_gdnative.cpp deleted file mode 100644 index f14691027a..0000000000 --- a/modules/gdnative/arvr/arvr_interface_gdnative.cpp +++ /dev/null @@ -1,439 +0,0 @@ -/*************************************************************************/ -/* arvr_interface_gdnative.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.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 "arvr_interface_gdnative.h" -#include "core/input/input_filter.h" -#include "servers/arvr/arvr_positional_tracker.h" -#include "servers/rendering/rendering_server_globals.h" - -void ARVRInterfaceGDNative::_bind_methods() { - ADD_PROPERTY_DEFAULT("interface_is_initialized", false); - ADD_PROPERTY_DEFAULT("ar_is_anchor_detection_enabled", false); -} - -ARVRInterfaceGDNative::ARVRInterfaceGDNative() { - print_verbose("Construct gdnative interface\n"); - - // we won't have our data pointer until our library gets set - data = nullptr; - - interface = nullptr; -} - -ARVRInterfaceGDNative::~ARVRInterfaceGDNative() { - print_verbose("Destruct gdnative interface\n"); - - if (interface != nullptr && is_initialized()) { - uninitialize(); - }; - - // cleanup after ourselves - cleanup(); -} - -void ARVRInterfaceGDNative::cleanup() { - if (interface != nullptr) { - interface->destructor(data); - data = nullptr; - interface = nullptr; - } -} - -void ARVRInterfaceGDNative::set_interface(const godot_arvr_interface_gdnative *p_interface) { - // this should only be called once, just being paranoid.. - if (interface) { - cleanup(); - } - - // bind to our interface - interface = p_interface; - - // Now we do our constructing... - data = interface->constructor((godot_object *)this); -} - -StringName ARVRInterfaceGDNative::get_name() const { - - ERR_FAIL_COND_V(interface == nullptr, StringName()); - - godot_string result = interface->get_name(data); - - StringName name = *(String *)&result; - - godot_string_destroy(&result); - - return name; -} - -int ARVRInterfaceGDNative::get_capabilities() const { - int capabilities; - - ERR_FAIL_COND_V(interface == nullptr, 0); // 0 = None - - capabilities = interface->get_capabilities(data); - - return capabilities; -} - -bool ARVRInterfaceGDNative::get_anchor_detection_is_enabled() const { - - ERR_FAIL_COND_V(interface == nullptr, false); - - return interface->get_anchor_detection_is_enabled(data); -} - -void ARVRInterfaceGDNative::set_anchor_detection_is_enabled(bool p_enable) { - - ERR_FAIL_COND(interface == nullptr); - - interface->set_anchor_detection_is_enabled(data, p_enable); -} - -int ARVRInterfaceGDNative::get_camera_feed_id() { - - ERR_FAIL_COND_V(interface == nullptr, 0); - - if ((interface->version.major > 1) || ((interface->version.major) == 1 && (interface->version.minor >= 1))) { - return (unsigned int)interface->get_camera_feed_id(data); - } else { - return 0; - } -} - -bool ARVRInterfaceGDNative::is_stereo() { - bool stereo; - - ERR_FAIL_COND_V(interface == nullptr, false); - - stereo = interface->is_stereo(data); - - return stereo; -} - -bool ARVRInterfaceGDNative::is_initialized() const { - - ERR_FAIL_COND_V(interface == nullptr, false); - - return interface->is_initialized(data); -} - -bool ARVRInterfaceGDNative::initialize() { - ERR_FAIL_COND_V(interface == nullptr, false); - - bool initialized = interface->initialize(data); - - if (initialized) { - // if we successfully initialize our interface and we don't have a primary interface yet, this becomes our primary interface - - ARVRServer *arvr_server = ARVRServer::get_singleton(); - if ((arvr_server != nullptr) && (arvr_server->get_primary_interface() == nullptr)) { - arvr_server->set_primary_interface(this); - }; - }; - - return initialized; -} - -void ARVRInterfaceGDNative::uninitialize() { - ERR_FAIL_COND(interface == nullptr); - - ARVRServer *arvr_server = ARVRServer::get_singleton(); - if (arvr_server != nullptr) { - // Whatever happens, make sure this is no longer our primary interface - arvr_server->clear_primary_interface_if(this); - } - - interface->uninitialize(data); -} - -Size2 ARVRInterfaceGDNative::get_render_targetsize() { - - ERR_FAIL_COND_V(interface == nullptr, Size2()); - - godot_vector2 result = interface->get_render_targetsize(data); - Vector2 *vec = (Vector2 *)&result; - - return *vec; -} - -Transform ARVRInterfaceGDNative::get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform) { - Transform *ret; - - ERR_FAIL_COND_V(interface == nullptr, Transform()); - - godot_transform t = interface->get_transform_for_eye(data, (int)p_eye, (godot_transform *)&p_cam_transform); - - ret = (Transform *)&t; - - return *ret; -} - -CameraMatrix ARVRInterfaceGDNative::get_projection_for_eye(ARVRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) { - CameraMatrix cm; - - ERR_FAIL_COND_V(interface == nullptr, CameraMatrix()); - - interface->fill_projection_for_eye(data, (godot_real *)cm.matrix, (godot_int)p_eye, p_aspect, p_z_near, p_z_far); - - return cm; -} - -unsigned int ARVRInterfaceGDNative::get_external_texture_for_eye(ARVRInterface::Eyes p_eye) { - - ERR_FAIL_COND_V(interface == nullptr, 0); - - if ((interface->version.major > 1) || ((interface->version.major) == 1 && (interface->version.minor >= 1))) { - return (unsigned int)interface->get_external_texture_for_eye(data, (godot_int)p_eye); - } else { - return 0; - } -} - -void ARVRInterfaceGDNative::commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) { - - ERR_FAIL_COND(interface == nullptr); - - interface->commit_for_eye(data, (godot_int)p_eye, (godot_rid *)&p_render_target, (godot_rect2 *)&p_screen_rect); -} - -void ARVRInterfaceGDNative::process() { - ERR_FAIL_COND(interface == nullptr); - - interface->process(data); -} - -void ARVRInterfaceGDNative::notification(int p_what) { - ERR_FAIL_COND(interface == nullptr); - - // this is only available in interfaces that implement 1.1 or later - if ((interface->version.major > 1) || ((interface->version.major == 1) && (interface->version.minor > 0))) { - interface->notification(data, p_what); - } -} - -///////////////////////////////////////////////////////////////////////////////////// -// some helper callbacks - -extern "C" { - -void GDAPI godot_arvr_register_interface(const godot_arvr_interface_gdnative *p_interface) { - // If our major version is 0 or bigger then 10, we're likely looking at our constructor pointer from an older plugin - ERR_FAIL_COND_MSG((p_interface->version.major == 0) || (p_interface->version.major > 10), "GDNative ARVR interfaces build for Godot 3.0 are not supported."); - - Ref new_interface; - new_interface.instance(); - new_interface->set_interface((const godot_arvr_interface_gdnative *)p_interface); - ARVRServer::get_singleton()->add_interface(new_interface); -} - -godot_real GDAPI godot_arvr_get_worldscale() { - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, 1.0); - - return arvr_server->get_world_scale(); -} - -godot_transform GDAPI godot_arvr_get_reference_frame() { - godot_transform reference_frame; - Transform *reference_frame_ptr = (Transform *)&reference_frame; - - ARVRServer *arvr_server = ARVRServer::get_singleton(); - if (arvr_server != nullptr) { - *reference_frame_ptr = arvr_server->get_reference_frame(); - } else { - godot_transform_new_identity(&reference_frame); - } - - return reference_frame; -} - -void GDAPI godot_arvr_blit(godot_int p_eye, godot_rid *p_render_target, godot_rect2 *p_rect) { - // blits out our texture as is, handy for preview display of one of the eyes that is already rendered with lens distortion on an external HMD - ARVRInterface::Eyes eye = (ARVRInterface::Eyes)p_eye; -#if 0 - RID *render_target = (RID *)p_render_target; -#endif - Rect2 screen_rect = *(Rect2 *)p_rect; - - if (eye == ARVRInterface::EYE_LEFT) { - screen_rect.size.x /= 2.0; - } else if (p_eye == ARVRInterface::EYE_RIGHT) { - screen_rect.size.x /= 2.0; - screen_rect.position.x += screen_rect.size.x; - } -#ifndef _MSC_VER -#warning this needs to be redone -#endif -#if 0 - RSG::rasterizer->blit_render_target_to_screen(*render_target, screen_rect, 0); -#endif -} - -godot_int GDAPI godot_arvr_get_texid(godot_rid *p_render_target) { - // In order to send off our textures to display on our hardware we need the opengl texture ID instead of the render target RID - // This is a handy function to expose that. -#if 0 - RID *render_target = (RID *)p_render_target; - - RID eye_texture = RSG::storage->render_target_get_texture(*render_target); -#endif - -#ifndef _MSC_VER -#warning need to obtain this ID again -#endif - uint32_t texid = 0; //RS::get_singleton()->texture_get_texid(eye_texture); - - return texid; -} - -godot_int GDAPI godot_arvr_add_controller(char *p_device_name, godot_int p_hand, godot_bool p_tracks_orientation, godot_bool p_tracks_position) { - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, 0); - - InputFilter *input = InputFilter::get_singleton(); - ERR_FAIL_NULL_V(input, 0); - - ARVRPositionalTracker *new_tracker = memnew(ARVRPositionalTracker); - new_tracker->set_name(p_device_name); - new_tracker->set_type(ARVRServer::TRACKER_CONTROLLER); - if (p_hand == 1) { - new_tracker->set_hand(ARVRPositionalTracker::TRACKER_LEFT_HAND); - } else if (p_hand == 2) { - new_tracker->set_hand(ARVRPositionalTracker::TRACKER_RIGHT_HAND); - } - - // also register as joystick... - int joyid = input->get_unused_joy_id(); - if (joyid != -1) { - new_tracker->set_joy_id(joyid); - input->joy_connection_changed(joyid, true, p_device_name, ""); - } - - if (p_tracks_orientation) { - Basis orientation; - new_tracker->set_orientation(orientation); - } - if (p_tracks_position) { - Vector3 position; - new_tracker->set_position(position); - } - - // add our tracker to our server and remember its pointer - arvr_server->add_tracker(new_tracker); - - // note, this ID is only unique within controllers! - return new_tracker->get_tracker_id(); -} - -void GDAPI godot_arvr_remove_controller(godot_int p_controller_id) { - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL(arvr_server); - - InputFilter *input = InputFilter::get_singleton(); - ERR_FAIL_NULL(input); - - ARVRPositionalTracker *remove_tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, p_controller_id); - if (remove_tracker != nullptr) { - // unset our joystick if applicable - int joyid = remove_tracker->get_joy_id(); - if (joyid != -1) { - input->joy_connection_changed(joyid, false, "", ""); - remove_tracker->set_joy_id(-1); - } - - // remove our tracker from our server - arvr_server->remove_tracker(remove_tracker); - memdelete(remove_tracker); - } -} - -void GDAPI godot_arvr_set_controller_transform(godot_int p_controller_id, godot_transform *p_transform, godot_bool p_tracks_orientation, godot_bool p_tracks_position) { - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL(arvr_server); - - ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, p_controller_id); - if (tracker != nullptr) { - Transform *transform = (Transform *)p_transform; - if (p_tracks_orientation) { - tracker->set_orientation(transform->basis); - } - if (p_tracks_position) { - tracker->set_rw_position(transform->origin); - } - } -} - -void GDAPI godot_arvr_set_controller_button(godot_int p_controller_id, godot_int p_button, godot_bool p_is_pressed) { - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL(arvr_server); - - InputFilter *input = InputFilter::get_singleton(); - ERR_FAIL_NULL(input); - - ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, p_controller_id); - if (tracker != nullptr) { - int joyid = tracker->get_joy_id(); - if (joyid != -1) { - input->joy_button(joyid, p_button, p_is_pressed); - } - } -} - -void GDAPI godot_arvr_set_controller_axis(godot_int p_controller_id, godot_int p_axis, godot_real p_value, godot_bool p_can_be_negative) { - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL(arvr_server); - - InputFilter *input = InputFilter::get_singleton(); - ERR_FAIL_NULL(input); - - ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, p_controller_id); - if (tracker != nullptr) { - int joyid = tracker->get_joy_id(); - if (joyid != -1) { - InputFilter::JoyAxis jx; - jx.min = p_can_be_negative ? -1 : 0; - jx.value = p_value; - input->joy_axis(joyid, p_axis, jx); - } - } -} - -godot_real GDAPI godot_arvr_get_controller_rumble(godot_int p_controller_id) { - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, 0.0); - - ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, p_controller_id); - if (tracker != nullptr) { - return tracker->get_rumble(); - } - - return 0.0; -} -} diff --git a/modules/gdnative/arvr/arvr_interface_gdnative.h b/modules/gdnative/arvr/arvr_interface_gdnative.h deleted file mode 100644 index e38eb435c6..0000000000 --- a/modules/gdnative/arvr/arvr_interface_gdnative.h +++ /dev/null @@ -1,91 +0,0 @@ -/*************************************************************************/ -/* arvr_interface_gdnative.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.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. */ -/*************************************************************************/ - -#ifndef ARVR_INTERFACE_GDNATIVE_H -#define ARVR_INTERFACE_GDNATIVE_H - -#include "modules/gdnative/gdnative.h" -#include "servers/arvr/arvr_interface.h" - -/** - @authors Hinsbart & Karroffel & Mux213 - - This subclass of our AR/VR interface forms a bridge to GDNative. -*/ - -class ARVRInterfaceGDNative : public ARVRInterface { - GDCLASS(ARVRInterfaceGDNative, ARVRInterface); - - void cleanup(); - -protected: - const godot_arvr_interface_gdnative *interface; - void *data; - - static void _bind_methods(); - -public: - /** general interface information **/ - ARVRInterfaceGDNative(); - ~ARVRInterfaceGDNative(); - - void set_interface(const godot_arvr_interface_gdnative *p_interface); - - virtual StringName get_name() const; - virtual int get_capabilities() const; - - virtual bool is_initialized() const; - virtual bool initialize(); - virtual void uninitialize(); - - /** specific to AR **/ - virtual bool get_anchor_detection_is_enabled() const; - virtual void set_anchor_detection_is_enabled(bool p_enable); - virtual int get_camera_feed_id(); - - /** rendering and internal **/ - virtual Size2 get_render_targetsize(); - virtual bool is_stereo(); - virtual Transform get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform); - - // we expose a Vector version of this function to GDNative - Vector _get_projection_for_eye(ARVRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far); - - // and a CameraMatrix version to ARVRServer - virtual CameraMatrix get_projection_for_eye(ARVRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far); - - virtual unsigned int get_external_texture_for_eye(ARVRInterface::Eyes p_eye); - virtual void commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect); - - virtual void process(); - virtual void notification(int p_what); -}; - -#endif // ARVR_INTERFACE_GDNATIVE_H diff --git a/modules/gdnative/arvr/config.py b/modules/gdnative/arvr/config.py deleted file mode 100644 index d22f9454ed..0000000000 --- a/modules/gdnative/arvr/config.py +++ /dev/null @@ -1,6 +0,0 @@ -def can_build(env, platform): - return True - - -def configure(env): - pass diff --git a/modules/gdnative/arvr/register_types.cpp b/modules/gdnative/arvr/register_types.cpp deleted file mode 100644 index 0f6e2bca1a..0000000000 --- a/modules/gdnative/arvr/register_types.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/*************************************************************************/ -/* register_types.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.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 "register_types.h" -#include "arvr_interface_gdnative.h" - -void register_arvr_types() { - ClassDB::register_class(); -} - -void unregister_arvr_types() { -} diff --git a/modules/gdnative/arvr/register_types.h b/modules/gdnative/arvr/register_types.h deleted file mode 100644 index b0de6f7c14..0000000000 --- a/modules/gdnative/arvr/register_types.h +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************/ -/* register_types.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.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. */ -/*************************************************************************/ - -#ifndef ARVR_REGISTER_TYPES_H -#define ARVR_REGISTER_TYPES_H - -void register_arvr_types(); -void unregister_arvr_types(); - -#endif // ARVR_REGISTER_TYPES_H diff --git a/modules/gdnative/config.py b/modules/gdnative/config.py index 37e25a46d4..4b997e4bfe 100644 --- a/modules/gdnative/config.py +++ b/modules/gdnative/config.py @@ -9,7 +9,7 @@ def configure(env): def get_doc_classes(): return [ "@NativeScript", - "ARVRInterfaceGDNative", + "XRInterfaceGDNative", "GDNative", "GDNativeLibrary", "MultiplayerPeerGDNative", diff --git a/modules/gdnative/doc_classes/ARVRInterfaceGDNative.xml b/modules/gdnative/doc_classes/ARVRInterfaceGDNative.xml deleted file mode 100644 index e8405b64a3..0000000000 --- a/modules/gdnative/doc_classes/ARVRInterfaceGDNative.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - GDNative wrapper for an ARVR interface. - - - This is a wrapper class for GDNative implementations of the ARVR interface. To use a GDNative ARVR interface, simply instantiate this object and set your GDNative library containing the ARVR interface implementation. - - - - - - - - diff --git a/modules/gdnative/doc_classes/GDNativeLibrary.xml b/modules/gdnative/doc_classes/GDNativeLibrary.xml index 601e132d42..1aab864102 100644 --- a/modules/gdnative/doc_classes/GDNativeLibrary.xml +++ b/modules/gdnative/doc_classes/GDNativeLibrary.xml @@ -4,7 +4,7 @@ An external library containing functions or script classes to use in Godot. - A GDNative library can implement [NativeScript]s, global functions to call with the [GDNative] class, or low-level engine extensions through interfaces such as [ARVRInterfaceGDNative]. The library must be compiled for each platform and architecture that the project will run on. + A GDNative library can implement [NativeScript]s, global functions to call with the [GDNative] class, or low-level engine extensions through interfaces such as [XRInterfaceGDNative]. The library must be compiled for each platform and architecture that the project will run on. https://docs.godotengine.org/en/latest/tutorials/plugins/gdnative/gdnative-c-example.html diff --git a/modules/gdnative/doc_classes/XRInterfaceGDNative.xml b/modules/gdnative/doc_classes/XRInterfaceGDNative.xml new file mode 100644 index 0000000000..13de815793 --- /dev/null +++ b/modules/gdnative/doc_classes/XRInterfaceGDNative.xml @@ -0,0 +1,15 @@ + + + + GDNative wrapper for an XR interface. + + + This is a wrapper class for GDNative implementations of the XR interface. To use a GDNative XR interface, simply instantiate this object and set your GDNative library containing the XR interface implementation. + + + + + + + + diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json index e1d6c0c867..9473a3d419 100644 --- a/modules/gdnative/gdnative_api.json +++ b/modules/gdnative/gdnative_api.json @@ -5935,8 +5935,8 @@ ] }, { - "name": "arvr", - "type": "ARVR", + "name": "xr", + "type": "XR", "version": { "major": 1, "minor": 1 @@ -5944,24 +5944,24 @@ "next": null, "api": [ { - "name": "godot_arvr_register_interface", + "name": "godot_xr_register_interface", "return_type": "void", "arguments": [ - ["const godot_arvr_interface_gdnative *", "p_interface"] + ["const godot_xr_interface_gdnative *", "p_interface"] ] }, { - "name": "godot_arvr_get_worldscale", + "name": "godot_xr_get_worldscale", "return_type": "godot_real", "arguments": [] }, { - "name": "godot_arvr_get_reference_frame", + "name": "godot_xr_get_reference_frame", "return_type": "godot_transform", "arguments": [] }, { - "name": "godot_arvr_blit", + "name": "godot_xr_blit", "return_type": "void", "arguments": [ ["godot_int", "p_eye"], @@ -5970,14 +5970,14 @@ ] }, { - "name": "godot_arvr_get_texid", + "name": "godot_xr_get_texid", "return_type": "godot_int", "arguments": [ ["godot_rid *", "p_render_target"] ] }, { - "name": "godot_arvr_add_controller", + "name": "godot_xr_add_controller", "return_type": "godot_int", "arguments": [ ["char *", "p_device_name"], @@ -5987,14 +5987,14 @@ ] }, { - "name": "godot_arvr_remove_controller", + "name": "godot_xr_remove_controller", "return_type": "void", "arguments": [ ["godot_int", "p_controller_id"] ] }, { - "name": "godot_arvr_set_controller_transform", + "name": "godot_xr_set_controller_transform", "return_type": "void", "arguments": [ ["godot_int", "p_controller_id"], @@ -6004,7 +6004,7 @@ ] }, { - "name": "godot_arvr_set_controller_button", + "name": "godot_xr_set_controller_button", "return_type": "void", "arguments": [ ["godot_int", "p_controller_id"], @@ -6013,7 +6013,7 @@ ] }, { - "name": "godot_arvr_set_controller_axis", + "name": "godot_xr_set_controller_axis", "return_type": "void", "arguments": [ ["godot_int", "p_controller_id"], @@ -6023,7 +6023,7 @@ ] }, { - "name": "godot_arvr_get_controller_rumble", + "name": "godot_xr_get_controller_rumble", "return_type": "godot_real", "arguments": [ ["godot_int", "p_controller_id"] diff --git a/modules/gdnative/gdnative_builders.py b/modules/gdnative/gdnative_builders.py index 2d84f93d87..620935795f 100644 --- a/modules/gdnative/gdnative_builders.py +++ b/modules/gdnative/gdnative_builders.py @@ -19,7 +19,7 @@ def _build_gdnative_api_struct_header(api): "", "#include ", "#include ", - "#include ", + "#include ", "#include ", "#include ", "#include ", diff --git a/modules/gdnative/include/arvr/godot_arvr.h b/modules/gdnative/include/arvr/godot_arvr.h deleted file mode 100644 index aaef31a855..0000000000 --- a/modules/gdnative/include/arvr/godot_arvr.h +++ /dev/null @@ -1,92 +0,0 @@ -/*************************************************************************/ -/* godot_arvr.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.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. */ -/*************************************************************************/ - -#ifndef GODOT_NATIVEARVR_H -#define GODOT_NATIVEARVR_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// For future versions of the API we should only add new functions at the end of the structure and use the -// version info to detect whether a call is available - -// Use these to populate version in your plugin -#define GODOTVR_API_MAJOR 1 -#define GODOTVR_API_MINOR 1 - -typedef struct { - godot_gdnative_api_version version; /* version of our API */ - void *(*constructor)(godot_object *); - void (*destructor)(void *); - godot_string (*get_name)(const void *); - godot_int (*get_capabilities)(const void *); - godot_bool (*get_anchor_detection_is_enabled)(const void *); - void (*set_anchor_detection_is_enabled)(void *, godot_bool); - godot_bool (*is_stereo)(const void *); - godot_bool (*is_initialized)(const void *); - godot_bool (*initialize)(void *); - void (*uninitialize)(void *); - godot_vector2 (*get_render_targetsize)(const void *); - godot_transform (*get_transform_for_eye)(void *, godot_int, godot_transform *); - void (*fill_projection_for_eye)(void *, godot_real *, godot_int, godot_real, godot_real, godot_real); - void (*commit_for_eye)(void *, godot_int, godot_rid *, godot_rect2 *); - void (*process)(void *); - // only in 1.1 onwards - godot_int (*get_external_texture_for_eye)(void *, godot_int); - void (*notification)(void *, godot_int); - godot_int (*get_camera_feed_id)(void *); -} godot_arvr_interface_gdnative; - -void GDAPI godot_arvr_register_interface(const godot_arvr_interface_gdnative *p_interface); - -// helper functions to access ARVRServer data -godot_real GDAPI godot_arvr_get_worldscale(); -godot_transform GDAPI godot_arvr_get_reference_frame(); - -// helper functions for rendering -void GDAPI godot_arvr_blit(godot_int p_eye, godot_rid *p_render_target, godot_rect2 *p_rect); -godot_int GDAPI godot_arvr_get_texid(godot_rid *p_render_target); - -// helper functions for updating ARVR controllers -godot_int GDAPI godot_arvr_add_controller(char *p_device_name, godot_int p_hand, godot_bool p_tracks_orientation, godot_bool p_tracks_position); -void GDAPI godot_arvr_remove_controller(godot_int p_controller_id); -void GDAPI godot_arvr_set_controller_transform(godot_int p_controller_id, godot_transform *p_transform, godot_bool p_tracks_orientation, godot_bool p_tracks_position); -void GDAPI godot_arvr_set_controller_button(godot_int p_controller_id, godot_int p_button, godot_bool p_is_pressed); -void GDAPI godot_arvr_set_controller_axis(godot_int p_controller_id, godot_int p_axis, godot_real p_value, godot_bool p_can_be_negative); -godot_real GDAPI godot_arvr_get_controller_rumble(godot_int p_controller_id); - -#ifdef __cplusplus -} -#endif - -#endif /* !GODOT_NATIVEARVR_H */ diff --git a/modules/gdnative/include/xr/godot_xr.h b/modules/gdnative/include/xr/godot_xr.h new file mode 100644 index 0000000000..22f7f021c4 --- /dev/null +++ b/modules/gdnative/include/xr/godot_xr.h @@ -0,0 +1,91 @@ +/*************************************************************************/ +/* godot_xr.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.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. */ +/*************************************************************************/ + +#ifndef GODOT_NATIVEXR_H +#define GODOT_NATIVEXR_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// For future versions of the API we should only add new functions at the end of the structure and use the +// version info to detect whether a call is available + +// Use these to populate version in your plugin +#define GODOTVR_API_MAJOR 1 +#define GODOTVR_API_MINOR 1 + +typedef struct { + godot_gdnative_api_version version; /* version of our API */ + void *(*constructor)(godot_object *); + void (*destructor)(void *); + godot_string (*get_name)(const void *); + godot_int (*get_capabilities)(const void *); + godot_bool (*get_anchor_detection_is_enabled)(const void *); + void (*set_anchor_detection_is_enabled)(void *, godot_bool); + godot_bool (*is_stereo)(const void *); + godot_bool (*is_initialized)(const void *); + godot_bool (*initialize)(void *); + void (*uninitialize)(void *); + godot_vector2 (*get_render_targetsize)(const void *); + godot_transform (*get_transform_for_eye)(void *, godot_int, godot_transform *); + void (*fill_projection_for_eye)(void *, godot_real *, godot_int, godot_real, godot_real, godot_real); + void (*commit_for_eye)(void *, godot_int, godot_rid *, godot_rect2 *); + void (*process)(void *); + godot_int (*get_external_texture_for_eye)(void *, godot_int); + void (*notification)(void *, godot_int); + godot_int (*get_camera_feed_id)(void *); +} godot_xr_interface_gdnative; + +void GDAPI godot_xr_register_interface(const godot_xr_interface_gdnative *p_interface); + +// helper functions to access XRServer data +godot_real GDAPI godot_xr_get_worldscale(); +godot_transform GDAPI godot_xr_get_reference_frame(); + +// helper functions for rendering +void GDAPI godot_xr_blit(godot_int p_eye, godot_rid *p_render_target, godot_rect2 *p_rect); +godot_int GDAPI godot_xr_get_texid(godot_rid *p_render_target); + +// helper functions for updating XR controllers +godot_int GDAPI godot_xr_add_controller(char *p_device_name, godot_int p_hand, godot_bool p_tracks_orientation, godot_bool p_tracks_position); +void GDAPI godot_xr_remove_controller(godot_int p_controller_id); +void GDAPI godot_xr_set_controller_transform(godot_int p_controller_id, godot_transform *p_transform, godot_bool p_tracks_orientation, godot_bool p_tracks_position); +void GDAPI godot_xr_set_controller_button(godot_int p_controller_id, godot_int p_button, godot_bool p_is_pressed); +void GDAPI godot_xr_set_controller_axis(godot_int p_controller_id, godot_int p_axis, godot_real p_value, godot_bool p_can_be_negative); +godot_real GDAPI godot_xr_get_controller_rumble(godot_int p_controller_id); + +#ifdef __cplusplus +} +#endif + +#endif /* !GODOT_NATIVEXR_H */ diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp index 397a020689..67a286ee2e 100644 --- a/modules/gdnative/register_types.cpp +++ b/modules/gdnative/register_types.cpp @@ -34,11 +34,11 @@ #include "gdnative.h" -#include "arvr/register_types.h" #include "nativescript/register_types.h" #include "net/register_types.h" #include "pluginscript/register_types.h" #include "videodecoder/register_types.h" +#include "xr/register_types.h" #include "core/engine.h" #include "core/io/resource_loader.h" @@ -240,7 +240,7 @@ void register_gdnative_types() { GDNativeCallRegistry::singleton->register_native_call_type("standard_varcall", cb_standard_varcall); register_net_types(); - register_arvr_types(); + register_xr_types(); register_nativescript_types(); register_pluginscript_types(); register_videodecoder_types(); @@ -305,7 +305,7 @@ void unregister_gdnative_types() { unregister_videodecoder_types(); unregister_pluginscript_types(); unregister_nativescript_types(); - unregister_arvr_types(); + unregister_xr_types(); unregister_net_types(); memdelete(GDNativeCallRegistry::singleton); diff --git a/modules/gdnative/xr/SCsub b/modules/gdnative/xr/SCsub new file mode 100644 index 0000000000..0b2db3b504 --- /dev/null +++ b/modules/gdnative/xr/SCsub @@ -0,0 +1,6 @@ +#!/usr/bin/env python + +Import("env") +Import("env_gdnative") + +env_gdnative.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/gdnative/xr/config.py b/modules/gdnative/xr/config.py new file mode 100644 index 0000000000..d22f9454ed --- /dev/null +++ b/modules/gdnative/xr/config.py @@ -0,0 +1,6 @@ +def can_build(env, platform): + return True + + +def configure(env): + pass diff --git a/modules/gdnative/xr/register_types.cpp b/modules/gdnative/xr/register_types.cpp new file mode 100644 index 0000000000..da3a7dc4b8 --- /dev/null +++ b/modules/gdnative/xr/register_types.cpp @@ -0,0 +1,40 @@ +/*************************************************************************/ +/* register_types.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.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 "register_types.h" +#include "xr_interface_gdnative.h" + +void register_xr_types() { + ClassDB::register_class(); + ClassDB::add_compatibility_class("ARVRInterfaceGDNative", "XRInterfaceGDNative"); +} + +void unregister_xr_types() { +} diff --git a/modules/gdnative/xr/register_types.h b/modules/gdnative/xr/register_types.h new file mode 100644 index 0000000000..2501d28651 --- /dev/null +++ b/modules/gdnative/xr/register_types.h @@ -0,0 +1,37 @@ +/*************************************************************************/ +/* register_types.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.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. */ +/*************************************************************************/ + +#ifndef XR_REGISTER_TYPES_H +#define XR_REGISTER_TYPES_H + +void register_xr_types(); +void unregister_xr_types(); + +#endif // XR_REGISTER_TYPES_H diff --git a/modules/gdnative/xr/xr_interface_gdnative.cpp b/modules/gdnative/xr/xr_interface_gdnative.cpp new file mode 100644 index 0000000000..0451945139 --- /dev/null +++ b/modules/gdnative/xr/xr_interface_gdnative.cpp @@ -0,0 +1,428 @@ +/*************************************************************************/ +/* xr_interface_gdnative.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.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 "xr_interface_gdnative.h" +#include "core/input/input_filter.h" +#include "servers/rendering/rendering_server_globals.h" +#include "servers/xr/xr_positional_tracker.h" + +void XRInterfaceGDNative::_bind_methods() { + ADD_PROPERTY_DEFAULT("interface_is_initialized", false); + ADD_PROPERTY_DEFAULT("ar_is_anchor_detection_enabled", false); +} + +XRInterfaceGDNative::XRInterfaceGDNative() { + print_verbose("Construct gdnative interface\n"); + + // we won't have our data pointer until our library gets set + data = nullptr; + + interface = nullptr; +} + +XRInterfaceGDNative::~XRInterfaceGDNative() { + print_verbose("Destruct gdnative interface\n"); + + if (interface != nullptr && is_initialized()) { + uninitialize(); + }; + + // cleanup after ourselves + cleanup(); +} + +void XRInterfaceGDNative::cleanup() { + if (interface != nullptr) { + interface->destructor(data); + data = nullptr; + interface = nullptr; + } +} + +void XRInterfaceGDNative::set_interface(const godot_xr_interface_gdnative *p_interface) { + // this should only be called once, just being paranoid.. + if (interface) { + cleanup(); + } + + // bind to our interface + interface = p_interface; + + // Now we do our constructing... + data = interface->constructor((godot_object *)this); +} + +StringName XRInterfaceGDNative::get_name() const { + + ERR_FAIL_COND_V(interface == nullptr, StringName()); + + godot_string result = interface->get_name(data); + + StringName name = *(String *)&result; + + godot_string_destroy(&result); + + return name; +} + +int XRInterfaceGDNative::get_capabilities() const { + int capabilities; + + ERR_FAIL_COND_V(interface == nullptr, 0); // 0 = None + + capabilities = interface->get_capabilities(data); + + return capabilities; +} + +bool XRInterfaceGDNative::get_anchor_detection_is_enabled() const { + + ERR_FAIL_COND_V(interface == nullptr, false); + + return interface->get_anchor_detection_is_enabled(data); +} + +void XRInterfaceGDNative::set_anchor_detection_is_enabled(bool p_enable) { + + ERR_FAIL_COND(interface == nullptr); + + interface->set_anchor_detection_is_enabled(data, p_enable); +} + +int XRInterfaceGDNative::get_camera_feed_id() { + + ERR_FAIL_COND_V(interface == nullptr, 0); + + return (unsigned int)interface->get_camera_feed_id(data); +} + +bool XRInterfaceGDNative::is_stereo() { + bool stereo; + + ERR_FAIL_COND_V(interface == nullptr, false); + + stereo = interface->is_stereo(data); + + return stereo; +} + +bool XRInterfaceGDNative::is_initialized() const { + + ERR_FAIL_COND_V(interface == nullptr, false); + + return interface->is_initialized(data); +} + +bool XRInterfaceGDNative::initialize() { + ERR_FAIL_COND_V(interface == nullptr, false); + + bool initialized = interface->initialize(data); + + if (initialized) { + // if we successfully initialize our interface and we don't have a primary interface yet, this becomes our primary interface + + XRServer *xr_server = XRServer::get_singleton(); + if ((xr_server != nullptr) && (xr_server->get_primary_interface() == nullptr)) { + xr_server->set_primary_interface(this); + }; + }; + + return initialized; +} + +void XRInterfaceGDNative::uninitialize() { + ERR_FAIL_COND(interface == nullptr); + + XRServer *xr_server = XRServer::get_singleton(); + if (xr_server != nullptr) { + // Whatever happens, make sure this is no longer our primary interface + xr_server->clear_primary_interface_if(this); + } + + interface->uninitialize(data); +} + +Size2 XRInterfaceGDNative::get_render_targetsize() { + + ERR_FAIL_COND_V(interface == nullptr, Size2()); + + godot_vector2 result = interface->get_render_targetsize(data); + Vector2 *vec = (Vector2 *)&result; + + return *vec; +} + +Transform XRInterfaceGDNative::get_transform_for_eye(XRInterface::Eyes p_eye, const Transform &p_cam_transform) { + Transform *ret; + + ERR_FAIL_COND_V(interface == nullptr, Transform()); + + godot_transform t = interface->get_transform_for_eye(data, (int)p_eye, (godot_transform *)&p_cam_transform); + + ret = (Transform *)&t; + + return *ret; +} + +CameraMatrix XRInterfaceGDNative::get_projection_for_eye(XRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) { + CameraMatrix cm; + + ERR_FAIL_COND_V(interface == nullptr, CameraMatrix()); + + interface->fill_projection_for_eye(data, (godot_real *)cm.matrix, (godot_int)p_eye, p_aspect, p_z_near, p_z_far); + + return cm; +} + +unsigned int XRInterfaceGDNative::get_external_texture_for_eye(XRInterface::Eyes p_eye) { + + ERR_FAIL_COND_V(interface == nullptr, 0); + + return (unsigned int)interface->get_external_texture_for_eye(data, (godot_int)p_eye); +} + +void XRInterfaceGDNative::commit_for_eye(XRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) { + + ERR_FAIL_COND(interface == nullptr); + + interface->commit_for_eye(data, (godot_int)p_eye, (godot_rid *)&p_render_target, (godot_rect2 *)&p_screen_rect); +} + +void XRInterfaceGDNative::process() { + ERR_FAIL_COND(interface == nullptr); + + interface->process(data); +} + +void XRInterfaceGDNative::notification(int p_what) { + ERR_FAIL_COND(interface == nullptr); + + interface->notification(data, p_what); +} + +///////////////////////////////////////////////////////////////////////////////////// +// some helper callbacks + +extern "C" { + +void GDAPI godot_xr_register_interface(const godot_xr_interface_gdnative *p_interface) { + // Must be on a version 4 plugin + ERR_FAIL_COND_MSG(p_interface->version.major < 4, "GDNative XR interfaces build for Godot 3.x are not supported."); + + Ref new_interface; + new_interface.instance(); + new_interface->set_interface((const godot_xr_interface_gdnative *)p_interface); + XRServer::get_singleton()->add_interface(new_interface); +} + +godot_real GDAPI godot_xr_get_worldscale() { + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, 1.0); + + return xr_server->get_world_scale(); +} + +godot_transform GDAPI godot_xr_get_reference_frame() { + godot_transform reference_frame; + Transform *reference_frame_ptr = (Transform *)&reference_frame; + + XRServer *xr_server = XRServer::get_singleton(); + if (xr_server != nullptr) { + *reference_frame_ptr = xr_server->get_reference_frame(); + } else { + godot_transform_new_identity(&reference_frame); + } + + return reference_frame; +} + +void GDAPI godot_xr_blit(godot_int p_eye, godot_rid *p_render_target, godot_rect2 *p_rect) { + // blits out our texture as is, handy for preview display of one of the eyes that is already rendered with lens distortion on an external HMD + XRInterface::Eyes eye = (XRInterface::Eyes)p_eye; +#if 0 + RID *render_target = (RID *)p_render_target; +#endif + Rect2 screen_rect = *(Rect2 *)p_rect; + + if (eye == XRInterface::EYE_LEFT) { + screen_rect.size.x /= 2.0; + } else if (p_eye == XRInterface::EYE_RIGHT) { + screen_rect.size.x /= 2.0; + screen_rect.position.x += screen_rect.size.x; + } +#ifndef _MSC_VER +#warning this needs to be redone +#endif +#if 0 + RSG::rasterizer->blit_render_target_to_screen(*render_target, screen_rect, 0); +#endif +} + +godot_int GDAPI godot_xr_get_texid(godot_rid *p_render_target) { + // In order to send off our textures to display on our hardware we need the opengl texture ID instead of the render target RID + // This is a handy function to expose that. +#if 0 + RID *render_target = (RID *)p_render_target; + + RID eye_texture = RSG::storage->render_target_get_texture(*render_target); +#endif + +#ifndef _MSC_VER +#warning need to obtain this ID again +#endif + uint32_t texid = 0; //RS::get_singleton()->texture_get_texid(eye_texture); + + return texid; +} + +godot_int GDAPI godot_xr_add_controller(char *p_device_name, godot_int p_hand, godot_bool p_tracks_orientation, godot_bool p_tracks_position) { + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, 0); + + InputFilter *input = InputFilter::get_singleton(); + ERR_FAIL_NULL_V(input, 0); + + XRPositionalTracker *new_tracker = memnew(XRPositionalTracker); + new_tracker->set_name(p_device_name); + new_tracker->set_type(XRServer::TRACKER_CONTROLLER); + if (p_hand == 1) { + new_tracker->set_hand(XRPositionalTracker::TRACKER_LEFT_HAND); + } else if (p_hand == 2) { + new_tracker->set_hand(XRPositionalTracker::TRACKER_RIGHT_HAND); + } + + // also register as joystick... + int joyid = input->get_unused_joy_id(); + if (joyid != -1) { + new_tracker->set_joy_id(joyid); + input->joy_connection_changed(joyid, true, p_device_name, ""); + } + + if (p_tracks_orientation) { + Basis orientation; + new_tracker->set_orientation(orientation); + } + if (p_tracks_position) { + Vector3 position; + new_tracker->set_position(position); + } + + // add our tracker to our server and remember its pointer + xr_server->add_tracker(new_tracker); + + // note, this ID is only unique within controllers! + return new_tracker->get_tracker_id(); +} + +void GDAPI godot_xr_remove_controller(godot_int p_controller_id) { + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL(xr_server); + + InputFilter *input = InputFilter::get_singleton(); + ERR_FAIL_NULL(input); + + XRPositionalTracker *remove_tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id); + if (remove_tracker != nullptr) { + // unset our joystick if applicable + int joyid = remove_tracker->get_joy_id(); + if (joyid != -1) { + input->joy_connection_changed(joyid, false, "", ""); + remove_tracker->set_joy_id(-1); + } + + // remove our tracker from our server + xr_server->remove_tracker(remove_tracker); + memdelete(remove_tracker); + } +} + +void GDAPI godot_xr_set_controller_transform(godot_int p_controller_id, godot_transform *p_transform, godot_bool p_tracks_orientation, godot_bool p_tracks_position) { + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL(xr_server); + + XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id); + if (tracker != nullptr) { + Transform *transform = (Transform *)p_transform; + if (p_tracks_orientation) { + tracker->set_orientation(transform->basis); + } + if (p_tracks_position) { + tracker->set_rw_position(transform->origin); + } + } +} + +void GDAPI godot_xr_set_controller_button(godot_int p_controller_id, godot_int p_button, godot_bool p_is_pressed) { + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL(xr_server); + + InputFilter *input = InputFilter::get_singleton(); + ERR_FAIL_NULL(input); + + XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id); + if (tracker != nullptr) { + int joyid = tracker->get_joy_id(); + if (joyid != -1) { + input->joy_button(joyid, p_button, p_is_pressed); + } + } +} + +void GDAPI godot_xr_set_controller_axis(godot_int p_controller_id, godot_int p_axis, godot_real p_value, godot_bool p_can_be_negative) { + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL(xr_server); + + InputFilter *input = InputFilter::get_singleton(); + ERR_FAIL_NULL(input); + + XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id); + if (tracker != nullptr) { + int joyid = tracker->get_joy_id(); + if (joyid != -1) { + InputFilter::JoyAxis jx; + jx.min = p_can_be_negative ? -1 : 0; + jx.value = p_value; + input->joy_axis(joyid, p_axis, jx); + } + } +} + +godot_real GDAPI godot_xr_get_controller_rumble(godot_int p_controller_id) { + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, 0.0); + + XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id); + if (tracker != nullptr) { + return tracker->get_rumble(); + } + + return 0.0; +} +} diff --git a/modules/gdnative/xr/xr_interface_gdnative.h b/modules/gdnative/xr/xr_interface_gdnative.h new file mode 100644 index 0000000000..64f1282a7e --- /dev/null +++ b/modules/gdnative/xr/xr_interface_gdnative.h @@ -0,0 +1,91 @@ +/*************************************************************************/ +/* xr_interface_gdnative.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.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. */ +/*************************************************************************/ + +#ifndef XR_INTERFACE_GDNATIVE_H +#define XR_INTERFACE_GDNATIVE_H + +#include "modules/gdnative/gdnative.h" +#include "servers/xr/xr_interface.h" + +/** + @authors Hinsbart & Karroffel & Mux213 + + This subclass of our AR/VR interface forms a bridge to GDNative. +*/ + +class XRInterfaceGDNative : public XRInterface { + GDCLASS(XRInterfaceGDNative, XRInterface); + + void cleanup(); + +protected: + const godot_xr_interface_gdnative *interface; + void *data; + + static void _bind_methods(); + +public: + /** general interface information **/ + XRInterfaceGDNative(); + ~XRInterfaceGDNative(); + + void set_interface(const godot_xr_interface_gdnative *p_interface); + + virtual StringName get_name() const; + virtual int get_capabilities() const; + + virtual bool is_initialized() const; + virtual bool initialize(); + virtual void uninitialize(); + + /** specific to AR **/ + virtual bool get_anchor_detection_is_enabled() const; + virtual void set_anchor_detection_is_enabled(bool p_enable); + virtual int get_camera_feed_id(); + + /** rendering and internal **/ + virtual Size2 get_render_targetsize(); + virtual bool is_stereo(); + virtual Transform get_transform_for_eye(XRInterface::Eyes p_eye, const Transform &p_cam_transform); + + // we expose a Vector version of this function to GDNative + Vector _get_projection_for_eye(XRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far); + + // and a CameraMatrix version to XRServer + virtual CameraMatrix get_projection_for_eye(XRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far); + + virtual unsigned int get_external_texture_for_eye(XRInterface::Eyes p_eye); + virtual void commit_for_eye(XRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect); + + virtual void process(); + virtual void notification(int p_what); +}; + +#endif // XR_INTERFACE_GDNATIVE_H -- cgit v1.2.3