iwer 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/build/iwer.js +412 -1291
  2. package/build/iwer.min.js +52 -11
  3. package/build/iwer.module.js +412 -1291
  4. package/build/iwer.module.min.js +52 -11
  5. package/lib/action/ActionPlayer.d.ts.map +1 -1
  6. package/lib/action/ActionPlayer.js.map +1 -1
  7. package/lib/action/ActionRecorder.d.ts.map +1 -1
  8. package/lib/action/ActionRecorder.js +1 -1
  9. package/lib/action/ActionRecorder.js.map +1 -1
  10. package/lib/anchors/XRAnchor.d.ts.map +1 -1
  11. package/lib/anchors/XRAnchor.js.map +1 -1
  12. package/lib/device/XRController.d.ts.map +1 -1
  13. package/lib/device/XRController.js.map +1 -1
  14. package/lib/device/XRDevice.d.ts +1 -1
  15. package/lib/device/XRDevice.d.ts.map +1 -1
  16. package/lib/device/XRDevice.js +8 -3
  17. package/lib/device/XRDevice.js.map +1 -1
  18. package/lib/device/XRHandInput.d.ts.map +1 -1
  19. package/lib/device/XRHandInput.js.map +1 -1
  20. package/lib/device/XRTrackedInput.d.ts.map +1 -1
  21. package/lib/device/XRTrackedInput.js.map +1 -1
  22. package/lib/device/configs/controller/meta.js.map +1 -1
  23. package/lib/device/configs/hand/pinch.js.map +1 -1
  24. package/lib/device/configs/hand/point.js.map +1 -1
  25. package/lib/device/configs/hand/relaxed.js.map +1 -1
  26. package/lib/device/configs/headset/meta.js.map +1 -1
  27. package/lib/events/XRInputSourceEvent.d.ts.map +1 -1
  28. package/lib/events/XRInputSourceEvent.js.map +1 -1
  29. package/lib/events/XRInputSourcesChangeEvent.d.ts.map +1 -1
  30. package/lib/events/XRInputSourcesChangeEvent.js.map +1 -1
  31. package/lib/events/XRReferenceSpaceEvent.d.ts.map +1 -1
  32. package/lib/events/XRReferenceSpaceEvent.js.map +1 -1
  33. package/lib/events/XRSessionEvent.d.ts.map +1 -1
  34. package/lib/events/XRSessionEvent.js.map +1 -1
  35. package/lib/frameloop/XRFrame.d.ts.map +1 -1
  36. package/lib/frameloop/XRFrame.js.map +1 -1
  37. package/lib/gamepad/Gamepad.d.ts.map +1 -1
  38. package/lib/gamepad/Gamepad.js.map +1 -1
  39. package/lib/hittest/XRHitTest.d.ts.map +1 -1
  40. package/lib/hittest/XRHitTest.js.map +1 -1
  41. package/lib/hittest/XRRay.d.ts.map +1 -1
  42. package/lib/hittest/XRRay.js.map +1 -1
  43. package/lib/initialization/XRSystem.d.ts.map +1 -1
  44. package/lib/initialization/XRSystem.js.map +1 -1
  45. package/lib/input/XRHand.d.ts.map +1 -1
  46. package/lib/input/XRHand.js.map +1 -1
  47. package/lib/input/XRInputSource.d.ts.map +1 -1
  48. package/lib/input/XRInputSource.js.map +1 -1
  49. package/lib/labels/labels.d.ts.map +1 -1
  50. package/lib/labels/labels.js.map +1 -1
  51. package/lib/layers/XRWebGLLayer.d.ts.map +1 -1
  52. package/lib/layers/XRWebGLLayer.js.map +1 -1
  53. package/lib/meshes/XRMesh.d.ts.map +1 -1
  54. package/lib/meshes/XRMesh.js.map +1 -1
  55. package/lib/planes/XRPlane.d.ts.map +1 -1
  56. package/lib/planes/XRPlane.js.map +1 -1
  57. package/lib/pose/XRJointPose.d.ts.map +1 -1
  58. package/lib/pose/XRJointPose.js.map +1 -1
  59. package/lib/pose/XRPose.d.ts.map +1 -1
  60. package/lib/pose/XRPose.js.map +1 -1
  61. package/lib/pose/XRViewerPose.d.ts.map +1 -1
  62. package/lib/pose/XRViewerPose.js.map +1 -1
  63. package/lib/primitives/XRRigidTransform.d.ts.map +1 -1
  64. package/lib/primitives/XRRigidTransform.js.map +1 -1
  65. package/lib/session/XRRenderState.d.ts.map +1 -1
  66. package/lib/session/XRRenderState.js.map +1 -1
  67. package/lib/session/XRSession.d.ts.map +1 -1
  68. package/lib/session/XRSession.js.map +1 -1
  69. package/lib/spaces/XRJointSpace.d.ts.map +1 -1
  70. package/lib/spaces/XRJointSpace.js.map +1 -1
  71. package/lib/spaces/XRReferenceSpace.d.ts.map +1 -1
  72. package/lib/spaces/XRReferenceSpace.js.map +1 -1
  73. package/lib/spaces/XRSpace.d.ts.map +1 -1
  74. package/lib/spaces/XRSpace.js.map +1 -1
  75. package/lib/utils/Math.d.ts.map +1 -1
  76. package/lib/utils/Math.js.map +1 -1
  77. package/lib/version.d.ts +1 -1
  78. package/lib/version.js +1 -1
  79. package/lib/views/XRView.d.ts.map +1 -1
  80. package/lib/views/XRView.js.map +1 -1
  81. package/lib/views/XRViewport.d.ts.map +1 -1
  82. package/lib/views/XRViewport.js.map +1 -1
  83. package/package.json +61 -61
@@ -5,7 +5,7 @@
5
5
 
6
6
  // Configuration Constants
7
7
  var EPSILON = 0.000001;
8
- var ARRAY_TYPE = typeof Float32Array !== "undefined" ? Float32Array : Array;
8
+ var ARRAY_TYPE$1 = typeof Float32Array !== "undefined" ? Float32Array : Array;
9
9
 
10
10
  /**
11
11
  * 3x3 Matrix
@@ -17,9 +17,9 @@ var ARRAY_TYPE = typeof Float32Array !== "undefined" ? Float32Array : Array;
17
17
  *
18
18
  * @returns {mat3} a new 3x3 matrix
19
19
  */
