Skip to content

Commit

Permalink
feat(WebXR): Add support for Looking Glass display
Browse files Browse the repository at this point in the history
Adds support for rendering to Looking Glass holographic display
via Looking Glass WebXR polyfill.

View transforms provided by the Looking Glass WebXR polyfill are
retrieved each frame and used to render into a quilt to be copied onto
the Looking Glass external display.

xref https://lookingglassfactory.com/webxr

xref https://docs.lookingglassfactory.com/keyconcepts/quilts
  • Loading branch information
tbirdso committed Feb 28, 2023
1 parent 0107730 commit ec79a95
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions Sources/Rendering/OpenGL/RenderWindow/Constants.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export declare enum XrSessionTypes {
HmdVR = 0,
MobileAR = 1,
LookingGlassVR = 2
}

declare const _default: {
Expand Down
1 change: 1 addition & 0 deletions Sources/Rendering/OpenGL/RenderWindow/Constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const XrSessionTypes = {
HmdVR: 0, // Head-mounted display (HMD), two-camera virtual reality session
MobileAR: 1, // Mobile device, single-camera augmented reality session
LookingGlassVR: 2, // Looking Glass hologram display, N-camera virtual reality session
};

export default {
Expand Down
25 changes: 20 additions & 5 deletions Sources/Rendering/OpenGL/RenderWindow/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,34 @@ export interface vtkOpenGLRenderWindow extends vtkOpenGLRenderWindowBase {
get3DContext(options: I3DContextOptions): Nullable<WebGLRenderingContext>;

/**
*
* Request an XR session on the user device with WebXR,
* typically in response to a user request such as a button press.
*/
startVR(): void;
startXR(): void;

/**
* When an XR session is available, set up the XRWebGLLayer
* and request the first animation frame for the device
*/
enterXR(): void,

/**
* Adjust world-to-physical parameters for different viewing modalities
*
* @param {Number} inputRescaleFactor
* @param {Number} inputTranslateZ
*/
resetXRScene(inputRescaleFactor: number, inputTranslateZ: number): void,

/**
*
* Request to stop the current XR session
*/
stopVR(): void;
stopXR(): void;

/**
*
*/
vrRender(): void;
xrRender(): void;

/**
*
Expand Down
13 changes: 12 additions & 1 deletion Sources/Rendering/OpenGL/RenderWindow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,13 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
// No handling for non-eye viewport
return;
}
} else if (model.xrSessionType === XrSessionTypes.LookingGlassVR) {
const startX = viewport.x / glLayer.framebufferWidth;
const startY = viewport.y / glLayer.framebufferHeight;
const endX = (viewport.x + viewport.width) / glLayer.framebufferWidth;
const endY =
(viewport.y + viewport.height) / glLayer.framebufferHeight;
ren.setViewport(startX, startY, endX, endY);
} else {
ren.setViewport(0, 0, 1, 1);
}
Expand All @@ -490,6 +497,11 @@ function vtkOpenGLRenderWindow(publicAPI, model) {

publicAPI.traverseAllPasses();
});

// Reset scissorbox before any subsequent rendering to external displays
// on frame end, such as rendering to a Looking Glass display.
gl.scissor(0, 0, glLayer.framebufferWidth, glLayer.framebufferHeight);
gl.disable(gl.SCISSOR_TEST);
}
};

Expand Down Expand Up @@ -1294,7 +1306,6 @@ const DEFAULT_VALUES = {
defaultToWebgl2: true, // attempt webgl2 on by default
activeFramebuffer: null,
xrSession: null,
xrSessionType: null,
xrReferenceSpace: null,
xrSupported: true,
imageFormat: 'image/png',
Expand Down

0 comments on commit ec79a95

Please sign in to comment.