super-three 0.157.0 → 0.157.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.
@@ -13,12 +13,16 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
13
13
  const maxSamples = capabilities.maxSamples;
14
14
  const multisampledRTTExt = extensions.has( 'WEBGL_multisampled_render_to_texture' ) ? extensions.get( 'WEBGL_multisampled_render_to_texture' ) : null;
15
15
  const supportsInvalidateFramebuffer = typeof navigator === 'undefined' ? false : /OculusBrowser/g.test( navigator.userAgent );
16
+ const multiviewExt = extensions.has( 'OCULUS_multiview' ) ? extensions.get( 'OCULUS_multiview' ) : null;
16
17
 
17
18
  const _videoTextures = new WeakMap();
18
19
  let _canvas;
19
20
 
20
21
  const _sources = new WeakMap(); // maps WebglTexture objects to instances of Source
21
22
 
23
+ let _deferredUploads = [];
24
+ let _deferTextureUploads = false;
25
+
22
26
  // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
23
27
  // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
24
28
  // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
@@ -486,8 +490,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
486
490
 
487
491
  } else {
488
492
 
489
- uploadTexture( textureProperties, texture, slot );
490
- return;
493
+ if ( uploadTexture( textureProperties, texture, slot ) ) {
494
+
495
+ return;
496
+
497
+ }
491
498
 
492
499
  }
493
500
 
@@ -720,8 +727,45 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
720
727
 
721
728
  }
722
729
 
730
+ function setDeferTextureUploads( deferFlag ) {
731
+
732
+ _deferTextureUploads = deferFlag;
733
+
734
+ }
735
+
736
+ function runDeferredUploads() {
737
+
738
+ const previousDeferSetting = _deferTextureUploads;
739
+ _deferTextureUploads = false;
740
+
741
+ for ( const upload of _deferredUploads ) {
742
+
743
+ uploadTexture( upload.textureProperties, upload.texture, upload.slot );
744
+ upload.texture.isPendingDeferredUpload = false;
745
+
746
+ }
747
+
748
+ _deferredUploads = [];
749
+
750
+ _deferTextureUploads = previousDeferSetting;
751
+
752
+ }
753
+
723
754
  function uploadTexture( textureProperties, texture, slot ) {
724
755
 
756
+ if ( _deferTextureUploads ) {
757
+
758
+ if ( ! texture.isPendingDeferredUpload ) {
759
+
760
+ texture.isPendingDeferredUpload = true;
761
+ _deferredUploads.push( { textureProperties: textureProperties, texture: texture, slot: slot } );
762
+
763
+ }
764
+
765
+ return false;
766
+
767
+ }
768
+
725
769
  let textureType = _gl.TEXTURE_2D;
726
770
 
727
771
  if ( texture.isDataArrayTexture || texture.isCompressedArrayTexture ) textureType = _gl.TEXTURE_2D_ARRAY;
@@ -1138,6 +1182,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1138
1182
  }
1139
1183
 
1140
1184
  textureProperties.__version = texture.version;
1185
+ return true;
1141
1186
 
1142
1187
  }
1143
1188
 
@@ -1367,7 +1412,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1367
1412
  const width = Math.max( 1, renderTarget.width >> level );
1368
1413
  const height = Math.max( 1, renderTarget.height >> level );
1369
1414
 
1370
- if ( textureTarget === _gl.TEXTURE_3D || textureTarget === _gl.TEXTURE_2D_ARRAY ) {
1415
+ if ( renderTarget.isWebGLMultiviewRenderTarget === true ) {
1416
+
1417
+ state.texStorage3D( _gl.TEXTURE_2D_ARRAY, 0, glInternalFormat, renderTarget.width, renderTarget.height, renderTarget.numViews );
1418
+
1419
+ } else if ( textureTarget === _gl.TEXTURE_3D || textureTarget === _gl.TEXTURE_2D_ARRAY ) {
1371
1420
 
1372
1421
  state.texImage3D( textureTarget, level, glInternalFormat, width, height, renderTarget.depth, 0, glFormat, glType, null );
1373
1422
 
@@ -1381,13 +1430,31 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1381
1430
 
1382
1431
  state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
1383
1432
 
1384
- if ( useMultisampledRTT( renderTarget ) ) {
1433
+ const multisampled = useMultisampledRTT( renderTarget );
1385
1434
 
1386
- multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( texture ).__webglTexture, 0, getRenderTargetSamples( renderTarget ) );
1435
+ if ( renderTarget.isWebGLMultiviewRenderTarget === true ) {
1436
+
1437
+ if ( multisampled ) {
1438
+
1439
+ multiviewExt.framebufferTextureMultisampleMultiviewOVR( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get( texture ).__webglTexture, 0, getRenderTargetSamples( renderTarget ), 0, renderTarget.numViews );
1440
+
1441
+ } else {
1442
+
1443
+ multiviewExt.framebufferTextureMultiviewOVR( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get( texture ).__webglTexture, 0, 0, renderTarget.numViews );
1444
+
1445
+ }
1387
1446
 
1388
1447
  } else if ( textureTarget === _gl.TEXTURE_2D || ( textureTarget >= _gl.TEXTURE_CUBE_MAP_POSITIVE_X && textureTarget <= _gl.TEXTURE_CUBE_MAP_NEGATIVE_Z ) ) { // see #24753
1389
1448
 
1390
- _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( texture ).__webglTexture, level );
1449
+ if ( multisampled ) {
1450
+
1451
+ multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( texture ).__webglTexture, 0, getRenderTargetSamples( renderTarget ) );
1452
+
1453
+ } else {
1454
+
1455
+ _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( texture ).__webglTexture, level );
1456
+
1457
+ }
1391
1458
 
