Skip to content

Commit

Permalink
Merge pull request #90374 from BastiaanOlij/openxr_refresh_rate_signal
Browse files Browse the repository at this point in the history
OpenXR: Add refresh rate signal support
  • Loading branch information
akien-mga committed Apr 8, 2024
2 parents 5c5563f + 148ff6a commit 0fd440e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions modules/openxr/doc_classes/OpenXRInterface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@
Informs the user queued a recenter of the player position.
</description>
</signal>
<signal name="refresh_rate_changed">
<param index="0" name="refresh_rate" type="float" />
<description>
Informs the user the HMD refresh rate has changed.
[b]Node:[/b] Only emitted if XR runtime supports the refresh rate extension.
</description>
</signal>
<signal name="session_begun">
<description>
Informs our OpenXR session has been started.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/**************************************************************************/

#include "openxr_fb_display_refresh_rate_extension.h"
#include "../openxr_interface.h"

OpenXRDisplayRefreshRateExtension *OpenXRDisplayRefreshRateExtension::singleton = nullptr;

Expand Down Expand Up @@ -64,6 +65,23 @@ void OpenXRDisplayRefreshRateExtension::on_instance_destroyed() {
display_refresh_rate_ext = false;
}

bool OpenXRDisplayRefreshRateExtension::on_event_polled(const XrEventDataBuffer &event) {
switch (event.type) {
case XR_TYPE_EVENT_DATA_DISPLAY_REFRESH_RATE_CHANGED_FB: {
const XrEventDataDisplayRefreshRateChangedFB *event_fb = (XrEventDataDisplayRefreshRateChangedFB *)&event;

OpenXRInterface *xr_interface = OpenXRAPI::get_singleton()->get_xr_interface();
if (xr_interface) {
xr_interface->on_refresh_rate_changes(event_fb->toDisplayRefreshRate);
}

return true;
} break;
default:
return false;
}
}

float OpenXRDisplayRefreshRateExtension::get_refresh_rate() const {
float refresh_rate = 0.0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class OpenXRDisplayRefreshRateExtension : public OpenXRExtensionWrapper {

virtual void on_instance_created(const XrInstance p_instance) override;
virtual void on_instance_destroyed() override;
virtual bool on_event_polled(const XrEventDataBuffer &event) override;

float get_refresh_rate() const;
void set_refresh_rate(float p_refresh_rate);
Expand Down
1 change: 1 addition & 0 deletions modules/openxr/openxr_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ class OpenXRAPI {
String get_error_string(XrResult result) const;
String get_swapchain_format_name(int64_t p_swapchain_format) const;

OpenXRInterface *get_xr_interface() const { return xr_interface; }
void set_xr_interface(OpenXRInterface *p_xr_interface);
static void register_extension_wrapper(OpenXRExtensionWrapper *p_extension_wrapper);
static void unregister_extension_wrapper(OpenXRExtensionWrapper *p_extension_wrapper);
Expand Down
5 changes: 5 additions & 0 deletions modules/openxr/openxr_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void OpenXRInterface::_bind_methods() {
ADD_SIGNAL(MethodInfo("session_focussed"));
ADD_SIGNAL(MethodInfo("session_visible"));
ADD_SIGNAL(MethodInfo("pose_recentered"));
ADD_SIGNAL(MethodInfo("refresh_rate_changed", PropertyInfo(Variant::FLOAT, "refresh_rate")));

// Display refresh rate
ClassDB::bind_method(D_METHOD("get_display_refresh_rate"), &OpenXRInterface::get_display_refresh_rate);
Expand Down Expand Up @@ -1258,6 +1259,10 @@ void OpenXRInterface::on_pose_recentered() {
emit_signal(SNAME("pose_recentered"));
}

void OpenXRInterface::on_refresh_rate_changes(float p_new_rate) {
emit_signal(SNAME("refresh_rate_changed"), p_new_rate);
}

/** Hand tracking. */
void OpenXRInterface::set_motion_range(const Hand p_hand, const HandMotionRange p_motion_range) {
ERR_FAIL_INDEX(p_hand, HAND_MAX);
Expand Down
1 change: 1 addition & 0 deletions modules/openxr/openxr_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class OpenXRInterface : public XRInterface {
void on_state_focused();
void on_state_stopping();
void on_pose_recentered();
void on_refresh_rate_changes(float p_new_rate);
void tracker_profile_changed(RID p_tracker, RID p_interaction_profile);

/** Hand tracking. */
Expand Down

0 comments on commit 0fd440e

Please sign in to comment.