Skip to content

Commit

Permalink
Merge pull request #20 from beaufortfrancois/webxr
Browse files Browse the repository at this point in the history
Add WebXR support in misc section
  • Loading branch information
beaufortfrancois authored Dec 17, 2024
2 parents d6ff2e1 + 7707476 commit 772b650
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,53 @@ function checkWGSLLanguageFeatures(parent) {
]));
}

async function checkWebXRSupport() {
// If XRGPUBinding is not available, WebXR is not supported.
if (!('XRGPUBinding' in window)) {
return 'not supported';
}

try {
// Check if immersive VR or AR sessions are supported.
const [isImmersiveVrSupported, isImmersiveArSupported] = await Promise.all([
navigator.xr?.isSessionSupported('immersive-vr'),
navigator.xr?.isSessionSupported('immersive-ar'),
]);

// If no immersive sessions are supported, WebXR is not supported.
if (!(isImmersiveVrSupported || isImmersiveArSupported)) {
return 'not supported';
}

let xrCompatibleAccessed = false;
const xrAdapterOptions = {
get xrCompatible() {
xrCompatibleAccessed = true;
return true;
}
};

// Otherwise, request an adapter with XR compatible options.
const adapter = await navigator.gpu.requestAdapter(xrAdapterOptions);

// If an adapter is found and it's XR compatible, WebXR is supported.
return adapter && xrCompatibleAccessed ? 'likely supported' : 'not supported';
} catch (error) {
// If an error occurs during adapter request, WebXR support is unknown.
return 'unknown';
}
}

async function checkMisc(parent, {haveFallback}) {
const obj = {};
const presentationFormat = navigator.gpu.getPreferredCanvasFormat();
obj.getPreferredCanvasFormat = presentationFormat;
if (!haveFallback) {
obj['fallback adapter'] = 'not supported';
}

obj['WebXR support'] = await checkWebXRSupport();

try {
const adapter = await navigator.gpu.requestAdapter();
const device = await adapter.requestDevice();
Expand Down Expand Up @@ -700,6 +740,7 @@ async function main() {
{ powerPreference: "low-power", },
{ powerPreference: "low-power", forceFallbackAdapter: true, },
{ compatibilityMode: true, featureLevel: "compatibility" },
{ xrCompatible: true },
];

const adapterIds = new Map();
Expand Down

0 comments on commit 772b650

Please sign in to comment.