1392
1459
  }
1393
1460
 
@@ -1401,7 +1468,59 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1401
1468
 
1402
1469
  _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
1403
1470
 
1404
- if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
1471
+ if ( renderTarget.isWebGLMultiviewRenderTarget === true ) {
1472
+
1473
+ const useMultisample = useMultisampledRTT( renderTarget );
1474
+ const numViews = renderTarget.numViews;
1475
+
1476
+ const depthTexture = renderTarget.depthTexture;
1477
+ let glInternalFormat = _gl.DEPTH_COMPONENT24;
1478
+ let glDepthAttachment = _gl.DEPTH_ATTACHMENT;
1479
+
1480
+ if ( depthTexture && depthTexture.isDepthTexture ) {
1481
+
1482
+ if ( depthTexture.type === FloatType ) {
1483
+
1484
+ glInternalFormat = _gl.DEPTH_COMPONENT32F;
1485
+
1486
+ } else if ( depthTexture.type === UnsignedInt248Type ) {
1487
+
1488
+ glInternalFormat = _gl.DEPTH24_STENCIL8;
1489
+ glDepthAttachment = _gl.DEPTH_STENCIL_ATTACHMENT;
1490
+
1491
+ }
1492
+
1493
+ // we're defaulting to _gl.DEPTH_COMPONENT24 so don't assign here
1494
+ // or else DeepScan will complain
1495
+
1496
+ // else if ( depthTexture.type === UnsignedIntType ) {
1497
+
1498
+ // glInternalFormat = _gl.DEPTH_COMPONENT24;
1499
+
1500
+ // }
1501
+
1502
+ }
1503
+
1504
+ let depthStencilTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
1505
+ if ( depthStencilTexture === undefined ) {
1506
+
1507
+ depthStencilTexture = _gl.createTexture();
1508
+ _gl.bindTexture( _gl.TEXTURE_2D_ARRAY, depthStencilTexture );
1509
+ _gl.texStorage3D( _gl.TEXTURE_2D_ARRAY, 1, glInternalFormat, renderTarget.width, renderTarget.height, numViews );
1510
+
1511
+ }
1512
+
1513
+ if ( useMultisample ) {
1514
+
1515
+ multiviewExt.framebufferTextureMultisampleMultiviewOVR( _gl.FRAMEBUFFER, glDepthAttachment, depthStencilTexture, 0, getRenderTargetSamples( renderTarget ), 0, numViews );
1516
+
1517
+ } else {
1518
+
1519
+ multiviewExt.framebufferTextureMultiviewOVR( _gl.FRAMEBUFFER, glDepthAttachment, depthStencilTexture, 0, 0, numViews );
1520
+
1521
+ }
1522
+
1523
+ } else if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
1405
1524
 
1406
1525
  let glInternalFormat = ( isWebGL2 === true ) ? _gl.DEPTH_COMPONENT24 : _gl.DEPTH_COMPONENT16;
1407
1526
 
@@ -1525,37 +1644,85 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1525
1644
  }
1526
1645
 
1527
1646
  setTexture2D( renderTarget.depthTexture, 0 );
1647
+ if ( renderTarget.depthTexture.image.depth != 1 ) {
1648
+
1649
+ setTexture2DArray( renderTarget.depthTexture, 0 );
1650
+
1651
+ } else {
1652
+
1653
+ setTexture2D( renderTarget.depthTexture, 0 );
1654
+
1655
+ }
1528
1656
 
