How to use makeXrCompatible method in wpt

Best JavaScript code snippet using wpt

webXRManagedOutputCanvas.ts

Source:webXRManagedOutputCanvas.ts Github

copy

Full Screen

1import { Nullable } from "../types";2import { ThinEngine } from "../Engines/thinEngine";3import { WebXRRenderTarget } from "./webXRTypes";4import { WebXRSessionManager } from "./webXRSessionManager";5import { Observable } from "../Misc/observable";6import { Tools } from "../Misc/tools";7import { WebXRLayerWrapper } from "./webXRLayerWrapper";8import { WebXRWebGLLayerWrapper } from "./webXRWebGLLayer";9/**10 * Configuration object for WebXR output canvas11 */12export class WebXRManagedOutputCanvasOptions {13 /**14 * An optional canvas in case you wish to create it yourself and provide it here.15 * If not provided, a new canvas will be created16 */17 public canvasElement?: HTMLCanvasElement;18 /**19 * Options for this XR Layer output20 */21 public canvasOptions?: XRWebGLLayerInit;22 /**23 * CSS styling for a newly created canvas (if not provided)24 */25 public newCanvasCssStyle?: string;26 /**27 * Get the default values of the configuration object28 * @param engine defines the engine to use (can be null)29 * @returns default values of this configuration object30 */31 public static GetDefaults(engine?: ThinEngine): WebXRManagedOutputCanvasOptions {32 const defaults = new WebXRManagedOutputCanvasOptions();33 defaults.canvasOptions = {34 antialias: true,35 depth: true,36 stencil: engine ? engine.isStencilEnable : true,37 alpha: true,38 multiview: false,39 framebufferScaleFactor: 1,40 };41 defaults.newCanvasCssStyle = "position:absolute; bottom:0px;right:0px;z-index:10;width:90%;height:100%;background-color: #000000;";42 return defaults;43 }44}45/**46 * Creates a canvas that is added/removed from the webpage when entering/exiting XR47 */48export class WebXRManagedOutputCanvas implements WebXRRenderTarget {49 private _canvas: Nullable<HTMLCanvasElement> = null;50 private _engine: Nullable<ThinEngine> = null;51 private _originalCanvasSize: {52 width: number;53 height: number;54 };55 /**56 * Rendering context of the canvas which can be used to display/mirror xr content57 */58 public canvasContext: WebGLRenderingContext;59 /**60 * xr layer for the canvas61 */62 public xrLayer: Nullable<XRWebGLLayer> = null;63 private _xrLayerWrapper: Nullable<WebXRLayerWrapper> = null;64 /**65 * Observers registered here will be triggered when the xr layer was initialized66 */67 public onXRLayerInitObservable: Observable<XRWebGLLayer> = new Observable();68 /**69 * Initializes the canvas to be added/removed upon entering/exiting xr70 * @param _xrSessionManager The XR Session manager71 * @param _options optional configuration for this canvas output. defaults will be used if not provided72 */73 constructor(_xrSessionManager: WebXRSessionManager, private _options: WebXRManagedOutputCanvasOptions = WebXRManagedOutputCanvasOptions.GetDefaults()) {74 this._engine = _xrSessionManager.scene.getEngine();75 this._engine.onDisposeObservable.addOnce(() => {76 this._engine = null;77 });78 if (!_options.canvasElement) {79 const canvas = document.createElement("canvas");80 canvas.style.cssText = this._options.newCanvasCssStyle || "position:absolute; bottom:0px;right:0px;";81 this._setManagedOutputCanvas(canvas);82 } else {83 this._setManagedOutputCanvas(_options.canvasElement);84 }85 _xrSessionManager.onXRSessionInit.add(() => {86 this._addCanvas();87 });88 _xrSessionManager.onXRSessionEnded.add(() => {89 this._removeCanvas();90 });91 }92 /**93 * Disposes of the object94 */95 public dispose() {96 this._removeCanvas();97 this._setManagedOutputCanvas(null);98 }99 /**100 * Initializes a XRWebGLLayer to be used as the session's baseLayer.101 * @param xrSession xr session102 * @returns a promise that will resolve once the XR Layer has been created103 */104 public async initializeXRLayerAsync(xrSession: XRSession): Promise<XRWebGLLayer> {105 const createLayer = () => {106 this.xrLayer = new XRWebGLLayer(xrSession, this.canvasContext, this._options.canvasOptions);107 this._xrLayerWrapper = new WebXRWebGLLayerWrapper(this.xrLayer);108 this.onXRLayerInitObservable.notifyObservers(this.xrLayer);109 return this.xrLayer;110 };111 // support canvases without makeXRCompatible112 if (!(this.canvasContext as any).makeXRCompatible) {113 return Promise.resolve(createLayer());114 }115 return (this.canvasContext as any)116 .makeXRCompatible()117 .then(118 // catch any error and continue. When using the emulator is throws this error for no apparent reason.119 () => { },120 () => {121 // log the error, continue nonetheless!122 Tools.Warn("Error executing makeXRCompatible. This does not mean that the session will work incorrectly.");123 }124 )125 .then(() => {126 return createLayer();127 });128 }129 private _addCanvas() {130 if (this._canvas && this._engine && this._canvas !== this._engine.getRenderingCanvas()) {131 document.body.appendChild(this._canvas);132 }133 if (this.xrLayer) {134 this._setCanvasSize(true);135 } else {136 this.onXRLayerInitObservable.addOnce(() => {137 this._setCanvasSize(true);138 });139 }140 }141 private _removeCanvas() {142 if (this._canvas && this._engine && document.body.contains(this._canvas) && this._canvas !== this._engine.getRenderingCanvas()) {143 document.body.removeChild(this._canvas);144 }145 this._setCanvasSize(false);146 }147 private _setCanvasSize(init: boolean = true, xrLayer = this._xrLayerWrapper) {148 if (!this._canvas || !this._engine) {149 return;150 }151 if (init) {152 if (xrLayer) {153 if (this._canvas !== this._engine.getRenderingCanvas()) {154 this._canvas.style.width = xrLayer.getWidth() + "px";155 this._canvas.style.height = xrLayer.getHeight() + "px";156 } else {157 this._engine.setSize(xrLayer.getWidth(), xrLayer.getHeight());158 }159 }160 } else {161 if (this._originalCanvasSize) {162 if (this._canvas !== this._engine.getRenderingCanvas()) {163 this._canvas.style.width = this._originalCanvasSize.width + "px";164 this._canvas.style.height = this._originalCanvasSize.height + "px";165 } else {166 this._engine.setSize(this._originalCanvasSize.width, this._originalCanvasSize.height);167 }168 }169 }170 }171 private _setManagedOutputCanvas(canvas: Nullable<HTMLCanvasElement>) {172 this._removeCanvas();173 if (!canvas) {174 this._canvas = null;175 (this.canvasContext as any) = null;176 } else {177 this._originalCanvasSize = {178 width: canvas.offsetWidth,179 height: canvas.offsetHeight,180 };181 this._canvas = canvas;182 this.canvasContext = <any>this._canvas.getContext("webgl2");183 if (!this.canvasContext) {184 this.canvasContext = <any>this._canvas.getContext("webgl");185 }186 }187 }...

Full Screen

Full Screen

polyfill-globals.js

Source:polyfill-globals.js Github

copy

Full Screen

1/*2 * Copyright 2017 Google Inc. All Rights Reserved.3 * Licensed under the Apache License, Version 2.0 (the "License");4 * you may not use this file except in compliance with the License.5 * You may obtain a copy of the License at6 *7 * http://www.apache.org/licenses/LICENSE-2.08 *9 * Unless required by applicable law or agreed to in writing, software10 * distributed under the License is distributed on an "AS IS" BASIS,11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12 * See the License for the specific language governing permissions and13 * limitations under the License.14 */15import {16 POLYFILLED_XR_COMPATIBLE,17 XR_COMPATIBLE,18} from './constants';19const contextTypes = ['webgl', 'experimental-webgl'];20/**21 * Takes the WebGLRenderingContext constructor22 * and creates a `makeXRCompatible` function if it does not exist.23 * Returns a boolean indicating whether or not the function24 * was polyfilled.25 *26 * @param {WebGLRenderingContext}27 * @return {boolean}28 */29export const polyfillMakeXRCompatible = Context => {30 if (typeof Context.prototype.makeXRCompatible === 'function') {31 return false;32 }33 // Create `makeXRCompatible` and if successful, store34 // the XRDevice as a private attribute for error checking35 Context.prototype.makeXRCompatible = function () {36 this[XR_COMPATIBLE] = true;37 // This is all fake, so just resolve immediately.38 return Promise.resolve();39 };40 return true;41};42/**43 * Takes the HTMLCanvasElement or OffscreenCanvas constructor44 * and wraps its `getContext` function to patch the context with a45 * POLYFILLED_XR_COMPATIBLE bit so the API knows it's also working with a46 * polyfilled `xrCompatible` bit. Can do extra checking for validity.47 *48 * @param {HTMLCanvasElement} Canvas49 */50export const polyfillGetContext = (Canvas) => {51 const getContext = Canvas.prototype.getContext;52 Canvas.prototype.getContext = function (contextType, glAttribs) {53 const ctx = getContext.call(this, contextType, glAttribs);54 if (ctx) {55 // Set this bit so the API knows the WebGLRenderingContext is56 // also polyfilled a bit57 ctx[POLYFILLED_XR_COMPATIBLE] = true;58 // If we've polyfilled WebGLRenderingContext's xrCompatible59 // bit, store the boolean in the private token if created via60 // creation parameters61 if (glAttribs && ('xrCompatible' in glAttribs)) {62 ctx[XR_COMPATIBLE] = glAttribs.xrCompatible;63 }64 }65 return ctx;66 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var xrCompatible = wptoolkit.makeXrCompatible();3console.log(xrCompatible);4var wptoolkit = require('wptoolkit');5var xrCompatible = wptoolkit.makeXrCompatible();6console.log(xrCompatible);7var wptoolkit = require('wptoolkit');8var xrCompatible = wptoolkit.makeXrCompatible();9console.log(xrCompatible);10var wptoolkit = require('wptoolkit');11var xrCompatible = wptoolkit.makeXrCompatible();12console.log(xrCompatible);13var wptoolkit = require('wptoolkit');14var xrCompatible = wptoolkit.makeXrCompatible();15console.log(xrCompatible);16var wptoolkit = require('wptoolkit');17var xrCompatible = wptoolkit.makeXrCompatible();18console.log(xrCompatible);19var wptoolkit = require('wptoolkit');20var xrCompatible = wptoolkit.makeXrCompatible();21console.log(xrCompatible);22var wptoolkit = require('wptoolkit');23var xrCompatible = wptoolkit.makeXrCompatible();24console.log(xrCompatible);25var wptoolkit = require('wptoolkit');26var xrCompatible = wptoolkit.makeXrCompatible();27console.log(xrCompatible);28var wptoolkit = require('wptoolkit');29var xrCompatible = wptoolkit.makeXrCompatible();30console.log(xrCompatible);31var wptoolkit = require('wptoolkit');32var xrCompatible = wptoolkit.makeXrCompatible();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var canvas = document.createElement('canvas');3var gl = canvas.getContext('webgl2');4wptoolkit.makeXrCompatible(gl);5makeXrCompatible() method6var canvas = document.createElement('canvas');7var gl = canvas.getContext('webgl2');8wptoolkit.makeXrCompatible(gl).then(function (result) {9 console.log("makeXrCompatible returned " + result);10}).catch(function (error) {11 console.log("makeXrCompatible returned error: " + error);12});13makeXrCompatible(gl)14var canvas = document.createElement('canvas');15var gl = canvas.getContext('webgl2');16wptoolkit.makeXrCompatible(gl).then(function (result) {17 console.log("makeXrCompatible returned " + result);18}).catch(function (error) {19 console.log("makeXrCompatible returned error: " + error);20});21var wptoolkit = require('wptoolkit');22var canvas = document.createElement('canvas');23var gl = canvas.getContext('webgl2');

Full Screen

Using AI Code Generation

copy

Full Screen

1var toolkit = require('wptoolkit');2var xrCompatible = toolkit.makeXrCompatible();3console.log(xrCompatible);4var toolkit = require('wptoolkit');5var xrCompatible = toolkit.makeXrCompatible();6console.log(xrCompatible);7var toolkit = require('wptoolkit');8var xrCompatible = toolkit.makeXrCompatible();9console.log(xrCompatible);10var toolkit = require('wptoolkit');11var xrCompatible = toolkit.makeXrCompatible();12console.log(xrCompatible);13var toolkit = require('wptoolkit');14var xrCompatible = toolkit.makeXrCompatible();15console.log(xrCompatible);16var toolkit = require('wptoolkit');17var xrCompatible = toolkit.makeXrCompatible();18console.log(xrCompatible);19var toolkit = require('wptoolkit');20var xrCompatible = toolkit.makeXrCompatible();21console.log(xrCompatible);22var toolkit = require('wptoolkit');23var xrCompatible = toolkit.makeXrCompatible();24console.log(xrCompatible);25var toolkit = require('wptoolkit');26var xrCompatible = toolkit.makeXrCompatible();27console.log(xrCompatible);28var toolkit = require('wptoolkit');29var xrCompatible = toolkit.makeXrCompatible();30console.log(xrCompatible);31var toolkit = require('wptoolkit');32var xrCompatible = toolkit.makeXrCompatible();33console.log(xrCompatible);34var toolkit = require('wptoolkit');

Full Screen

Using AI Code Generation

copy

Full Screen

1const xrLayer = new XRWebGLLayer(session, gl);2xrLayer.makeXrCompatible();3const session = await navigator.xr.requestSession('immersive-vr', { optionalFeatures: ['local-floor'], requiredFeatures: ['local-floor'], baseLayer: xrLayer });4const frameOfReference = await session.requestFrameOfReference('local-floor');5const referenceSpace = await session.requestReferenceSpace(frameOfReference);6const frame = session.requestAnimationFrame();7const viewerPose = frame.getViewerPose(referenceSpace);8const view = viewerPose.views[0];9const viewMatrix = view.transform.matrix;10const viewMatrixInverse = view.transform.inverse.matrix;11const viewMatrixInverseTranspose = view.transform.inverse.transpose.matrix;12const projectionMatrix = view.projectionMatrix;13const projectionMatrixInverse = view.projectionMatrixInverse;14const projectionMatrixInverseTranspose = view.projectionMatrixInverseTranspose;15const viewProjectionMatrix = view.viewProjectionMatrix;16const viewProjectionMatrixInverse = view.viewProjectionMatrixInverse;17const viewProjectionMatrixInverseTranspose = view.viewProjectionMatrixInverseTranspose;18const viewport = view.viewport;19const eye = view.eye;20const offset = view.offset;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptb = new WebXRTest();2var canvas = document.getElementById("renderCanvas");3wptb.makeXrCompatible(canvas).then(function () {4});5var wptb = new WebXRTest();6var canvas = document.getElementById("renderCanvas");7wptb.makeXrCompatible(canvas).then(function () {8});

Full Screen

Using AI Code Generation

copy

Full Screen

1const canvas = document.querySelector('canvas');2var gl = canvas.getContext('webgl');3var xrCompatible = gl.makeXRCompatible();4var sessionType = 'immersive-vr';5var supported = await navigator.xr.isSessionSupported(sessionType);6var sessionType = 'immersive-vr';7var session = await navigator.xr.requestSession(sessionType);8var callback = function(t, frame) {9};10var id = wptoolkit.requestAnimationFrame(callback);11var id = 0;12var result = wptoolkit.cancelAnimationFrame(id);13var session = navigator.xr.requestSession('immersive-vr');14var type = 'local';15var referenceSpace = await session.requestReferenceSpace(type);16var session = navigator.xr.requestSession('immersive-vr');17var state = { baseLayer: new XRWebGLLayer(session, gl) };

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful