webXRLayerWrapper.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Wrapper over subclasses of XRLayer.
  3. * @internal
  4. */
  5. export class WebXRLayerWrapper {
  6. /**
  7. * Check if fixed foveation is supported on this device
  8. */
  9. get isFixedFoveationSupported() {
  10. return this.layerType == "XRWebGLLayer" && typeof this.layer.fixedFoveation == "number";
  11. }
  12. /**
  13. * Get the fixed foveation currently set, as specified by the webxr specs
  14. * If this returns null, then fixed foveation is not supported
  15. */
  16. get fixedFoveation() {
  17. if (this.isFixedFoveationSupported) {
  18. return this.layer.fixedFoveation;
  19. }
  20. return null;
  21. }
  22. /**
  23. * Set the fixed foveation to the specified value, as specified by the webxr specs
  24. * This value will be normalized to be between 0 and 1, 1 being max foveation, 0 being no foveation
  25. */
  26. set fixedFoveation(value) {
  27. if (this.isFixedFoveationSupported) {
  28. const val = Math.max(0, Math.min(1, value || 0));
  29. this.layer.fixedFoveation = val;
  30. }
  31. }
  32. /**
  33. * Create a render target provider for the wrapped layer.
  34. * @param xrSessionManager The XR Session Manager
  35. * @returns A new render target texture provider for the wrapped layer.
  36. */
  37. createRenderTargetTextureProvider(xrSessionManager) {
  38. this._rttWrapper = this._createRenderTargetTextureProvider(xrSessionManager);
  39. return this._rttWrapper;
  40. }
  41. dispose() {
  42. if (this._rttWrapper) {
  43. this._rttWrapper.dispose();
  44. this._rttWrapper = null;
  45. }
  46. }
  47. constructor(
  48. /** The width of the layer's framebuffer. */
  49. getWidth,
  50. /** The height of the layer's framebuffer. */
  51. getHeight,
  52. /** The XR layer that this WebXRLayerWrapper wraps. */
  53. layer,
  54. /** The type of XR layer that is being wrapped. */
  55. layerType,
  56. /** Create a render target provider for the wrapped layer. */
  57. _createRenderTargetTextureProvider) {
  58. this.getWidth = getWidth;
  59. this.getHeight = getHeight;
  60. this.layer = layer;
  61. this.layerType = layerType;
  62. this._createRenderTargetTextureProvider = _createRenderTargetTextureProvider;
  63. this._rttWrapper = null;
  64. }
  65. }
  66. //# sourceMappingURL=webXRLayerWrapper.js.map