1529
1657
  const webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
1530
1658
  const samples = getRenderTargetSamples( renderTarget );
1531
1659
 
1532
- if ( renderTarget.depthTexture.format === DepthFormat ) {
1660
+ if ( renderTarget.isWebGLMultiviewRenderTarget === true ) {
1533
1661
 
1534
- if ( useMultisampledRTT( renderTarget ) ) {
1662
+ const useMultisample = useMultisampledRTT( renderTarget );
1663
+ const numViews = renderTarget.numViews;
1535
1664
 
1536
- multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples );
1665
+ if ( renderTarget.depthTexture.format === DepthFormat ) {
1537
1666
 
1538
- } else {
1667
+ if ( useMultisample ) {
1539
1668
 
1540
- _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
1669
+ multiviewExt.framebufferTextureMultisampleMultiviewOVR( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, webglDepthTexture, 0, samples, 0, numViews );
1541
1670
 
1542
- }
1671
+ } else {
1543
1672
 
1544
- } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
1673
+ multiviewExt.framebufferTextureMultiviewOVR( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, webglDepthTexture, 0, 0, numViews );
1674
+
1675
+ }
1676
+
1677
+ } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
1678
+
1679
+ if ( useMultisample ) {
1680
+
1681
+ multiviewExt.framebufferTextureMultisampleMultiviewOVR( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, webglDepthTexture, 0, samples, 0, numViews );
1682
+
1683
+ } else {
1545
1684
 
1546
- if ( useMultisampledRTT( renderTarget ) ) {
1685
+ multiviewExt.framebufferTextureMultiviewOVR( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, webglDepthTexture, 0, 0, numViews );
1547
1686
 
1548
- multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples );
1687
+ }
1549
1688
 
1550
1689
  } else {
1551
1690
 
1552
- _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
1691
+ throw new Error( 'Unknown depthTexture format' );
1553
1692
 
1554
1693
  }
1555
1694
 
1556
1695
  } else {
1557
1696
 
1558
- throw new Error( 'Unknown depthTexture format' );
1697
+ if ( renderTarget.depthTexture.format === DepthFormat ) {
1698
+
1699
+ if ( useMultisampledRTT( renderTarget ) ) {
1700
+
1701
+ multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples );
1702
+
1703
+ } else {
1704
+
1705
+ _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
1706
+
1707
+ }
1708
+
1709
+ } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
1710
+
1711
+ if ( useMultisampledRTT( renderTarget ) ) {
1712
+
1713
+ multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples );
1714
+
1715
+ } else {
1716
+
1717
+ _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
1718
+
1719
+ }
1720
+
1721
+ } else {
1722
+
1723
+ throw new Error( 'Unknown depthTexture format' );
1724
+
1725
+ }
1559
1726
 
1560
1727
  }
1561
1728
 
@@ -1834,6 +2001,12 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1834
2001
 
1835
2002
  }
1836
2003
 
2004
+ if ( renderTarget.isWebGLMultiviewRenderTarget === true ) {
2005
+
2006
+ glTextureType = _gl.TEXTURE_2D_ARRAY;
2007
+
2008
+ }
2009
+
1837
2010
  state.bindTexture( glTextureType, textureProperties.__webglTexture );
1838
2011
  setTextureParameters( glTextureType, texture, supportsMips );
1839
2012
 
@@ -1863,9 +2036,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1863
2036
 
1864
2037
  // Setup depth and stencil buffers
1865
2038
 
1866
- if ( renderTarget.depthBuffer ) {
2039
+ if ( renderTarget.depthBuffer || renderTarget.isWebGLMultiviewRenderTarget === true ) {
1867
2040
 
1868
- setupDepthRenderbuffer( renderTarget );
2041
+ this.setupDepthRenderbuffer( renderTarget );
1869
2042
 
1870
2043
  }
1871
2044
 
@@ -2101,12 +2274,16 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
2101
2274
  this.setTexture3D = setTexture3D;
2102
2275
  this.setTextureCube = setTextureCube;
2103
2276
  this.rebindTextures = rebindTextures;
2277
+ this.uploadTexture = uploadTexture;
2104
2278
  this.setupRenderTarget = setupRenderTarget;
2105
2279
  this.updateRenderTargetMipmap = updateRenderTargetMipmap;
2106
2280
  this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
2281
+ this.setupDepthTexture = setupDepthTexture;
2107
2282
  this.setupDepthRenderbuffer = setupDepthRenderbuffer;
2108
2283
  this.setupFrameBufferTexture = setupFrameBufferTexture;
2109
2284
  this.useMultisampledRTT = useMultisampledRTT;
2285
+ this.runDeferredUploads = runDeferredUploads;
2286
+ this.setDeferTextureUploads = setDeferTextureUploads;
2110
2287
 
2111
2288
  }
