How to use glBinding method in wpt

Best JavaScript code snippet using wpt

XREstimatedLight.js

Source:XREstimatedLight.js Github

copy

Full Screen

1import {2 DirectionalLight,3 Group,4 LightProbe,5 WebGLCubeRenderTarget6} from "../../../build/three.module.js";7class SessionLightProbe {8 constructor( xrLight, renderer, lightProbe, environmentEstimation, estimationStartCallback ) {9 this.xrLight = xrLight;10 this.renderer = renderer;11 this.lightProbe = lightProbe;12 this.xrWebGLBinding = null;13 this.estimationStartCallback = estimationStartCallback;14 this.frameCallback = this.onXRFrame.bind( this );15 const session = renderer.xr.getSession();16 // If the XRWebGLBinding class is available then we can also query an17 // estimated reflection cube map.18 if ( environmentEstimation && 'XRWebGLBinding' in window ) {19 // This is the simplest way I know of to initialize a WebGL cubemap in Three.20 const cubeRenderTarget = new WebGLCubeRenderTarget( 16 );21 xrLight.environment = cubeRenderTarget.texture;22 const gl = renderer.getContext();23 // Ensure that we have any extensions needed to use the preferred cube map format.24 switch ( session.preferredReflectionFormat ) {25 case 'srgba8':26 gl.getExtension( 'EXT_sRGB' );27 break;28 case 'rgba16f':29 gl.getExtension( 'OES_texture_half_float' );30 break;31 }32 this.xrWebGLBinding = new XRWebGLBinding( session, gl );33 this.lightProbe.addEventListener('reflectionchange', () => {34 this.updateReflection();35 });36 }37 // Start monitoring the XR animation frame loop to look for lighting38 // estimation changes.39 session.requestAnimationFrame( this.frameCallback );40 }41 updateReflection() {42 const textureProperties = this.renderer.properties.get( this.xrLight.environment );43 if ( textureProperties ) {44 const cubeMap = this.xrWebGLBinding.getReflectionCubeMap( this.lightProbe );45 if ( cubeMap ) {46 textureProperties.__webglTexture = cubeMap;47 }48 }49 }50 onXRFrame( time, xrFrame ) {51 // If either this obejct or the XREstimatedLight has been destroyed, stop52 // running the frame loop.53 if ( ! this.xrLight ) {54 return;55 }56 const session = xrFrame.session;57 session.requestAnimationFrame( this.frameCallback );58 const lightEstimate = xrFrame.getLightEstimate( this.lightProbe );59 if ( lightEstimate ) {60 // We can copy the estimate's spherical harmonics array directly into the light probe.61 this.xrLight.lightProbe.sh.fromArray( lightEstimate.sphericalHarmonicsCoefficients );62 this.xrLight.lightProbe.intensity = 1.0;63 // For the directional light we have to normalize the color and set the scalar as the64 // intensity, since WebXR can return color values that exceed 1.0.65 const intensityScalar = Math.max( 1.0,66 Math.max( lightEstimate.primaryLightIntensity.x,67 Math.max( lightEstimate.primaryLightIntensity.y,68 lightEstimate.primaryLightIntensity.z ) ) );69 this.xrLight.directionalLight.color.setRGB(70 lightEstimate.primaryLightIntensity.x / intensityScalar,71 lightEstimate.primaryLightIntensity.y / intensityScalar,72 lightEstimate.primaryLightIntensity.z / intensityScalar );73 this.xrLight.directionalLight.intensity = intensityScalar;74 this.xrLight.directionalLight.position.copy( lightEstimate.primaryLightDirection );75 if ( this.estimationStartCallback ) {76 this.estimationStartCallback();77 this.estimationStartCallback = null;78 }79 }80 }81 dispose() {82 this.xrLight = null;83 this.renderer = null;84 this.lightProbe = null;85 this.xrWebGLBinding = null;86 }87}88export class XREstimatedLight extends Group {89 constructor( renderer, environmentEstimation = true ) {90 super();91 this.lightProbe = new LightProbe();92 this.lightProbe.intensity = 0;93 this.add( this.lightProbe );94 this.directionalLight = new DirectionalLight();95 this.directionalLight.intensity = 0;96 this.add( this.directionalLight );97 // Will be set to a cube map in the SessionLightProbe is environment estimation is98 // available and requested.99 this.environment = null;100 let sessionLightProbe = null;101 let estimationStarted = false;102 renderer.xr.addEventListener( 'sessionstart', () => {103 const session = renderer.xr.getSession();104 if ( 'requestLightProbe' in session ) {105 session.requestLightProbe( {106 reflectionFormat: session.preferredReflectionFormat107 } ).then( ( probe ) => {108 sessionLightProbe = new SessionLightProbe( this, renderer, probe, environmentEstimation, () => {109 estimationStarted = true;110 // Fired to indicate that the estimated lighting values are now being updated.111 this.dispatchEvent( { type: 'estimationstart' } );112 } );113 } );114 }115 } );116 renderer.xr.addEventListener( 'sessionend', () => {117 if ( sessionLightProbe ) {118 sessionLightProbe.dispose();119 sessionLightProbe = null;120 }121 if ( estimationStarted ) {122 // Fired to indicate that the estimated lighting values are no longer being updated.123 this.dispatchEvent( { type: 'estimationend' } );124 }125 } );126 // Done inline to provide access to sessionLightProbe.127 this.dispose = () => {128 if ( sessionLightProbe ) {129 sessionLightProbe.dispose();130 sessionLightProbe = null;131 }132 this.remove( this.lightProbe );133 this.lightProbe = null;134 this.remove( this.directionalLight );135 this.directionalLight = null;136 this.environment = null;137 };138 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var gl = webgl2.glBinding.getGLContext();2var program = gl.createProgram();3gl.attachShader(program, vertexShader);4gl.attachShader(program, fragmentShader);5gl.linkProgram(program);6gl.useProgram(program);7var uniformLocation = gl.getUniformLocation(program, "u_color");8gl.uniform4f(uniformLocation, 1.0, 0.0, 0.0, 1.0);9var positionLocation = gl.getAttribLocation(program, "a_position");10var positionBuffer = gl.createBuffer();11gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);12];13gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(positions), gl.STATIC_DRAW);14gl.enableVertexAttribArray(positionLocation);15gl.vertexAttribPointer(16 positionLocation, size, type, normalize, stride, offset);17var primitiveType = gl.TRIANGLES;18var offset = 0;19var count = 3;20gl.drawArrays(primitiveType, offset, count);21wpt.runTest();

Full Screen

Using AI Code Generation

copy

Full Screen

1const {wpt} = require('wpt-runner');2const {wpt} = require('wpt-runner');3const {wpt} = require('wpt-runner');4const {wpt} = require('wpt-runner');5const {wpt} = require('wpt-runner');6const {wpt} = require('wpt-runner');7const {wpt} = require('wpt-runner');

Full Screen

Using AI Code Generation

copy

Full Screen

1var gl = canvas.getContext("webgl2", {xrCompatible: true});2var glbinding = gl.getBinding();3var gl2 = glbinding.wrapGL2(gl);4var gl = canvas.getContext("webgl2", {xrCompatible: true});5var glbinding = gl.getBinding();6var gl2 = glbinding.wrapGL2(gl);7var gl = canvas.getContext("webgl2", {xrCompatible: true});8var glbinding = gl.getBinding();9var gl2 = glbinding.wrapGL2(gl);10var gl = canvas.getContext("webgl2", {xrCompatible: true});11var glbinding = gl.getBinding();12var gl2 = glbinding.wrapGL2(gl);13var gl = canvas.getContext("webgl2", {xrCompatible: true});14var glbinding = gl.getBinding();15var gl2 = glbinding.wrapGL2(gl);16var gl = canvas.getContext("webgl2", {xrCompatible: true});17var glbinding = gl.getBinding();18var gl2 = glbinding.wrapGL2(gl);19var gl = canvas.getContext("webgl2", {xrCompatible: true});20var glbinding = gl.getBinding();21var gl2 = glbinding.wrapGL2(gl);22var gl = canvas.getContext("webgl2", {xrCompatible: true});23var glbinding = gl.getBinding();24var gl2 = glbinding.wrapGL2(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