Path: blob/master/modules/openxr/extensions/openxr_future_extension.h
10278 views
/**************************************************************************/1/* openxr_future_extension.h */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#pragma once3132/*33The OpenXR future extension forms the basis of OpenXRs ability to34execute logic asynchronously.3536Asynchronous functions will return a future object which can be37polled each frame to determine if the asynchronous function has38been completed.3940If so the future can be used to obtain final return values.41The API call for this is often part of the extension that utilizes42the future.4344We will be using Godot Callables to drive responses on futures.45*/4647#include "../util.h"48#include "core/object/ref_counted.h"49#include "openxr_extension_wrapper.h"5051#include <openxr/openxr.h>5253class OpenXRFutureExtension;5455class OpenXRFutureResult : public RefCounted {56GDCLASS(OpenXRFutureResult, RefCounted);5758friend class OpenXRFutureExtension;5960protected:61static void _bind_methods();6263void _mark_as_finished();64void _mark_as_cancelled();6566public:67enum ResultStatus {68RESULT_RUNNING,69RESULT_FINISHED,70RESULT_CANCELLED,71};7273ResultStatus get_status() const;74XrFutureEXT get_future() const;7576void set_result_value(const Variant &p_result_value);77Variant get_result_value() const;7879void cancel_future();8081OpenXRFutureResult(XrFutureEXT p_future, const Callable &p_on_success);8283private:84ResultStatus status = RESULT_RUNNING;85XrFutureEXT future;86Variant result_value;87Callable on_success_callback;8889uint64_t _get_future() const;90};9192VARIANT_ENUM_CAST(OpenXRFutureResult::ResultStatus);9394class OpenXRFutureExtension : public OpenXRExtensionWrapper {95GDCLASS(OpenXRFutureExtension, OpenXRExtensionWrapper);9697protected:98static void _bind_methods();99100public:101static OpenXRFutureExtension *get_singleton();102103OpenXRFutureExtension();104virtual ~OpenXRFutureExtension() override;105106virtual HashMap<String, bool *> get_requested_extensions() override;107108virtual void on_instance_created(const XrInstance p_instance) override;109virtual void on_instance_destroyed() override;110virtual void on_session_destroyed() override;111112virtual void on_process() override;113114bool is_active() const;115116Ref<OpenXRFutureResult> register_future(XrFutureEXT p_future, const Callable &p_on_success = Callable());117void cancel_future(XrFutureEXT p_future);118119private:120static OpenXRFutureExtension *singleton;121122bool future_ext = false;123124HashMap<XrFutureEXT, Ref<OpenXRFutureResult>> futures;125126// Make these accessible from GDExtension and/or GDScript127Ref<OpenXRFutureResult> _register_future(uint64_t p_future, const Callable &p_on_success = Callable());128void _cancel_future(uint64_t p_future);129130// OpenXR API call wrappers131132// Futures133EXT_PROTO_XRRESULT_FUNC3(xrPollFutureEXT, (XrInstance), instance, (const XrFuturePollInfoEXT *), poll_info, (XrFuturePollResultEXT *), poll_result);134EXT_PROTO_XRRESULT_FUNC2(xrCancelFutureEXT, (XrInstance), instance, (const XrFutureCancelInfoEXT *), cancel_info);135};136137138