2112
2289
 
@@ -5,6 +5,7 @@ import { Vector3 } from '../../math/Vector3.js';
5
5
  import { Vector4 } from '../../math/Vector4.js';
6
6
  import { RAD2DEG } from '../../math/MathUtils.js';
7
7
  import { WebGLAnimation } from '../webgl/WebGLAnimation.js';
8
+ import { WebGLMultiviewRenderTarget } from '../WebGLMultiviewRenderTarget.js';
8
9
  import { WebGLRenderTarget } from '../WebGLRenderTarget.js';
9
10
  import { WebXRController } from './WebXRController.js';
10
11
  import { DepthTexture } from '../../textures/DepthTexture.js';
@@ -12,7 +13,7 @@ import { DepthFormat, DepthStencilFormat, RGBAFormat, UnsignedByteType, Unsigned
12
13
 
13
14
  class WebXRManager extends EventDispatcher {
14
15
 
15
- constructor( renderer, gl ) {
16
+ constructor( renderer, gl, extensions, useMultiview ) {
16
17
 
17
18
  super();
18
19
 
@@ -68,6 +69,7 @@ class WebXRManager extends EventDispatcher {
68
69
  this.enabled = false;
69
70
 
70
71
  this.isPresenting = false;
72
+ this.isMultiview = false;
71
73
 
72
74
  this.getCameraPose = function ( ) {
73
75
 
@@ -311,29 +313,51 @@ class WebXRManager extends EventDispatcher {
311
313
 
312
314
  }
313
315
 
316
+ scope.isMultiview = useMultiview && extensions.has( 'OCULUS_multiview' );
317
+
314
318
  const projectionlayerInit = {
315
319
  colorFormat: gl.RGBA8,
316
320
  depthFormat: glDepthFormat,
317
321
  scaleFactor: framebufferScaleFactor
318
322
  };
319
323
 
324
+ if ( scope.isMultiview ) {
325
+
326
+ projectionlayerInit.textureType = 'texture-array';
327
+
328
+ }
329
+
320
330
  glBinding = new XRWebGLBinding( session, gl );
321
331
 
322
332
  glProjLayer = glBinding.createProjectionLayer( projectionlayerInit );
323
333
 
324
334
  session.updateRenderState( { layers: [ glProjLayer ] } );
325
335
 
326
- newRenderTarget = new WebGLRenderTarget(
327
- glProjLayer.textureWidth,
328
- glProjLayer.textureHeight,
329
- {
330
- format: RGBAFormat,
331
- type: UnsignedByteType,
332
- depthTexture: new DepthTexture( glProjLayer.textureWidth, glProjLayer.textureHeight, depthType, undefined, undefined, undefined, undefined, undefined, undefined, depthFormat ),
333
- stencilBuffer: attributes.stencil,
334
- colorSpace: renderer.outputColorSpace,
335
- samples: attributes.antialias ? 4 : 0
336
- } );
336
+ const renderTargetOptions = {
337
+ format: RGBAFormat,
338
+ type: UnsignedByteType,
339
+ depthTexture: new DepthTexture( glProjLayer.textureWidth, glProjLayer.textureHeight, depthType, undefined, undefined, undefined, undefined, undefined, undefined, depthFormat ),
340
+ stencilBuffer: attributes.stencil,
341
+ colorSpace: renderer.outputColorSpace,
342
+ samples: attributes.antialias ? 4 : 0
343
+ };
344
+
345
+ if ( scope.isMultiview ) {
346
+
347
+ const extension = extensions.get( 'OCULUS_multiview' );
348
+
349
+ this.maxNumViews = gl.getParameter( extension.MAX_VIEWS_OVR );
350
+
351
+ newRenderTarget = new WebGLMultiviewRenderTarget( glProjLayer.textureWidth, glProjLayer.textureHeight, 2, renderTargetOptions );
352
+
353
+ } else {
354
+
355
+ newRenderTarget = new WebGLRenderTarget(
356
+ glProjLayer.textureWidth,
357
+ glProjLayer.textureHeight,
358
+ renderTargetOptions );
359
+
360
+ }
337
361
 
338
362
  const renderTargetProperties = renderer.properties.get( newRenderTarget );
339
363
  renderTargetProperties.__ignoreDepthValues = glProjLayer.ignoreDepthValues;