20
- function create$5() {
21
- var out = new ARRAY_TYPE(9);
22
- if (ARRAY_TYPE != Float32Array) {
20
+ function create$6() {
21
+ var out = new ARRAY_TYPE$1(9);
22
+ if (ARRAY_TYPE$1 != Float32Array) {
23
23
  out[1] = 0;
24
24
  out[2] = 0;
25
25
  out[3] = 0;
@@ -43,9 +43,9 @@ function create$5() {
43
43
  *
44
44
  * @returns {mat4} a new 4x4 matrix
45
45
  */
46
- function create$4() {
47
- var out = new ARRAY_TYPE(16);
48
- if (ARRAY_TYPE != Float32Array) {
46
+ function create$5() {
47
+ var out = new ARRAY_TYPE$1(16);
48
+ if (ARRAY_TYPE$1 != Float32Array) {
49
49
  out[1] = 0;
50
50
  out[2] = 0;
51
51
  out[3] = 0;
@@ -73,7 +73,7 @@ function create$4() {
73
73
  * @returns {mat4} a new 4x4 matrix
74
74
  */
75
75
  function clone(a) {
76
- var out = new ARRAY_TYPE(16);
76
+ var out = new ARRAY_TYPE$1(16);
77
77
  out[0] = a[0];
78
78
  out[1] = a[1];
79
79
  out[2] = a[2];
@@ -216,7 +216,7 @@ function invert(out, a) {
216
216
  * @param {ReadonlyMat4} b the second operand
217
217
  * @returns {mat4} out
218
218
  */
219
- function multiply$1(out, a, b) {
219
+ function multiply$2(out, a, b) {
220
220
  var a00 = a[0],
221
221
  a01 = a[1],
222
222
  a02 = a[2],
@@ -454,7 +454,7 @@ function getScaling(out, mat) {
454
454
  * @return {quat} out
455
455
  */
456
456
  function getRotation(out, mat) {
457
- var scaling = new ARRAY_TYPE(3);
457
+ var scaling = new ARRAY_TYPE$1(3);
458
458
  getScaling(scaling, mat);
459
459
  var is1 = 1 / scaling[0];
460
460
  var is2 = 1 / scaling[1];
@@ -555,50 +555,6 @@ function fromRotationTranslationScale(out, q, v, s) {
555
555
  return out;
556
556
  }
557
557
 
558
- /**
559
- * Calculates a 4x4 matrix from the given quaternion
560
- *
561
- * @param {mat4} out mat4 receiving operation result
562
- * @param {ReadonlyQuat} q Quaternion to create matrix from
563
- *
564
- * @returns {mat4} out
565
- */
566
- function fromQuat(out, q) {
567
- var x = q[0],
568
- y = q[1],
569
- z = q[2],
570
- w = q[3];
571
- var x2 = x + x;
572
- var y2 = y + y;
573
- var z2 = z + z;
574
- var xx = x * x2;
575
- var yx = y * x2;
576
- var yy = y * y2;
577
- var zx = z * x2;
578
- var zy = z * y2;
579
- var zz = z * z2;
580
- var wx = w * x2;
581
- var wy = w * y2;
582
- var wz = w * z2;
583
- out[0] = 1 - yy - zz;
584
- out[1] = yx + wz;
585
- out[2] = zx - wy;
586
- out[3] = 0;
587
- out[4] = yx - wz;
588
- out[5] = 1 - xx - zz;
589
- out[6] = zy + wx;
590
- out[7] = 0;
591
- out[8] = zx + wy;
592
- out[9] = zy - wx;
593
- out[10] = 1 - xx - yy;
594
- out[11] = 0;
595
- out[12] = 0;
596
- out[13] = 0;
597
- out[14] = 0;
598
- out[15] = 1;
599
- return out;
600
- }
601
-
602
558
  /**
603
559
  * Generates a perspective projection matrix with the given bounds.
604
560
  * The near/far clip planes correspond to a normalized device coordinate Z range of [-1, 1],
@@ -655,9 +611,9 @@ var perspective = perspectiveNO;
655
611
  *
656
612
  * @returns {vec3} a new 3D vector
657
613
  */
658
- function create$3() {
659
- var out = new ARRAY_TYPE(3);
660
- if (ARRAY_TYPE != Float32Array) {
614
+ function create$4() {
615
+ var out = new ARRAY_TYPE$1(3);
616
+ if (ARRAY_TYPE$1 != Float32Array) {
661
617
  out[0] = 0;
662
618
  out[1] = 0;
663
619
  out[2] = 0;
@@ -687,7 +643,7 @@ function length(a) {
687
643
  * @returns {vec3} a new 3D vector
688
644
  */
689
645
  function fromValues$2(x, y, z) {
690
- var out = new ARRAY_TYPE(3);
646
+ var out = new ARRAY_TYPE$1(3);
691
647
  out[0] = x;
692
648
  out[1] = y;
693
649
  out[2] = z;
@@ -869,7 +825,7 @@ var len = length;
869
825
  * @function
870
826
  */
871
827
  (function () {
872
- var vec = create$3();
828
+ var vec = create$4();
873
829
  return function (a, stride, offset, count, fn, arg) {
874
830
  var i, l;
875
831
  if (!stride) {
@@ -906,9 +862,9 @@ var len = length;
906
862
  *
907
863
  * @returns {vec4} a new 4D vector
908
864
  */
909
- function create$2() {
910
- var out = new ARRAY_TYPE(4);
911
- if (ARRAY_TYPE != Float32Array) {
865
+ function create$3() {
866
+ var out = new ARRAY_TYPE$1(4);
867
+ if (ARRAY_TYPE$1 != Float32Array) {
912
868
  out[0] = 0;
913
869
  out[1] = 0;
914
870
  out[2] = 0;
@@ -927,7 +883,7 @@ function create$2() {
927
883
  * @returns {vec4} a new 4D vector
928
884
  */
929
885
  function fromValues$1(x, y, z, w) {
930
- var out = new ARRAY_TYPE(4);
886
+ var out = new ARRAY_TYPE$1(4);
931
887
  out[0] = x;
932
888
  out[1] = y;
933
889
  out[2] = z;
@@ -1024,7 +980,7 @@ function transformMat4(out, a, m) {
1024
980
  * @function
1025
981
  */
1026
982
  (function () {
1027
- var vec = create$2();
983
+ var vec = create$3();
1028
984
  return function (a, stride, offset, count, fn, arg) {
1029
985
  var i, l;
1030
986
  if (!stride) {
@@ -1063,9 +1019,9 @@ function transformMat4(out, a, m) {
1063
1019
  *
1064
1020
  * @returns {quat} a new quaternion
1065
1021
  */
1066
- function create$1() {
1067
- var out = new ARRAY_TYPE(4);
1068
- if (ARRAY_TYPE != Float32Array) {
1022
+ function create$2() {
1023
+ var out = new ARRAY_TYPE$1(4);
1024
+ if (ARRAY_TYPE$1 != Float32Array) {
1069
1025
  out[0] = 0;
1070
1026
  out[1] = 0;
1071
1027
  out[2] = 0;
@@ -1101,7 +1057,7 @@ function setAxisAngle(out, axis, rad) {
1101
1057
  * @param {ReadonlyQuat} b the second operand
1102
1058
  * @returns {quat} out
1103
1059
  */
1104
- function multiply(out, a, b) {
1060
+ function multiply$1(out, a, b) {
1105
1061
  var ax = a[0],
1106
1062
  ay = a[1],
1107
1063
  az = a[2],
@@ -1284,7 +1240,7 @@ var normalize = normalize$1;
1284
1240
  * @returns {quat} out
1285
1241
  */
1286
1242
  (function () {
1287
- var tmpvec3 = create$3();
1243
+ var tmpvec3 = create$4();
1288
1244
  var xUnitVec3 = fromValues$2(1, 0, 0);
1289
1245
  var yUnitVec3 = fromValues$2(0, 1, 0);
1290
1246
  return function (out, a, b) {
@@ -1324,8 +1280,8 @@ var normalize = normalize$1;
1324
1280
  * @returns {quat} out
1325
1281
  */
1326
1282
  (function () {
1327
- var temp1 = create$1();
1328
- var temp2 = create$1();
1283
+ var temp1 = create$2();
1284
+ var temp2 = create$2();
1329
1285
  return function (out, a, b, c, d, t) {
1330
1286
  slerp(temp1, a, d, t);
1331
1287
  slerp(temp2, b, c, t);
@@ -1345,7 +1301,7 @@ var normalize = normalize$1;
1345
1301
  * @returns {quat} out
1346
1302
  */
1347
1303
  (function () {
1348
- var matr = create$5();
1304
+ var matr = create$6();
1349
1305
  return function (out, view, right, up) {
1350
1306
  matr[0] = right[0];
1351
1307
  matr[3] = right[1];
@@ -1360,63 +1316,6 @@ var normalize = normalize$1;
1360
1316
  };
1361
1317
  })();
1362
1318
 
1363
- /**
1364
- * 2 Dimensional Vector
1365
- * @module vec2
1366
- */
1367
-
1368
- /**
1369
- * Creates a new, empty vec2
1370
- *
1371
- * @returns {vec2} a new 2D vector
1372
- */
1373
- function create() {
1374
- var out = new ARRAY_TYPE(2);
1375
- if (ARRAY_TYPE != Float32Array) {
1376
- out[0] = 0;
1377
- out[1] = 0;
1378
- }
1379
- return out;
1380
- }
1381
-
1382
- /**
1383
- * Perform some operation over an array of vec2s.
1384
- *
1385
- * @param {Array} a the array of vectors to iterate over
1386
- * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed
1387
- * @param {Number} offset Number of elements to skip at the beginning of the array
1388
- * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array
1389
- * @param {Function} fn Function to call for each vector in the array
1390
- * @param {Object} [arg] additional argument to pass to fn
1391
- * @returns {Array} a
1392
- * @function
1393
- */
1394
- (function () {
1395
- var vec = create();
1396
- return function (a, stride, offset, count, fn, arg) {
1397
- var i, l;
1398
- if (!stride) {
1399
- stride = 2;
1400
- }
1401
- if (!offset) {
1402
- offset = 0;
1403
- }
1404
- if (count) {
1405
- l = Math.min(count * stride + offset, a.length);
1406
- } else {
1407
- l = a.length;
1408
- }
1409
- for (i = offset; i < l; i += stride) {
1410
- vec[0] = a[i];
1411
- vec[1] = a[i + 1];
1412
- fn(vec, vec, arg);
1413
- a[i] = vec[0];
1414
- a[i + 1] = vec[1];
1415
- }
1416
- return a;
1417
- };
1418
- })();
1419
-
1420
1319
  /**
1421
1320
  * Copyright (c) Meta Platforms, Inc. and affiliates.
1422
1321
  *
@@ -1462,14 +1361,14 @@ class XRSpace extends EventTarget {
1462
1361
  super();
1463
1362
  this[P_SPACE] = {
1464
1363
  parentSpace,
1465
- offsetMatrix: offsetMatrix ? clone(offsetMatrix) : create$4(),
1364
+ offsetMatrix: offsetMatrix ? clone(offsetMatrix) : create$5(),
1466
1365
  emulated: true,
1467
1366
  };
1468
1367
  }
1469
1368
  }
1470
1369
  class GlobalSpace extends XRSpace {
1471
1370
  constructor() {
1472
- super(undefined, create$4()); // GlobalSpace has no parent
1371
+ super(undefined, create$5()); // GlobalSpace has no parent
1473
1372
  }
1474
1373
  }
1475
1374
  class XRSpaceUtils {
@@ -1481,7 +1380,7 @@ class XRSpaceUtils {
1481
1380
  // Update the rotation component of the offsetMatrix of a given XRSpace using a quaternion
1482
1381
  static updateOffsetQuaternion(space, quaternion) {
1483
1382
  const offsetMatrix = space[P_SPACE].offsetMatrix;
1484
- const translation = create$3();
1383
+ const translation = create$4();
1485
1384
  getTranslation(translation, offsetMatrix);
1486
1385
  fromRotationTranslation(offsetMatrix, quaternion, translation);
1487
1386
  }
@@ -1491,11 +1390,11 @@ class XRSpaceUtils {
1491
1390
  copy$3(offsetMatrix, matrix);
1492
1391
  }
1493
1392
  // Calculate the global offset matrix for a given XRSpace
1494
- static calculateGlobalOffsetMatrix(space, globalOffset = create$4()) {
1393
+ static calculateGlobalOffsetMatrix(space, globalOffset = create$5()) {
1495
1394
  const parentOffset = space[P_SPACE].parentSpace
1496
1395
  ? XRSpaceUtils.calculateGlobalOffsetMatrix(space[P_SPACE].parentSpace)
1497
- : create$4(); // Identity matrix for GlobalSpace
1498
- multiply$1(globalOffset, parentOffset, space[P_SPACE].offsetMatrix);
1396
+ : create$5(); // Identity matrix for GlobalSpace
1397
+ multiply$2(globalOffset, parentOffset, space[P_SPACE].offsetMatrix);
1499
1398
  return globalOffset;
1500
1399
  }
1501
1400
  }
@@ -1513,7 +1412,7 @@ class XRSpaceUtils {
1513
1412
  class Vector3 {
1514
1413
  constructor(x = 0, y = 0, z = 0) {
1515
1414
  this.vec3 = fromValues$2(x, y, z);
1516
- this.tempVec3 = create$3();
1415
+ this.tempVec3 = create$4();
1517
1416
  }
1518
1417
  get x() {
1519
1418
  return this.vec3[0];
@@ -1575,7 +1474,7 @@ class Vector3 {
1575
1474
  class Quaternion {
1576
1475
  constructor(x = 0, y = 0, z = 0, w = 1) {
1577
1476
  this.quat = fromValues(x, y, z, w);
1578
- this.tempQuat = create$1();
1477
+ this.tempQuat = create$2();
1579
1478
  }
1580
1479
  get x() {
1581
1480
  return this.quat[0];
@@ -1624,7 +1523,7 @@ class Quaternion {
1624
1523
  }
1625
1524
  multiply(q) {
1626
1525
  copy(this.tempQuat, this.quat);
1627
- multiply(this.quat, this.tempQuat, q.quat);
1526
+ multiply$1(this.quat, this.tempQuat, q.quat);
1628
1527
  return this;
1629
1528
  }
1630
1529
  setFromAxisAngle(axis, angle) {
@@ -2250,14 +2149,14 @@ class XRRigidTransform {
2250
2149
  constructor(position, orientation) {
2251
2150
  // Default values
2252
2151
  const defaultPosition = fromValues$2(0, 0, 0);
2253
- const defaultOrientation = create$1();
2152
+ const defaultOrientation = create$2();
2254
2153
  this[P_RIGID_TRANSFORM] = {
2255
- matrix: create$4(),
2154
+ matrix: create$5(),
2256
2155
  position: position
2257
2156
  ? fromValues$2(position.x, position.y, position.z)
2258
2157
  : defaultPosition,
2259
2158
  orientation: orientation
2260
- ? normalize(create$1(), fromValues(orientation.x, orientation.y, orientation.z, orientation.w))
2159
+ ? normalize(create$2(), fromValues(orientation.x, orientation.y, orientation.z, orientation.w))
2261
2160
  : defaultOrientation,
2262
2161
  inverse: null,
2263
2162
  };
@@ -2279,14 +2178,14 @@ class XRRigidTransform {
2279
2178
  }
2280
2179
  get inverse() {
2281
2180
  if (!this[P_RIGID_TRANSFORM].inverse) {
2282
- const invMatrix = create$4();
2181
+ const invMatrix = create$5();
2283
2182
  if (!invert(invMatrix, this[P_RIGID_TRANSFORM].matrix)) {
2284
2183
  throw new Error('Matrix is not invertible.');
2285
2184
  }
2286
2185
  // Decomposing the inverse matrix into position and orientation
2287
- let invPosition = create$3();
2186
+ let invPosition = create$4();
2288
2187
  getTranslation(invPosition, invMatrix);
2289
- let invOrientation = create$1();
2188
+ let invOrientation = create$2();
2290
2189
  getRotation(invOrientation, invMatrix);
2291
2190
  // Creating a new XRRigidTransform for the inverse
2292
2191
  this[P_RIGID_TRANSFORM].inverse = new XRRigidTransform(new DOMPointReadOnly(invPosition[0], invPosition[1], invPosition[2], 1), new DOMPointReadOnly(invOrientation[0], invOrientation[1], invOrientation[2], invOrientation[3]));
@@ -2312,8 +2211,8 @@ class XRRay {
2312
2211
  if (origin instanceof XRRigidTransform) {
2313
2212
  const transform = origin;
2314
2213
  const matrix = transform.matrix;
2315
- const originVec4 = set$1(create$2(), _origin.x, _origin.y, _origin.z, _origin.w);
2316
- const directionVec4 = set$1(create$2(), _direction.x, _direction.y, _direction.z, _direction.w);
2214
+ const originVec4 = set$1(create$3(), _origin.x, _origin.y, _origin.z, _origin.w);
2215
+ const directionVec4 = set$1(create$3(), _direction.x, _direction.y, _direction.z, _direction.w);
2317
2216
  transformMat4(originVec4, originVec4, matrix);
2318
2217
  transformMat4(directionVec4, directionVec4, matrix);
2319
2218
  _origin.x = originVec4[0];
@@ -2365,23 +2264,23 @@ class XRRay {
2365
2264
  if (this[P_RAY].matrix) {
2366
2265
  return this[P_RAY].matrix;
2367
2266
  }
2368
- const z = set$2(create$3(), 0, 0, -1);
2369
- const origin = set$2(create$3(), this[P_RAY].origin.x, this[P_RAY].origin.y, this[P_RAY].origin.z);
2370
- const direction = set$2(create$3(), this[P_RAY].direction.x, this[P_RAY].direction.y, this[P_RAY].direction.z);
2371
- const axis = cross(create$3(), direction, z);
2267
+ const z = set$2(create$4(), 0, 0, -1);
2268
+ const origin = set$2(create$4(), this[P_RAY].origin.x, this[P_RAY].origin.y, this[P_RAY].origin.z);
2269
+ const direction = set$2(create$4(), this[P_RAY].direction.x, this[P_RAY].direction.y, this[P_RAY].direction.z);
2270
+ const axis = cross(create$4(), direction, z);
2372
2271
  const cosAngle = dot(direction, z);
2373
- const rotation = create$4();
2272
+ const rotation = create$5();
2374
2273
  if (cosAngle > -1 && cosAngle < 1) {
2375
2274
  fromRotation(rotation, Math.acos(cosAngle), axis);
2376
2275
  }
2377
2276
  else if (cosAngle === -1) {
2378
- fromRotation(rotation, Math.acos(cosAngle), set$2(create$3(), 1, 0, 0));
2277
+ fromRotation(rotation, Math.acos(cosAngle), set$2(create$4(), 1, 0, 0));
2379
2278
  }
2380
2279
  else {
2381
2280
  identity(rotation);
2382
2281
  }
2383
- const translation = fromTranslation(create$4(), origin);
2384
- const matrix = multiply$1(create$4(), translation, rotation);
2282
+ const translation = fromTranslation(create$5(), origin);
2283
+ const matrix = multiply$2(create$5(), translation, rotation);
2385
2284
  this[P_RAY].matrix = new Float32Array(matrix);
2386
2285
  return this[P_RAY].matrix;
2387
2286
  }
@@ -2648,14 +2547,14 @@ class XRViewerPose extends XRPose {
2648
2547
  * This source code is licensed under the MIT license found in the
2649
2548
  * LICENSE file in the root directory of this source tree.
2650
2549
  */
2651
- const spaceGlobalMatrix = create$4();
2652
- const baseSpaceGlobalMatrix = create$4();
2653
- const baseSpaceGlobalMatrixInverse = create$4();
2550
+ const spaceGlobalMatrix = create$5();
2551
+ const baseSpaceGlobalMatrix = create$5();
2552
+ const baseSpaceGlobalMatrixInverse = create$5();
2654
2553
  const getOffsetMatrix = (offsetMatrix, space, baseSpace) => {
2655
2554
  XRSpaceUtils.calculateGlobalOffsetMatrix(space, spaceGlobalMatrix);
2656
2555
  XRSpaceUtils.calculateGlobalOffsetMatrix(baseSpace, baseSpaceGlobalMatrix);
2657
2556
  invert(baseSpaceGlobalMatrixInverse, baseSpaceGlobalMatrix);
2658
- multiply$1(offsetMatrix, baseSpaceGlobalMatrixInverse, spaceGlobalMatrix);
2557
+ multiply$2(offsetMatrix, baseSpaceGlobalMatrixInverse, spaceGlobalMatrix);
2659
2558
  };
2660
2559
  class XRFrame {
2661
2560
  constructor(session, id, active, animationFrame, predictedDisplayTime) {
@@ -2665,7 +2564,7 @@ class XRFrame {
2665
2564
  active,
2666
2565
  animationFrame,
2667
2566
  predictedDisplayTime,
2668
- tempMat4: create$4(),
2567
+ tempMat4: create$5(),
2669
2568
  detectedPlanes: new XRPlaneSet(),
2670
2569
  detectedMeshes: new XRMeshSet(),
2671
2570
  trackedAnchors: session[P_SESSION].frameTrackedAnchors,
@@ -2683,9 +2582,9 @@ class XRFrame {
2683
2582
  throw new DOMException('XRFrame access outside the callback that produced it is invalid.', 'InvalidStateError');
2684
2583
  }
2685
2584
  getOffsetMatrix(this[P_FRAME].tempMat4, space, baseSpace);
2686
- const position = create$3();
2585
+ const position = create$4();
2687
2586
  getTranslation(position, this[P_FRAME].tempMat4);
2688
- const orientation = create$1();
2587
+ const orientation = create$2();
2689
2588
  getRotation(orientation, this[P_FRAME].tempMat4);
2690
2589
  return new XRPose(new XRRigidTransform({ x: position[0], y: position[1], z: position[2], w: 1.0 }, {
2691
2590
  x: orientation[0],
@@ -2836,9 +2735,9 @@ class XRSession extends EventTarget {
2836
2735
  isSystemKeyboardSupported: false,
2837
2736
  ended: false,
2838
2737
  projectionMatrices: {
2839
- [XREye.Left]: create$4(),
2840
- [XREye.Right]: create$4(),
2841
- [XREye.None]: create$4(),
2738
+ [XREye.Left]: create$5(),
2739
+ [XREye.Right]: create$5(),
2740
+ [XREye.None]: create$5(),
2842
2741
  },
2843
2742
  getProjectionMatrix: (eye) => {
2844
2743
  return this[P_SESSION].projectionMatrices[eye];
@@ -3087,8 +2986,8 @@ class XRSession extends EventTarget {
3087
2986
  const sourceSpace = hitTestSource[P_HIT_TEST].space;
3088
2987
  const sourceGlobalOffset = XRSpaceUtils.calculateGlobalOffsetMatrix(sourceSpace);
3089
2988
  const rayLocalOffset = hitTestSource[P_HIT_TEST].offsetRay.matrix;
3090
- const rayGlobalOffset = create$4();
3091
- multiply$1(rayGlobalOffset, sourceGlobalOffset, rayLocalOffset);
2989
+ const rayGlobalOffset = create$5();
2990
+ multiply$2(rayGlobalOffset, sourceGlobalOffset, rayLocalOffset);
3092
2991
  const hitTestResults = [];
3093
2992
  sem.computeHitTestResults(rayGlobalOffset).forEach((matrix) => {
3094
2993
  const offsetSpace = new XRSpace(globalSpace, matrix);
@@ -4260,15 +4159,15 @@ const XRHandGamepadConfig = {
4260
4159
  buttons: [{ id: 'pinch', type: 'analog', eventTrigger: 'select' }],
4261
4160
  axes: [],
4262
4161
  };
4263
- const fromPosition = create$3();
4264
- const fromQuaternion = create$1();
4265
- const fromScale = create$3();
4266
- const toPosition = create$3();
4267
- const toQuaternion = create$1();
4268
- const toScale = create$3();
4269
- const interpolatedPosition = create$3();
4270
- const interpolatedQuaternion = create$1();
4271
- const interpolatedScale = create$3();
4162
+ const fromPosition = create$4();
4163
+ const fromQuaternion = create$2();
4164
+ const fromScale = create$4();
4165
+ const toPosition = create$4();
4166
+ const toQuaternion = create$2();
4167
+ const toScale = create$4();
4168
+ const interpolatedPosition = create$4();
4169
+ const interpolatedQuaternion = create$2();
4170
+ const interpolatedScale = create$4();
4272
4171
  const interpolateMatrix = (out, fromMatrix, toMatrix, alpha) => {
4273
4172
  getTranslation(fromPosition, fromMatrix);
4274
4173
  getRotation(fromQuaternion, fromMatrix);
@@ -4461,8 +4360,8 @@ class ActionPlayer {
4461
4360
  playing: false,
4462
4361
  viewerSpace,
4463
4362
  viewSpaces,
4464
- vec3: create$3(),
4465
- quat: create$1(),
4363
+ vec3: create$4(),
4364
+ quat: create$2(),
4466
4365
  };
4467
4366
  fromTranslation(this[P_ACTION_PLAYER].viewSpaces[XREye.Left][P_SPACE].offsetMatrix, fromValues$2(-ipd / 2, 0, 0));
4468
4367
  fromTranslation(this[P_ACTION_PLAYER].viewSpaces[XREye.Right][P_SPACE].offsetMatrix, fromValues$2(ipd / 2, 0, 0));
@@ -4628,7 +4527,7 @@ class ActionPlayer {
4628
4527
  }
4629
4528
  }
4630
4529
 
4631
- const VERSION = "2.1.0";
4530
+ const VERSION = "2.1.1";
4632
4531
 
4633
4532
  /**
4634
4533
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -4769,21 +4668,48 @@ class XRViewport {
4769
4668
  }
4770
4669
 
4771
4670
  /**
4772
- * Copyright (c) Facebook, Inc. and its affiliates.
4671
+ * @license
4672
+ * webxr-layers-polyfill
4673
+ * Version 1.1.0
4674
+ * Copyright (c) 2021 Facebook, Inc. and its affiliates.
4773
4675
  * Licensed under the Apache License, Version 2.0 (the "License");
4774
4676
  * you may not use this file except in compliance with the License.
4775
4677
  * You may obtain a copy of the License at
4776
- *
4678
+ *
4777
4679
  * http://www.apache.org/licenses/LICENSE-2.0
4778
- *
4680
+ *
4779
4681
  * Unless required by applicable law or agreed to in writing, software
4780
4682
  * distributed under the License is distributed on an "AS IS" BASIS,
4781
4683
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4782
4684
  * See the License for the specific language governing permissions and
4783
4685
  * limitations under the License.
4784
- */
4785
- // Import WebXR types globally
4786
- /// <reference types="webxr" />
4686
+ */
4687
+
4688
+ /**
4689
+ * @license
4690
+ * gl-matrix
4691
+ * Version 3.4.3
4692
+ * Copyright (c) 2015-2021, Brandon Jones, Colin MacKenzie IV.
4693
+ *
4694
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
4695
+ * of this software and associated documentation files (the "Software"), to deal
4696
+ * in the Software without restriction, including without limitation the rights
4697
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
4698
+ * copies of the Software, and to permit persons to whom the Software is
4699
+ * furnished to do so, subject to the following conditions:
4700
+ *
4701
+ * The above copyright notice and this permission notice shall be included in
4702
+ * all copies or substantial portions of the Software.
4703
+ *
4704
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4705
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4706
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
4707
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
4708
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
4709
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
4710
+ * THE SOFTWARE.
4711
+ */
4712
+
4787
4713
  var XRTextureType;
4788
4714
  (function (XRTextureType) {
4789
4715
  XRTextureType["texture"] = "texture";
@@ -4798,39 +4724,10 @@ var XRLayerLayout;
4798
4724
  XRLayerLayout["stereo-top-bottom"] = "stereo-top-bottom";
4799
4725
  })(XRLayerLayout || (XRLayerLayout = {}));
4800
4726
 
4801
- /**
4802
- * Copyright (c) Facebook, Inc. and its affiliates.
4803
- * Licensed under the Apache License, Version 2.0 (the "License");
4804
- * you may not use this file except in compliance with the License.
4805
- * You may obtain a copy of the License at
4806
- *
4807
- * http://www.apache.org/licenses/LICENSE-2.0
4808
- *
4809
- * Unless required by applicable law or agreed to in writing, software
4810
- * distributed under the License is distributed on an "AS IS" BASIS,
4811
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4812
- * See the License for the specific language governing permissions and
4813
- * limitations under the License.
4814
- */
4815
- /// <reference types="webxr" />
4816
4727
  const isReferenceSpace = (arg) => {
4817
4728
  return arg && typeof arg.getOffsetReferenceSpace === 'function';
4818
4729
  };
4819
4730
 
4820
- /**
4821
- * Copyright (c) Facebook, Inc. and its affiliates.
4822
- * Licensed under the Apache License, Version 2.0 (the "License");
4823
- * you may not use this file except in compliance with the License.
4824
- * You may obtain a copy of the License at
4825
- *
4826
- * http://www.apache.org/licenses/LICENSE-2.0
4827
- *
4828
- * Unless required by applicable law or agreed to in writing, software
4829
- * distributed under the License is distributed on an "AS IS" BASIS,
4830
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4831
- * See the License for the specific language governing permissions and
4832
- * limitations under the License.
4833
- */
4834
4731
  const getGlobal = () => {
4835
4732
  return typeof global !== 'undefined'
4836
4733
  ? global
@@ -4841,31 +4738,6 @@ const getGlobal = () => {
4841
4738
  : {};
4842
4739
  };
4843
4740
 
4844
- /**
4845
- * Copyright (c) Facebook, Inc. and its affiliates.
4846
- * Licensed under the Apache License, Version 2.0 (the "License");
4847
- * you may not use this file except in compliance with the License.
4848
- * You may obtain a copy of the License at
4849
- *
4850
- * http://www.apache.org/licenses/LICENSE-2.0
4851
- *
4852
- * Unless required by applicable law or agreed to in writing, software
4853
- * distributed under the License is distributed on an "AS IS" BASIS,
4854
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4855
- * See the License for the specific language governing permissions and
4856
- * limitations under the License.
4857
- */
4858
- /**
4859
- * In WebGL2, internalFormat and format no longer need to be the same, but
4860
- * must be defined very specifically. This is a helper utility that, given a sized or unsized format,
4861
- * returns both formats as well as the type for that format.
4862
- * See https://registry.khronos.org/webgl/specs/latest/2.0/#TEXTURE_TYPES_FORMATS_FROM_DOM_ELEMENTS_TABLE
4863
- * or https://webgl2fundamentals.org/webgl/lessons/webgl-data-textures.html for more information.
4864
- *
4865
- * @param context WebGL2 Rendering context used for the enums
4866
- * @param providedFormat The provided format (sized or unsized) to retrieve other formats for
4867
- * @returns
4868
- */
4869
4741
  const getFormatsFromInternalFormat = (context, providedFormat) => {
4870
4742
  switch (providedFormat) {
4871
4743
  case context.RGBA8:
@@ -5037,8 +4909,6 @@ const getFormatsFromInternalFormat = (context, providedFormat) => {
5037
4909
  textureFormat: context.DEPTH_STENCIL,
5038
4910
  type: context.FLOAT_32_UNSIGNED_INT_24_8_REV,
5039
4911
  };
5040
- // DEPTH_COMPONENT and DEPTH_STENCIL are invalid internalFormats,
5041
- // so we have to account for those too
5042
4912
  case context.DEPTH_COMPONENT:
5043
4913
  return getFormatsFromInternalFormat(context, context.DEPTH_COMPONENT24);
5044
4914
  case context.DEPTH_STENCIL:
@@ -5058,20 +4928,6 @@ const getFormatsFromInternalFormat = (context, providedFormat) => {
5058
4928
  }
5059
4929
  };
5060
4930
 
5061
- /**
5062
- * Copyright (c) Facebook, Inc. and its affiliates.
5063
- * Licensed under the Apache License, Version 2.0 (the "License");
5064
- * you may not use this file except in compliance with the License.
5065
- * You may obtain a copy of the License at
5066
- *
5067
- * http://www.apache.org/licenses/LICENSE-2.0
5068
- *
5069
- * Unless required by applicable law or agreed to in writing, software
5070
- * distributed under the License is distributed on an "AS IS" BASIS,
5071
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5072
- * See the License for the specific language governing permissions and
5073
- * limitations under the License.
5074
- */
5075
4931
  class XRCompositionLayerPolyfill {
5076
4932
  constructor() {
5077
4933
  this._hasRunDeferredInitialize = false;
@@ -5087,25 +4943,16 @@ class XRCompositionLayerPolyfill {
5087
4943
  destroy() {
5088
4944
  this._colorTextures = [];
5089
4945
  this._depthStencilTextures = [];
5090
- // destroy underlying GL attachments
5091
4946
  }
5092
- // EventTarget things. Figure this out from the WebXR polyfill!
5093
4947
  addEventListener(type, listener, options) { }
5094
- /**
5095
- * Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.
5096
- */
5097
4948
  dispatchEvent(event) {
5098
4949
  return false;
5099
4950
  }
5100
- /**
5101
- * Removes the event listener in target's event listener list with the same type, callback, and options.
5102
- */
5103
4951
  removeEventListener(type, callback, options) { }
5104
4952
  getContext() {
5105
4953
  return this.context;
5106
4954
  }
5107
4955
  getTextureType() {
5108
- // override this please
5109
4956
  throw new Error('Unimplemented');
5110
4957
  }
5111
4958
  get colorTextures() {
@@ -5114,11 +4961,9 @@ class XRCompositionLayerPolyfill {
5114
4961
  get depthStencilTextures() {
5115
4962
  return this._depthStencilTextures;
5116
4963
  }
5117
- // POLYFILL ONLY: Get metadata for textures
5118
4964
  get colorTexturesMeta() {
5119
4965
  return this._texturesMeta;
5120
4966
  }
5121
- // POLYFILL ONLY: Get media source for media layers
5122
4967
  get media() {
5123
4968
  if (!this.isMediaLayer()) {
5124
4969
  console.warn('Attempted to retrieve media from a non-media layer');
@@ -5130,15 +4975,11 @@ class XRCompositionLayerPolyfill {
5130
4975
  textureType === XRTextureType['texture-array']) {
5131
4976
  throw new TypeError();
5132
4977
  }
5133
- // UNIMPLEMENTED: If textureType is "texture-array" and not all of the session’s views in the list of views have the same recommended WebGL texture resolution,
5134
- // throw a NotSupportedError and abort these steps.
5135
4978
  if (layout === XRLayerLayout.mono) {
5136
4979
  return layout;
5137
4980
  }
5138
4981
  if (layout === XRLayerLayout.default) {
5139
- // If the size of list of views is 1, return "mono" and abort these steps.
5140
- if (this.session.internalViews &&
5141
- this.session.internalViews.length === 1) {
4982
+ if (this.session.internalViews && this.session.internalViews.length === 1) {
5142
4983
  return XRLayerLayout['mono'];
5143
4984
  }
5144
4985
  if (textureType === XRTextureType['texture-array']) {
@@ -5146,61 +4987,36 @@ class XRCompositionLayerPolyfill {
5146
4987
  }
5147
4988
  }
5148
4989
  if (layout === XRLayerLayout.default || layout === XRLayerLayout.stereo) {
5149
- // If the user agent prefers "stereo-left-right" layout, return "stereo-left-right" and abort these steps.
5150
4990
  return XRLayerLayout['stereo-left-right'];
5151
- // If the user agent prefers "stereo-top-bottom" layout, return "stereo-top-bottom" and abort these steps.
5152
4991
  }
5153
4992
  return layout;
5154
4993
  }
5155
- // projection and cube layers are never media layers
5156
4994
  isMediaLayer() {
5157
4995
  return this._media !== null;
5158
4996
  }
5159
- // LAZY INITIALIZATION
5160
- ////////////////////////
5161
- // override this to initialize things, assuming that session.views already exists
5162
4997
  _deferredInitialize() { }
5163
- // Call this to run deferred initialize
5164
- // do not override it
5165
4998
  initializeIfNeeded() {
5166
- // OVERRIDE THIS
5167
4999
  if (!this._hasRunDeferredInitialize) {
5168
5000
  this._hasRunDeferredInitialize = true;
5169
5001
  this._deferredInitialize();
5170
5002
  }
5171
5003
  }
5172
- // ALLOCATING TEXTURES
5173
- // NOTE: Projection layers override this behavior
5174
- ///////////////////////////////////////////////////
5175
- // https://www.w3.org/TR/webxrlayers-1/#allocate-color-textures
5176
5004
  _allocateColorTexturesInternal(textureType, init) {
5177
5005
  let session = this.session;
5178
5006
  let views = session.internalViews;
5179
5007
  if (!views || views.length === 0) {
5180
- // can't allocate if there are no views
5181
5008
  console.warn("We can't allocate color textures without views");
5182
5009
  return;
5183
5010
  }
5184
- // TODO UNIMPLEMENTED: If init’s mipLevels is smaller than 1, throw a InvalidStateError and abort these steps.
5185
- // TODO UNIMPLEMENTED: If init’s mipLevels is larger than 1 and viewPixelWidth and viewPixelHeight are not powers of 2,
5186
- // throw a InvalidStateError and abort these steps
5187
- // POLYFILL ONLY: initialize layout if we haven't already
5188
5011
  this.initializeIfNeeded();
5189
- // UNIMPLEMENTED: If init’s colorFormat is not in the list of color formats
5190
- // for non-projection layers, throw a NotSupportedError and abort these steps.
5191
5012
  if (this.layout === XRLayerLayout.mono) {
5192
5013
  if (textureType === XRTextureType['texture-array']) {
5193
- // Initialize array with 1 new instance of an opaque texture in the relevant realm of this context created
5194
- // as a TEXTURE_2D_ARRAY texture with 1 internal texture using context and init’s colorFormat, mipLevels, viewPixelWidth and viewPixelHeight values.
5195
5014
  const newTexture = this._createNewColorTexture(init.viewPixelWidth, init.viewPixelHeight, textureType, init.colorFormat);
5196
5015
  this._texturesMeta = [newTexture];
5197
5016
  this._colorTextures = [newTexture.texture];
5198
5017
  return;
5199
5018
  }
5200
5019
  else {
5201
- // Initialize array with 1 new instance of an opaque texture in the relevant realm of context created as a
5202
- // TEXTURE_2D texture with context and
5203
- // init’s colorFormat, mipLevels, viewPixelWidth and viewPixelHeight values.
5204
5020
  const newTexture = this._createNewColorTexture(init.viewPixelWidth, init.viewPixelHeight, textureType, init.colorFormat);
5205
5021
  this._texturesMeta = [newTexture];
5206
5022
  this._colorTextures = [newTexture.texture];
@@ -5209,10 +5025,6 @@ class XRCompositionLayerPolyfill {
5209
5025
  }
5210
5026
  else if (this.layout === XRLayerLayout.stereo) {
5211
5027
  if (textureType === XRTextureType['texture-array']) {
5212
- // Initialize array with 1 new instance of an opaque texture in the relevant realm of context created as a
5213
- // TEXTURE_2D_ARRAY texture with 2 layers using context and init’s colorFormat, mipLevels, viewPixelWidth and viewPixelHeight values.
5214
- // TODO: use a new createNewColorTextureArray function for this!
5215
- // See https://github.com/WebGLSamples/WebGL2Samples/blob/master/samples/texture_2d_array.html#L145-L160
5216
5028
  const newTexture = this._createNewColorTexture(init.viewPixelWidth, init.viewPixelHeight, textureType, init.colorFormat, 2);
5217
5029
  this._texturesMeta = [newTexture];
5218
5030
  this._colorTextures = [newTexture.texture];
@@ -5250,9 +5062,6 @@ class XRCompositionLayerPolyfill {
5250
5062
  if (init.mipLevels < 1) {
5251
5063
  throw new Error('Invalid miplevel. Miplevel needs to be >= 1');
5252
5064
  }
5253
- // UNIMPLEMENTED: If init’s mipLevels is larger than 1 and
5254
- // viewPixelWidth and viewPixelHeight are not powers of 2,
5255
- // throw a InvalidStateError and abort these steps.
5256
5065
  if (this.layout === XRLayerLayout.mono) {
5257
5066
  if (textureType === XRTextureType['texture-array']) {
5258
5067
  const newTexture = this._createNewDepthStencilTexture(init.viewPixelWidth, init.viewPixelHeight, textureType, init.depthFormat);
@@ -5293,11 +5102,9 @@ class XRCompositionLayerPolyfill {
5293
5102
  return this._createGenericPolyfillTexture(textureType, width, height, colorFormat, 0, layers);
5294
5103
  }
5295
5104
  _createNewDepthStencilTexture(width, height, textureType, depthFormat, layers = 1) {
5296
- // If we have layers and are a texture-array, do that instead.
5297
5105
  return this._createGenericPolyfillTexture(textureType, width, height, depthFormat, 0, layers);
5298
5106
  }
5299
5107
  _createGenericPolyfillTexture(textureType, width, height, textureFormat, mipmapLevel = 0, numLayers = 1) {
5300
- // CHECKS FOR CORRECTNESS
5301
5108
  if (textureType === XRTextureType['texture-array'] && numLayers <= 1) {
5302
5109
  console.warn('creating a texture array with a single layer...');
5303
5110
  }
@@ -5305,10 +5112,6 @@ class XRCompositionLayerPolyfill {
5305
5112
  this.context instanceof WebGLRenderingContext) {
5306
5113
  throw new Error('WebGL 1 does not support texture array');
5307
5114
  }
5308
- // AUTO-ANTIALIASING DETECTION
5309
- const autoSamples = this._getAutoSampleCount();
5310
- const useAutoAA = autoSamples > 1;
5311
- // CREATE THE TEXTURE AND SURROUNDING METADATA
5312
5115
  let texture = this.context.createTexture();
5313
5116
  let textureMeta = {
5314
5117
  width,
@@ -5317,14 +5120,7 @@ class XRCompositionLayerPolyfill {
5317
5120
  type: textureType,
5318
5121
  textureFormat: textureFormat,
5319
5122
  texture,
5320
- // Add internal MSAA tracking
5321
- _msaaFramebuffer: null,
5322
- _resolveFramebuffer: null,
5323
- _autoAntialiasing: useAutoAA,
5324
- _samples: autoSamples,
5325
5123
  };
5326
- // DEPTH_COMPONENT is not a valid internalFormat in WebGL2.
5327
- // https://stackoverflow.com/a/60703526
5328
5124
  let internalFormat = textureFormat;
5329
5125
  let texImageType = this.context.UNSIGNED_BYTE;
5330
5126
  if (this.context instanceof WebGL2RenderingContext) {
@@ -5334,20 +5130,16 @@ class XRCompositionLayerPolyfill {
5334
5130
  texImageType = expectedFormats.type;
5335
5131
  }
5336
5132
  else {
5337
- // WebGL1 specific code
5338
5133
  if (textureFormat === this.context.DEPTH_COMPONENT) {
5339
5134
  texImageType = this.context.UNSIGNED_INT;
5340
5135
  }
5341
5136
  if (textureFormat === this.context.DEPTH_STENCIL) {
5342
- // this only exists if we have the WEBGL_depth_texture extension, but
5343
- // we assume that we must have it in order to get this far.
5344
5137
  texImageType = this.context.UNSIGNED_INT_24_8_WEBGL;
5345
5138
  }
5346
5139
  }
5347
5140
  if (textureType === XRTextureType['texture-array'] &&
5348
5141
  this.context instanceof WebGL2RenderingContext) {
5349
5142
  console.warn('texture-array layers are supported...questionably in the polyfill at the moment. Use at your own risk.');
5350
- // create a 2d texture array
5351
5143
  const existingTextureBinding = this.context.getParameter(this.context.TEXTURE_BINDING_2D_ARRAY);
5352
5144
  this.context.bindTexture(this.context.TEXTURE_2D_ARRAY, texture);
5353
5145
  if (this._getSupportedDepthFormats().indexOf(textureFormat) >= 0) {
@@ -5359,27 +5151,11 @@ class XRCompositionLayerPolyfill {
5359
5151
  this.context.bindTexture(this.context.TEXTURE_2D_ARRAY, existingTextureBinding);
5360
5152
  }
5361
5153
  else {
5362
- // regular texture 2d
5363
5154
  const existingTextureBinding = this.context.getParameter(this.context.TEXTURE_BINDING_2D);
5364
5155
  this.context.bindTexture(this.context.TEXTURE_2D, texture);
5365
5156
  this.context.texImage2D(this.context.TEXTURE_2D, 0, internalFormat, width, height, 0, textureFormat, texImageType, null);
5366
5157
  this.context.bindTexture(this.context.TEXTURE_2D, existingTextureBinding);
5367
5158
  }
5368
- // AUTO-ENABLE MSAA FOR DESKTOP - but only for color textures, not depth
5369
- if (useAutoAA && this.context instanceof WebGL2RenderingContext) {
5370
- const isDepthTexture = this._getSupportedDepthFormats().indexOf(textureFormat) >= 0;
5371
- if (!isDepthTexture) {
5372
- try {
5373
- this._createAutoMSAAFramebuffers(textureMeta, width, height, internalFormat);
5374
- console.log(`Auto-enabled ${autoSamples}x MSAA for layer texture (${width}x${height})`);
5375
- }
5376
- catch (error) {
5377
- console.warn('Failed to create MSAA framebuffers, falling back to non-AA:', error);
5378
- textureMeta._autoAntialiasing = false;
5379
- textureMeta._samples = 1;
5380
- }
5381
- }
5382
- }
5383
5159
  return textureMeta;
5384
5160
  }
5385
5161
  _getSupportedDepthFormats() {
@@ -5395,117 +5171,37 @@ class XRCompositionLayerPolyfill {
5395
5171
  }
5396
5172
  return supportedDepthFormats;
5397
5173
  }
5398
- // AUTO-ANTIALIASING HELPERS FOR DESKTOP
5399
- ////////////////////////////////////////////
5400
- _shouldAutoEnableAntialiasing() {
5401
- // Auto-enable AA for desktop environments (IWER)
5402
- // Option 1: Check for IWER specifically
5403
- if (typeof window.IWER !== 'undefined') {
5404
- return true;
5405
- }
5406
- // Option 2: Detect desktop via user agent (more general)
5407
- const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
5408
- if (isMobile) {
5409
- return false;
5410
- }
5411
- // Option 3: Only enable if WebGL2 supports MSAA
5412
- if (!(this.context instanceof WebGL2RenderingContext)) {
5413
- return false;
5414
- }
5415
- // Check if MSAA is actually supported
5416
- const maxSamples = this.context.getParameter(this.context.MAX_SAMPLES);
5417
- return maxSamples > 1;
5418
- }
5419
- _getAutoSampleCount() {
5420
- if (!this._shouldAutoEnableAntialiasing())
5421
- return 1;
5422
- // Get max samples supported, but cap at reasonable level
5423
- const maxSamples = this.context.getParameter(this.context.MAX_SAMPLES);
5424
- return Math.min(maxSamples, 4); // Use 4x MSAA as reasonable default
5425
- }
5426
- _createAutoMSAAFramebuffers(textureMeta, width, height, colorFormat, depthFormat) {
5427
- const gl = this.context;
5428
- // Create MSAA color renderbuffer
5429
- const colorRenderbuffer = gl.createRenderbuffer();
5430
- gl.bindRenderbuffer(gl.RENDERBUFFER, colorRenderbuffer);
5431
- gl.renderbufferStorageMultisample(gl.RENDERBUFFER, textureMeta._samples, colorFormat, width, height);
5432
- // Create MSAA depth renderbuffer (if depth format provided)
5433
- let depthRenderbuffer = null;
5434
- if (depthFormat) {
5435
- depthRenderbuffer = gl.createRenderbuffer();
5436
- gl.bindRenderbuffer(gl.RENDERBUFFER, depthRenderbuffer);
5437
- gl.renderbufferStorageMultisample(gl.RENDERBUFFER, textureMeta._samples, depthFormat, width, height);
5438
- }
5439
- // Create MSAA framebuffer
5440
- const msaaFramebuffer = gl.createFramebuffer();
5441
- gl.bindFramebuffer(gl.FRAMEBUFFER, msaaFramebuffer);
5442
- gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorRenderbuffer);
5443
- if (depthRenderbuffer) {
5444
- gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthRenderbuffer);
5445
- }
5446
- // Create resolve framebuffer (uses the regular texture)
5447
- const resolveFramebuffer = gl.createFramebuffer();
5448
- gl.bindFramebuffer(gl.FRAMEBUFFER, resolveFramebuffer);
5449
- if (textureMeta.type === XRTextureType['texture-array']) {
5450
- // For texture arrays, attach the first layer
5451
- gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, textureMeta.texture, 0, 0);
5452
- }
5453
- else {
5454
- // For regular textures
5455
- gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, textureMeta.texture, 0);
5456
- }
5457
- // Store for later use
5458
- textureMeta._msaaFramebuffer = msaaFramebuffer;
5459
- textureMeta._resolveFramebuffer = resolveFramebuffer;
5460
- // Clean up bindings
5461
- gl.bindRenderbuffer(gl.RENDERBUFFER, null);
5462
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
5463
- }
5464
5174
  }
5465
5175
 
5466
- /**
5467
- * Copyright (c) Facebook, Inc. and its affiliates.
5468
- * Licensed under the Apache License, Version 2.0 (the "License");
5469
- * you may not use this file except in compliance with the License.
5470
- * You may obtain a copy of the License at
5471
- *
5472
- * http://www.apache.org/licenses/LICENSE-2.0
5473
- *
5474
- * Unless required by applicable law or agreed to in writing, software
5475
- * distributed under the License is distributed on an "AS IS" BASIS,
5476
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5477
- * See the License for the specific language governing permissions and
5478
- * limitations under the License.
5479
- */
5480
5176
  const defaultCylinderLayerInit = {
5481
5177
  colorFormat: 0x1908,
5482
5178
  mipLevels: 1,
5483
5179
  layout: XRLayerLayout.mono,
5484
5180
  isStatic: false,
5485
- space: null, // this is required
5486
- viewPixelHeight: 0, // this is required
5487
- viewPixelWidth: 0, // this is required
5181
+ space: null,
5182
+ viewPixelHeight: 0,
5183
+ viewPixelWidth: 0,
5488
5184
  textureType: XRTextureType.texture,
5489
5185
  radius: 2.0,
5490
- centralAngle: 0.78539, // pi / 4
5186
+ centralAngle: 0.78539,
5491
5187
  aspectRatio: 2.0,
5492
5188
  };
5493
5189
  const defaultMediaCylinderLayerInit = {
5494
5190
  layout: XRLayerLayout.mono,
5495
5191
  invertStereo: false,
5496
- space: null, // this is required
5192
+ space: null,
5497
5193
  radius: 2.0,
5498
- centralAngle: 0.78539, // pi / 4
5194
+ centralAngle: 0.78539,
5499
5195
  };
5500
5196
  class XRCylinderLayer extends XRCompositionLayerPolyfill {
5501
5197
  constructor(init, media) {
5502
5198
  super();
5503
- this._media = media ?? null;
5199
+ this._media = media !== null && media !== void 0 ? media : null;
5504
5200
  if (this.isMediaLayer()) {
5505
- this.init = { ...defaultMediaCylinderLayerInit, ...init };
5201
+ this.init = Object.assign(Object.assign({}, defaultMediaCylinderLayerInit), init);
5506
5202
  }
5507
5203
  else {
5508
- this.init = { ...defaultCylinderLayerInit, ...init };
5204
+ this.init = Object.assign(Object.assign({}, defaultCylinderLayerInit), init);
5509
5205
  }
5510
5206
  this.radius = this.init.radius;
5511
5207
  this.centralAngle = this.init.centralAngle;
@@ -5557,7 +5253,6 @@ class XRCylinderLayer extends XRCompositionLayerPolyfill {
5557
5253
  }
5558
5254
  return this._depthStencilTextures;
5559
5255
  }
5560
- // POLYFILL ONLY: Get metadata for textures
5561
5256
  get colorTexturesMeta() {
5562
5257
  if (this.isMediaLayer()) {
5563
5258
  throw new Error('Media layers do not have associated textures');
@@ -5568,68 +5263,51 @@ class XRCylinderLayer extends XRCompositionLayerPolyfill {
5568
5263
  return this._texturesMeta;
5569
5264
  }
5570
5265
  get width() {
5571
- // circumference of the arc
5572
5266
  const circumference = 2 * this.radius * Math.PI;
5573
5267
  const percentage = this.centralAngle / (2 * Math.PI);
5574
5268
  return circumference * percentage;
5575
5269
  }
5576
5270
  get height() {
5577
- // aspect ratio is width / height
5578
5271
  return this.width / this.aspectRatio;
5579
5272
  }
5580
5273
  }
5581
5274
 
5582
- /**
5583
- * Copyright (c) Facebook, Inc. and its affiliates.
5584
- * Licensed under the Apache License, Version 2.0 (the "License");
5585
- * you may not use this file except in compliance with the License.
5586
- * You may obtain a copy of the License at
5587
- *
5588
- * http://www.apache.org/licenses/LICENSE-2.0
5589
- *
5590
- * Unless required by applicable law or agreed to in writing, software
5591
- * distributed under the License is distributed on an "AS IS" BASIS,
5592
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5593
- * See the License for the specific language governing permissions and
5594
- * limitations under the License.
5595
- */
5596
5275
  const defaultEquirectLayerInit = {
5597
5276
  colorFormat: 0x1908,
5598
5277
  mipLevels: 1,
5599
5278
  layout: XRLayerLayout.mono,
5600
5279
  isStatic: false,
5601
- space: null, // this is required
5602
- viewPixelHeight: 0, // this is required
5603
- viewPixelWidth: 0, // this is required
5280
+ space: null,
5281
+ viewPixelHeight: 0,
5282
+ viewPixelWidth: 0,
5604
5283
  textureType: XRTextureType.texture,
5605
5284
  radius: 0,
5606
- centralHorizontalAngle: 6.28318, // 2pi
5607
- upperVerticalAngle: 1.570795, // pi/2
5608
- lowerVerticalAngle: -1.570795, // -pi/2
5285
+ centralHorizontalAngle: 6.28318,
5286
+ upperVerticalAngle: 1.570795,
5287
+ lowerVerticalAngle: -1.570795,
5609
5288
  };
5610
5289
  const defaultMediaEquirectLayerInit = {
5611
- space: null, // this is required
5290
+ space: null,
5612
5291
  layout: XRLayerLayout.mono,
5613
5292
  invertStereo: false,
5614
5293
  radius: 0,
5615
- centralHorizontalAngle: 6.28318, // 2pi
5616
- upperVerticalAngle: 1.570795, // pi/2
5617
- lowerVerticalAngle: -1.570795, // -pi/2
5294
+ centralHorizontalAngle: 6.28318,
5295
+ upperVerticalAngle: 1.570795,
5296
+ lowerVerticalAngle: -1.570795,
5618
5297
  };
5619
5298
  class XREquirectLayer extends XRCompositionLayerPolyfill {
5620
5299
  constructor(init, media) {
5621
5300
  super();
5622
- this._media = media ?? null;
5301
+ this._media = media !== null && media !== void 0 ? media : null;
5623
5302
  if (this.isMediaLayer()) {
5624
- this.init = { ...defaultMediaEquirectLayerInit, ...init };
5303
+ this.init = Object.assign(Object.assign({}, defaultMediaEquirectLayerInit), init);
5625
5304
  }
5626
5305
  else {
5627
- this.init = { ...defaultEquirectLayerInit, ...init };
5306
+ this.init = Object.assign(Object.assign({}, defaultEquirectLayerInit), init);
5628
5307
  }
5629
5308
  if (!isReferenceSpace(this.init.space)) {
5630
5309
  throw new TypeError("Equirect layer's space needs to be an XRReferenceSpace");
5631
5310
  }
5632
- // UNIMPLEMENTED: If init's space has a type of 'viewer', throw TypeError and abort these steps.
5633
5311
  this.radius = this.init.radius;
5634
5312
  this.centralHorizontalAngle = this.init.centralHorizontalAngle;
5635
5313
  this.upperVerticalAngle = this.init.upperVerticalAngle;
@@ -5681,7 +5359,6 @@ class XREquirectLayer extends XRCompositionLayerPolyfill {
5681
5359
  }
5682
5360
  return this._depthStencilTextures;
5683
5361
  }
5684
- // POLYFILL ONLY: Get metadata for textures
5685
5362
  get colorTexturesMeta() {
5686
5363
  if (this.isMediaLayer()) {
5687
5364
  throw new Error('Media layers do not have associated textures');
@@ -5693,47 +5370,32 @@ class XREquirectLayer extends XRCompositionLayerPolyfill {
5693
5370
  }
5694
5371
  }
5695
5372
 
5696
- /**
5697
- * Copyright (c) Facebook, Inc. and its affiliates.
5698
- * Licensed under the Apache License, Version 2.0 (the "License");
5699
- * you may not use this file except in compliance with the License.
5700
- * You may obtain a copy of the License at
5701
- *
5702
- * http://www.apache.org/licenses/LICENSE-2.0
5703
- *
5704
- * Unless required by applicable law or agreed to in writing, software
5705
- * distributed under the License is distributed on an "AS IS" BASIS,
5706
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5707
- * See the License for the specific language governing permissions and
5708
- * limitations under the License.
5709
- */
5710
5373
  const defaultQuadLayerInit = {
5711
5374
  colorFormat: 0x1908,
5712
5375
  mipLevels: 1,
5713
5376
  layout: XRLayerLayout.mono,
5714
5377
  isStatic: false,
5715
- space: null, // this is required
5716
- viewPixelHeight: 0, // this is required
5717
- viewPixelWidth: 0, // this is required
5378
+ space: null,
5379
+ viewPixelHeight: 0,
5380
+ viewPixelWidth: 0,
5718
5381
  textureType: XRTextureType.texture,
5719
5382
  width: 1.0,
5720
5383
  height: 1.0,
5721
5384
  };
5722
5385
  const defaultMediaQuadLayerInit = {
5723
- space: null, // this is required
5386
+ space: null,
5724
5387
  layout: XRLayerLayout.mono,
5725
5388
  invertStereo: false,
5726
5389
  };
5727
5390
  class XRQuadLayer extends XRCompositionLayerPolyfill {
5728
- // media should only be added if it's a media layer...
5729
5391
  constructor(init, media) {
5730
5392
  super();
5731
- this._media = media ?? null;
5393
+ this._media = media !== null && media !== void 0 ? media : null;
5732
5394
  if (this.isMediaLayer()) {
5733
- this.init = { ...defaultMediaQuadLayerInit, ...init };
5395
+ this.init = Object.assign(Object.assign({}, defaultMediaQuadLayerInit), init);
5734
5396
  }
5735
5397
  else {
5736
- this.init = { ...defaultQuadLayerInit, ...init };
5398
+ this.init = Object.assign(Object.assign({}, defaultQuadLayerInit), init);
5737
5399
  }
5738
5400
  this.width = this.init.width;
5739
5401
  this.height = this.init.height;
@@ -5759,7 +5421,6 @@ class XRQuadLayer extends XRCompositionLayerPolyfill {
5759
5421
  if (this.isMediaLayer()) {
5760
5422
  return XRTextureType.texture;
5761
5423
  }
5762
- // override this please
5763
5424
  return this.init.textureType;
5764
5425
  }
5765
5426
  _deferredInitialize() {
@@ -5785,7 +5446,6 @@ class XRQuadLayer extends XRCompositionLayerPolyfill {
5785
5446
  }
5786
5447
  return this._depthStencilTextures;
5787
5448
  }
5788
- // POLYFILL ONLY: Get metadata for textures
5789
5449
  get colorTexturesMeta() {
5790
5450
  if (this.isMediaLayer()) {
5791
5451
  throw new Error('Media layers do not have associated textures');
@@ -5797,27 +5457,12 @@ class XRQuadLayer extends XRCompositionLayerPolyfill {
5797
5457
  }
5798
5458
  }
5799
5459
 
5800
- /**
5801
- * Copyright (c) Facebook, Inc. and its affiliates.
5802
- * Licensed under the Apache License, Version 2.0 (the "License");
5803
- * you may not use this file except in compliance with the License.
5804
- * You may obtain a copy of the License at
5805
- *
5806
- * http://www.apache.org/licenses/LICENSE-2.0
5807
- *
5808
- * Unless required by applicable law or agreed to in writing, software
5809
- * distributed under the License is distributed on an "AS IS" BASIS,
5810
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5811
- * See the License for the specific language governing permissions and
5812
- * limitations under the License.
5813
- */
5814
5460
  class XRMediaBindingPolyfill {
5815
5461
  constructor(session) {
5816
5462
  this.session = session;
5817
5463
  if (this.session.ended) {
5818
5464
  throw new Error('Session has ended');
5819
5465
  }
5820
- // UNIMPLEMENTED: If session is not an immersive session, throw an InvalidStateError and abort these steps.
5821
5466
  }
5822
5467
  createQuadLayer(video, init) {
5823
5468
  if (this.session.ended) {
@@ -5867,7 +5512,6 @@ class XRMediaBindingPolyfill {
5867
5512
  if (!isReferenceSpace(init.space)) {
5868
5513
  throw new Error("Media Equirect layer's space must be of type XRReferenceSpace");
5869
5514
  }
5870
- // UNIMPLEMENTED: If init’s space has a type of "viewer", throw InvalidStateError and abort these steps.
5871
5515
  let layer = new XREquirectLayer(init, video);
5872
5516
  layer.needsRedraw = false;
5873
5517
  layer.initialize(this.session);
@@ -5886,34 +5530,19 @@ class XRMediaBindingPolyfill {
5886
5530
  }
5887
5531
  }
5888
5532
 
5889
- /**
5890
- * Copyright (c) Facebook, Inc. and its affiliates.
5891
- * Licensed under the Apache License, Version 2.0 (the "License");
5892
- * you may not use this file except in compliance with the License.
5893
- * You may obtain a copy of the License at
5894
- *
5895
- * http://www.apache.org/licenses/LICENSE-2.0
5896
- *
5897
- * Unless required by applicable law or agreed to in writing, software
5898
- * distributed under the License is distributed on an "AS IS" BASIS,
5899
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5900
- * See the License for the specific language governing permissions and
5901
- * limitations under the License.
5902
- */
5903
5533
  const defaultXRProjectionLayerInit = {
5904
5534
  textureType: XRTextureType.texture,
5905
5535
  colorFormat: 0x1908,
5906
5536
  depthFormat: 0x1902,
5907
- scaleFactor: 1.5, // More conservative scaling for better performance
5537
+ scaleFactor: 1.0,
5908
5538
  };
5909
5539
  class XRProjectionLayer extends XRCompositionLayerPolyfill {
5910
5540
  constructor(init = defaultXRProjectionLayerInit) {
5911
5541
  super();
5912
- this.init = { ...defaultXRProjectionLayerInit, ...init };
5542
+ this.init = Object.assign(Object.assign({}, defaultXRProjectionLayerInit), init);
5913
5543
  }
5914
5544
  initialize(session, context) {
5915
5545
  super.initialize(session, context);
5916
- // POLYFILL ONLY: initialize layout
5917
5546
  this.initializeIfNeeded();
5918
5547
  let baseLayer = session.getBaseLayer();
5919
5548
  this.textureWidth = baseLayer.framebufferWidth * this.init.scaleFactor;
@@ -5931,38 +5560,20 @@ class XRProjectionLayer extends XRCompositionLayerPolyfill {
5931
5560
  let session = this.session;
5932
5561
  let views = session.internalViews;
5933
5562
  if (!views || views.length === 0) {
5934
- // can't allocate if there are no views
5935
5563
  console.warn("We can't allocate color textures without views");
5936
5564
  return;
5937
5565
  }
5938
5566
  let baseLayer = session.getBaseLayer();
5939
5567
  let numViews = views.length;
5940
- let width;
5568
+ let width = baseLayer.framebufferWidth * this.init.scaleFactor / views.length;
5941
5569
  let height = baseLayer.framebufferHeight * this.init.scaleFactor;
5942
- // For texture-array types, each layer should be full resolution
5943
- // Only divide by views.length for separate textures per view
5944
- if (this.init.textureType === XRTextureType['texture-array']) {
5945
- width = baseLayer.framebufferWidth * this.init.scaleFactor;
5946
- }
5947
- else {
5948
- width =
5949
- (baseLayer.framebufferWidth * this.init.scaleFactor) / views.length;
5950
- }
5951
- if (this.layout === XRLayerLayout.mono ||
5952
- this.layout === XRLayerLayout.default) {
5570
+ if (this.layout === XRLayerLayout.mono || this.layout === XRLayerLayout.default) {
5953
5571
  if (this.init.textureType === XRTextureType['texture-array']) {
5954
- // UNIMPLEMENTED: If the session’s views in the list of views don’t all have the same recommended WebGL texture resolution excluding the secondary views,
5955
- // throw a NotSupportedError and abort these steps.
5956
- // Initialize array with 1 new instance of an opaque texture in the relevant realm of context created as a TEXTURE_2D_ARRAY texture
5957
- // with numViews layers using context, textureFormat, width and height.
5958
5572
  let texture = this._createNewColorTexture(width, height, XRTextureType['texture-array'], this.init.colorFormat, numViews);
5959
5573
  polyFillArray = [texture];
5960
5574
  }
5961
5575
  else {
5962
5576
  for (let view of views) {
5963
- // let texture be a new instance of an opaque texture
5964
- // in the relevant realm of context created as a TEXTURE_2D texture
5965
- // with context, textureFormat, width and height
5966
5577
  let texture = this._createNewColorTexture(width, height, XRTextureType.texture, this.init.colorFormat);
5967
5578
  polyFillArray.push(texture);
5968
5579
  }
@@ -5989,16 +5600,12 @@ class XRProjectionLayer extends XRCompositionLayerPolyfill {
5989
5600
  let session = this.session;
5990
5601
  let views = session.internalViews;
5991
5602
  if (!views || views.length === 0) {
5992
- // can't allocate if there are no views
5993
5603
  return;
5994
5604
  }
5995
- // if textureFormat is a 0 abort steps.
5996
5605
  if (this.init.depthFormat === 0) {
5997
5606
  this._depthStencilTextures = [];
5998
5607
  return;
5999
5608
  }
6000
- // If context is a WebGLRenderingContext and the WEBGL_depth_texture extension
6001
- // is not enabled in context, return array and abort these steps.
6002
5609
  if (this.context instanceof WebGLRenderingContext) {
6003
5610
  let depthExtension = this.context.getExtension('WEBGL_depth_texture');
6004
5611
  if (!depthExtension) {
@@ -6006,9 +5613,6 @@ class XRProjectionLayer extends XRCompositionLayerPolyfill {
6006
5613
  return;
6007
5614
  }
6008
5615
  }
6009
- // UNIMPLEMENTED: If textureFormat is not in the list of depth formats for projection layers,
6010
- // throw a NotSupportedError and abort these steps.
6011
- // INITIALIZE EVERYTHING
6012
5616
  let array = [];
6013
5617
  let polyFillArray = [];
6014
5618
  const createTextureArray = () => {
@@ -6017,38 +5621,18 @@ class XRProjectionLayer extends XRCompositionLayerPolyfill {
6017
5621
  array.push(tex.texture);
6018
5622
  }
6019
5623
  };
6020
- // POLYFILL ONLY: initialize layout if we haven't already
6021
5624
  this.initializeIfNeeded();
6022
5625
  let baseLayer = session.getBaseLayer();
6023
5626
  let numViews = views.length;
6024
- let width;
5627
+ let width = baseLayer.framebufferWidth * this.init.scaleFactor / views.length;
6025
5628
  let height = baseLayer.framebufferHeight * this.init.scaleFactor;
6026
- // For texture-array types, each layer should be full resolution
6027
- // Only divide by views.length for separate textures per view
6028
- if (this.init.textureType === XRTextureType['texture-array']) {
6029
- width = baseLayer.framebufferWidth * this.init.scaleFactor;
6030
- }
6031
- else {
6032
- width =
6033
- (baseLayer.framebufferWidth * this.init.scaleFactor) / views.length;
6034
- }
6035
- if (this.layout === XRLayerLayout.mono ||
6036
- this.layout === XRLayerLayout.default) {
5629
+ if (this.layout === XRLayerLayout.mono || this.layout === XRLayerLayout.default) {
6037
5630
  if (this.init.textureType === XRTextureType['texture-array']) {
6038
- // UNIMPLEMENTED: If the session’s views in the list of views don’t all have the same
6039
- // recommended WebGL texture resolution excluding the secondary views,
6040
- // throw a NotSupportedError and abort these steps.
6041
- // Initialize array with 1 new instance of an opaque texture in the relevant realm of
6042
- // context created as a TEXTURE_2D_ARRAY texture
6043
- // with numViews layers using context, textureFormat, width and height.
6044
5631
  let texture = this._createNewDepthStencilTexture(width, height, this.init.textureType, this.init.depthFormat, numViews);
6045
5632
  polyFillArray = [texture];
6046
5633
  }
6047
5634
  else {
6048
5635
  for (let view of views) {
6049
- // let texture be a new instance of an opaque texture
6050
- // in the relevant realm of context created as a TEXTURE_2D texture
6051
- // with context, textureFormat, width and height
6052
5636
  let texture = this._createNewDepthStencilTexture(width, height, this.init.textureType, this.init.depthFormat);
6053
5637
  polyFillArray.push(texture);
6054
5638
  }
@@ -6091,29 +5675,17 @@ class XRProjectionLayer extends XRCompositionLayerPolyfill {
6091
5675
  return this.init.textureType;
6092
5676
  }
6093
5677
  _deferredInitialize() {
6094
- // initialize layer.isStatic = false
6095
5678
  this.isStatic = false;
6096
- // Some browsers use the depth for reprojection
6097
5679
  this.ignoreDepthValues = false;
6098
- // layer's fixedFoveation should be 0
6099
5680
  this.fixedFoveation = 0;
6100
- // let layout be the result of determining the layout attribute with init’s textureType, context and "default".
6101
5681
  let layout = this.determineLayoutAttribute(this.init.textureType, this.context, XRLayerLayout.default);
6102
- // initialize layer's layout to the created layout
6103
5682
  this.layout = layout;
6104
5683
  this.needsRedraw = true;
6105
- // Let maximum scalefactor be the result of determining the maximum scalefactor with session, context and layout.
6106
5684
  let maxScaleFactor = this.determineMaximumScaleFactor();
6107
- // CONSERVATIVE: Use the specified scale factor without automatic adjustments
6108
- // This respects the user's choice and doesn't automatically scale up.
6109
- let conservativeScaleFactor = Math.min(this.init.scaleFactor, maxScaleFactor);
6110
- // If scaleFactor is larger than maximum scalefactor, set scaleFactor to maximum scalefactor.
6111
- this.init.scaleFactor;
6112
- let scaleFactor = conservativeScaleFactor;
5685
+ let scaleFactor = Math.min(this.init.scaleFactor, maxScaleFactor);
6113
5686
  this.init.scaleFactor = scaleFactor;
6114
5687
  }
6115
5688
  determineMaximumScaleFactor() {
6116
- // Let largest width be the largest width of the recommended WebGL texture resolution from the session's list of views excluding the secondary views.
6117
5689
  let baseLayer = this.session.getBaseLayer(this.context);
6118
5690
  let largestWidth = baseLayer.framebufferWidth;
6119
5691
  let largestHeight = baseLayer.framebufferHeight;
@@ -6125,40 +5697,20 @@ class XRProjectionLayer extends XRCompositionLayerPolyfill {
6125
5697
  }
6126
5698
  let largestViewDimension = Math.max(largestWidth, largestHeight);
6127
5699
  let largestTextureDimension = this.context.getParameter(this.context.MAX_TEXTURE_SIZE);
6128
- let maxScaleFactor = largestTextureDimension / largestViewDimension;
6129
- return maxScaleFactor;
5700
+ return largestTextureDimension / largestViewDimension;
6130
5701
  }
6131
5702
  }
6132
5703
 
6133
- /**
6134
- * Copyright (c) Facebook, Inc. and its affiliates.
6135
- * Licensed under the Apache License, Version 2.0 (the "License");
6136
- * you may not use this file except in compliance with the License.
6137
- * You may obtain a copy of the License at
6138
- *
6139
- * http://www.apache.org/licenses/LICENSE-2.0
6140
- *
6141
- * Unless required by applicable law or agreed to in writing, software
6142
- * distributed under the License is distributed on an "AS IS" BASIS,
6143
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6144
- * See the License for the specific language governing permissions and
6145
- * limitations under the License.
6146
- */
6147
5704
  const initializeViewport = (viewport, texture, layout, offset, numViews) => {
6148
5705
  let x = 0;
6149
5706
  let y = 0;
6150
5707
  let width = texture.width;
6151
5708
  let height = texture.height;
6152
- // If layout is "stereo-left-right":
6153
- // Set viewport’s x to the pixel width of texture multiplied by offset and divided by num.
6154
- // Set viewport’s width to the pixel width of subimage’s texture divided by num.
6155
5709
  if (layout === XRLayerLayout['stereo-left-right']) {
6156
5710
  x = (texture.width * offset) / numViews;
6157
5711
  width = texture.width / numViews;
6158
5712
  }
6159
5713
  else if (layout === XRLayerLayout['stereo-top-bottom']) {
6160
- // Set viewport’s y to the pixel height of texture multiplied by offset and divided by num.
6161
- // Set viewport’s height to the pixel height of subimage’s texture divided by num.
6162
5714
  y = (texture.height * offset) / numViews;
6163
5715
  height = texture.height / numViews;
6164
5716
  }
@@ -6168,59 +5720,31 @@ const initializeViewport = (viewport, texture, layout, offset, numViews) => {
6168
5720
  viewport.height = height;
6169
5721
  };
6170
5722
 
6171
- /**
6172
- * Copyright (c) Facebook, Inc. and its affiliates.
6173
- * Licensed under the Apache License, Version 2.0 (the "License");
6174
- * you may not use this file except in compliance with the License.
6175
- * You may obtain a copy of the License at
6176
- *
6177
- * http://www.apache.org/licenses/LICENSE-2.0
6178
- *
6179
- * Unless required by applicable law or agreed to in writing, software
6180
- * distributed under the License is distributed on an "AS IS" BASIS,
6181
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6182
- * See the License for the specific language governing permissions and
6183
- * limitations under the License.
6184
- */
6185
5723
  const compileShader = (gl, shaderSource, shaderType) => {
6186
- // Create the shader object
6187
5724
  var shader = gl.createShader(shaderType);
6188
- // Set the shader source code.
6189
5725
  gl.shaderSource(shader, shaderSource);
6190
- // Compile the shader
6191
5726
  gl.compileShader(shader);
6192
- // Check if it compiled
6193
5727
  var success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
6194
5728
  if (!success) {
6195
- // Something went wrong during compilation; get the error
6196
5729
  throw 'could not compile shader:' + gl.getShaderInfoLog(shader);
6197
5730
  }
6198
5731
  return shader;
6199
5732
  };
6200
- /**
6201
- * Creates a program from 2 shaders.
6202
- */
6203
5733
  const createProgram = (gl, vertexShader, fragmentShader) => {
6204
- // create a program.
6205
5734
  const program = gl.createProgram();
6206
5735
  const compiledVS = compileShader(gl, vertexShader, gl.VERTEX_SHADER);
6207
5736
  const compiledFS = compileShader(gl, fragmentShader, gl.FRAGMENT_SHADER);
6208
- // attach the shaders.
6209
5737
  gl.attachShader(program, compiledVS);
6210
5738
  gl.attachShader(program, compiledFS);
6211
5739
  gl.deleteShader(compiledVS);
6212
5740
  gl.deleteShader(compiledFS);
6213
- // link the program.
6214
5741
  gl.linkProgram(program);
6215
- // Check if it linked.
6216
5742
  var success = gl.getProgramParameter(program, gl.LINK_STATUS);
6217
5743
  if (!success) {
6218
- // something went wrong with the link
6219
5744
  throw 'program failed to link:' + gl.getProgramInfoLog(program);
6220
5745
  }
6221
5746
  return program;
6222
5747
  };
6223
- // USED FOR PROJECTION RENDERER
6224
5748
  const setRectangle = (gl, x, y, width, height) => {
6225
5749
  var x1 = x;
6226
5750
  var x2 = x + width;
@@ -6228,7 +5752,6 @@ const setRectangle = (gl, x, y, width, height) => {
6228
5752
  var y2 = y + height;
6229
5753
  gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([x1, y1, x2, y1, x1, y2, x1, y2, x2, y1, x2, y2]), gl.DYNAMIC_DRAW);
6230
5754
  };
6231
- // VAO support
6232
5755
  const applyVAOExtension = (gl) => {
6233
5756
  if (gl instanceof WebGL2RenderingContext) {
6234
5757
  return gl;
@@ -6246,23 +5769,8 @@ const applyVAOExtension = (gl) => {
6246
5769
  };
6247
5770
  };
6248
5771
 
6249
- /**
6250
- * Copyright (c) Facebook, Inc. and its affiliates.
6251
- * Licensed under the Apache License, Version 2.0 (the "License");
6252
- * you may not use this file except in compliance with the License.
6253
- * You may obtain a copy of the License at
6254
- *
6255
- * http://www.apache.org/licenses/LICENSE-2.0
6256
- *
6257
- * Unless required by applicable law or agreed to in writing, software
6258
- * distributed under the License is distributed on an "AS IS" BASIS,
6259
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6260
- * See the License for the specific language governing permissions and
6261
- * limitations under the License.
6262
- */
6263
- // template tagging for syntax highlight
6264
- const glsl$2 = (x) => x;
6265
- const vertexShader$2 = glsl$2 `
5772
+ const glsl = (x) => x;
5773
+ const vertexShader = glsl `
6266
5774
  attribute vec2 a_position;
6267
5775
  attribute vec2 a_texCoord;
6268
5776
 
@@ -6285,7 +5793,7 @@ void main() {
6285
5793
  v_texCoord = a_texCoord;
6286
5794
  }
6287
5795
  `;
6288
- const fragmentShader$2 = glsl$2 `
5796
+ const fragmentShader = glsl `
6289
5797
  precision mediump float;
6290
5798
 
6291
5799
  // our texture
@@ -6303,7 +5811,7 @@ class ProjectionRenderer {
6303
5811
  constructor(layer, context) {
6304
5812
  this.gl = context;
6305
5813
  this.layer = layer;
6306
- this.program = createProgram(this.gl, vertexShader$2, fragmentShader$2);
5814
+ this.program = createProgram(this.gl, vertexShader, fragmentShader);
6307
5815
  this.programInfo = {
6308
5816
  attribLocations: {
6309
5817
  a_position: this.gl.getAttribLocation(this.program, 'a_position'),
@@ -6316,14 +5824,12 @@ class ProjectionRenderer {
6316
5824
  let gl = this.gl;
6317
5825
  let baseLayer = session.getBaseLayer();
6318
5826
  gl.viewport(0, 0, baseLayer.framebufferWidth, baseLayer.framebufferHeight);
6319
- // get texture type of layer
6320
5827
  const textureType = this.layer.getTextureType();
6321
5828
  const existingTextureBinding = gl.getParameter(gl.TEXTURE_BINDING_2D);
6322
5829
  const existingActiveTexture = gl.getParameter(gl.ACTIVE_TEXTURE);
6323
5830
  if (textureType === XRTextureType.texture) {
6324
5831
  gl.activeTexture(gl.TEXTURE0);
6325
5832
  gl.bindTexture(gl.TEXTURE_2D, this.layer.colorTextures[0]);
6326
- // Set the parameters so we can render any size image.
6327
5833
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
6328
5834
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
6329
5835
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
@@ -6351,7 +5857,6 @@ This is probably an error with the polyfill itself; please file an issue on Gith
6351
5857
  const existingProgram = gl.getParameter(gl.CURRENT_PROGRAM);
6352
5858
  gl.useProgram(this.program);
6353
5859
  this.vaoGl.bindVertexArray(this.vao);
6354
- // Draw the rectangle.
6355
5860
  var primitiveType = gl.TRIANGLES;
6356
5861
  var offset = 0;
6357
5862
  var count = 6;
@@ -6359,8 +5864,6 @@ This is probably an error with the polyfill itself; please file an issue on Gith
6359
5864
  this.vaoGl.bindVertexArray(null);
6360
5865
  gl.useProgram(existingProgram);
6361
5866
  }
6362
- // this is used only for stereo-left-right and stereo-top-bottom layers, and is used to render
6363
- // a part of a texture to a view.
6364
5867
  _renderInternalStereo(view) {
6365
5868
  if (view.eye === 'none') {
6366
5869
  return this._renderInternal();
@@ -6369,10 +5872,7 @@ This is probably an error with the polyfill itself; please file an issue on Gith
6369
5872
  this.vaoGl.bindVertexArray(this.vao);
6370
5873
  const existingProgram = gl.getParameter(gl.CURRENT_PROGRAM);
6371
5874
  gl.useProgram(this.program);
6372
- // set position array and texture array
6373
- // we have to set the texture buffer data for every eye
6374
5875
  this._setStereoTextureBuffer(view.eye === 'right' ? 1 : 0);
6375
- // Draw the shape
6376
5876
  var primitiveType = gl.TRIANGLES;
6377
5877
  var offset = 0;
6378
5878
  var count = 6;
@@ -6383,29 +5883,23 @@ This is probably an error with the polyfill itself; please file an issue on Gith
6383
5883
  _createVAOs() {
6384
5884
  this._createTextureUVs();
6385
5885
  let gl = this.gl;
6386
- // makes sure that VAOs are usable on both WebGL1 and WebGL2
6387
5886
  this.vaoGl = applyVAOExtension(gl);
6388
- // position
6389
5887
  let positionBuffer = gl.createBuffer();
6390
5888
  this.vao = this.vaoGl.createVertexArray();
6391
5889
  this.vaoGl.bindVertexArray(this.vao);
6392
5890
  gl.enableVertexAttribArray(this.programInfo.attribLocations.a_position);
6393
5891
  gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
6394
5892
  setRectangle(gl, 0, 0, 1.0, 1.0);
6395
- // Tell the position attribute how to get data out of positionBuffer (ARRAY_BUFFER)
6396
- let size = 2; // 2 components per iteration
6397
- let type = gl.FLOAT; // the data is 32bit floats
6398
- let normalize = false; // don't normalize the data
6399
- let stride = 0; // 0 = move forward size * sizeof(type) each iteration to get the next position
6400
- let offset = 0; // start at the beginning of the buffer
5893
+ let size = 2;
5894
+ let type = gl.FLOAT;
5895
+ let normalize = false;
5896
+ let stride = 0;
5897
+ let offset = 0;
6401
5898
  gl.vertexAttribPointer(this.programInfo.attribLocations.a_position, size, type, normalize, stride, offset);
6402
- // textures
6403
5899
  this.texcoordBuffer = gl.createBuffer();
6404
5900
  gl.enableVertexAttribArray(this.programInfo.attribLocations.a_texCoord);
6405
5901
  gl.bindBuffer(gl.ARRAY_BUFFER, this.texcoordBuffer);
6406
5902
  gl.bufferData(gl.ARRAY_BUFFER, this.texturePoints, gl.DYNAMIC_DRAW);
6407
- // we can reset size, type, etc. here, but for projection
6408
- // layers they are the same between texture and position.
6409
5903
  gl.vertexAttribPointer(this.programInfo.attribLocations.a_texCoord, size, type, normalize, stride, offset);
6410
5904
  this.vaoGl.bindVertexArray(null);
6411
5905
  gl.bindBuffer(gl.ARRAY_BUFFER, null);
@@ -6413,23 +5907,31 @@ This is probably an error with the polyfill itself; please file an issue on Gith
6413
5907
  _setStereoTextureBuffer(index) {
6414
5908
  let gl = this.gl;
6415
5909
  gl.enableVertexAttribArray(this.programInfo.attribLocations.a_texCoord);
6416
- // bind the texcoord buffer.
6417
5910
  gl.bindBuffer(gl.ARRAY_BUFFER, this.texcoordBuffer);
6418
5911
  gl.bufferData(gl.ARRAY_BUFFER, this.stereoTexturePoints[index], gl.STATIC_DRAW);
6419
- // Tell the texcoord attribute how to get data out of texcoordBuffer (ARRAY_BUFFER)
6420
- var size = 2; // 2 components per iteration
6421
- var type = gl.FLOAT; // the data is 32bit floats
6422
- var normalize = false; // don't normalize the data
6423
- var stride = 0; // 0 = move forward size * sizeof(type) each iteration to get the next position
6424
- var offset = 0; // start at the beginning of the buffer
5912
+ var size = 2;
5913
+ var type = gl.FLOAT;
5914
+ var normalize = false;
5915
+ var stride = 0;
5916
+ var offset = 0;
6425
5917
  gl.vertexAttribPointer(this.programInfo.attribLocations.a_texCoord, size, type, normalize, stride, offset);
6426
5918
  gl.bindBuffer(gl.ARRAY_BUFFER, null);
6427
5919
  }
6428
5920
  _createTextureUVs() {
6429
5921
  this.texturePoints = new Float32Array([
6430
- 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0,
5922
+ 0.0,
5923
+ 0.0,
5924
+ 1.0,
5925
+ 0.0,
5926
+ 0.0,
5927
+ 1.0,
5928
+ 0.0,
5929
+ 1.0,
5930
+ 1.0,
5931
+ 0.0,
5932
+ 1.0,
5933
+ 1.0,
6431
5934
  ]);
6432
- // calculate stereo layers if needed
6433
5935
  const viewport = {
6434
5936
  x: 0,
6435
5937
  y: 0,
@@ -6444,9 +5946,8 @@ This is probably an error with the polyfill itself; please file an issue on Gith
6444
5946
  this.stereoTexturePoints[1] = this._offsetTextureUVsByRect(this.layer.colorTexturesMeta[0], this.texturePoints, viewport);
6445
5947
  }
6446
5948
  }
6447
- // used in stereo-left-right and stereo-top-down layers to obtain UVs on a part of a texture
6448
5949
  _offsetTextureUVsByRect(texture, inArray, textureRect) {
6449
- textureRect = textureRect ?? {
5950
+ textureRect = textureRect !== null && textureRect !== void 0 ? textureRect : {
6450
5951
  x: 0,
6451
5952
  y: 0,
6452
5953
  width: texture.width,
@@ -6472,7 +5973,7 @@ This is probably an error with the polyfill itself; please file an issue on Gith
6472
5973
  this.layer.layout === XRLayerLayout['stereo-top-bottom']);
6473
5974
  }
6474
5975
  }
6475
- const texArrayVertexShader$1 = glsl$2 `#version 300 es
5976
+ const texArrayVertexShader = glsl `#version 300 es
6476
5977
 
6477
5978
  in vec2 a_position;
6478
5979
  in vec2 a_texCoord;
@@ -6496,7 +5997,7 @@ void main() {
6496
5997
  v_texCoord = a_texCoord;
6497
5998
  }
6498
5999
  `;
6499
- const texArrayFragmentShader$1 = glsl$2 `#version 300 es
6000
+ const texArrayFragmentShader = glsl `#version 300 es
6500
6001
  precision mediump float;
6501
6002
  precision mediump int;
6502
6003
  precision mediump sampler2DArray;
@@ -6514,15 +6015,11 @@ void main() {
6514
6015
  }
6515
6016
 
6516
6017
  `;
6517
- // texture-arrays only exist on webgl2, so we can assume that we can
6518
- // use all the new features
6519
6018
  class ProjectionTextureArrayRenderer extends ProjectionRenderer {
6520
6019
  constructor(layer, context) {
6521
6020
  super(layer, context);
6522
- // recreate program to use texArray shaders
6523
- this.program = createProgram(this.gl, texArrayVertexShader$1, texArrayFragmentShader$1);
6021
+ this.program = createProgram(this.gl, texArrayVertexShader, texArrayFragmentShader);
6524
6022
  this._createVAOs();
6525
- // uniform
6526
6023
  this.u_layerInfo = this.gl.getUniformLocation(this.program, 'u_layer');
6527
6024
  }
6528
6025
  render(session) {
@@ -6532,7 +6029,6 @@ class ProjectionTextureArrayRenderer extends ProjectionRenderer {
6532
6029
  throw new Error('Using texture array projection renderer on a layer without texture array.');
6533
6030
  }
6534
6031
  let baseLayer = session.getBaseLayer();
6535
- // get texture type of layer
6536
6032
  const existingTextureBinding = gl.getParameter(gl.TEXTURE_BINDING_2D_ARRAY);
6537
6033
  gl.bindTexture(gl.TEXTURE_2D_ARRAY, this.layer.colorTextures[0]);
6538
6034
  gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
@@ -6551,7 +6047,6 @@ class ProjectionTextureArrayRenderer extends ProjectionRenderer {
6551
6047
  gl.useProgram(this.program);
6552
6048
  gl.bindVertexArray(this.vao);
6553
6049
  gl.uniform1i(this.u_layerInfo, layer);
6554
- // Draw the rectangle.
6555
6050
  var primitiveType = gl.TRIANGLES;
6556
6051
  var offset = 0;
6557
6052
  var count = 6;
@@ -6569,21 +6064,159 @@ const createProjectionRenderer = (layer, context) => {
6569
6064
  return new ProjectionRenderer(layer, context);
6570
6065
  };
6571
6066
 
6572
- /**
6573
- * Copyright (c) Facebook, Inc. and its affiliates.
6574
- * Licensed under the Apache License, Version 2.0 (the "License");
6575
- * you may not use this file except in compliance with the License.
6576
- * You may obtain a copy of the License at
6577
- *
6578
- * http://www.apache.org/licenses/LICENSE-2.0
6579
- *
6580
- * Unless required by applicable law or agreed to in writing, software
6581
- * distributed under the License is distributed on an "AS IS" BASIS,
6582
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6583
- * See the License for the specific language governing permissions and
6584
- * limitations under the License.
6585
- */
6586
- // template tagging for syntax highlight
6067
+ var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
6068
+ if (!Math.hypot) Math.hypot = function () {
6069
+ var y = 0,
6070
+ i = arguments.length;
6071
+ while (i--) {
6072
+ y += arguments[i] * arguments[i];
6073
+ }
6074
+ return Math.sqrt(y);
6075
+ };
6076
+
6077
+ function create() {
6078
+ var out = new ARRAY_TYPE(16);
6079
+ if (ARRAY_TYPE != Float32Array) {
6080
+ out[1] = 0;
6081
+ out[2] = 0;
6082
+ out[3] = 0;
6083
+ out[4] = 0;
6084
+ out[6] = 0;
6085
+ out[7] = 0;
6086
+ out[8] = 0;
6087
+ out[9] = 0;
6088
+ out[11] = 0;
6089
+ out[12] = 0;
6090
+ out[13] = 0;
6091
+ out[14] = 0;
6092
+ }
6093
+ out[0] = 1;
6094
+ out[5] = 1;
6095
+ out[10] = 1;
6096
+ out[15] = 1;
6097
+ return out;
6098
+ }
6099
+ function multiply(out, a, b) {
6100
+ var a00 = a[0],
6101
+ a01 = a[1],
6102
+ a02 = a[2],
6103
+ a03 = a[3];
6104
+ var a10 = a[4],
6105
+ a11 = a[5],
6106
+ a12 = a[6],
6107
+ a13 = a[7];
6108
+ var a20 = a[8],
6109
+ a21 = a[9],
6110
+ a22 = a[10],
6111
+ a23 = a[11];
6112
+ var a30 = a[12],
6113
+ a31 = a[13],
6114
+ a32 = a[14],
6115
+ a33 = a[15];
6116
+ var b0 = b[0],
6117
+ b1 = b[1],
6118
+ b2 = b[2],
6119
+ b3 = b[3];
6120
+ out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
6121
+ out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
6122
+ out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
6123
+ out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
6124
+ b0 = b[4];
6125
+ b1 = b[5];
6126
+ b2 = b[6];
6127
+ b3 = b[7];
6128
+ out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
6129
+ out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
6130
+ out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
6131
+ out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
6132
+ b0 = b[8];
6133
+ b1 = b[9];
6134
+ b2 = b[10];
6135
+ b3 = b[11];
6136
+ out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
6137
+ out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
6138
+ out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
6139
+ out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
6140
+ b0 = b[12];
6141
+ b1 = b[13];
6142
+ b2 = b[14];
6143
+ b3 = b[15];
6144
+ out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
6145
+ out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
6146
+ out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
6147
+ out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
6148
+ return out;
6149
+ }
6150
+ function fromQuat(out, q) {
6151
+ var x = q[0],
6152
+ y = q[1],
6153
+ z = q[2],
6154
+ w = q[3];
6155
+ var x2 = x + x;
6156
+ var y2 = y + y;
6157
+ var z2 = z + z;
6158
+ var xx = x * x2;
6159
+ var yx = y * x2;
6160
+ var yy = y * y2;
6161
+ var zx = z * x2;
6162
+ var zy = z * y2;
6163
+ var zz = z * z2;
6164
+ var wx = w * x2;
6165
+ var wy = w * y2;
6166
+ var wz = w * z2;
6167
+ out[0] = 1 - yy - zz;
6168
+ out[1] = yx + wz;
6169
+ out[2] = zx - wy;
6170
+ out[3] = 0;
6171
+ out[4] = yx - wz;
6172
+ out[5] = 1 - xx - zz;
6173
+ out[6] = zy + wx;
6174
+ out[7] = 0;
6175
+ out[8] = zx + wy;
6176
+ out[9] = zy - wx;
6177
+ out[10] = 1 - xx - yy;
6178
+ out[11] = 0;
6179
+ out[12] = 0;
6180
+ out[13] = 0;
6181
+ out[14] = 0;
6182
+ out[15] = 1;
6183
+ return out;
6184
+ }
6185
+
6186
+ function create$1() {
6187
+ var out = new ARRAY_TYPE(2);
6188
+ if (ARRAY_TYPE != Float32Array) {
6189
+ out[0] = 0;
6190
+ out[1] = 0;
6191
+ }
6192
+ return out;
6193
+ }
6194
+ (function () {
6195
+ var vec = create$1();
6196
+ return function (a, stride, offset, count, fn, arg) {
6197
+ var i, l;
6198
+ if (!stride) {
6199
+ stride = 2;
6200
+ }
6201
+ if (!offset) {
6202
+ offset = 0;
6203
+ }
6204
+ if (count) {
6205
+ l = Math.min(count * stride + offset, a.length);
6206
+ } else {
6207
+ l = a.length;
6208
+ }
6209
+ for (i = offset; i < l; i += stride) {
6210
+ vec[0] = a[i];
6211
+ vec[1] = a[i + 1];
6212
+ fn(vec, vec, arg);
6213
+ a[i] = vec[0];
6214
+ a[i + 1] = vec[1];
6215
+ }
6216
+ return a;
6217
+ };
6218
+ })();
6219
+
6587
6220
  const glsl$1 = (x) => x;
6588
6221
  const vertexShader$1 = glsl$1 `
6589
6222
  attribute vec4 a_position;
@@ -6618,8 +6251,7 @@ void main() {
6618
6251
  // gl_FragColor = vec4(1.0, 0, 0, 1.0);
6619
6252
  }
6620
6253
  `;
6621
- // shaders used for WebGL 2 texture-array case only
6622
- const texArrayVertexShader = glsl$1 `#version 300 es
6254
+ const texArrayVertexShader$1 = glsl$1 `#version 300 es
6623
6255
 
6624
6256
  in vec4 a_position;
6625
6257
  in vec2 a_texCoord;
@@ -6638,7 +6270,7 @@ void main() {
6638
6270
  v_texCoord = a_texCoord;
6639
6271
  }
6640
6272
  `;
6641
- const texArrayFragmentShader = glsl$1 `#version 300 es
6273
+ const texArrayFragmentShader$1 = glsl$1 `#version 300 es
6642
6274
  precision mediump float;
6643
6275
  precision mediump int;
6644
6276
  precision mediump sampler2DArray;
@@ -6656,7 +6288,6 @@ void main() {
6656
6288
  }
6657
6289
 
6658
6290
  `;
6659
- // used for everything except Projection and Cube layers
6660
6291
  class CompositionLayerRenderer {
6661
6292
  constructor(layer, context) {
6662
6293
  this.usesTextureArrayShaders = false;
@@ -6665,21 +6296,17 @@ class CompositionLayerRenderer {
6665
6296
  this.gl = context;
6666
6297
  this.layer = layer;
6667
6298
  let gl = this.gl;
6668
- this.transformMatrix = create$4();
6669
- // if we are WebGL 2 and texture type is texture-array, we are using
6670
- // the texture array GLES 3.0 shaders
6299
+ this.transformMatrix = create();
6671
6300
  if (context instanceof WebGL2RenderingContext &&
6672
6301
  this.layer.getTextureType() === XRTextureType['texture-array']) {
6673
6302
  this.usesTextureArrayShaders = true;
6674
6303
  }
6675
- // create the program
6676
6304
  if (this.usesTextureArrayShaders) {
6677
- this.program = createProgram(gl, texArrayVertexShader, texArrayFragmentShader);
6305
+ this.program = createProgram(gl, texArrayVertexShader$1, texArrayFragmentShader$1);
6678
6306
  }
6679
6307
  else {
6680
6308
  this.program = createProgram(gl, vertexShader$1, fragmentShader$1);
6681
6309
  }
6682
- // create program info
6683
6310
  this.programInfo = {
6684
6311
  attribLocations: {
6685
6312
  a_position: gl.getAttribLocation(this.program, 'a_position'),
@@ -6703,15 +6330,8 @@ class CompositionLayerRenderer {
6703
6330
  this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.savedVaoState.arrayBuffer);
6704
6331
  this.savedVaoState.vao = this.savedVaoState.arrayBuffer = null;
6705
6332
  }
6706
- /**
6707
- * Initializes the renderer. This should be run in the constructor of derived renderers.
6708
- * The reason why it isn't just in the constructor of the base renderer is because creating
6709
- * geometry may require additional computation in the derived class, which would run after a
6710
- * super() call.
6711
- */
6712
6333
  initialize() {
6713
6334
  let gl = this.gl;
6714
- // create media textures if needed
6715
6335
  if (this.layer.isMediaLayer()) {
6716
6336
  this.mediaTexture = gl.createTexture();
6717
6337
  this.mediaTexturePolyfill = {
@@ -6726,15 +6346,11 @@ class CompositionLayerRenderer {
6726
6346
  gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.layer.media.videoWidth, this.layer.media.videoHeight, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
6727
6347
  gl.bindTexture(gl.TEXTURE_2D, existingTextureBinding);
6728
6348
  }
6729
- // setup geometry and VAO
6730
6349
  this._createVAOs();
6731
6350
  }
6732
6351
  render(session, frame) {
6733
6352
  this.saveVaoState();
6734
6353
  let gl = this.gl;
6735
- // set viewport
6736
- // we already rendered the views into the layer's color textures
6737
- // so we can just render them all into the baselayer
6738
6354
  let baseLayer = session.getBaseLayer();
6739
6355
  let basePose = frame.getViewerPose(session.getReferenceSpace());
6740
6356
  const existingActiveTexture = gl.getParameter(gl.ACTIVE_TEXTURE);
@@ -6749,11 +6365,8 @@ class CompositionLayerRenderer {
6749
6365
  if (this.layer.isMediaLayer()) {
6750
6366
  throw new Error('This should never happen. Media layers should never be created with texture-array');
6751
6367
  }
6752
- // if we're using texture-array, there is always only a single entry in layer.colorTextures
6753
- // and instead we use the layers uniform to render out individual pieces.
6754
6368
  const existingTextureBinding = gl.getParameter(gl.TEXTURE_BINDING_2D_ARRAY);
6755
6369
  gl.bindTexture(gl.TEXTURE_2D_ARRAY, this.layer.colorTextures[0]);
6756
- // generate mips for static layers
6757
6370
  if (this.layer.isStatic) {
6758
6371
  if (this.layer.needsRedraw === true) {
6759
6372
  gl.generateMipmap(gl.TEXTURE_2D_ARRAY);
@@ -6767,16 +6380,12 @@ class CompositionLayerRenderer {
6767
6380
  gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, this.hasMipmap ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR);
6768
6381
  let layer = 0;
6769
6382
  if (this.layer.layout === XRLayerLayout.stereo) {
6770
- // STEREO CASE - we only have multiple layers if we have a stereo layer, in which case
6771
- // the right eye should use layer 1.
6772
6383
  switch (view.eye) {
6773
6384
  case 'right':
6774
6385
  layer = 1;
6775
6386
  break;
6776
6387
  }
6777
6388
  }
6778
- // for stereo-left-right and stereo-top-bottom, we need to update
6779
- // the texture UVs to get the correct slice of texture
6780
6389
  if (this._shouldUseStereoTexturePoints()) {
6781
6390
  this._renderInternalStereo(session, frame, view, layer);
6782
6391
  }
@@ -6789,13 +6398,11 @@ class CompositionLayerRenderer {
6789
6398
  else {
6790
6399
  const existingTextureBinding = gl.getParameter(gl.TEXTURE_BINDING_2D);
6791
6400
  if (this.layer.isMediaLayer()) {
6792
- // we have to bind the media to gl instead!
6793
6401
  gl.bindTexture(gl.TEXTURE_2D, this.mediaTexture);
6794
6402
  gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
6795
6403
  gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, this.layer.media.videoWidth, this.layer.media.videoHeight, gl.RGBA, gl.UNSIGNED_BYTE, this.layer.media);
6796
6404
  }
6797
6405
  else if (this.layer.layout === XRLayerLayout.stereo) {
6798
- // STEREO CASE - we have to pull out the multiple textures from the texture array
6799
6406
  switch (view.eye) {
6800
6407
  case 'right':
6801
6408
  gl.bindTexture(gl.TEXTURE_2D, this.layer.colorTextures[1]);
@@ -6805,10 +6412,8 @@ class CompositionLayerRenderer {
6805
6412
  }
6806
6413
  }
6807
6414
  else {
6808
- // for mono and split-screen stereo, we only have the one texture
6809
6415
  gl.bindTexture(gl.TEXTURE_2D, this.layer.colorTextures[0]);
6810
6416
  }
6811
- // generate mips for static layers
6812
6417
  if (this.layer.isStatic) {
6813
6418
  if (this.layer.needsRedraw === true) {
6814
6419
  gl.generateMipmap(gl.TEXTURE_2D);
@@ -6818,13 +6423,10 @@ class CompositionLayerRenderer {
6818
6423
  else {
6819
6424
  this.hasMipmap = this.layer.mipLevels > 0;
6820
6425
  }
6821
- // Set the parameters so we can render any size image.
6822
6426
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
6823
6427
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
6824
6428
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, this.hasMipmap ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR);
6825
6429
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, this.hasMipmap ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR);
6826
- // for stereo-left-right and stereo-top-bottom, we need to update
6827
- // the texture UVs to get the correct slice of texture
6828
6430
  if (this._shouldUseStereoTexturePoints()) {
6829
6431
  this._renderInternalStereo(session, frame, view);
6830
6432
  }
@@ -6837,19 +6439,14 @@ class CompositionLayerRenderer {
6837
6439
  }
6838
6440
  this.restoreVaoState();
6839
6441
  }
6840
- // override this to set position values!
6841
6442
  createPositionPoints() {
6842
6443
  return new Float32Array([]);
6843
6444
  }
6844
- // override this to set texture coords!
6845
6445
  createTextureUVs() {
6846
6446
  return new Float32Array([]);
6847
6447
  }
6848
- // STEREO RENDERING FUNCTIONS
6849
- ////////////////////////////////
6850
- // used in stereo-left-right and stereo-top-down layers to obtain UVs on a part of a texture
6851
6448
  _offsetTextureUVsByRect(texture, inArray, textureRect) {
6852
- textureRect = textureRect ?? {
6449
+ textureRect = textureRect !== null && textureRect !== void 0 ? textureRect : {
6853
6450
  x: 0,
6854
6451
  y: 0,
6855
6452
  width: texture.width,
@@ -6874,30 +6471,22 @@ class CompositionLayerRenderer {
6874
6471
  return (this.layer.layout === XRLayerLayout['stereo-left-right'] ||
6875
6472
  this.layer.layout === XRLayerLayout['stereo-top-bottom']);
6876
6473
  }
6877
- // NOTE: this does not initialize any data!
6878
- // TODO: this is probably more efficient as a separate shader.
6879
6474
  _setStereoTextureBuffer(index) {
6880
6475
  let gl = this.gl;
6881
6476
  gl.enableVertexAttribArray(this.programInfo.attribLocations.a_texCoord);
6882
- // bind the texcoord buffer.
6883
6477
  gl.bindBuffer(gl.ARRAY_BUFFER, this.texcoordBuffer);
6884
6478
  gl.bufferData(gl.ARRAY_BUFFER, this.stereoTexturePoints[index], gl.STATIC_DRAW);
6885
- // Tell the texcoord attribute how to get data out of texcoordBuffer (ARRAY_BUFFER)
6886
- var size = 2; // 2 components per iteration
6887
- var type = gl.FLOAT; // the data is 32bit floats
6888
- var normalize = false; // don't normalize the data
6889
- var stride = 0; // 0 = move forward size * sizeof(type) each iteration to get the next position
6890
- var offset = 0; // start at the beginning of the buffer
6479
+ var size = 2;
6480
+ var type = gl.FLOAT;
6481
+ var normalize = false;
6482
+ var stride = 0;
6483
+ var offset = 0;
6891
6484
  gl.vertexAttribPointer(this.programInfo.attribLocations.a_texCoord, size, type, normalize, stride, offset);
6892
6485
  gl.bindBuffer(gl.ARRAY_BUFFER, null);
6893
6486
  }
6894
- // INITIALIZATION
6895
- // THESE FUNCTIONS ARE CALLED IN CONSTRUCTOR
6896
- //////////////////////////////////////////////
6897
6487
  _recalculateVertices() {
6898
6488
  this.positionPoints = this.createPositionPoints();
6899
6489
  this.texturePoints = this.createTextureUVs();
6900
- // calculate stereo layers if needed
6901
6490
  const viewport = {
6902
6491
  x: 0,
6903
6492
  y: 0,
@@ -6911,9 +6500,6 @@ class CompositionLayerRenderer {
6911
6500
  this.stereoTexturePoints[0] = this._offsetTextureUVsByRect(this.mediaTexturePolyfill, this.texturePoints, viewport);
6912
6501
  initializeViewport(viewport, this.mediaTexturePolyfill, this.layer.layout, 1, 2);
6913
6502
  this.stereoTexturePoints[1] = this._offsetTextureUVsByRect(this.mediaTexturePolyfill, this.texturePoints, viewport);
6914
- // the texture is expected to be flipped on the y axis, which for top-down stereo causes
6915
- // left-right eye positions to be flipped too. So we fix that by switching the eye location
6916
- // in the texture
6917
6503
  if (this.layer.layout === XRLayerLayout['stereo-top-bottom']) {
6918
6504
  [this.stereoTexturePoints[0], this.stereoTexturePoints[1]] = [
6919
6505
  this.stereoTexturePoints[1],
@@ -6926,9 +6512,6 @@ class CompositionLayerRenderer {
6926
6512
  this.stereoTexturePoints[0] = this._offsetTextureUVsByRect(this.layer.colorTexturesMeta[0], this.texturePoints, viewport);
6927
6513
  initializeViewport(viewport, this.layer.colorTexturesMeta[0], this.layer.layout, 1, 2);
6928
6514
  this.stereoTexturePoints[1] = this._offsetTextureUVsByRect(this.layer.colorTexturesMeta[0], this.texturePoints, viewport);
6929
- // the texture is expected to be flipped on the y axis, which for top-down stereo causes
6930
- // left-right eye positions to be flipped too. So we fix that by switching the eye location
6931
- // in the texture
6932
6515
  if (this.layer.layout === XRLayerLayout['stereo-top-bottom']) {
6933
6516
  [this.stereoTexturePoints[0], this.stereoTexturePoints[1]] = [
6934
6517
  this.stereoTexturePoints[1],
@@ -6940,66 +6523,44 @@ class CompositionLayerRenderer {
6940
6523
  _createVAOs() {
6941
6524
  this._recalculateVertices();
6942
6525
  let gl = this.gl;
6943
- // makes sure that VAOs are usable on both WebGL1 and WebGL2
6944
6526
  this.vaoGl = applyVAOExtension(gl);
6945
- // push vao existing vao state
6946
6527
  this.saveVaoState();
6947
- // position
6948
6528
  let positionBuffer = gl.createBuffer();
6949
6529
  this.vao = this.vaoGl.createVertexArray();
6950
6530
  this.vaoGl.bindVertexArray(this.vao);
6951
- // Turn on the position attribute
6952
6531
  gl.enableVertexAttribArray(this.programInfo.attribLocations.a_position);
6953
- // Bind the position buffer.
6954
6532
  gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
6955
6533
  const positions = this.positionPoints;
6956
6534
  gl.bufferData(gl.ARRAY_BUFFER, positions, gl.STATIC_DRAW);
6957
- // Tell the position attribute how to get data out of positionBuffer (ARRAY_BUFFER)
6958
- var size = 3; // 3 components per iteration
6959
- var type = gl.FLOAT; // the data is 32bit floats
6960
- var normalize = false; // don't normalize the data
6961
- var stride = 0; // 0 = move forward size * sizeof(type) each iteration to get the next position
6962
- var offset = 0; // start at the beginning of the buffer
6535
+ var size = 3;
6536
+ var type = gl.FLOAT;
6537
+ var normalize = false;
6538
+ var stride = 0;
6539
+ var offset = 0;
6963
6540
  gl.vertexAttribPointer(this.programInfo.attribLocations.a_position, size, type, normalize, stride, offset);
6964
- // textures
6965
6541
  gl.enableVertexAttribArray(this.programInfo.attribLocations.a_texCoord);
6966
6542
  this.texcoordBuffer = gl.createBuffer();
6967
- // bind the texcoord buffer.
6968
6543
  gl.bindBuffer(gl.ARRAY_BUFFER, this.texcoordBuffer);
6969
6544
  gl.bufferData(gl.ARRAY_BUFFER, this.texturePoints, gl.STATIC_DRAW);
6970
- // Tell the texcoord attribute how to get data out of texcoordBuffer (ARRAY_BUFFER)
6971
- var size = 2; // 2 components per iteration
6972
- var type = gl.FLOAT; // the data is 32bit floats
6973
- var normalize = false; // don't normalize the data
6974
- var stride = 0; // 0 = move forward size * sizeof(type) each iteration to get the next position
6975
- var offset = 0; // start at the beginning of the buffer
6545
+ var size = 2;
6546
+ var type = gl.FLOAT;
6547
+ var normalize = false;
6548
+ var stride = 0;
6549
+ var offset = 0;
6976
6550
  gl.vertexAttribPointer(this.programInfo.attribLocations.a_texCoord, size, type, normalize, stride, offset);
6977
- // pop vao state
6978
6551
  this.restoreVaoState();
6979
6552
  }
6980
- // RENDERING
6981
- /////////////////
6982
- /**
6983
- * @param frame
6984
- * @param view
6985
- * @param layer only relevant for texture_arrays - used to determine which layer to render from.
6986
- */
6987
6553
  _renderInternal(session, frame, view, layer) {
6988
6554
  let gl = this.gl;
6989
- // Tell it to use our program (pair of shaders)
6990
6555
  const existingProgram = gl.getParameter(gl.CURRENT_PROGRAM);
6991
6556
  gl.useProgram(this.program);
6992
6557
  this.vaoGl.bindVertexArray(this.vao);
6993
- // LAYER
6994
6558
  if (this.usesTextureArrayShaders) {
6995
6559
  gl.uniform1i(this.programInfo.uniformLocations.u_layer, layer);
6996
6560
  }
6997
- // MATRIX
6998
- // set matrix
6999
6561
  this._setTransformMatrix(session, frame, view);
7000
6562
  gl.uniformMatrix4fv(this.programInfo.uniformLocations.u_matrix, false, this.transformMatrix);
7001
6563
  gl.uniformMatrix4fv(this.programInfo.uniformLocations.u_projectionMatrix, false, view.projectionMatrix);
7002
- // Draw the shape
7003
6564
  var primitiveType = gl.TRIANGLES;
7004
6565
  var offset = 0;
7005
6566
  var count = this.positionPoints.length / 3;
@@ -7007,32 +6568,21 @@ class CompositionLayerRenderer {
7007
6568
  this.vaoGl.bindVertexArray(null);
7008
6569
  gl.useProgram(existingProgram);
7009
6570
  }
7010
- // this is used only for stereo-left-right and stereo-top-bottom layers, and is used to render
7011
- // a part of a texture to a view.
7012
6571
  _renderInternalStereo(session, frame, view, layer) {
7013
6572
  if (view.eye === 'none') {
7014
6573
  return this._renderInternal(session, frame, view);
7015
6574
  }
7016
6575
  let gl = this.gl;
7017
6576
  this.vaoGl.bindVertexArray(this.vao);
7018
- // Tell it to use our program (pair of shaders)
7019
6577
  const existingProgram = gl.getParameter(gl.CURRENT_PROGRAM);
7020
6578
  gl.useProgram(this.program);
7021
- // set position array and texture array
7022
- // we have to set the texture buffer data for every eye
7023
6579
  this._setStereoTextureBuffer(view.eye === 'right' ? 1 : 0);
7024
- // LAYER
7025
6580
  if (this.usesTextureArrayShaders) {
7026
6581
  gl.uniform1i(this.programInfo.uniformLocations.u_layer, layer);
7027
6582
  }
7028
- // MATRIX
7029
- // set matrix
7030
6583
  this._setTransformMatrix(session, frame, view);
7031
- // we want the inverse, taken from the explainer:
7032
- // https://immersive-web.github.io/webxr/explainer.html#viewer-tracking-with-webgl
7033
6584
  gl.uniformMatrix4fv(this.programInfo.uniformLocations.u_matrix, false, this.transformMatrix);
7034
6585
  gl.uniformMatrix4fv(this.programInfo.uniformLocations.u_projectionMatrix, false, view.projectionMatrix);
7035
- // Draw the shape
7036
6586
  var primitiveType = gl.TRIANGLES;
7037
6587
  var offset = 0;
7038
6588
  var count = this.positionPoints.length / 3;
@@ -7042,26 +6592,11 @@ class CompositionLayerRenderer {
7042
6592
  }
7043
6593
  _setTransformMatrix(session, frame, view) {
7044
6594
  let objPose = frame.getPose(this.layer.space, session.getReferenceSpace());
7045
- multiply$1(this.transformMatrix, objPose.transform.matrix, this.layer.transform.matrix);
7046
- // see https://developer.mozilla.org/en-US/docs/Web/API/XRView/transform#examples for why we do this.
7047
- multiply$1(this.transformMatrix, view.transform.inverse.matrix, this.transformMatrix);
6595
+ multiply(this.transformMatrix, objPose.transform.matrix, this.layer.transform.matrix);
6596
+ multiply(this.transformMatrix, view.transform.inverse.matrix, this.transformMatrix);
7048
6597
  }
7049
6598
  }
7050
6599
 
7051
- /**
7052
- * Copyright (c) Facebook, Inc. and its affiliates.
7053
- * Licensed under the Apache License, Version 2.0 (the "License");
7054
- * you may not use this file except in compliance with the License.
7055
- * You may obtain a copy of the License at
7056
- *
7057
- * http://www.apache.org/licenses/LICENSE-2.0
7058
- *
7059
- * Unless required by applicable law or agreed to in writing, software
7060
- * distributed under the License is distributed on an "AS IS" BASIS,
7061
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7062
- * See the License for the specific language governing permissions and
7063
- * limitations under the License.
7064
- */
7065
6600
  class QuadRenderer extends CompositionLayerRenderer {
7066
6601
  constructor(layer, context) {
7067
6602
  super(layer, context);
@@ -7072,27 +6607,21 @@ class QuadRenderer extends CompositionLayerRenderer {
7072
6607
  const height = this.layer.height;
7073
6608
  const z = 0;
7074
6609
  const positions = [
7075
- // bottom left
7076
6610
  -width,
7077
6611
  -height,
7078
6612
  z,
7079
- // bottom right
7080
6613
  width,
7081
6614
  -height,
7082
6615
  z,
7083
- // top left
7084
6616
  -width,
7085
6617
  height,
7086
6618
  z,
7087
- // top left
7088
6619
  -width,
7089
6620
  height,
7090
6621
  z,
7091
- // bottom right
7092
6622
  width,
7093
6623
  -height,
7094
6624
  z,
7095
- // top right
7096
6625
  width,
7097
6626
  height,
7098
6627
  z,
@@ -7100,26 +6629,10 @@ class QuadRenderer extends CompositionLayerRenderer {
7100
6629
  return new Float32Array(positions);
7101
6630
  }
7102
6631
  createTextureUVs() {
7103
- return new Float32Array([
7104
- 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0,
7105
- ]);
6632
+ return new Float32Array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0]);
7106
6633
  }
7107
6634
  }
7108
6635
 
7109
- /**
7110
- * Copyright (c) Facebook, Inc. and its affiliates.
7111
- * Licensed under the Apache License, Version 2.0 (the "License");
7112
- * you may not use this file except in compliance with the License.
7113
- * You may obtain a copy of the License at
7114
- *
7115
- * http://www.apache.org/licenses/LICENSE-2.0
7116
- *
7117
- * Unless required by applicable law or agreed to in writing, software
7118
- * distributed under the License is distributed on an "AS IS" BASIS,
7119
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7120
- * See the License for the specific language governing permissions and
7121
- * limitations under the License.
7122
- */
7123
6636
  class CylinderRenderer extends CompositionLayerRenderer {
7124
6637
  constructor(layer, context) {
7125
6638
  super(layer, context);
@@ -7128,41 +6641,31 @@ class CylinderRenderer extends CompositionLayerRenderer {
7128
6641
  }
7129
6642
  createPositionPoints() {
7130
6643
  const positions = [];
7131
- // assume the central point is (0, 0, 0)
7132
6644
  const angle = this.layer.centralAngle;
7133
6645
  const height = this.layer.height;
7134
6646
  const radius = this.layer.radius;
7135
6647
  const radiansPerSegment = angle / this.segments;
7136
6648
  const theta = Math.PI / 2 - angle / 2;
7137
6649
  const unitCirclePositions = [];
7138
- // first point - on the right. We'll eventually have to flip the aray
7139
- const firstUnitPoint = create();
6650
+ const firstUnitPoint = create$1();
7140
6651
  firstUnitPoint[0] = radius * Math.cos(theta);
7141
6652
  firstUnitPoint[1] = -radius * Math.sin(theta);
7142
6653
  unitCirclePositions.push(firstUnitPoint);
7143
6654
  for (let i = 0; i < this.segments; i++) {
7144
- const nextPoint = create();
6655
+ const nextPoint = create$1();
7145
6656
  nextPoint[0] = radius * Math.cos(theta + radiansPerSegment * (i + 1));
7146
6657
  nextPoint[1] = -radius * Math.sin(theta + radiansPerSegment * (i + 1));
7147
6658
  unitCirclePositions.push(nextPoint);
7148
6659
  }
7149
- // flip the array to get the segments on the unit circle
7150
6660
  unitCirclePositions.reverse();
7151
6661
  for (let i = 0; i < this.segments; i++) {
7152
6662
  const u = unitCirclePositions[i];
7153
6663
  const v = unitCirclePositions[i + 1];
7154
- // we need six points per quad:
7155
- // bottom left
7156
6664
  positions.push(u[0], -height / 2, u[1]);
7157
- // bottom right
7158
6665
  positions.push(v[0], -height / 2, v[1]);
7159
- //top left
7160
6666
  positions.push(u[0], height / 2, u[1]);
7161
- //top left
7162
6667
  positions.push(u[0], height / 2, u[1]);
7163
- // bottom right
7164
6668
  positions.push(v[0], -height / 2, v[1]);
7165
- // top right
7166
6669
  positions.push(v[0], height / 2, v[1]);
7167
6670
  }
7168
6671
  return new Float32Array(positions);
@@ -7170,41 +6673,20 @@ class CylinderRenderer extends CompositionLayerRenderer {
7170
6673
  createTextureUVs() {
7171
6674
  let textureUVs = [];
7172
6675
  const texturePercent = 1.0 / this.segments;
7173
- // texture UVs are 2D. We still need 6 vertices per quad.
7174
6676
  for (let i = 0; i < this.segments; i++) {
7175
6677
  let leftX = texturePercent * i;
7176
6678
  let rightX = texturePercent * (i + 1);
7177
- // bottom left
7178
6679
  textureUVs.push(leftX, 0);
7179
- // bottom right
7180
6680
  textureUVs.push(rightX, 0);
7181
- // top left
7182
6681
  textureUVs.push(leftX, 1);
7183
- // top left
7184
6682
  textureUVs.push(leftX, 1);
7185
- // bottom right
7186
6683
  textureUVs.push(rightX, 0);
7187
- // top right
7188
6684
  textureUVs.push(rightX, 1);
7189
6685
  }
7190
6686
  return new Float32Array(textureUVs);
7191
6687
  }
7192
6688
  }
7193
6689
 
7194
- /**
7195
- * Copyright (c) Facebook, Inc. and its affiliates.
7196
- * Licensed under the Apache License, Version 2.0 (the "License");
7197
- * you may not use this file except in compliance with the License.
7198
- * You may obtain a copy of the License at
7199
- *
7200
- * http://www.apache.org/licenses/LICENSE-2.0
7201
- *
7202
- * Unless required by applicable law or agreed to in writing, software
7203
- * distributed under the License is distributed on an "AS IS" BASIS,
7204
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7205
- * See the License for the specific language governing permissions and
7206
- * limitations under the License.
7207
- */
7208
6690
  class EquirectRenderer extends CompositionLayerRenderer {
7209
6691
  constructor(layer, context) {
7210
6692
  super(layer, context);
@@ -7217,25 +6699,18 @@ class EquirectRenderer extends CompositionLayerRenderer {
7217
6699
  if (radius === 0) {
7218
6700
  radius = 25;
7219
6701
  }
7220
- // TODO investigate why a bigger radius doesn't work
7221
6702
  if (radius > 25) {
7222
6703
  radius = 25;
7223
6704
  }
7224
- // this uses spherical coordinates.
7225
- // theta = the 'horizontal' axis, spanning the x and z axes Note that negative z is forward
7226
- // phi = the 'vertical' axis, going up and down the y axis.
7227
6705
  const horizAngle = this.layer.centralHorizontalAngle;
7228
- // phi (vertical) values need to be mapped from 0 to pi, where 0 is the top
7229
- // of the sphere and pi is the bottom. So we do that here...
7230
6706
  const phi1 = this.layer.upperVerticalAngle + Math.PI / 2;
7231
6707
  const phi2 = this.layer.lowerVerticalAngle + Math.PI / 2;
7232
- const startPhi = phi1; // start phi. 0 for top of the sphere
7233
- const endPhi = phi2; // end phi. pi for the bottom of the sphere
7234
- const startTheta = Math.PI / 2 - horizAngle / 2; // start theta. 0 to start at the x axis.
7235
- const endTheta = startTheta + horizAngle; // end theta. 2pi for whole circumference
6708
+ const startPhi = phi1;
6709
+ const endPhi = phi2;
6710
+ const startTheta = Math.PI / 2 - horizAngle / 2;
6711
+ const endTheta = startTheta + horizAngle;
7236
6712
  const phiRange = endPhi - startPhi;
7237
6713
  const thetaRange = endTheta - startTheta;
7238
- // base points
7239
6714
  const basePoints = [];
7240
6715
  for (let y = 0; y <= this.segmentsPerAxis; y++) {
7241
6716
  for (let x = 0; x <= this.segmentsPerAxis; x++) {
@@ -7246,29 +6721,18 @@ class EquirectRenderer extends CompositionLayerRenderer {
7246
6721
  let phi = phiRange * v + startPhi;
7247
6722
  const ux = Math.cos(theta) * Math.sin(phi);
7248
6723
  const uy = Math.cos(phi);
7249
- // this is negative because negative z is forward...
7250
6724
  const uz = -Math.sin(theta) * Math.sin(phi);
7251
6725
  basePoints.push([r * ux, r * uy, r * uz]);
7252
6726
  }
7253
6727
  }
7254
- // now we have all the points of the sphere in...something of an order.
7255
- // let's convert it to positions
7256
- // if we decide to change the x and y, this should be the x
7257
6728
  const numVertsAround = this.segmentsPerAxis + 1;
7258
6729
  for (let x = 0; x < this.segmentsPerAxis; x++) {
7259
6730
  for (let y = 0; y < this.segmentsPerAxis; y++) {
7260
- // create the quad from those four points
7261
- // bottom left
7262
6731
  positions.push(...basePoints[y * numVertsAround + x]);
7263
- // bottom right
7264
6732
  positions.push(...basePoints[y * numVertsAround + x + 1]);
7265
- //top left
7266
6733
  positions.push(...basePoints[(y + 1) * numVertsAround + x]);
7267
- //top left
7268
6734
  positions.push(...basePoints[(y + 1) * numVertsAround + x]);
7269
- // bottom right
7270
6735
  positions.push(...basePoints[y * numVertsAround + x + 1]);
7271
- // top right
7272
6736
  positions.push(...basePoints[(y + 1) * numVertsAround + x + 1]);
7273
6737
  }
7274
6738
  }
@@ -7287,17 +6751,11 @@ class EquirectRenderer extends CompositionLayerRenderer {
7287
6751
  const numVertsAround = this.segmentsPerAxis + 1;
7288
6752
  for (let x = 0; x < this.segmentsPerAxis; x++) {
7289
6753
  for (let y = 0; y < this.segmentsPerAxis; y++) {
7290
- // bottom left
7291
6754
  triUVs.push(...baseUVs[y * numVertsAround + x]);
7292
- // bottom right
7293
6755
  triUVs.push(...baseUVs[y * numVertsAround + x + 1]);
7294
- //top left
7295
6756
  triUVs.push(...baseUVs[(y + 1) * numVertsAround + x]);
7296
- //top left
7297
6757
  triUVs.push(...baseUVs[(y + 1) * numVertsAround + x]);
7298
- // bottom right
7299
6758
  triUVs.push(...baseUVs[y * numVertsAround + x + 1]);
7300
- // top right
7301
6759
  triUVs.push(...baseUVs[(y + 1) * numVertsAround + x + 1]);
7302
6760
  }
7303
6761
  }
@@ -7305,28 +6763,14 @@ class EquirectRenderer extends CompositionLayerRenderer {
7305
6763
  }
7306
6764
  }
7307
6765
 
7308
- /**
7309
- * Copyright (c) Facebook, Inc. and its affiliates.
7310
- * Licensed under the Apache License, Version 2.0 (the "License");
7311
- * you may not use this file except in compliance with the License.
7312
- * You may obtain a copy of the License at
7313
- *
7314
- * http://www.apache.org/licenses/LICENSE-2.0
7315
- *
7316
- * Unless required by applicable law or agreed to in writing, software
7317
- * distributed under the License is distributed on an "AS IS" BASIS,
7318
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7319
- * See the License for the specific language governing permissions and
7320
- * limitations under the License.
7321
- */
7322
6766
  const defaultCubeLayerInit = {
7323
6767
  colorFormat: 0x1908,
7324
6768
  mipLevels: 1,
7325
6769
  layout: XRLayerLayout.mono,
7326
6770
  isStatic: false,
7327
- space: null, // this is required
7328
- viewPixelHeight: 0, // this is required
7329
- viewPixelWidth: 0, // this is required
6771
+ space: null,
6772
+ viewPixelHeight: 0,
6773
+ viewPixelWidth: 0,
7330
6774
  };
7331
6775
  class XRCubeLayer extends XRCompositionLayerPolyfill {
7332
6776
  constructor(init = defaultCubeLayerInit) {
@@ -7334,8 +6778,7 @@ class XRCubeLayer extends XRCompositionLayerPolyfill {
7334
6778
  if (!isReferenceSpace(init.space)) {
7335
6779
  throw new TypeError("XRCubeLayer's space needs to be an XRReferenceSpace");
7336
6780
  }
7337
- // UNIMPLEMENTED: if init.space has a type of "viewer", throw TypeError and abort these steps
7338
- this.init = { ...defaultCubeLayerInit, ...init };
6781
+ this.init = Object.assign(Object.assign({}, defaultCubeLayerInit), init);
7339
6782
  this.space = this.init.space;
7340
6783
  this.isStatic = this.init.isStatic;
7341
6784
  if (this.init.orientation) {
@@ -7380,8 +6823,6 @@ class XRCubeLayer extends XRCompositionLayerPolyfill {
7380
6823
  if (!this.init.depthFormat) {
7381
6824
  return;
7382
6825
  }
7383
- // If context is a WebGLRenderingContext and the WEBGL_depth_texture extension
7384
- // is not enabled in context, throw TypeError
7385
6826
  if (this.context instanceof WebGLRenderingContext) {
7386
6827
  let depthExtension = this.context.getExtension('WEBGL_depth_texture');
7387
6828
  if (!depthExtension) {
@@ -7412,7 +6853,6 @@ class XRCubeLayer extends XRCompositionLayerPolyfill {
7412
6853
  };
7413
6854
  const existingTextureBinding = this.context.getParameter(this.context.TEXTURE_BINDING_CUBE_MAP);
7414
6855
  this.context.bindTexture(this.context.TEXTURE_CUBE_MAP, texture);
7415
- // initialize size for all the sides of the cubemap
7416
6856
  for (let i = 0; i < 6; i++) {
7417
6857
  this.context.texImage2D(this.context.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, textureMeta.textureFormat, textureMeta.width, textureMeta.height, 0, textureMeta.textureFormat, this.context.UNSIGNED_BYTE, null);
7418
6858
  }
@@ -7431,8 +6871,6 @@ class XRCubeLayer extends XRCompositionLayerPolyfill {
7431
6871
  };
7432
6872
  const existingTextureBinding = this.context.getParameter(this.context.TEXTURE_BINDING_CUBE_MAP);
7433
6873
  this.context.bindTexture(this.context.TEXTURE_CUBE_MAP, texture);
7434
- // DEPTH_COMPONENT is not a valid internalFormat in WebGL2.
7435
- // https://stackoverflow.com/a/60703526
7436
6874
  let internalFormat = this.init.depthFormat;
7437
6875
  if (this.context instanceof WebGL2RenderingContext) {
7438
6876
  if (internalFormat === this.context.DEPTH_COMPONENT) {
@@ -7442,7 +6880,6 @@ class XRCubeLayer extends XRCompositionLayerPolyfill {
7442
6880
  internalFormat = this.context.DEPTH24_STENCIL8;
7443
6881
  }
7444
6882
  }
7445
- // initialize size for all the sides of the cubemap
7446
6883
  for (let i = 0; i < 6; i++) {
7447
6884
  this.context.texImage2D(this.context.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internalFormat, textureMeta.width, textureMeta.height, 0, textureMeta.textureFormat, this.context.UNSIGNED_INT, null);
7448
6885
  }
@@ -7454,23 +6891,8 @@ class XRCubeLayer extends XRCompositionLayerPolyfill {
7454
6891
  }
7455
6892
  }
7456
6893
 
7457
- /**
7458
- * Copyright (c) Facebook, Inc. and its affiliates.
7459
- * Licensed under the Apache License, Version 2.0 (the "License");
7460
- * you may not use this file except in compliance with the License.
7461
- * You may obtain a copy of the License at
7462
- *
7463
- * http://www.apache.org/licenses/LICENSE-2.0
7464
- *
7465
- * Unless required by applicable law or agreed to in writing, software
7466
- * distributed under the License is distributed on an "AS IS" BASIS,
7467
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7468
- * See the License for the specific language governing permissions and
7469
- * limitations under the License.
7470
- */
7471
- // template tagging for syntax highlight
7472
- const glsl = (x) => x;
7473
- const vertexShader = glsl `
6894
+ const glsl$2 = (x) => x;
6895
+ const vertexShader$2 = glsl$2 `
7474
6896
  attribute vec4 a_position;
7475
6897
  uniform mat4 u_projectionMatrix;
7476
6898
  uniform mat4 u_matrix;
@@ -7482,7 +6904,7 @@ void main() {
7482
6904
  v_normal = normalize(a_position.xyz);
7483
6905
  }
7484
6906
  `;
7485
- const fragmentShader = glsl `
6907
+ const fragmentShader$2 = glsl$2 `
7486
6908
  precision mediump float;
7487
6909
 
7488
6910
  varying vec3 v_normal;
@@ -7493,18 +6915,14 @@ void main() {
7493
6915
  gl_FragColor = textureCube(u_texture, normalize(v_normal));
7494
6916
  }
7495
6917
  `;
7496
- // see https://webglfundamentals.org/webgl/lessons/webgl-cube-maps.html
7497
- // and https://github.com/xdsopl/webgl/blob/master/cubemap.html
7498
6918
  class CubeRenderer {
7499
6919
  constructor(layer, gl) {
7500
6920
  this.savedVaoState = { vao: null, arrayBuffer: null };
7501
6921
  this.hasMipmap = false;
7502
6922
  this.layer = layer;
7503
6923
  this.gl = gl;
7504
- this.transformMatrix = create$4();
7505
- // create the program
7506
- this.program = createProgram(gl, vertexShader, fragmentShader);
7507
- // create program info
6924
+ this.transformMatrix = create();
6925
+ this.program = createProgram(gl, vertexShader$2, fragmentShader$2);
7508
6926
  this.programInfo = {
7509
6927
  attribLocations: {
7510
6928
  a_position: gl.getAttribLocation(this.program, 'a_position'),
@@ -7515,7 +6933,6 @@ class CubeRenderer {
7515
6933
  u_projectionMatrix: gl.getUniformLocation(this.program, 'u_projectionMatrix'),
7516
6934
  },
7517
6935
  };
7518
- // setup geometry and VAO
7519
6936
  this._createVAOs();
7520
6937
  }
7521
6938
  saveVaoState() {
@@ -7538,7 +6955,6 @@ class CubeRenderer {
7538
6955
  gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
7539
6956
  gl.activeTexture(gl.TEXTURE0);
7540
6957
  const existingTextureBinding = gl.getParameter(gl.TEXTURE_BINDING_CUBE_MAP);
7541
- // STEREO CASE: 0 is left eye, 1 is right eye
7542
6958
  if (this.layer.layout === XRLayerLayout.stereo) {
7543
6959
  const index = view.eye === 'right' ? 1 : 0;
7544
6960
  gl.bindTexture(gl.TEXTURE_CUBE_MAP, this.layer.colorTextures[index]);
@@ -7546,7 +6962,6 @@ class CubeRenderer {
7546
6962
  else {
7547
6963
  gl.bindTexture(gl.TEXTURE_CUBE_MAP, this.layer.colorTextures[0]);
7548
6964
  }
7549
- // generate mips for static layers
7550
6965
  if (this.layer.isStatic) {
7551
6966
  if (this.layer.needsRedraw === true) {
7552
6967
  gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
@@ -7564,10 +6979,8 @@ class CubeRenderer {
7564
6979
  }
7565
6980
  this.restoreVaoState();
7566
6981
  }
7567
- // override this to set position values!
7568
6982
  createPositionPoints() {
7569
6983
  const w = 0.5;
7570
- // prettier-ignore
7571
6984
  const positions = [
7572
6985
  -w, -w, -w,
7573
6986
  -w, w, -w,
@@ -7613,9 +7026,6 @@ class CubeRenderer {
7613
7026
  const existingProgram = gl.getParameter(gl.CURRENT_PROGRAM);
7614
7027
  gl.useProgram(this.program);
7615
7028
  this.vaoGl.bindVertexArray(this.vao);
7616
- // MATRIX
7617
- // set matrix
7618
- // apply only the orientation of the pose and the layer to the transform matrix.
7619
7029
  fromQuat(this.transformMatrix, [
7620
7030
  orientation.x,
7621
7031
  orientation.y,
@@ -7623,7 +7033,7 @@ class CubeRenderer {
7623
7033
  orientation.w,
7624
7034
  ]);
7625
7035
  if (!this._poseOrientationMatrix) {
7626
- this._poseOrientationMatrix = create$4();
7036
+ this._poseOrientationMatrix = create();
7627
7037
  }
7628
7038
  fromQuat(this._poseOrientationMatrix, [
7629
7039
  view.transform.inverse.orientation.x,
@@ -7631,13 +7041,10 @@ class CubeRenderer {
7631
7041
  view.transform.inverse.orientation.z,
7632
7042
  view.transform.inverse.orientation.w,
7633
7043
  ]);
7634
- multiply$1(this.transformMatrix, this.transformMatrix, this._poseOrientationMatrix);
7044
+ multiply(this.transformMatrix, this.transformMatrix, this._poseOrientationMatrix);
7635
7045
  gl.uniformMatrix4fv(this.programInfo.uniformLocations.u_matrix, false, this.transformMatrix);
7636
7046
  gl.uniformMatrix4fv(this.programInfo.uniformLocations.u_projectionMatrix, false, view.projectionMatrix);
7637
- // TEXTURE
7638
- // Tell the shader to use texture unit 0 for u_texture
7639
7047
  gl.uniform1i(this.programInfo.uniformLocations.u_texture, 0);
7640
- // Draw the shape
7641
7048
  var primitiveType = gl.TRIANGLES;
7642
7049
  var offset = 0;
7643
7050
  var count = this.positionPoints.length / 3;
@@ -7651,46 +7058,25 @@ class CubeRenderer {
7651
7058
  _createVAOs() {
7652
7059
  this._recalculateVertices();
7653
7060
  let gl = this.gl;
7654
- // makes sure that VAOs are usable on both WebGL1 and WebGL2
7655
7061
  this.vaoGl = applyVAOExtension(gl);
7656
7062
  this.saveVaoState();
7657
- // position
7658
7063
  let positionBuffer = gl.createBuffer();
7659
7064
  this.vao = this.vaoGl.createVertexArray();
7660
7065
  this.vaoGl.bindVertexArray(this.vao);
7661
- // Turn on the position attribute
7662
7066
  gl.enableVertexAttribArray(this.programInfo.attribLocations.a_position);
7663
- // Bind the position buffer.
7664
7067
  gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
7665
7068
  const positions = this.positionPoints;
7666
7069
  gl.bufferData(gl.ARRAY_BUFFER, positions, gl.STATIC_DRAW);
7667
- // Tell the position attribute how to get data out of positionBuffer (ARRAY_BUFFER)
7668
- var size = 3; // 3 components per iteration
7669
- var type = gl.FLOAT; // the data is 32bit floats
7670
- var normalize = false; // don't normalize the data
7671
- var stride = 0; // 0 = move forward size * sizeof(type) each iteration to get the next position
7672
- var offset = 0; // start at the beginning of the buffer
7070
+ var size = 3;
7071
+ var type = gl.FLOAT;
7072
+ var normalize = false;
7073
+ var stride = 0;
7074
+ var offset = 0;
7673
7075
  gl.vertexAttribPointer(this.programInfo.attribLocations.a_position, size, type, normalize, stride, offset);
7674
7076
  this.restoreVaoState();
7675
7077
  }
7676
7078
  }
7677
7079
 
7678
- /**
7679
- * Copyright (c) Facebook, Inc. and its affiliates.
7680
- * Licensed under the Apache License, Version 2.0 (the "License");
7681
- * you may not use this file except in compliance with the License.
7682
- * You may obtain a copy of the License at
7683
- *
7684
- * http://www.apache.org/licenses/LICENSE-2.0
7685
- *
7686
- * Unless required by applicable law or agreed to in writing, software
7687
- * distributed under the License is distributed on an "AS IS" BASIS,
7688
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7689
- * See the License for the specific language governing permissions and
7690
- * limitations under the License.
7691
- */
7692
- // type here to avoid trying to include XRWebGLLayer from the webxr package
7693
- // because XRWebGLLayer was defined as a class, not an interface.
7694
7080
  class XRSessionWithLayer {
7695
7081
  constructor() {
7696
7082
  this.mode = 'inline';
@@ -7698,11 +7084,9 @@ class XRSessionWithLayer {
7698
7084
  this.views = [];
7699
7085
  this.initializedViews = false;
7700
7086
  this.isPolyfillActive = false;
7701
- // TASK QUEUE
7702
7087
  this.taskQueue = [];
7703
7088
  }
7704
7089
  requestAnimationFrame(animationFrameCallback) {
7705
- // if we don't have a pose, get the pose
7706
7090
  if (!this.injectedFrameCallback) {
7707
7091
  this.injectedFrameCallback = (time, frame) => {
7708
7092
  let gl = this.context;
@@ -7713,7 +7097,6 @@ class XRSessionWithLayer {
7713
7097
  this.initializedViews = true;
7714
7098
  }
7715
7099
  }
7716
- // Layers MUST be cleared to (0, 0, 0, 0) at the beginning of the frame
7717
7100
  if (this.isPolyfillActive && this.initializedViews) {
7718
7101
  if (!this.tempFramebuffer) {
7719
7102
  this.tempFramebuffer = gl.createFramebuffer();
@@ -7723,30 +7106,15 @@ class XRSessionWithLayer {
7723
7106
  const existingFrameBuffer = gl.getParameter(gl.FRAMEBUFFER_BINDING);
7724
7107
  gl.clearColor(0, 0, 0, 0);
7725
7108
  for (let layer of this.layers) {
7726
- // TODO: spec says all of them should be cleared, but clearing quad layers causes the layer
7727
- // to disappear...
7728
7109
  if (!(layer instanceof XRProjectionLayer)) {
7729
7110
  continue;
7730
7111
  }
7731
- // Skip if layer textures aren't allocated yet
7732
- if (!layer.colorTextures || !layer.colorTexturesMeta || layer.colorTextures.length === 0) {
7733
- continue;
7734
- }
7735
- // clear color textures
7736
7112
  for (let i = 0; i < layer.colorTextures.length; i++) {
7737
7113
  let textureType = layer.colorTexturesMeta[i].type;
7738
- let textureMeta = layer.colorTexturesMeta[i];
7739
7114
  if (textureType === XRTextureType['texture-array']) ;
7740
- else if (textureMeta._autoAntialiasing && textureMeta._msaaFramebuffer) {
7741
- // For MSAA textures, clear the MSAA framebuffer directly
7742
- gl.bindFramebuffer(gl.FRAMEBUFFER, textureMeta._msaaFramebuffer);
7743
- gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
7744
- }
7745
7115
  else {
7746
- // Regular texture clearing (original logic)
7747
7116
  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, layer.colorTextures[i], 0);
7748
- if (layer.depthStencilTextures &&
7749
- i < layer.depthStencilTextures.length) {
7117
+ if (layer.depthStencilTextures && i < layer.depthStencilTextures.length) {
7750
7118
  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, layer.depthStencilTextures[i], 0);
7751
7119
  }
7752
7120
  else {
@@ -7756,18 +7124,11 @@ class XRSessionWithLayer {
7756
7124
  }
7757
7125
  }
7758
7126
  }
7759
- // set framebuffer back before rendering anything
7760
7127
  gl.bindFramebuffer(gl.FRAMEBUFFER, existingFrameBuffer);
7761
7128
  gl.clearColor(existingClearColor[0], existingClearColor[1], existingClearColor[2], existingClearColor[3]);
7762
7129
  }
7763
7130
  animationFrameCallback(time, frame);
7764
- // AUTO-RESOLVE MSAA FRAMEBUFFERS AFTER USER RENDERING
7765
- if (this.isPolyfillActive && this.initializedViews) {
7766
- this._autoResolveMSAAFramebuffers();
7767
- }
7768
- // render the layers
7769
7131
  if (this.isPolyfillActive && this.initializedViews) {
7770
- // store values so we can reset it after our rendering pass.
7771
7132
  let prevBlend = gl.isEnabled(gl.BLEND);
7772
7133
  let prevDepthTest = gl.isEnabled(gl.DEPTH_TEST);
7773
7134
  let prevCullFace = gl.isEnabled(gl.CULL_FACE);
@@ -7776,8 +7137,6 @@ class XRSessionWithLayer {
7776
7137
  gl.bindFramebuffer(gl.FRAMEBUFFER, this.getBaseLayer().framebuffer);
7777
7138
  gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
7778
7139
  gl.clearColor(existingClearColor[0], existingClearColor[1], existingClearColor[2], existingClearColor[3]);
7779
- // you need to enable gl.BLEND for the
7780
- // blend function to operate. And for alpha to multiply.
7781
7140
  gl.enable(gl.BLEND);
7782
7141
  gl.disable(gl.DEPTH_TEST);
7783
7142
  gl.disable(gl.CULL_FACE);
@@ -7786,13 +7145,10 @@ class XRSessionWithLayer {
7786
7145
  let prevBlendDestRGB = gl.getParameter(gl.BLEND_DST_RGB);
7787
7146
  let prevBlendDestAlpha = gl.getParameter(gl.BLEND_DST_ALPHA);
7788
7147
  gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
7789
- // get all layers!
7790
7148
  for (let layer of this.layers) {
7791
7149
  if (!this.renderers) {
7792
7150
  this.renderers = new WeakMap();
7793
7151
  }
7794
- // if it's not a media layer, we need to render a normal WebGL Layer
7795
- // which involves using custom shaders per layer type.
7796
7152
  if (layer instanceof XRProjectionLayer) {
7797
7153
  if (!this.renderers.has(layer)) {
7798
7154
  this.renderers.set(layer, createProjectionRenderer(layer, this.context));
@@ -7829,14 +7185,10 @@ class XRSessionWithLayer {
7829
7185
  renderer.render(this, frame);
7830
7186
  }
7831
7187
  else {
7832
- // XRWebGLLayer
7833
7188
  const webglLayer = layer;
7834
7189
  if (webglLayer.framebuffer === null) {
7835
- // webglLayer is the same as the base layer, so we skip it since
7836
- // we rendered into the framebuffer already.
7837
7190
  continue;
7838
7191
  }
7839
- // TODO: test this, because this is totally untested.
7840
7192
  if (gl instanceof WebGL2RenderingContext) {
7841
7193
  gl.bindFramebuffer(gl.READ_FRAMEBUFFER, webglLayer.framebuffer);
7842
7194
  gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, this.getBaseLayer().framebuffer);
@@ -7847,7 +7199,6 @@ class XRSessionWithLayer {
7847
7199
  }
7848
7200
  }
7849
7201
  }
7850
- // restore previous settings
7851
7202
  if (!prevBlend) {
7852
7203
  gl.disable(gl.BLEND);
7853
7204
  }
@@ -7857,10 +7208,8 @@ class XRSessionWithLayer {
7857
7208
  if (prevCullFace) {
7858
7209
  gl.enable(gl.CULL_FACE);
7859
7210
  }
7860
- // restore previous blendFunc
7861
7211
  gl.blendFuncSeparate(prevBlendSrcRGB, prevBlendDestRGB, prevBlendSrcAlpha, prevBlendDestAlpha);
7862
7212
  gl.bindFramebuffer(gl.FRAMEBUFFER, existingFrameBuffer);
7863
- // run task queue
7864
7213
  while (this.taskQueue.length > 0) {
7865
7214
  const task = this.taskQueue.shift();
7866
7215
  task();
@@ -7870,10 +7219,6 @@ class XRSessionWithLayer {
7870
7219
  }
7871
7220
  this._requestAnimationFrame(this.injectedFrameCallback);
7872
7221
  }
7873
- // An implementation of session.updateRenderState({ layers: [...layers] });
7874
- // that overrides layers and sets the baseLayer to one that is custom created in this
7875
- // polyfilled session, and then adds the contents of the other layers onto that base layer
7876
- // and saves the custom layers as state on the object
7877
7222
  updateRenderState(XRRenderStateInit) {
7878
7223
  this.existingBaseLayer = XRRenderStateInit.baseLayer;
7879
7224
  if (XRRenderStateInit.layers) {
@@ -7882,14 +7227,8 @@ class XRSessionWithLayer {
7882
7227
  if (!this.activeRenderState) {
7883
7228
  this.createActiveRenderState();
7884
7229
  }
7885
- this.activeRenderState = {
7886
- ...this.activeRenderState,
7887
- ...XRRenderStateInit,
7888
- };
7230
+ this.activeRenderState = Object.assign(Object.assign({}, this.activeRenderState), XRRenderStateInit);
7889
7231
  if (!XRRenderStateInit.layers) {
7890
- // no layer information in this renderState, so we don't need to update
7891
- // context or the renderState object before passing it to the underlying
7892
- // updateRenderState function.
7893
7232
  this._updateRenderState(XRRenderStateInit);
7894
7233
  return;
7895
7234
  }
@@ -7907,48 +7246,31 @@ class XRSessionWithLayer {
7907
7246
  const canvas = document.createElement('canvas');
7908
7247
  context = canvas.getContext('webgl2', { xrCompatible: true });
7909
7248
  if (!context) {
7910
- // fallback to webgl 1 if 2 is not supported.
7911
- // the session only creates the context if there are only
7912
- // media layers, so this should work regardless.
7913
7249
  context = canvas.getContext('webgl', { xrCompatible: true });
7914
7250
  }
7915
7251
  if (!context) {
7916
- // we don't support webGL at all...this is a failure case.
7917
- // though, we probably should've errored out long before reaching this.
7918
7252
  throw new Error('No webGL support detected.');
7919
7253
  }
7920
7254
  document.body.appendChild(context.canvas);
7921
- // TODO: Figure out if we actually need to resize the canvas.
7922
7255
  function onResize() {
7923
- context.canvas.width =
7924
- context.canvas.clientWidth * window.devicePixelRatio;
7925
- context.canvas.height =
7926
- context.canvas.clientHeight * window.devicePixelRatio;
7256
+ context.canvas.width = context.canvas.clientWidth * window.devicePixelRatio;
7257
+ context.canvas.height = context.canvas.clientHeight * window.devicePixelRatio;
7927
7258
  }
7928
7259
  window.addEventListener('resize', onResize);
7929
7260
  onResize();
7930
7261
  }
7931
7262
  this.createInternalLayer(context);
7932
7263
  this.isPolyfillActive = true;
7933
- // add the internal layer as the base layer
7934
- this._updateRenderState({
7935
- ...layerRenderStateInit,
7936
- baseLayer: this.internalLayer,
7937
- });
7264
+ this._updateRenderState(Object.assign(Object.assign({}, layerRenderStateInit), { baseLayer: this.internalLayer }));
7938
7265
  }
7939
- // POLYFILL SPECIFIC
7940
- // called on requestSession to make sure polyfilled XRSession has
7941
- // access to some assumed default views.
7942
7266
  initializeSession(mode) {
7943
7267
  this.mode = mode;
7944
- // temporary reference space to grab views
7945
7268
  this
7946
7269
  .requestReferenceSpace('local')
7947
7270
  .then((refSpace) => {
7948
7271
  this.referenceSpace = refSpace;
7949
7272
  })
7950
7273
  .catch((e) => {
7951
- // do nothing.
7952
7274
  });
7953
7275
  this.requestReferenceSpace('viewer').then((viewerSpace) => {
7954
7276
  this.viewerSpace = viewerSpace;
@@ -7956,7 +7278,6 @@ class XRSessionWithLayer {
7956
7278
  }
7957
7279
  getBaseLayer(context) {
7958
7280
  if (!this.internalLayer && !this.existingBaseLayer && context) {
7959
- // TODO: this might be buggy if the context has changed...
7960
7281
  this.createInternalLayer(context);
7961
7282
  }
7962
7283
  return this.internalLayer || this.existingBaseLayer;
@@ -8002,16 +7323,11 @@ class XRSessionWithLayer {
8002
7323
  return this.internalLayer;
8003
7324
  }
8004
7325
  setContext(context) {
8005
- // reset everything that depends on context
8006
7326
  this.context = context;
8007
7327
  this.tempFramebuffer = context.createFramebuffer();
8008
7328
  this.renderers = new WeakMap();
8009
7329
  }
8010
7330
  createActiveRenderState() {
8011
- // this code ensures that we return an object that follows the interface for XRRenderState
8012
- // with the layers array added, regardless of whether we're on device or in emulator
8013
- // since sometimes XRRenderState is a native object, and other times it's a symbol, and
8014
- // other times defined as a plain JS object.
8015
7331
  const _global = getGlobal();
8016
7332
  let prototypeNames = Object.getOwnPropertyNames(_global.XRRenderState.prototype);
8017
7333
  const renderStateClone = {};
@@ -8021,55 +7337,8 @@ class XRSessionWithLayer {
8021
7337
  renderStateClone.layers = [];
8022
7338
  this.activeRenderState = renderStateClone;
8023
7339
  }
8024
- // AUTO-RESOLVE MSAA FRAMEBUFFERS FOR DESKTOP ANTIALIASING
8025
- _autoResolveMSAAFramebuffers() {
8026
- const gl = this.context;
8027
- if (!gl || !(gl instanceof WebGL2RenderingContext)) {
8028
- return;
8029
- }
8030
- // Find all layers that need MSAA resolving
8031
- for (let layer of this.layers) {
8032
- if (layer instanceof XRCompositionLayerPolyfill) {
8033
- // Check each texture meta for auto-antialiasing
8034
- if (layer.colorTexturesMeta) {
8035
- for (let textureMeta of layer.colorTexturesMeta) {
8036
- if (textureMeta._autoAntialiasing &&
8037
- textureMeta._msaaFramebuffer &&
8038
- textureMeta._resolveFramebuffer) {
8039
- try {
8040
- // Resolve MSAA to final texture
8041
- gl.bindFramebuffer(gl.READ_FRAMEBUFFER, textureMeta._msaaFramebuffer);
8042
- gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, textureMeta._resolveFramebuffer);
8043
- gl.blitFramebuffer(0, 0, textureMeta.width, textureMeta.height, 0, 0, textureMeta.width, textureMeta.height, gl.COLOR_BUFFER_BIT, gl.NEAREST);
8044
- }
8045
- catch (error) {
8046
- console.warn('Failed to resolve MSAA framebuffer:', error);
8047
- }
8048
- }
8049
- }
8050
- }
8051
- }
8052
- }
8053
- // Clean up bindings
8054
- gl.bindFramebuffer(gl.READ_FRAMEBUFFER, null);
8055
- gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null);
8056
- }
8057
7340
  }
8058
7341
 
8059
- /**
8060
- * Copyright (c) Facebook, Inc. and its affiliates.
8061
- * Licensed under the Apache License, Version 2.0 (the "License");
8062
- * you may not use this file except in compliance with the License.
8063
- * You may obtain a copy of the License at
8064
- *
8065
- * http://www.apache.org/licenses/LICENSE-2.0
8066
- *
8067
- * Unless required by applicable law or agreed to in writing, software
8068
- * distributed under the License is distributed on an "AS IS" BASIS,
8069
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8070
- * See the License for the specific language governing permissions and
8071
- * limitations under the License.
8072
- */
8073
7342
  class XRWebGLSubImagePolyfill {
8074
7343
  constructor() {
8075
7344
  this.viewport = {
@@ -8081,20 +7350,6 @@ class XRWebGLSubImagePolyfill {
8081
7350
  }
8082
7351
  }
8083
7352
 
8084
- /**
8085
- * Copyright (c) Facebook, Inc. and its affiliates.
8086
- * Licensed under the Apache License, Version 2.0 (the "License");
8087
- * you may not use this file except in compliance with the License.
8088
- * You may obtain a copy of the License at
8089
- *
8090
- * http://www.apache.org/licenses/LICENSE-2.0
8091
- *
8092
- * Unless required by applicable law or agreed to in writing, software
8093
- * distributed under the License is distributed on an "AS IS" BASIS,
8094
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8095
- * See the License for the specific language governing permissions and
8096
- * limitations under the License.
8097
- */
8098
7353
  class XRWebGLBindingPolyfill {
8099
7354
  constructor(session, context) {
8100
7355
  this.session = session;
@@ -8109,13 +7364,7 @@ class XRWebGLBindingPolyfill {
8109
7364
  if (this.context.isContextLost()) {
8110
7365
  throw new Error('context is lost');
8111
7366
  }
8112
- // initialize a composition layer on layer with session and context
8113
7367
  layer.initialize(this.session, this.context);
8114
- // POLYFILL ONLY: all the initialization in between here happens on the XRProjectionLayer object, since some of the steps need to be deferred until
8115
- // the views are available
8116
- // UNIMPLEMENTED: Everything with secondary views. The polyfill ignores them.
8117
- // UNIMPLEMENTED: Allocate and initialize resources compatible with session’s XR device, including GPU accessible memory buffers, as required to support the compositing of layer.
8118
- // UNIMPLEMENTED: If layer’s resources were unable to be created for any reason, throw an OperationError and abort these steps.
8119
7368
  return layer;
8120
7369
  }
8121
7370
  createQuadLayer(init = defaultQuadLayerInit) {
@@ -8130,7 +7379,6 @@ class XRWebGLBindingPolyfill {
8130
7379
  }
8131
7380
  const layer = new XRQuadLayer(init);
8132
7381
  layer.initialize(this.session, this.context);
8133
- // everything else is created in the layer's deferred initialize step.
8134
7382
  return layer;
8135
7383
  }
8136
7384
  createCylinderLayer(init = defaultCylinderLayerInit) {
@@ -8145,7 +7393,6 @@ class XRWebGLBindingPolyfill {
8145
7393
  }
8146
7394
  const layer = new XRCylinderLayer(init);
8147
7395
  layer.initialize(this.session, this.context);
8148
- // everything else is created in the layer's deferred initialize step
8149
7396
  return layer;
8150
7397
  }
8151
7398
  createEquirectLayer(init = defaultEquirectLayerInit) {
@@ -8161,10 +7408,8 @@ class XRWebGLBindingPolyfill {
8161
7408
  if (!isReferenceSpace(init.space)) {
8162
7409
  throw new TypeError('Equirect layer requires an XRReferenceSpace');
8163
7410
  }
8164
- // UNIMPLEMENTED: If init’s space has a type of "viewer", throw TypeError and abort these steps.
8165
7411
  let layer = new XREquirectLayer(init);
8166
7412
  layer.initialize(this.session, this.context);
8167
- // everything else is created in the layer's deferred initialize step
8168
7413
  return layer;
8169
7414
  }
8170
7415
  createCubeLayer(init) {
@@ -8180,19 +7425,14 @@ class XRWebGLBindingPolyfill {
8180
7425
  if (!isReferenceSpace(init.space)) {
8181
7426
  throw new TypeError('XRCubeLayer requires a space of type XRReferenceSpace');
8182
7427
  }
8183
- // UNIMPLEMENTED: If init’s space has a type of "viewer", throw TypeError and abort these steps.
8184
7428
  let layer = new XRCubeLayer(init);
8185
- // set up color and depth textures, which doesn't need to be asynchronous
8186
- // this happens in layer.initialize
8187
7429
  layer.initialize(this.session, this.context);
8188
7430
  return layer;
8189
7431
  }
8190
7432
  getSubImage(layer, frame, eye = 'none') {
8191
- if (layer.isStatic && layer.needsRedraw === false) {
7433
+ if (layer.isStatic && (layer.needsRedraw === false)) {
8192
7434
  throw new Error('Invalid state for subimage creation');
8193
7435
  }
8194
- // if getSubImage was called previously with same binding, layer, and eye, the
8195
- // user agent may return the same subimage as returned by earlier call
8196
7436
  let existingSubImage = this.subImageCache.tryGetCachedSubImage(this.context, layer, eye);
8197
7437
  if (existingSubImage) {
8198
7438
  return existingSubImage;
@@ -8216,9 +7456,6 @@ class XRWebGLBindingPolyfill {
8216
7456
  index = 1;
8217
7457
  }
8218
7458
  }
8219
- // UNIMPLEMENTED: If validate the state of the XRWebGLSubImage creation function with layer and frame is false,
8220
- // throw an InvalidStateError and abort these steps.
8221
- // if layer is created with textureType 'texture-array'
8222
7459
  if (layer.getTextureType() === XRTextureType['texture-array']) {
8223
7460
  subimage.imageIndex = index;
8224
7461
  }
@@ -8226,7 +7463,6 @@ class XRWebGLBindingPolyfill {
8226
7463
  subimage.imageIndex = 0;
8227
7464
  }
8228
7465
  let _textureIndex = 0;
8229
- // initialize colorTexture
8230
7466
  if (layer.getTextureType() === XRTextureType.texture) {
8231
7467
  subimage.colorTexture = layer.colorTextures[index];
8232
7468
  _textureIndex = index;
@@ -8235,12 +7471,6 @@ class XRWebGLBindingPolyfill {
8235
7471
  subimage.colorTexture = layer.colorTextures[0];
8236
7472
  _textureIndex = 0;
8237
7473
  }
8238
- // Add Three.js expected properties for multiview compatibility
8239
- if (subimage.colorTexture && typeof subimage.colorTexture === 'object') {
8240
- subimage.colorTexture.isWebGLMultiviewRenderTarget =
8241
- layer.getTextureType() === XRTextureType['texture-array'];
8242
- }
8243
- // initialize depthStencilTexture
8244
7474
  if (!layer.depthStencilTextures || !layer.depthStencilTextures.length) {
8245
7475
  subimage.depthStencilTexture = null;
8246
7476
  }
@@ -8250,14 +7480,6 @@ class XRWebGLBindingPolyfill {
8250
7480
  else {
8251
7481
  subimage.depthStencilTexture = layer.depthStencilTextures[0];
8252
7482
  }
8253
- // Add Three.js expected properties for multiview compatibility
8254
- if (subimage.depthStencilTexture &&
8255
- typeof subimage.depthStencilTexture === 'object') {
8256
- subimage.depthStencilTexture.isWebGLMultiviewRenderTarget =
8257
- layer.getTextureType() === XRTextureType['texture-array'];
8258
- }
8259
- // Set subimage’s textureWidth to the pixel width of subimage’s colorTexture.
8260
- // Set subimage’s textureHeight to the pixel height of subimage’s colorTexture.
8261
7483
  const layerMeta = layer.colorTexturesMeta[_textureIndex];
8262
7484
  subimage.textureWidth = layerMeta.width;
8263
7485
  subimage.textureHeight = layerMeta.height;
@@ -8266,62 +7488,32 @@ class XRWebGLBindingPolyfill {
8266
7488
  layer.layout === XRLayerLayout['stereo-top-bottom']) {
8267
7489
  viewsPerTexture = 2;
8268
7490
  }
8269
- // Run initialize viewport on subimage's viewport with subimage’s colorTexture, layer’s layout, index and num.
8270
- // https://immersive-web.github.io/layers/#initialize-the-viewport
8271
7491
  initializeViewport(subimage.viewport, layerMeta, layer.layout, index, viewsPerTexture);
8272
- // queue task to set needsRedraw to false
8273
7492
  this.session.queueTask(() => {
8274
7493
  layer.needsRedraw = false;
8275
7494
  });
8276
7495
  this.subImageCache.cacheSubImage(subimage, this.context, layer, eye);
8277
7496
  return subimage;
8278
7497
  }
8279
- // This is mostly used for rendering to projection layers!
8280
- // https://immersive-web.github.io/layers/#dom-xrwebglbinding-getviewsubimage
8281
7498
  getViewSubImage(layer, view) {
8282
- // if getViewSubImage was called previously with same binding, layer, and view, the
8283
- // user agent may return the same subimage as returned by earlier call
8284
7499
  let existingSubImage = this.subImageCache.tryGetCachedViewSubImage(this.context, layer, view);
8285
7500
  if (existingSubImage) {
8286
7501
  return existingSubImage;
8287
7502
  }
8288
7503
  let subimage = new XRWebGLSubImagePolyfill();
8289
- // UNIMPLEMENTED: let frame be the view's frame
8290
- // how do we get that?
8291
7504
  let session = this.session;
8292
7505
  if (!session.internalViews || !session.internalViews.length) {
8293
- console.warn('getViewSubImage called before views are available, returning placeholder');
8294
- // Return a placeholder subimage with safe defaults
8295
- subimage.imageIndex = 0;
8296
- // Create dummy texture objects that won't cause null reference errors
8297
- const dummyColorTexture = {
8298
- isWebGLMultiviewRenderTarget: false
8299
- };
8300
- const dummyDepthTexture = {
8301
- isWebGLMultiviewRenderTarget: false
8302
- };
8303
- subimage.colorTexture = dummyColorTexture;
8304
- subimage.depthStencilTexture = dummyDepthTexture;
8305
- subimage.textureWidth = 1024; // Safe default
8306
- subimage.textureHeight = 1024; // Safe default
8307
- subimage.viewport = { x: 0, y: 0, width: 1024, height: 1024 };
7506
+ console.warn('Tried to get view sub image before we have any views');
8308
7507
  return subimage;
8309
7508
  }
8310
- // UNIMPLEMENTED: If validate the state of the XRWebGLSubImage creation function with layer and frame is false,
8311
- // throw an InvalidStateError and abort these steps.
8312
- // UNIMPLEMENTED: if view's active flag is false, throw InvalidStateError
8313
- // not relevant?
8314
- // let index be the offset in the session's list of views.
8315
7509
  let index = session.getViewIndex(view);
8316
7510
  let _textureIndex = 0;
8317
- // initialize imageIndex
8318
7511
  if (layer.getTextureType() === XRTextureType['texture-array']) {
8319
7512
  subimage.imageIndex = index;
8320
7513
  }
8321
7514
  else {
8322
7515
  subimage.imageIndex = 0;
8323
7516
  }
8324
- // Initialize colorTexture
8325
7517
  if (layer.layout === XRLayerLayout.default &&
8326
7518
  layer.getTextureType() === XRTextureType.texture) {
8327
7519
  subimage.colorTexture = layer.colorTextures[index];
@@ -8331,25 +7523,6 @@ class XRWebGLBindingPolyfill {
8331
7523
  subimage.colorTexture = layer.colorTextures[0];
8332
7524
  _textureIndex = 0;
8333
7525
  }
8334
- // TRANSPARENT MSAA: Use MSAA framebuffer for rendering if available
8335
- const textureMeta = layer.colorTexturesMeta[_textureIndex];
8336
- if (textureMeta._autoAntialiasing && textureMeta._msaaFramebuffer) {
8337
- // For rendering, applications will bind to the MSAA framebuffer
8338
- subimage.framebuffer = textureMeta._msaaFramebuffer;
8339
- // Mark this subimage as needing resolve after rendering
8340
- subimage._needsResolve = true;
8341
- subimage._resolveFromFramebuffer = textureMeta._msaaFramebuffer;
8342
- subimage._resolveToFramebuffer = textureMeta._resolveFramebuffer;
8343
- subimage._textureMeta = textureMeta;
8344
- // The colorTexture still points to the final resolved texture for read operations
8345
- // This maintains API compatibility
8346
- }
8347
- // Add Three.js expected properties for multiview compatibility
8348
- if (subimage.colorTexture && typeof subimage.colorTexture === 'object') {
8349
- subimage.colorTexture.isWebGLMultiviewRenderTarget =
8350
- layer.getTextureType() === XRTextureType['texture-array'];
8351
- }
8352
- // initialize depthStencilTexture
8353
7526
  if (layer.depthStencilTextures.length === 0) {
8354
7527
  subimage.depthStencilTexture = null;
8355
7528
  }
@@ -8360,18 +7533,8 @@ class XRWebGLBindingPolyfill {
8360
7533
  else {
8361
7534
  subimage.depthStencilTexture = layer.depthStencilTextures[0];
8362
7535
  }
8363
- // Add Three.js expected properties for multiview compatibility
8364
- if (subimage.depthStencilTexture &&
8365
- typeof subimage.depthStencilTexture === 'object') {
8366
- subimage.depthStencilTexture.isWebGLMultiviewRenderTarget =
8367
- layer.getTextureType() === XRTextureType['texture-array'];
8368
- }
8369
- // Set subimage’s textureWidth to the pixel width of subimage’s colorTexture.
8370
- // Set subimage’s textureHeight to the pixel height of subimage’s colorTexture.
8371
7536
  subimage.textureWidth = layer.colorTexturesMeta[_textureIndex].width;
8372
7537
  subimage.textureHeight = layer.colorTexturesMeta[_textureIndex].height;
8373
- // Run initialize viewport on subimage's viewport with subimage’s colorTexture, layer’s layout, index and num.
8374
- // https://immersive-web.github.io/layers/#initialize-the-viewport
8375
7538
  initializeViewport(subimage.viewport, layer.colorTexturesMeta[_textureIndex], layer.layout, index, session.internalViews.length);
8376
7539
  layer.needsRedraw = false;
8377
7540
  this.subImageCache.cacheViewSubImage(subimage, this.context, layer, view);
@@ -8409,7 +7572,8 @@ class SubImageCache {
8409
7572
  this.cache.set(context, layerMap);
8410
7573
  }
8411
7574
  tryGetCachedSubImage(context, layer, eye) {
8412
- return this.cache.get(context)?.get(layer)?.get(eye);
7575
+ var _a, _b;
7576
+ return (_b = (_a = this.cache.get(context)) === null || _a === void 0 ? void 0 : _a.get(layer)) === null || _b === void 0 ? void 0 : _b.get(eye);
8413
7577
  }
8414
7578
  cacheViewSubImage(subimage, context, layer, view) {
8415
7579
  let viewMap = new Map();
@@ -8419,56 +7583,22 @@ class SubImageCache {
8419
7583
  this.viewCache.set(context, layerMap);
8420
7584
  }
8421
7585
  tryGetCachedViewSubImage(context, layer, view) {
8422
- return this.viewCache.get(context)?.get(layer)?.get(view);
7586
+ var _a, _b;
7587
+ return (_b = (_a = this.viewCache.get(context)) === null || _a === void 0 ? void 0 : _a.get(layer)) === null || _b === void 0 ? void 0 : _b.get(view);
8423
7588
  }
8424
7589
  }
8425
7590
 
8426
- /**
8427
- * Copyright (c) Facebook, Inc. and its affiliates.
8428
- * Licensed under the Apache License, Version 2.0 (the "License");
8429
- * you may not use this file except in compliance with the License.
8430
- * You may obtain a copy of the License at
8431
- *
8432
- * http://www.apache.org/licenses/LICENSE-2.0
8433
- *
8434
- * Unless required by applicable law or agreed to in writing, software
8435
- * distributed under the License is distributed on an "AS IS" BASIS,
8436
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8437
- * See the License for the specific language governing permissions and
8438
- * limitations under the License.
8439
- */
8440
7591
  const isLayersNativelySupported = (global) => {
8441
7592
  if (!global.navigator.xr) {
8442
7593
  return false;
8443
7594
  }
8444
- // we currently key off of the existence of both
8445
- // XRWebGLBinding and XRMedia binding, because certain browsers
8446
- // may implement one and not the other.
8447
- // If either are missing, we need the whole polyfill, unfortunately;
8448
- // the way that the polyfilled XRSession handles layers assumes that all layers
8449
- // need to be polyfilled.
8450
7595
  if (global.XRMediaBinding && global.XRWebGLBinding) {
8451
7596
  return true;
8452
7597
  }
8453
7598
  return false;
8454
7599
  };
8455
7600
 
8456
- /**
8457
- * Copyright (c) Facebook, Inc. and its affiliates.
8458
- * Licensed under the Apache License, Version 2.0 (the "License");
8459
- * you may not use this file except in compliance with the License.
8460
- * You may obtain a copy of the License at
8461
- *
8462
- * http://www.apache.org/licenses/LICENSE-2.0
8463
- *
8464
- * Unless required by applicable law or agreed to in writing, software
8465
- * distributed under the License is distributed on an "AS IS" BASIS,
8466
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8467
- * See the License for the specific language governing permissions and
8468
- * limitations under the License.
8469
- */
8470
- /// <reference types="webxr" />
8471
- let WebXRLayersPolyfill$1 = class WebXRLayersPolyfill {
7601
+ class WebXRLayersPolyfill {
8472
7602
  constructor() {
8473
7603
  this.injected = false;
8474
7604
  const _global = getGlobal();
@@ -8482,7 +7612,6 @@ let WebXRLayersPolyfill$1 = class WebXRLayersPolyfill {
8482
7612
  console.warn('Polyfill has already been injected...');
8483
7613
  }
8484
7614
  if (isLayersNativelySupported(global)) {
8485
- // we don't need to polyfill anything, so leave things untouched
8486
7615
  return;
8487
7616
  }
8488
7617
  this._polyfillRequiredLayersFeature(global);
@@ -8497,24 +7626,15 @@ let WebXRLayersPolyfill$1 = class WebXRLayersPolyfill {
8497
7626
  global.XRSession.prototype._requestAnimationFrame =
8498
7627
  global.XRSession.prototype.requestAnimationFrame;
8499
7628
  let renderStateGetter = Object.getOwnPropertyDescriptor(global.XRSession.prototype, 'renderState');
8500
- if (renderStateGetter) {
8501
- Object.defineProperty(global.XRSession.prototype, '_renderState', renderStateGetter);
8502
- }
7629
+ Object.defineProperty(global.XRSession.prototype, '_renderState', renderStateGetter);
8503
7630
  let polyfillRenderStateGetter = Object.getOwnPropertyDescriptor(XRSessionWithLayer.prototype, 'renderState');
8504
- if (polyfillRenderStateGetter) {
8505
- Object.defineProperty(global.XRSession.prototype, 'renderState', polyfillRenderStateGetter);
8506
- }
8507
- // this lets us grab all the functions and getters from XRSesssionWithLayer and put them into XRSession
7631
+ Object.defineProperty(global.XRSession.prototype, 'renderState', polyfillRenderStateGetter);
8508
7632
  let prototypeNames = Object.getOwnPropertyNames(XRSessionWithLayer.prototype);
8509
7633
  for (let item of prototypeNames) {
8510
7634
  let propertyDescriptor = Object.getOwnPropertyDescriptor(XRSessionWithLayer.prototype, item);
8511
- if (propertyDescriptor) {
8512
- Object.defineProperty(global.XRSession.prototype, item, propertyDescriptor);
8513
- }
7635
+ Object.defineProperty(global.XRSession.prototype, item, propertyDescriptor);
8514
7636
  }
8515
7637
  }
8516
- // This is a glorious hack to remove the 'layers' string from requiredFeatures so that XRSystem doesn't
8517
- // throw an error when we try to request a session.
8518
7638
  _polyfillRequiredLayersFeature(global) {
8519
7639
  const existingRequestSession = global.navigator.xr.requestSession;
8520
7640
  Object.defineProperty(global.navigator.xr, 'requestSessionInternal', { writable: true });
@@ -8522,14 +7642,12 @@ let WebXRLayersPolyfill$1 = class WebXRLayersPolyfill {
8522
7642
  const newRequestSession = (sessionMode, sessionInit) => {
8523
7643
  const modifiedSessionPromise = (mode, init) => {
8524
7644
  return global.navigator.xr.requestSessionInternal(mode, init).then((session) => {
8525
- // create internal required variables
8526
7645
  Object.assign(session, new XRSessionWithLayer());
8527
7646
  let polyfilledSession = session;
8528
7647
  polyfilledSession.initializeSession(sessionMode);
8529
7648
  return Promise.resolve(polyfilledSession);
8530
7649
  });
8531
7650
  };
8532
- // we don't have to do anything if we aren't in VR or don't require layers
8533
7651
  if (sessionMode !== 'immersive-vr') {
8534
7652
  return modifiedSessionPromise(sessionMode, sessionInit);
8535
7653
  }
@@ -8537,9 +7655,7 @@ let WebXRLayersPolyfill$1 = class WebXRLayersPolyfill {
8537
7655
  return modifiedSessionPromise(sessionMode, sessionInit);
8538
7656
  }
8539
7657
  if (sessionInit.requiredFeatures && sessionInit.requiredFeatures.indexOf('layers') > -1) {
8540
- // create a clone of the sessionInit to avoid mutating it (in case the client wants to inspect it)
8541
- const sessionInitClone = { ...sessionInit };
8542
- // remove layers from the requiredFeatures
7658
+ const sessionInitClone = Object.assign({}, sessionInit);
8543
7659
  const reqFeatures = [...sessionInit.requiredFeatures];
8544
7660
  const layersIndex = reqFeatures.indexOf('layers');
8545
7661
  reqFeatures.splice(layersIndex, 1);
@@ -8551,7 +7667,7 @@ let WebXRLayersPolyfill$1 = class WebXRLayersPolyfill {
8551
7667
  Object.defineProperty(global.navigator.xr, 'requestSession', { writable: true });
8552
7668
  global.navigator.xr.requestSession = newRequestSession;
8553
7669
  }
8554
- };
7670
+ }
8555
7671
 
8556
7672
  /**
8557
7673
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -8632,7 +7748,7 @@ class XRDevice {
8632
7748
  visibilityState: 'visible',
8633
7749
  pendingVisibilityState: null,
8634
7750
  xrSystem: null,
8635
- matrix: create$4(),
7751
+ matrix: create$5(),
8636
7752
  globalSpace,
8637
7753
  viewerSpace,
8638
7754
  viewSpaces,
@@ -8800,7 +7916,7 @@ class XRDevice {
8800
7916
  globalObject['XRInputSourcesChangeEvent'] = XRInputSourcesChangeEvent;
8801
7917
  globalObject['XRReferenceSpaceEvent'] = XRReferenceSpaceEvent;
8802
7918
  if (polyfillLayers) {
8803
- new WebXRLayersPolyfill$1();
7919
+ new WebXRLayersPolyfill();
8804
7920
  }
8805
7921
  else {
8806
7922
  globalObject['XRMediaBinding'] = undefined;
@@ -8926,11 +8042,16 @@ class XRDevice {
8926
8042
  return this[P_DEVICE].name;
8927
8043
  }
8928
8044
  grantOfferedSession() {
8929
- var _a;
8930
- const pSystem = (_a = this[P_DEVICE].xrSystem) === null || _a === void 0 ? void 0 : _a[P_SYSTEM];
8045
+ const xrSystem = this[P_DEVICE].xrSystem;
8046
+ const pSystem = xrSystem === null || xrSystem === void 0 ? void 0 : xrSystem[P_SYSTEM];
8931
8047
  if (pSystem && pSystem.offeredSessionConfig) {
8932
- pSystem.grantSession(pSystem.offeredSessionConfig);
8048
+ const { resolve, reject, mode, options } = pSystem.offeredSessionConfig;
8049
+ // Clear the offered session config first
8933
8050
  pSystem.offeredSessionConfig = undefined;
8051
+ // Use the same requestSession flow to ensure identical behavior
8052
+ xrSystem.requestSession(mode, options)
8053
+ .then(resolve)
8054
+ .catch(reject);
8934
8055
  }
8935
8056
  }
8936
8057
  recenter() {
@@ -9249,7 +8370,7 @@ const metaQuest3 = {
9249
8370
  */
9250
8371
  const compress = (arr) => {
9251
8372
  const out = [];
9252
- arr.forEach((num) => {
8373
+ Array.from(arr).forEach((num) => {
9253
8374
  out.push(parseFloat(num.toFixed(3)));
9254
8375
  });
9255
8376
  return out;
@@ -9272,8 +8393,8 @@ class ActionRecorder {
9272
8393
  const viewerMatrix = (_a = frame.getViewerPose(this[P_ACTION_RECORDER].refSpace)) === null || _a === void 0 ? void 0 : _a.transform.matrix;
9273
8394
  if (!viewerMatrix)
9274
8395
  return;
9275
- const position = getTranslation(create$3(), viewerMatrix);
9276
- const quaternion = getRotation(create$1(), viewerMatrix);
8396
+ const position = getTranslation(create$4(), viewerMatrix);
8397
+ const quaternion = getRotation(create$2(), viewerMatrix);
9277
8398
  const actionFrame = {
9278
8399
  timeStamp,
9279
8400
  position,
@@ -9307,8 +8428,8 @@ class ActionRecorder {
9307
8428
  const schema = this[P_ACTION_RECORDER].schemaMap.get(index);
9308
8429
  const targetRayMatrix = (_a = frame.getPose(inputSource.targetRaySpace, this[P_ACTION_RECORDER].refSpace)) === null || _a === void 0 ? void 0 : _a.transform.matrix;
9309
8430
  if (targetRayMatrix) {
9310
- const targetRayPosition = getTranslation(create$3(), targetRayMatrix);
9311
- const targetRayQuaternion = getRotation(create$1(), targetRayMatrix);
8431
+ const targetRayPosition = getTranslation(create$4(), targetRayMatrix);
8432
+ const targetRayQuaternion = getRotation(create$2(), targetRayMatrix);
9312
8433
  const inputFrame = {
9313
8434
  index,
9314
8435
  targetRayTransform: {
@@ -9319,8 +8440,8 @@ class ActionRecorder {
9319
8440
  if (schema.hasGrip) {
9320
8441
  const gripMatrix = (_b = frame.getPose(inputSource.gripSpace, this[P_ACTION_RECORDER].refSpace)) === null || _b === void 0 ? void 0 : _b.transform.matrix;
9321
8442
  if (gripMatrix) {
9322
- const position = getTranslation(create$3(), gripMatrix);
9323
- const quaternion = getRotation(create$1(), gripMatrix);
8443
+ const position = getTranslation(create$4(), gripMatrix);
8444
+ const quaternion = getRotation(create$2(), gripMatrix);
9324
8445
  inputFrame.gripTransform = {
9325
8446
  position,
9326
8447
  quaternion,
@@ -9339,8 +8460,8 @@ class ActionRecorder {
9339
8460
  for (let offset = 0; offset < 25; offset++) {
9340
8461
  const jointMatrix = this[P_ACTION_RECORDER].jointTransforms.slice(offset * 16, (offset + 1) * 16);
9341
8462
  const radius = this[P_ACTION_RECORDER].jointRadii[offset];
9342
- const position = getTranslation(create$3(), jointMatrix);
9343
- const quaternion = getRotation(create$1(), jointMatrix);
8463
+ const position = getTranslation(create$4(), jointMatrix);
8464
+ const quaternion = getRotation(create$2(), jointMatrix);
9344
8465
  const jointName = jointSpaces[offset].jointName;
9345
8466
  hand[jointName] = { position, quaternion, radius };
9346
8467
  }