Skip to content

Instantly share code, notes, and snippets.

@maluoi
Created August 14, 2025 17:24
Show Gist options
  • Save maluoi/d6d0265518efa20d927544c71898a205 to your computer and use it in GitHub Desktop.
Save maluoi/d6d0265518efa20d927544c71898a205 to your computer and use it in GitHub Desktop.
Simplified implementation of XR_FB_display_refresh_rate for StereoKit
using System;
namespace StereoKit.Framework
{
class XrRefreshRate : IStepper
{
int _rate;
public bool Enabled { get; private set; }
public XrRefreshRate() : this(0) { }
public XrRefreshRate(int rate)
{
_rate = rate;
if (SK.IsInitialized)
Log.Err("XrRefreshRate must be Setup before StereoKit is initialized!");
Backend.OpenXR.RequestExt("XR_FB_display_refresh_rate");
}
public bool Initialize()
{
Enabled =
Backend.XRType == BackendXRType.OpenXR &&
Backend.OpenXR.ExtEnabled("XR_FB_display_refresh_rate") &&
LoadBindings();
if (Enabled && _rate != 0)
SetRefreshRate(_rate);
return true;
}
public void SetRefreshRate(int rate)
{
if (Enabled)
xrRequestDisplayRefreshRateFB(Backend.OpenXR.Session, rate);
}
public void Shutdown() { Enabled = false; }
public void Step() { }
#region OpenXR Bindings
enum XrResult : Int32 { Success = 0 }
delegate XrResult del_xrRequestDisplayRefreshRateFB( ulong session, float displayRefreshRate);
del_xrRequestDisplayRefreshRateFB xrRequestDisplayRefreshRateFB;
bool LoadBindings()
{
xrRequestDisplayRefreshRateFB = Backend.OpenXR.GetFunction<del_xrRequestDisplayRefreshRateFB>("xrRequestDisplayRefreshRateFB");
return xrRequestDisplayRefreshRateFB != null;
}
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment