Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebXR FrameRate #6077

Merged
merged 5 commits into from
Feb 21, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/framework/xr/xr-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@
*/
_depthFar = 1000;

/**
* @type {number[]|null}
* @private
*/
_supportedFrameRates = null;

/**
* @type {number}
* @private
Expand Down Expand Up @@ -633,6 +639,30 @@
});
}

/**
* Update target frame rate of an XR session to one of supported value provided by
* supportedFrameRates list.
*

Check failure on line 645 in src/framework/xr/xr-manager.js

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
mvaligursky marked this conversation as resolved.
Show resolved Hide resolved
* @param {number} frameRate - Target frame rate. It should be any value from the list
* of supportedFrameRates.
* @param {Function} [callback] - Callback that will be called when frameRate has been
* updated or failed to update with error provided.
*/
updateTargetFrameRate(frameRate, callback) {
if (!this._session?.updateTargetFrameRate) {
callback?.(new Error('unable to update frameRate'));
return;
}

this._session.updateTargetFrameRate(frameRate)
.then(() => {
callback?.();
})
.catch((err) => {
callback?.(err);
});
}

/**
* @param {string} type - Session type.
* @private
Expand Down Expand Up @@ -709,6 +739,16 @@

this._createBaseLayer();

if (this.session.supportedFrameRates) {
this._supportedFrameRates = Array.from(this.session.supportedFrameRates);
} else {
this._supportedFrameRates = null;
}

this._session.addEventListener('frameratechange', () => {
this.fire('frameratechange', this._session?.frameRate);
});

// request reference space
session.requestReferenceSpace(spaceType).then((referenceSpace) => {
this._referenceSpace = referenceSpace;
Expand Down Expand Up @@ -949,6 +989,25 @@
return this._session;
}

/**
* XR session frameRate or null if this information is not available. This value can change
* during an active XR session.
*
* @type {number|null}
*/
get frameRate() {
return this._session?.frameRate ?? null;
}

/**
* List of supported frame rates, or null if this data is not available.
*
* @type {number[]|null}
*/
get supportedFrameRates() {
return this._supportedFrameRates;
}

/**
* Framebuffer scale factor. This value is read-only and can only be set when starting a new
* XR session.
Expand Down
Loading