@luma.gl/webgl 9.0.0-alpha.46 → 9.0.0-alpha.48

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 (88) hide show
  1. package/LICENSE +34 -0
  2. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  3. package/dist/adapter/converters/device-parameters.js +73 -40
  4. package/dist/adapter/converters/device-parameters.js.map +1 -1
  5. package/dist/adapter/converters/sampler-parameters.js +60 -61
  6. package/dist/adapter/converters/sampler-parameters.js.map +1 -1
  7. package/dist/adapter/converters/shader-formats.js +12 -13
  8. package/dist/adapter/converters/shader-formats.js.map +1 -1
  9. package/dist/adapter/converters/texture-formats.js +179 -180
  10. package/dist/adapter/converters/texture-formats.js.map +1 -1
  11. package/dist/adapter/converters/vertex-formats.js +20 -21
  12. package/dist/adapter/converters/vertex-formats.js.map +1 -1
  13. package/dist/adapter/device-helpers/device-features.js +2 -2
  14. package/dist/adapter/device-helpers/device-features.js.map +1 -1
  15. package/dist/adapter/device-helpers/device-limits.js +53 -54
  16. package/dist/adapter/device-helpers/device-limits.js.map +1 -1
  17. package/dist/adapter/device-helpers/get-device-info.d.ts.map +1 -1
  18. package/dist/adapter/device-helpers/get-device-info.js +23 -12
  19. package/dist/adapter/device-helpers/get-device-info.js.map +1 -1
  20. package/dist/adapter/helpers/decode-webgl-types.js +31 -32
  21. package/dist/adapter/helpers/decode-webgl-types.js.map +1 -1
  22. package/dist/adapter/helpers/get-shader-layout.js +29 -30
  23. package/dist/adapter/helpers/get-shader-layout.js.map +1 -1
  24. package/dist/adapter/helpers/parse-shader-compiler-log.d.ts.map +1 -1
  25. package/dist/adapter/helpers/parse-shader-compiler-log.js +16 -4
  26. package/dist/adapter/helpers/parse-shader-compiler-log.js.map +1 -1
  27. package/dist/adapter/helpers/set-uniform.js +40 -41
  28. package/dist/adapter/helpers/set-uniform.js.map +1 -1
  29. package/dist/adapter/helpers/webgl-topology-utils.js +38 -39
  30. package/dist/adapter/helpers/webgl-topology-utils.js.map +1 -1
  31. package/dist/adapter/objects/webgl-renderbuffer.js +5 -6
  32. package/dist/adapter/objects/webgl-renderbuffer.js.map +1 -1
  33. package/dist/adapter/resources/webgl-buffer.js +14 -15
  34. package/dist/adapter/resources/webgl-buffer.js.map +1 -1
  35. package/dist/adapter/resources/webgl-command-buffer.js +25 -26
  36. package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
  37. package/dist/adapter/resources/webgl-framebuffer.js +22 -23
  38. package/dist/adapter/resources/webgl-framebuffer.js.map +1 -1
  39. package/dist/adapter/resources/webgl-render-pass.js +2 -3
  40. package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
  41. package/dist/adapter/resources/webgl-render-pipeline.js +7 -8
  42. package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
  43. package/dist/adapter/resources/webgl-sampler.js +2 -3
  44. package/dist/adapter/resources/webgl-sampler.js.map +1 -1
  45. package/dist/adapter/resources/webgl-shader.js +3 -4
  46. package/dist/adapter/resources/webgl-shader.js.map +1 -1
  47. package/dist/adapter/resources/webgl-texture.js +27 -28
  48. package/dist/adapter/resources/webgl-texture.js.map +1 -1
  49. package/dist/adapter/resources/webgl-transform-feedback.d.ts +5 -11
  50. package/dist/adapter/resources/webgl-transform-feedback.d.ts.map +1 -1
  51. package/dist/adapter/resources/webgl-transform-feedback.js +16 -13
  52. package/dist/adapter/resources/webgl-transform-feedback.js.map +1 -1
  53. package/dist/adapter/resources/webgl-vertex-array.d.ts +2 -2
  54. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
  55. package/dist/adapter/resources/webgl-vertex-array.js +5 -6
  56. package/dist/adapter/resources/webgl-vertex-array.js.map +1 -1
  57. package/dist/adapter/webgl-device.js.map +1 -1
  58. package/dist/classic/accessor.js +4 -5
  59. package/dist/classic/accessor.js.map +1 -1
  60. package/dist/classic/copy-and-blit.js +16 -17
  61. package/dist/classic/copy-and-blit.js.map +1 -1
  62. package/dist/classic/format-utils.js +14 -15
  63. package/dist/classic/format-utils.js.map +1 -1
  64. package/dist/classic/typed-array-utils.d.ts +2 -0
  65. package/dist/classic/typed-array-utils.d.ts.map +1 -1
  66. package/dist/classic/typed-array-utils.js +18 -19
  67. package/dist/classic/typed-array-utils.js.map +1 -1
  68. package/dist/context/debug/webgl-developer-tools.js +0 -1
  69. package/dist/context/debug/webgl-developer-tools.js.map +1 -1
  70. package/dist/context/parameters/webgl-parameter-tables.js +256 -257
  71. package/dist/context/parameters/webgl-parameter-tables.js.map +1 -1
  72. package/dist/context/polyfill/get-parameter-polyfill.js +34 -35
  73. package/dist/context/polyfill/get-parameter-polyfill.js.map +1 -1
  74. package/dist/context/polyfill/polyfill-table.js +9 -10
  75. package/dist/context/polyfill/polyfill-table.js.map +1 -1
  76. package/dist/context/polyfill/polyfill-vertex-array-object.js +17 -17
  77. package/dist/context/polyfill/polyfill-vertex-array-object.js.map +1 -1
  78. package/dist/dist.dev.js +987 -2700
  79. package/dist/index.cjs +390 -267
  80. package/dist.min.js +39 -28
  81. package/package.json +5 -5
  82. package/src/adapter/converters/device-parameters.ts +40 -25
  83. package/src/adapter/device-helpers/get-device-info.ts +36 -8
  84. package/src/adapter/helpers/parse-shader-compiler-log.ts +21 -7
  85. package/src/adapter/resources/webgl-transform-feedback.ts +13 -16
  86. package/src/adapter/resources/webgl-vertex-array.ts +4 -3
  87. package/src/adapter/webgl-device.ts +3 -2
  88. package/src/classic/typed-array-utils.ts +2 -0
@@ -1,5 +1,4 @@
1
1
  import { Buffer, assert } from '@luma.gl/core';
2
- import { GL } from '@luma.gl/constants';
3
2
  const DEBUG_DATA_LENGTH = 10;
4
3
  export class WEBGLBuffer extends Buffer {
5
4
  constructor(device) {
@@ -11,7 +10,7 @@ export class WEBGLBuffer extends Buffer {
11
10
  this.handle = void 0;
12
11
  this.glTarget = void 0;
13
12
  this.glUsage = void 0;
14
- this.glIndexType = GL.UNSIGNED_SHORT;
13
+ this.glIndexType = 5123;
15
14
  this.byteLength = void 0;
16
15
  this.bytesUsed = void 0;
17
16
  this.debugData = null;
@@ -26,7 +25,7 @@ export class WEBGLBuffer extends Buffer {
26
25
  });
27
26
  this.glTarget = getWebGLTarget(this.props.usage);
28
27
  this.glUsage = getWebGLUsage(this.props.usage);
29
- this.glIndexType = this.props.indexType === 'uint32' ? GL.UNSIGNED_INT : GL.UNSIGNED_SHORT;
28
+ this.glIndexType = this.props.indexType === 'uint32' ? 5125 : 5123;
30
29
  this.debugData = null;
31
30
  if (props.data) {
32
31
  this._initWithData(props.data, props.byteOffset, props.byteLength);
@@ -77,7 +76,7 @@ export class WEBGLBuffer extends Buffer {
77
76
  let byteOffset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
78
77
  const srcOffset = 0;
79
78
  const byteLength = undefined;
80
- const glTarget = this.device.isWebGL2 ? GL.COPY_WRITE_BUFFER : this.glTarget;
79
+ const glTarget = this.device.isWebGL2 ? 36663 : this.glTarget;
81
80
  this.gl.bindBuffer(glTarget, this.handle);
82
81
  if (srcOffset !== 0 || byteLength !== undefined) {
83
82
  this.device.assertWebGL2();
@@ -95,9 +94,9 @@ export class WEBGLBuffer extends Buffer {
95
94
  byteLength = (_byteLength = byteLength) !== null && _byteLength !== void 0 ? _byteLength : this.byteLength;
96
95
  const data = new Uint8Array(byteLength);
97
96
  const dstOffset = 0;
98
- this.gl.bindBuffer(GL.COPY_READ_BUFFER, this.handle);
99
- this.gl2.getBufferSubData(GL.COPY_READ_BUFFER, byteOffset, data, dstOffset, byteLength);
100
- this.gl.bindBuffer(GL.COPY_READ_BUFFER, null);
97
+ this.gl.bindBuffer(36662, this.handle);
98
+ this.gl2.getBufferSubData(36662, byteOffset, data, dstOffset, byteLength);
99
+ this.gl.bindBuffer(36662, null);
101
100
  return data;
102
101
  }
103
102
  _invalidateDebugData() {
@@ -112,26 +111,26 @@ export class WEBGLBuffer extends Buffer {
112
111
  }
113
112
  function getWebGLTarget(usage) {
114
113
  if (usage & Buffer.INDEX) {
115
- return GL.ELEMENT_ARRAY_BUFFER;
114
+ return 34963;
116
115
  }
117
116
  if (usage & Buffer.VERTEX) {
118
- return GL.ARRAY_BUFFER;
117
+ return 34962;
119
118
  }
120
119
  if (usage & Buffer.UNIFORM) {
121
- return GL.UNIFORM_BUFFER;
120
+ return 35345;
122
121
  }
123
- return GL.ARRAY_BUFFER;
122
+ return 34962;
124
123
  }
125
124
  function getWebGLUsage(usage) {
126
125
  if (usage & Buffer.INDEX) {
127
- return GL.STATIC_DRAW;
126
+ return 35044;
128
127
  }
129
128
  if (usage & Buffer.VERTEX) {
130
- return GL.STATIC_DRAW;
129
+ return 35044;
131
130
  }
132
131
  if (usage & Buffer.UNIFORM) {
133
- return GL.DYNAMIC_DRAW;
132
+ return 35048;
134
133
  }
135
- return GL.STATIC_DRAW;
134
+ return 35044;
136
135
  }
137
136
  //# sourceMappingURL=webgl-buffer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-buffer.js","names":["Buffer","assert","GL","DEBUG_DATA_LENGTH","WEBGLBuffer","constructor","device","props","arguments","length","undefined","gl","gl2","handle","glTarget","glUsage","glIndexType","UNSIGNED_SHORT","byteLength","bytesUsed","debugData","createBuffer","setSpectorMetadata","data","getWebGLTarget","usage","getWebGLUsage","indexType","UNSIGNED_INT","_initWithData","byteOffset","_initWithByteLength","ArrayBuffer","isView","_getWriteTarget","bindBuffer","bufferData","bufferSubData","slice","trackAllocatedMemory","Float32Array","destroy","destroyed","removeStats","trackDeallocatedMemory","deleteBuffer","write","srcOffset","isWebGL2","COPY_WRITE_BUFFER","assertWebGL2","readAsync","_byteLength","Uint8Array","dstOffset","COPY_READ_BUFFER","getBufferSubData","_invalidateDebugData","_getReadTarget","INDEX","ELEMENT_ARRAY_BUFFER","VERTEX","ARRAY_BUFFER","UNIFORM","UNIFORM_BUFFER","STATIC_DRAW","DYNAMIC_DRAW"],"sources":["../../../src/adapter/resources/webgl-buffer.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {BufferProps} from '@luma.gl/core';\nimport {Buffer, assert} from '@luma.gl/core';\nimport {GL} from '@luma.gl/constants';\nimport {WebGLDevice} from '../webgl-device';\n\nconst DEBUG_DATA_LENGTH = 10;\n\n/** WebGL Buffer interface */\nexport class WEBGLBuffer extends Buffer {\n readonly device: WebGLDevice;\n readonly gl: WebGLRenderingContext;\n readonly gl2: WebGL2RenderingContext | null;\n readonly handle: WebGLBuffer;\n\n /** Target in OpenGL defines the type of buffer */\n readonly glTarget: GL.ARRAY_BUFFER | GL.ELEMENT_ARRAY_BUFFER | GL.UNIFORM_BUFFER;\n /** Usage is a hint on how frequently the buffer will be updates */\n readonly glUsage: GL.STATIC_DRAW | GL.DYNAMIC_DRAW;\n /** Index type is needed when issuing draw calls, so we pre-compute it */\n readonly glIndexType: GL.UNSIGNED_SHORT | GL.UNSIGNED_INT = GL.UNSIGNED_SHORT;\n\n /** Number of bytes allocated on the GPU for this buffer */\n byteLength: number;\n /** Number of bytes used */\n bytesUsed: number;\n /** A partial CPU-side copy of the data in this buffer, for debugging purposes */\n debugData: ArrayBuffer | null = null;\n\n constructor(device: WebGLDevice, props: BufferProps = {}) {\n super(device, props);\n\n this.device = device;\n this.gl = this.device.gl;\n this.gl2 = this.device.gl2;\n\n const handle = typeof props === 'object' ? props.handle : undefined;\n this.handle = handle || this.gl.createBuffer();\n device.setSpectorMetadata(this.handle, {...this.props, data: typeof this.props.data});\n\n // - In WebGL1, need to make sure we use GL.ELEMENT_ARRAY_BUFFER when initializing element buffers\n // otherwise buffer type will lock to generic (non-element) buffer\n // - In WebGL2, we can use GL.COPY_READ_BUFFER which avoids locking the type here\n this.glTarget = getWebGLTarget(this.props.usage);\n this.glUsage = getWebGLUsage(this.props.usage);\n this.glIndexType = this.props.indexType === 'uint32' ? GL.UNSIGNED_INT : GL.UNSIGNED_SHORT;\n\n this.debugData = null;\n\n // Set data: (re)initializes the buffer\n if (props.data) {\n this._initWithData(props.data, props.byteOffset, props.byteLength);\n } else {\n this._initWithByteLength(props.byteLength || 0);\n }\n }\n\n // PRIVATE METHODS\n\n /** Allocate a new buffer and initialize to contents of typed array */\n _initWithData(\n data,\n byteOffset: number = 0,\n byteLength: number = data.byteLength + byteOffset\n ): this {\n assert(ArrayBuffer.isView(data));\n\n const glTarget = this._getWriteTarget();\n this.gl.bindBuffer(glTarget, this.handle);\n this.gl.bufferData(glTarget, byteLength, this.glUsage);\n this.gl.bufferSubData(glTarget, byteOffset, data);\n this.gl.bindBuffer(glTarget, null);\n\n this.debugData = data.slice(0, DEBUG_DATA_LENGTH);\n this.bytesUsed = byteLength;\n this.byteLength = byteLength;\n this.trackAllocatedMemory(byteLength);\n\n return this;\n }\n\n // Allocate a GPU buffer of specified size.\n _initWithByteLength(byteLength: number): this {\n assert(byteLength >= 0);\n\n // Workaround needed for Safari (#291):\n // gl.bufferData with size equal to 0 crashes. Instead create zero sized array.\n let data = byteLength;\n if (byteLength === 0) {\n // @ts-expect-error\n data = new Float32Array(0);\n }\n\n const glTarget = this._getWriteTarget();\n\n this.gl.bindBuffer(glTarget, this.handle);\n this.gl.bufferData(glTarget, data, this.glUsage);\n this.gl.bindBuffer(glTarget, null);\n\n this.debugData = null;\n this.bytesUsed = byteLength;\n this.byteLength = byteLength;\n\n return this;\n }\n\n override destroy(): void {\n if (!this.destroyed && this.handle) {\n this.removeStats();\n this.trackDeallocatedMemory();\n this.gl.deleteBuffer(this.handle);\n this.destroyed = true;\n // @ts-expect-error\n this.handle = null;\n }\n }\n\n override write(data: ArrayBufferView, byteOffset: number = 0): void {\n const srcOffset = 0;\n const byteLength = undefined; // data.byteLength;\n\n // Create the buffer - binding it here for the first time locks the type\n // In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type\n const glTarget = this.device.isWebGL2 ? GL.COPY_WRITE_BUFFER : this.glTarget;\n this.gl.bindBuffer(glTarget, this.handle);\n // WebGL2: subData supports additional srcOffset and length parameters\n if (srcOffset !== 0 || byteLength !== undefined) {\n this.device.assertWebGL2();\n this.gl2.bufferSubData(glTarget, byteOffset, data, srcOffset, byteLength);\n } else {\n this.gl.bufferSubData(glTarget, byteOffset, data);\n }\n this.gl.bindBuffer(glTarget, null);\n\n // TODO - update local `data` if offsets are right\n // this.debugData = data.slice(byteOffset, 40);\n }\n\n /** Read data from the buffer */\n override async readAsync(byteOffset = 0, byteLength?: number): Promise<Uint8Array> {\n this.device.assertWebGL2();\n\n byteLength = byteLength ?? this.byteLength;\n const data = new Uint8Array(byteLength);\n const dstOffset = 0;\n\n // Use GL.COPY_READ_BUFFER to avoid disturbing other targets and locking type\n this.gl.bindBuffer(GL.COPY_READ_BUFFER, this.handle);\n this.gl2.getBufferSubData(GL.COPY_READ_BUFFER, byteOffset, data, dstOffset, byteLength);\n this.gl.bindBuffer(GL.COPY_READ_BUFFER, null);\n\n // TODO - update local `data` if offsets are 0\n // this.debugData = null;\n\n return data;\n }\n\n // PROTECTED METHODS (INTENDED FOR USE BY OTHER FRAMEWORK CODE ONLY)\n\n _invalidateDebugData() {\n this.debugData = null;\n }\n\n _getWriteTarget() {\n return this.glTarget;\n // return this.device.isWebGL2 ? GL.COPY_WRITE_BUFFER : this.glTarget;\n }\n\n _getReadTarget() {\n return this.glTarget;\n // return this.device.isWebGL2 ? GL.COPY_READ_BUFFER : this.glTarget;\n }\n}\n\n// static MAP_READ = 0x01;\n// static MAP_WRITE = 0x02;\n// static COPY_SRC = 0x0004;\n// static COPY_DST = 0x0008;\n// static INDEX = 0x0010;\n// static VERTEX = 0x0020;\n// static UNIFORM = 0x0040;\n// static STORAGE = 0x0080;\n// static INDIRECT = 0x0100;\n// static QUERY_RESOLVE = 0x0200;\n\nfunction getWebGLTarget(\n usage: number\n): GL.ARRAY_BUFFER | GL.ELEMENT_ARRAY_BUFFER | GL.UNIFORM_BUFFER {\n if (usage & Buffer.INDEX) {\n return GL.ELEMENT_ARRAY_BUFFER;\n }\n if (usage & Buffer.VERTEX) {\n return GL.ARRAY_BUFFER;\n }\n if (usage & Buffer.UNIFORM) {\n return GL.UNIFORM_BUFFER;\n }\n\n // gl.COPY_READ_BUFFER: Buffer for copying from one buffer object to another.\n // gl.COPY_WRITE_BUFFER: Buffer for copying from one buffer object to another.\n // gl.TRANSFORM_FEEDBACK_BUFFER: Buffer for transform feedback operations.\n // gl.PIXEL_PACK_BUFFER: Buffer used for pixel transfer operations.\n // gl.PIXEL_UNPACK_BUFFER: Buffer used for pixel transfer operations.\n\n // Binding a buffer for the first time locks the type\n // In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type\n return GL.ARRAY_BUFFER;\n}\n\n/** @todo usage is not passed correctly */\nfunction getWebGLUsage(usage: number): GL.STATIC_DRAW | GL.DYNAMIC_DRAW {\n if (usage & Buffer.INDEX) {\n return GL.STATIC_DRAW;\n }\n if (usage & Buffer.VERTEX) {\n return GL.STATIC_DRAW;\n }\n if (usage & Buffer.UNIFORM) {\n return GL.DYNAMIC_DRAW;\n }\n return GL.STATIC_DRAW;\n}\n"],"mappings":"AAIA,SAAQA,MAAM,EAAEC,MAAM,QAAO,eAAe;AAC5C,SAAQC,EAAE,QAAO,oBAAoB;AAGrC,MAAMC,iBAAiB,GAAG,EAAE;AAG5B,OAAO,MAAMC,WAAW,SAASJ,MAAM,CAAC;EAoBtCK,WAAWA,CAACC,MAAmB,EAA2B;IAAA,IAAzBC,KAAkB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IACtD,KAAK,CAACF,MAAM,EAAEC,KAAK,CAAC;IAAC,KApBdD,MAAM;IAAA,KACNK,EAAE;IAAA,KACFC,GAAG;IAAA,KACHC,MAAM;IAAA,KAGNC,QAAQ;IAAA,KAERC,OAAO;IAAA,KAEPC,WAAW,GAAwCd,EAAE,CAACe,cAAc;IAAA,KAG7EC,UAAU;IAAA,KAEVC,SAAS;IAAA,KAETC,SAAS,GAAuB,IAAI;IAKlC,IAAI,CAACd,MAAM,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AAC2D,KAAK,EAAE;IACxB,OAAOzD,EAAE,CAAC0D,oBAAoB;EAChC;EACA,IAAInC,KAAK,GAAGzB,MAAM,CAAC6D,MAAM,EAAE;IACzB,OAAO3D,EAAE,CAAC4D,YAAY;EACxB;EACA,IAAIrC,KAAK,GAAGzB,MAAM,CAAC+D,OAAO,EAAE;IAC1B,OAAO7D,EAAE,CAAC8D,cAAc;EAC1B;EAUA,OAAO9D,EAAE,CAAC4D,YAAY;AACxB;AAGA,SAASpC,aAAaA,CAACD,KAAa,EAAoC;EACtE,IAAIA,KAAK,GAAGzB,MAAM,CAAC2D,KAAK,EAAE;IACxB,OAAOzD,EAAE,CAAC+D,WAAW;EACvB;EACA,IAAIxC,KAAK,GAAGzB,MAAM,CAAC6D,MAAM,EAAE;IACzB,OAAO3D,EAAE,CAAC+D,WAAW;EACvB;EACA,IAAIxC,KAAK,GAAGzB,MAAM,CAAC+D,OAAO,EAAE;IAC1B,OAAO7D,EAAE,CAACgE,YAAY;EACxB;EACA,OAAOhE,EAAE,CAAC+D,WAAW;AACvB"}
1
+ {"version":3,"file":"webgl-buffer.js","names":["Buffer","assert","DEBUG_DATA_LENGTH","WEBGLBuffer","constructor","device","props","arguments","length","undefined","gl","gl2","handle","glTarget","glUsage","glIndexType","byteLength","bytesUsed","debugData","createBuffer","setSpectorMetadata","data","getWebGLTarget","usage","getWebGLUsage","indexType","_initWithData","byteOffset","_initWithByteLength","ArrayBuffer","isView","_getWriteTarget","bindBuffer","bufferData","bufferSubData","slice","trackAllocatedMemory","Float32Array","destroy","destroyed","removeStats","trackDeallocatedMemory","deleteBuffer","write","srcOffset","isWebGL2","assertWebGL2","readAsync","_byteLength","Uint8Array","dstOffset","getBufferSubData","_invalidateDebugData","_getReadTarget","INDEX","VERTEX","UNIFORM"],"sources":["../../../src/adapter/resources/webgl-buffer.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {BufferProps} from '@luma.gl/core';\nimport {Buffer, assert} from '@luma.gl/core';\nimport {GL} from '@luma.gl/constants';\nimport {WebGLDevice} from '../webgl-device';\n\nconst DEBUG_DATA_LENGTH = 10;\n\n/** WebGL Buffer interface */\nexport class WEBGLBuffer extends Buffer {\n readonly device: WebGLDevice;\n readonly gl: WebGLRenderingContext;\n readonly gl2: WebGL2RenderingContext | null;\n readonly handle: WebGLBuffer;\n\n /** Target in OpenGL defines the type of buffer */\n readonly glTarget: GL.ARRAY_BUFFER | GL.ELEMENT_ARRAY_BUFFER | GL.UNIFORM_BUFFER;\n /** Usage is a hint on how frequently the buffer will be updates */\n readonly glUsage: GL.STATIC_DRAW | GL.DYNAMIC_DRAW;\n /** Index type is needed when issuing draw calls, so we pre-compute it */\n readonly glIndexType: GL.UNSIGNED_SHORT | GL.UNSIGNED_INT = GL.UNSIGNED_SHORT;\n\n /** Number of bytes allocated on the GPU for this buffer */\n byteLength: number;\n /** Number of bytes used */\n bytesUsed: number;\n /** A partial CPU-side copy of the data in this buffer, for debugging purposes */\n debugData: ArrayBuffer | null = null;\n\n constructor(device: WebGLDevice, props: BufferProps = {}) {\n super(device, props);\n\n this.device = device;\n this.gl = this.device.gl;\n this.gl2 = this.device.gl2;\n\n const handle = typeof props === 'object' ? props.handle : undefined;\n this.handle = handle || this.gl.createBuffer();\n device.setSpectorMetadata(this.handle, {...this.props, data: typeof this.props.data});\n\n // - In WebGL1, need to make sure we use GL.ELEMENT_ARRAY_BUFFER when initializing element buffers\n // otherwise buffer type will lock to generic (non-element) buffer\n // - In WebGL2, we can use GL.COPY_READ_BUFFER which avoids locking the type here\n this.glTarget = getWebGLTarget(this.props.usage);\n this.glUsage = getWebGLUsage(this.props.usage);\n this.glIndexType = this.props.indexType === 'uint32' ? GL.UNSIGNED_INT : GL.UNSIGNED_SHORT;\n\n this.debugData = null;\n\n // Set data: (re)initializes the buffer\n if (props.data) {\n this._initWithData(props.data, props.byteOffset, props.byteLength);\n } else {\n this._initWithByteLength(props.byteLength || 0);\n }\n }\n\n // PRIVATE METHODS\n\n /** Allocate a new buffer and initialize to contents of typed array */\n _initWithData(\n data,\n byteOffset: number = 0,\n byteLength: number = data.byteLength + byteOffset\n ): this {\n assert(ArrayBuffer.isView(data));\n\n const glTarget = this._getWriteTarget();\n this.gl.bindBuffer(glTarget, this.handle);\n this.gl.bufferData(glTarget, byteLength, this.glUsage);\n this.gl.bufferSubData(glTarget, byteOffset, data);\n this.gl.bindBuffer(glTarget, null);\n\n this.debugData = data.slice(0, DEBUG_DATA_LENGTH);\n this.bytesUsed = byteLength;\n this.byteLength = byteLength;\n this.trackAllocatedMemory(byteLength);\n\n return this;\n }\n\n // Allocate a GPU buffer of specified size.\n _initWithByteLength(byteLength: number): this {\n assert(byteLength >= 0);\n\n // Workaround needed for Safari (#291):\n // gl.bufferData with size equal to 0 crashes. Instead create zero sized array.\n let data = byteLength;\n if (byteLength === 0) {\n // @ts-expect-error\n data = new Float32Array(0);\n }\n\n const glTarget = this._getWriteTarget();\n\n this.gl.bindBuffer(glTarget, this.handle);\n this.gl.bufferData(glTarget, data, this.glUsage);\n this.gl.bindBuffer(glTarget, null);\n\n this.debugData = null;\n this.bytesUsed = byteLength;\n this.byteLength = byteLength;\n\n return this;\n }\n\n override destroy(): void {\n if (!this.destroyed && this.handle) {\n this.removeStats();\n this.trackDeallocatedMemory();\n this.gl.deleteBuffer(this.handle);\n this.destroyed = true;\n // @ts-expect-error\n this.handle = null;\n }\n }\n\n override write(data: ArrayBufferView, byteOffset: number = 0): void {\n const srcOffset = 0;\n const byteLength = undefined; // data.byteLength;\n\n // Create the buffer - binding it here for the first time locks the type\n // In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type\n const glTarget = this.device.isWebGL2 ? GL.COPY_WRITE_BUFFER : this.glTarget;\n this.gl.bindBuffer(glTarget, this.handle);\n // WebGL2: subData supports additional srcOffset and length parameters\n if (srcOffset !== 0 || byteLength !== undefined) {\n this.device.assertWebGL2();\n this.gl2.bufferSubData(glTarget, byteOffset, data, srcOffset, byteLength);\n } else {\n this.gl.bufferSubData(glTarget, byteOffset, data);\n }\n this.gl.bindBuffer(glTarget, null);\n\n // TODO - update local `data` if offsets are right\n // this.debugData = data.slice(byteOffset, 40);\n }\n\n /** Read data from the buffer */\n override async readAsync(byteOffset = 0, byteLength?: number): Promise<Uint8Array> {\n this.device.assertWebGL2();\n\n byteLength = byteLength ?? this.byteLength;\n const data = new Uint8Array(byteLength);\n const dstOffset = 0;\n\n // Use GL.COPY_READ_BUFFER to avoid disturbing other targets and locking type\n this.gl.bindBuffer(GL.COPY_READ_BUFFER, this.handle);\n this.gl2.getBufferSubData(GL.COPY_READ_BUFFER, byteOffset, data, dstOffset, byteLength);\n this.gl.bindBuffer(GL.COPY_READ_BUFFER, null);\n\n // TODO - update local `data` if offsets are 0\n // this.debugData = null;\n\n return data;\n }\n\n // PROTECTED METHODS (INTENDED FOR USE BY OTHER FRAMEWORK CODE ONLY)\n\n _invalidateDebugData() {\n this.debugData = null;\n }\n\n _getWriteTarget() {\n return this.glTarget;\n // return this.device.isWebGL2 ? GL.COPY_WRITE_BUFFER : this.glTarget;\n }\n\n _getReadTarget() {\n return this.glTarget;\n // return this.device.isWebGL2 ? GL.COPY_READ_BUFFER : this.glTarget;\n }\n}\n\n// static MAP_READ = 0x01;\n// static MAP_WRITE = 0x02;\n// static COPY_SRC = 0x0004;\n// static COPY_DST = 0x0008;\n// static INDEX = 0x0010;\n// static VERTEX = 0x0020;\n// static UNIFORM = 0x0040;\n// static STORAGE = 0x0080;\n// static INDIRECT = 0x0100;\n// static QUERY_RESOLVE = 0x0200;\n\nfunction getWebGLTarget(\n usage: number\n): GL.ARRAY_BUFFER | GL.ELEMENT_ARRAY_BUFFER | GL.UNIFORM_BUFFER {\n if (usage & Buffer.INDEX) {\n return GL.ELEMENT_ARRAY_BUFFER;\n }\n if (usage & Buffer.VERTEX) {\n return GL.ARRAY_BUFFER;\n }\n if (usage & Buffer.UNIFORM) {\n return GL.UNIFORM_BUFFER;\n }\n\n // gl.COPY_READ_BUFFER: Buffer for copying from one buffer object to another.\n // gl.COPY_WRITE_BUFFER: Buffer for copying from one buffer object to another.\n // gl.TRANSFORM_FEEDBACK_BUFFER: Buffer for transform feedback operations.\n // gl.PIXEL_PACK_BUFFER: Buffer used for pixel transfer operations.\n // gl.PIXEL_UNPACK_BUFFER: Buffer used for pixel transfer operations.\n\n // Binding a buffer for the first time locks the type\n // In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type\n return GL.ARRAY_BUFFER;\n}\n\n/** @todo usage is not passed correctly */\nfunction getWebGLUsage(usage: number): GL.STATIC_DRAW | GL.DYNAMIC_DRAW {\n if (usage & Buffer.INDEX) {\n return GL.STATIC_DRAW;\n }\n if (usage & Buffer.VERTEX) {\n return GL.STATIC_DRAW;\n }\n if (usage & Buffer.UNIFORM) {\n return GL.DYNAMIC_DRAW;\n }\n return GL.STATIC_DRAW;\n}\n"],"mappings":"AAIA,SAAQA,MAAM,EAAEC,MAAM,QAAO,eAAe;AAI5C,MAAMC,iBAAiB,GAAG,EAAE;AAG5B,OAAO,MAAMC,WAAW,SAASH,MAAM,CAAC;EAoBtCI,WAAWA,CAACC,MAAmB,EAA2B;IAAA,IAAzBC,KAAkB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IACtD,KAAK,CAACF,MAAM,EAAEC,KAAK,CAAC;IAAC,KApBdD,MAAM;IAAA,KACNK,EAAE;IAAA,KACFC,GAAG;IAAA,KACHC,MAAM;IAAA,KAGNC,QAAQ;IAAA,KAERC,OAAO;IAAA,KAEPC,WAAW;IAAA,KAGpBC,UAAU;IAAA,KAEVC,SAAS;IAAA,KAETC,SAAS,GAAuB,IAAI;IAKlC,IAAI,CAACb,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACK,EAAE,GAAG,IAAI,CAACL,MAAM,CAACK,EAAE;IACxB,IAAI,CAACC,GAAG,GAAG,IAAI,CAACN,MAAM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,MAAM,EAAE;IACzB;EACF;EACA,IAAIhC,KAAK,GAAGvB,MAAM,CAACwD,OAAO,EAAE;IAC1B;EACF;EACA;AACF"}
@@ -1,5 +1,4 @@
1
1
  import { CommandBuffer, Texture } from '@luma.gl/core';
2
- import { GL } from '@luma.gl/constants';
3
2
  import { WEBGLTexture } from "./webgl-texture.js";
4
3
  import { getWebGLTextureParameters } from "../converters/texture-formats.js";
5
4
  function cast(value) {
@@ -38,11 +37,11 @@ function _copyBufferToBuffer(device, options) {
38
37
  const gl2 = device.assertWebGL2();
39
38
  if (gl2) {
40
39
  var _options$sourceOffset, _options$destinationO;
41
- gl2.bindBuffer(GL.COPY_READ_BUFFER, source.handle);
42
- gl2.bindBuffer(GL.COPY_WRITE_BUFFER, destination.handle);
43
- gl2.copyBufferSubData(GL.COPY_READ_BUFFER, GL.COPY_WRITE_BUFFER, (_options$sourceOffset = options.sourceOffset) !== null && _options$sourceOffset !== void 0 ? _options$sourceOffset : 0, (_options$destinationO = options.destinationOffset) !== null && _options$destinationO !== void 0 ? _options$destinationO : 0, options.size);
44
- gl2.bindBuffer(GL.COPY_READ_BUFFER, null);
45
- gl2.bindBuffer(GL.COPY_WRITE_BUFFER, null);
40
+ gl2.bindBuffer(36662, source.handle);
41
+ gl2.bindBuffer(36663, destination.handle);
42
+ gl2.copyBufferSubData(36662, 36663, (_options$sourceOffset = options.sourceOffset) !== null && _options$sourceOffset !== void 0 ? _options$sourceOffset : 0, (_options$destinationO = options.destinationOffset) !== null && _options$destinationO !== void 0 ? _options$destinationO : 0, options.size);
43
+ gl2.bindBuffer(36662, null);
44
+ gl2.bindBuffer(36663, null);
46
45
  } else {
47
46
  throw new Error('copyBufferToBuffer not implemented in WebGL1');
48
47
  }
@@ -82,12 +81,12 @@ function _copyTextureToBuffer(device, options) {
82
81
  const sourceParams = getWebGLTextureParameters(framebuffer.texture.format, true);
83
82
  const sourceFormat = sourceParams.dataFormat;
84
83
  const sourceType = sourceParams.type;
85
- gl2.bindBuffer(GL.PIXEL_PACK_BUFFER, webglBuffer.handle);
86
- gl2.bindFramebuffer(GL.FRAMEBUFFER, framebuffer.handle);
84
+ gl2.bindBuffer(35051, webglBuffer.handle);
85
+ gl2.bindFramebuffer(36160, framebuffer.handle);
87
86
  gl2.readPixels(origin[0], origin[1], sourceWidth, sourceHeight, sourceFormat, sourceType, byteOffset);
88
87
  } finally {
89
- gl2.bindBuffer(GL.PIXEL_PACK_BUFFER, null);
90
- gl2.bindFramebuffer(GL.FRAMEBUFFER, null);
88
+ gl2.bindBuffer(35051, null);
89
+ gl2.bindFramebuffer(36160, null);
91
90
  if (destroyFramebuffer) {
92
91
  framebuffer.destroy();
93
92
  }
@@ -104,14 +103,14 @@ function _copyTextureToTexture(device, options) {
104
103
  height = options.destination.width
105
104
  } = options;
106
105
  const destinationMipmaplevel = 0;
107
- const destinationInternalFormat = GL.RGBA;
106
+ const destinationInternalFormat = 6408;
108
107
  const {
109
108
  framebuffer,
110
109
  destroyFramebuffer
111
110
  } = getFramebuffer(source);
112
111
  const [sourceX, sourceY] = origin;
113
112
  const isSubCopy = false;
114
- device.gl.bindFramebuffer(GL.FRAMEBUFFER, framebuffer.handle);
113
+ device.gl.bindFramebuffer(36160, framebuffer.handle);
115
114
  let texture = null;
116
115
  let textureTarget;
117
116
  if (destination instanceof WEBGLTexture) {
@@ -136,18 +135,18 @@ function _copyTextureToTexture(device, options) {
136
135
  }
137
136
  export function glFormatToComponents(format) {
138
137
  switch (format) {
139
- case GL.ALPHA:
140
- case GL.R32F:
141
- case GL.RED:
138
+ case 6406:
139
+ case 33326:
140
+ case 6403:
142
141
  return 1;
143
- case GL.RG32F:
144
- case GL.RG:
142
+ case 33328:
143
+ case 33319:
145
144
  return 2;
146
- case GL.RGB:
147
- case GL.RGB32F:
145
+ case 6407:
146
+ case 34837:
148
147
  return 3;
149
- case GL.RGBA:
150
- case GL.RGBA32F:
148
+ case 6408:
149
+ case 34836:
151
150
  return 4;
152
151
  default:
153
152
  throw new Error('GLFormat');
@@ -155,13 +154,13 @@ export function glFormatToComponents(format) {
155
154
  }
156
155
  export function glTypeToBytes(type) {
157
156
  switch (type) {
158
- case GL.UNSIGNED_BYTE:
157
+ case 5121:
159
158
  return 1;
160
- case GL.UNSIGNED_SHORT_5_6_5:
161
- case GL.UNSIGNED_SHORT_4_4_4_4:
162
- case GL.UNSIGNED_SHORT_5_5_5_1:
159
+ case 33635:
160
+ case 32819:
161
+ case 32820:
163
162
  return 2;
164
- case GL.FLOAT:
163
+ case 5126:
165
164
  return 4;
166
165
  default:
167
166
  throw new Error('GLType');
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-command-buffer.js","names":["CommandBuffer","Texture","GL","WEBGLTexture","getWebGLTextureParameters","cast","value","WEBGLCommandBuffer","constructor","device","commands","submitCommands","arguments","length","undefined","command","name","_copyBufferToBuffer","options","_copyBufferToTexture","_copyTextureToBuffer","_copyTextureToTexture","source","destination","gl2","assertWebGL2","_options$sourceOffset","_options$destinationO","bindBuffer","COPY_READ_BUFFER","handle","COPY_WRITE_BUFFER","copyBufferSubData","sourceOffset","destinationOffset","size","Error","mipLevel","aspect","width","height","depthOrArrayLayers","origin","byteOffset","bytesPerRow","rowsPerImage","framebuffer","destroyFramebuffer","getFramebuffer","webglBuffer","sourceWidth","sourceHeight","sourceParams","texture","format","sourceFormat","dataFormat","sourceType","type","PIXEL_PACK_BUFFER","bindFramebuffer","FRAMEBUFFER","readPixels","destroy","destinationMipmaplevel","destinationInternalFormat","RGBA","sourceX","sourceY","isSubCopy","gl","textureTarget","Number","isFinite","bind","copyTexImage2D","unbind","glFormatToComponents","ALPHA","R32F","RED","RG32F","RG","RGB","RGB32F","RGBA32F","glTypeToBytes","UNSIGNED_BYTE","UNSIGNED_SHORT_5_6_5","UNSIGNED_SHORT_4_4_4_4","UNSIGNED_SHORT_5_5_5_1","FLOAT","id","createFramebuffer","colorAttachments"],"sources":["../../../src/adapter/resources/webgl-command-buffer.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {\n CopyBufferToBufferOptions,\n CopyBufferToTextureOptions,\n CopyTextureToBufferOptions,\n CopyTextureToTextureOptions\n} from '@luma.gl/core';\nimport {CommandBuffer, Texture, Framebuffer} from '@luma.gl/core';\nimport {GL} from '@luma.gl/constants';\n\nimport {WebGLDevice} from '../webgl-device';\nimport {WEBGLBuffer} from './webgl-buffer';\nimport {WEBGLTexture} from './webgl-texture';\nimport {WEBGLFramebuffer} from './webgl-framebuffer';\nimport {getWebGLTextureParameters} from '../converters/texture-formats';\n\nfunction cast<T>(value: unknown): T {\n return value as T;\n}\n\ntype CopyBufferToBufferCommand = {\n name: 'copy-buffer-to-buffer';\n options: CopyBufferToBufferOptions;\n};\n\ntype CopyBufferToTextureCommand = {\n name: 'copy-buffer-to-texture';\n options: CopyBufferToTextureOptions;\n};\n\ntype CopyTextureToBufferCommand = {\n name: 'copy-texture-to-buffer';\n options: CopyTextureToBufferOptions;\n};\n\ntype CopyTextureToTextureCommand = {\n name: 'copy-texture-to-texture';\n options: CopyTextureToTextureOptions;\n};\n\ntype Command =\n | CopyBufferToBufferCommand\n | CopyBufferToTextureCommand\n | CopyTextureToBufferCommand\n | CopyTextureToTextureCommand;\n\nexport class WEBGLCommandBuffer extends CommandBuffer {\n device: WebGLDevice;\n commands: Command[] = [];\n\n constructor(device: WebGLDevice) {\n super(device, {});\n this.device = device;\n }\n\n submitCommands(commands: Command[] = this.commands) {\n for (const command of commands) {\n switch (command.name) {\n case 'copy-buffer-to-buffer':\n _copyBufferToBuffer(this.device, command.options);\n break;\n case 'copy-buffer-to-texture':\n _copyBufferToTexture(this.device, command.options);\n break;\n case 'copy-texture-to-buffer':\n _copyTextureToBuffer(this.device, command.options);\n break;\n case 'copy-texture-to-texture':\n _copyTextureToTexture(this.device, command.options);\n break;\n }\n }\n }\n}\n\nfunction _copyBufferToBuffer(device: WebGLDevice, options: CopyBufferToBufferOptions): void {\n const source = cast<WEBGLBuffer>(options.source);\n const destination = cast<WEBGLBuffer>(options.destination);\n\n const gl2 = device.assertWebGL2();\n if (gl2) {\n // In WebGL2 we can perform the copy on the GPU\n // Use GL.COPY_READ_BUFFER+GL.COPY_WRITE_BUFFER avoid disturbing other targets and locking type\n gl2.bindBuffer(GL.COPY_READ_BUFFER, source.handle);\n gl2.bindBuffer(GL.COPY_WRITE_BUFFER, destination.handle);\n gl2.copyBufferSubData(\n GL.COPY_READ_BUFFER,\n GL.COPY_WRITE_BUFFER,\n options.sourceOffset ?? 0,\n options.destinationOffset ?? 0,\n options.size\n );\n gl2.bindBuffer(GL.COPY_READ_BUFFER, null);\n gl2.bindBuffer(GL.COPY_WRITE_BUFFER, null);\n } else {\n // TODO - in WebGL1 we would have to read back to CPU\n // read / write buffer from / to CPU\n throw new Error('copyBufferToBuffer not implemented in WebGL1');\n }\n}\n\n/**\n * Copies data from a Buffer object into a Texture object\n * NOTE: doesn't wait for copy to be complete\n */\nfunction _copyBufferToTexture(device: WebGLDevice, options: CopyBufferToTextureOptions): void {\n throw new Error('Not implemented');\n}\n\n/**\n * Copies data from a Texture object into a Buffer object.\n * NOTE: doesn't wait for copy to be complete\n */\nfunction _copyTextureToBuffer(device: WebGLDevice, options: CopyTextureToBufferOptions): void {\n const {\n /** Texture to copy to/from. */\n source,\n /** Mip-map level of the texture to copy to/from. (Default 0) */\n mipLevel = 0,\n /** Defines which aspects of the texture to copy to/from. */\n aspect = 'all',\n\n /** Width to copy */\n width = options.source.width,\n /** Height to copy */\n height = options.source.height,\n depthOrArrayLayers = 0,\n /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */\n origin = [0, 0],\n\n /** Destination buffer */\n destination,\n /** Offset, in bytes, from the beginning of the buffer to the start of the image data (default 0) */\n byteOffset = 0,\n /**\n * The stride, in bytes, between the beginning of each block row and the subsequent block row.\n * Required if there are multiple block rows (i.e. the copy height or depth is more than one block).\n */\n bytesPerRow,\n /**\n * Number of block rows per single image of the texture.\n * rowsPerImage &times; bytesPerRow is the stride, in bytes, between the beginning of each image of data and the subsequent image.\n * Required if there are multiple images (i.e. the copy depth is more than one).\n */\n rowsPerImage\n } = options;\n\n // TODO - Not possible to read just stencil or depth part in WebGL?\n if (aspect !== 'all') {\n throw new Error('not supported');\n }\n\n // TODO - mipLevels are set when attaching texture to framebuffer\n if (mipLevel !== 0 || depthOrArrayLayers !== 0 || bytesPerRow || rowsPerImage) {\n throw new Error('not implemented');\n }\n\n // Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature\n const gl2 = device.assertWebGL2();\n\n const {framebuffer, destroyFramebuffer} = getFramebuffer(source);\n try {\n const webglBuffer = destination as WEBGLBuffer;\n const sourceWidth = width || framebuffer.width;\n const sourceHeight = height || framebuffer.height;\n const sourceParams = getWebGLTextureParameters(framebuffer.texture.format, true);\n const sourceFormat = sourceParams.dataFormat;\n const sourceType = sourceParams.type;\n\n // if (!target) {\n // // Create new buffer with enough size\n // const components = glFormatToComponents(sourceFormat);\n // const byteCount = glTypeToBytes(sourceType);\n // const byteLength = byteOffset + sourceWidth * sourceHeight * components * byteCount;\n // target = device.createBuffer({byteLength});\n // }\n\n gl2.bindBuffer(GL.PIXEL_PACK_BUFFER, webglBuffer.handle);\n gl2.bindFramebuffer(GL.FRAMEBUFFER, framebuffer.handle);\n\n gl2.readPixels(\n origin[0],\n origin[1],\n sourceWidth,\n sourceHeight,\n sourceFormat,\n sourceType,\n byteOffset\n );\n } finally {\n gl2.bindBuffer(GL.PIXEL_PACK_BUFFER, null);\n gl2.bindFramebuffer(GL.FRAMEBUFFER, null);\n\n if (destroyFramebuffer) {\n framebuffer.destroy();\n }\n }\n}\n\n/**\n * Copies data from a Framebuffer or a Texture object into a Buffer object.\n * NOTE: doesn't wait for copy to be complete, it programs GPU to perform a DMA transfer.\nexport function readPixelsToBuffer(\n source: Framebuffer | Texture,\n options?: {\n sourceX?: number;\n sourceY?: number;\n sourceFormat?: number;\n target?: Buffer; // A new Buffer object is created when not provided.\n targetByteOffset?: number; // byte offset in buffer object\n // following parameters are auto deduced if not provided\n sourceWidth?: number;\n sourceHeight?: number;\n sourceType?: number;\n }\n): Buffer\n */\n\n/**\n * Copy a rectangle from a Framebuffer or Texture object into a texture (at an offset)\n */\n// eslint-disable-next-line complexity, max-statements\nfunction _copyTextureToTexture(device: WebGLDevice, options: CopyTextureToTextureOptions): void {\n const {\n /** Texture to copy to/from. */\n source,\n /** Mip-map level of the texture to copy to/from. (Default 0) */\n // mipLevel = 0,\n /** Defines which aspects of the texture to copy to/from. */\n // aspect = 'all',\n /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */\n origin = [0, 0],\n\n /** Texture to copy to/from. */\n destination,\n /** Mip-map level of the texture to copy to/from. (Default 0) */\n // destinationMipLevel = options.mipLevel,\n /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */\n // destinationOrigin = [0, 0],\n /** Defines which aspects of the texture to copy to/from. */\n // destinationAspect = options.aspect,\n\n } = options;\n\n let {\n width = options.destination.width,\n height = options.destination.width,\n // depthOrArrayLayers = 0\n } = options;\n\n const destinationMipmaplevel = 0;\n const destinationInternalFormat = GL.RGBA;\n\n const {framebuffer, destroyFramebuffer} = getFramebuffer(source);\n const [sourceX, sourceY] = origin;\n\n const isSubCopy = false;\n // typeof destinationX !== 'undefined' ||\n // typeof destinationY !== 'undefined' ||\n // typeof destinationZ !== 'undefined';\n\n // destinationX = destinationX || 0;\n // destinationY = destinationY || 0;\n // destinationZ = destinationZ || 0;\n device.gl.bindFramebuffer(GL.FRAMEBUFFER, framebuffer.handle);\n // TODO - support gl.readBuffer (WebGL2 only)\n // const prevBuffer = gl.readBuffer(attachment);\n\n let texture = null;\n let textureTarget: GL;\n if (destination instanceof WEBGLTexture) {\n texture = destination;\n width = Number.isFinite(width) ? width : texture.width;\n height = Number.isFinite(height) ? height : texture.height;\n texture.bind(0);\n textureTarget = texture.destination;\n } else {\n throw new Error('whoops');\n // textureTarget = destination;\n }\n\n if (!isSubCopy) {\n device.gl.copyTexImage2D(\n textureTarget,\n destinationMipmaplevel,\n destinationInternalFormat,\n sourceX,\n sourceY,\n width,\n height,\n 0 /* border must be 0 */\n );\n } else {\n // switch (textureTarget) {\n // case GL.TEXTURE_2D:\n // case GL.TEXTURE_CUBE_MAP:\n // device.gl.copyTexSubImage2D(\n // textureTarget,\n // destinationMipmaplevel,\n // destinationX,\n // destinationY,\n // sourceX,\n // sourceY,\n // width,\n // height\n // );\n // break;\n // case GL.TEXTURE_2D_ARRAY:\n // case GL.TEXTURE_3D:\n // const gl2 = device.assertWebGL2();\n // gl2.copyTexSubImage3D(\n // textureTarget,\n // destinationMipmaplevel,\n // destinationX,\n // destinationY,\n // destinationZ,\n // sourceX,\n // sourceY,\n // width,\n // height\n // );\n // break;\n // default:\n // }\n }\n if (texture) {\n texture.unbind();\n }\n // ts-expect-error\n // device.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);\n if (destroyFramebuffer) {\n framebuffer.destroy();\n }\n return texture;\n}\n\n// Returns number of components in a specific readPixels WebGL format\nexport function glFormatToComponents(format): 1 | 2 | 3 | 4 {\n switch (format) {\n case GL.ALPHA:\n case GL.R32F:\n case GL.RED:\n return 1;\n case GL.RG32F:\n case GL.RG:\n return 2;\n case GL.RGB:\n case GL.RGB32F:\n return 3;\n case GL.RGBA:\n case GL.RGBA32F:\n return 4;\n // TODO: Add support for additional WebGL2 formats\n default:\n throw new Error('GLFormat');\n }\n}\n\n// Return byte count for given readPixels WebGL type\nexport function glTypeToBytes(type: GL): 1 | 2 | 4 {\n switch (type) {\n case GL.UNSIGNED_BYTE:\n return 1;\n case GL.UNSIGNED_SHORT_5_6_5:\n case GL.UNSIGNED_SHORT_4_4_4_4:\n case GL.UNSIGNED_SHORT_5_5_5_1:\n return 2;\n case GL.FLOAT:\n return 4;\n // TODO: Add support for additional WebGL2 types\n default:\n throw new Error('GLType');\n }\n}\n\n// Helper methods\n\nfunction getFramebuffer(source: Texture | Framebuffer): {\n framebuffer: WEBGLFramebuffer;\n destroyFramebuffer: boolean;\n} {\n if (source instanceof Texture) {\n const {width, height, id} = source;\n const framebuffer = source.device.createFramebuffer({\n id: `framebuffer-for-${id}`,\n width,\n height,\n colorAttachments: [source]\n }) as unknown as WEBGLFramebuffer;\n\n return {framebuffer, destroyFramebuffer: true};\n }\n return {framebuffer: source as unknown as WEBGLFramebuffer, destroyFramebuffer: false};\n}\n"],"mappings":"AASA,SAAQA,aAAa,EAAEC,OAAO,QAAoB,eAAe;AACjE,SAAQC,EAAE,QAAO,oBAAoB;AAAC,SAI9BC,YAAY;AAAA,SAEZC,yBAAyB;AAEjC,SAASC,IAAIA,CAAIC,KAAc,EAAK;EAClC,OAAOA,KAAK;AACd;AA4BA,OAAO,MAAMC,kBAAkB,SAASP,aAAa,CAAC;EAIpDQ,WAAWA,CAACC,MAAmB,EAAE;IAC/B,KAAK,CAACA,MAAM,EAAE,CAAC,CAAC,CAAC;IAAC,KAJpBA,MAAM;IAAA,KACNC,QAAQ,GAAc,EAAE;IAItB,IAAI,CAACD,MAAM,GAAGA,MAAM;EACtB;EAEAE,cAAcA,CAAA,EAAsC;IAAA,IAArCD,QAAmB,GAAAE,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI,CAACF,QAAQ;IAChD,KAAK,MAAMK,OAAO,IAAIL,QAAQ,EAAE;MAC9B,QAAQK,OAAO,CAACC,IAAI;QAClB,KAAK,uBAAuB;UAC1BC,mBAAmB,CAAC,IAAI,CAACR,MAAM,EAAEM,OAAO,CAACG,OAAO,CAAC;UACjD;QACF,KAAK,wBAAwB;UAC3BC,oBAAoB,CAAC,IAAI,CAACV,MAAM,EAAEM,OAAO,CAACG,OAAO,CAAC;UAClD;QACF,KAAK,wBAAwB;UAC3BE,oBAAoB,CAAC,IAAI,CAACX,MAAM,EAAEM,OAAO,CAACG,OAAO,CAAC;UAClD;QACF,KAAK,yBAAyB;UAC5BG,qBAAqB,CAAC,IAAI,C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AAC5B,IAAQ,EAAa;EACjD,QAAQA,IAAI;IACV,KAAKxD,EAAE,CAACqF,aAAa;MACnB,OAAO,CAAC;IACV,KAAKrF,EAAE,CAACsF,oBAAoB;IAC5B,KAAKtF,EAAE,CAACuF,sBAAsB;IAC9B,KAAKvF,EAAE,CAACwF,sBAAsB;MAC5B,OAAO,CAAC;IACV,KAAKxF,EAAE,CAACyF,KAAK;MACX,OAAO,CAAC;IAEV;MACE,MAAM,IAAIvD,KAAK,CAAC,QAAQ,CAAC;EAC7B;AACF;AAIA,SAASY,cAAcA,CAAC1B,MAA6B,EAGnD;EACA,IAAIA,MAAM,YAAYrB,OAAO,EAAE;IAC7B,MAAM;MAACsC,KAAK;MAAEC,MAAM;MAAEoD;IAAE,CAAC,GAAGtE,MAAM;IAClC,MAAMwB,WAAW,GAAGxB,MAAM,CAACb,MAAM,CAACoF,iBAAiB,CAAC;MAClDD,EAAE,EAAG,mBAAkBA,EAAG,EAAC;MAC3BrD,KAAK;MACLC,MAAM;MACNsD,gBAAgB,EAAE,CAACxE,MAAM;IAC3B,CAAC,CAAgC;IAEjC,OAAO;MAACwB,WAAW;MAAEC,kBAAkB,EAAE;IAAI,CAAC;EAChD;EACA,OAAO;IAACD,WAAW,EAAExB,MAAqC;IAAEyB,kBAAkB,EAAE;EAAK,CAAC;AACxF"}
1
+ {"version":3,"file":"webgl-command-buffer.js","names":["CommandBuffer","Texture","WEBGLTexture","getWebGLTextureParameters","cast","value","WEBGLCommandBuffer","constructor","device","commands","submitCommands","arguments","length","undefined","command","name","_copyBufferToBuffer","options","_copyBufferToTexture","_copyTextureToBuffer","_copyTextureToTexture","source","destination","gl2","assertWebGL2","_options$sourceOffset","_options$destinationO","bindBuffer","handle","copyBufferSubData","sourceOffset","destinationOffset","size","Error","mipLevel","aspect","width","height","depthOrArrayLayers","origin","byteOffset","bytesPerRow","rowsPerImage","framebuffer","destroyFramebuffer","getFramebuffer","webglBuffer","sourceWidth","sourceHeight","sourceParams","texture","format","sourceFormat","dataFormat","sourceType","type","bindFramebuffer","readPixels","destroy","destinationMipmaplevel","destinationInternalFormat","sourceX","sourceY","isSubCopy","gl","textureTarget","Number","isFinite","bind","copyTexImage2D","unbind","glFormatToComponents","glTypeToBytes","id","createFramebuffer","colorAttachments"],"sources":["../../../src/adapter/resources/webgl-command-buffer.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {\n CopyBufferToBufferOptions,\n CopyBufferToTextureOptions,\n CopyTextureToBufferOptions,\n CopyTextureToTextureOptions\n} from '@luma.gl/core';\nimport {CommandBuffer, Texture, Framebuffer} from '@luma.gl/core';\nimport {GL} from '@luma.gl/constants';\n\nimport {WebGLDevice} from '../webgl-device';\nimport {WEBGLBuffer} from './webgl-buffer';\nimport {WEBGLTexture} from './webgl-texture';\nimport {WEBGLFramebuffer} from './webgl-framebuffer';\nimport {getWebGLTextureParameters} from '../converters/texture-formats';\n\nfunction cast<T>(value: unknown): T {\n return value as T;\n}\n\ntype CopyBufferToBufferCommand = {\n name: 'copy-buffer-to-buffer';\n options: CopyBufferToBufferOptions;\n};\n\ntype CopyBufferToTextureCommand = {\n name: 'copy-buffer-to-texture';\n options: CopyBufferToTextureOptions;\n};\n\ntype CopyTextureToBufferCommand = {\n name: 'copy-texture-to-buffer';\n options: CopyTextureToBufferOptions;\n};\n\ntype CopyTextureToTextureCommand = {\n name: 'copy-texture-to-texture';\n options: CopyTextureToTextureOptions;\n};\n\ntype Command =\n | CopyBufferToBufferCommand\n | CopyBufferToTextureCommand\n | CopyTextureToBufferCommand\n | CopyTextureToTextureCommand;\n\nexport class WEBGLCommandBuffer extends CommandBuffer {\n device: WebGLDevice;\n commands: Command[] = [];\n\n constructor(device: WebGLDevice) {\n super(device, {});\n this.device = device;\n }\n\n submitCommands(commands: Command[] = this.commands) {\n for (const command of commands) {\n switch (command.name) {\n case 'copy-buffer-to-buffer':\n _copyBufferToBuffer(this.device, command.options);\n break;\n case 'copy-buffer-to-texture':\n _copyBufferToTexture(this.device, command.options);\n break;\n case 'copy-texture-to-buffer':\n _copyTextureToBuffer(this.device, command.options);\n break;\n case 'copy-texture-to-texture':\n _copyTextureToTexture(this.device, command.options);\n break;\n }\n }\n }\n}\n\nfunction _copyBufferToBuffer(device: WebGLDevice, options: CopyBufferToBufferOptions): void {\n const source = cast<WEBGLBuffer>(options.source);\n const destination = cast<WEBGLBuffer>(options.destination);\n\n const gl2 = device.assertWebGL2();\n if (gl2) {\n // In WebGL2 we can perform the copy on the GPU\n // Use GL.COPY_READ_BUFFER+GL.COPY_WRITE_BUFFER avoid disturbing other targets and locking type\n gl2.bindBuffer(GL.COPY_READ_BUFFER, source.handle);\n gl2.bindBuffer(GL.COPY_WRITE_BUFFER, destination.handle);\n gl2.copyBufferSubData(\n GL.COPY_READ_BUFFER,\n GL.COPY_WRITE_BUFFER,\n options.sourceOffset ?? 0,\n options.destinationOffset ?? 0,\n options.size\n );\n gl2.bindBuffer(GL.COPY_READ_BUFFER, null);\n gl2.bindBuffer(GL.COPY_WRITE_BUFFER, null);\n } else {\n // TODO - in WebGL1 we would have to read back to CPU\n // read / write buffer from / to CPU\n throw new Error('copyBufferToBuffer not implemented in WebGL1');\n }\n}\n\n/**\n * Copies data from a Buffer object into a Texture object\n * NOTE: doesn't wait for copy to be complete\n */\nfunction _copyBufferToTexture(device: WebGLDevice, options: CopyBufferToTextureOptions): void {\n throw new Error('Not implemented');\n}\n\n/**\n * Copies data from a Texture object into a Buffer object.\n * NOTE: doesn't wait for copy to be complete\n */\nfunction _copyTextureToBuffer(device: WebGLDevice, options: CopyTextureToBufferOptions): void {\n const {\n /** Texture to copy to/from. */\n source,\n /** Mip-map level of the texture to copy to/from. (Default 0) */\n mipLevel = 0,\n /** Defines which aspects of the texture to copy to/from. */\n aspect = 'all',\n\n /** Width to copy */\n width = options.source.width,\n /** Height to copy */\n height = options.source.height,\n depthOrArrayLayers = 0,\n /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */\n origin = [0, 0],\n\n /** Destination buffer */\n destination,\n /** Offset, in bytes, from the beginning of the buffer to the start of the image data (default 0) */\n byteOffset = 0,\n /**\n * The stride, in bytes, between the beginning of each block row and the subsequent block row.\n * Required if there are multiple block rows (i.e. the copy height or depth is more than one block).\n */\n bytesPerRow,\n /**\n * Number of block rows per single image of the texture.\n * rowsPerImage &times; bytesPerRow is the stride, in bytes, between the beginning of each image of data and the subsequent image.\n * Required if there are multiple images (i.e. the copy depth is more than one).\n */\n rowsPerImage\n } = options;\n\n // TODO - Not possible to read just stencil or depth part in WebGL?\n if (aspect !== 'all') {\n throw new Error('not supported');\n }\n\n // TODO - mipLevels are set when attaching texture to framebuffer\n if (mipLevel !== 0 || depthOrArrayLayers !== 0 || bytesPerRow || rowsPerImage) {\n throw new Error('not implemented');\n }\n\n // Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature\n const gl2 = device.assertWebGL2();\n\n const {framebuffer, destroyFramebuffer} = getFramebuffer(source);\n try {\n const webglBuffer = destination as WEBGLBuffer;\n const sourceWidth = width || framebuffer.width;\n const sourceHeight = height || framebuffer.height;\n const sourceParams = getWebGLTextureParameters(framebuffer.texture.format, true);\n const sourceFormat = sourceParams.dataFormat;\n const sourceType = sourceParams.type;\n\n // if (!target) {\n // // Create new buffer with enough size\n // const components = glFormatToComponents(sourceFormat);\n // const byteCount = glTypeToBytes(sourceType);\n // const byteLength = byteOffset + sourceWidth * sourceHeight * components * byteCount;\n // target = device.createBuffer({byteLength});\n // }\n\n gl2.bindBuffer(GL.PIXEL_PACK_BUFFER, webglBuffer.handle);\n gl2.bindFramebuffer(GL.FRAMEBUFFER, framebuffer.handle);\n\n gl2.readPixels(\n origin[0],\n origin[1],\n sourceWidth,\n sourceHeight,\n sourceFormat,\n sourceType,\n byteOffset\n );\n } finally {\n gl2.bindBuffer(GL.PIXEL_PACK_BUFFER, null);\n gl2.bindFramebuffer(GL.FRAMEBUFFER, null);\n\n if (destroyFramebuffer) {\n framebuffer.destroy();\n }\n }\n}\n\n/**\n * Copies data from a Framebuffer or a Texture object into a Buffer object.\n * NOTE: doesn't wait for copy to be complete, it programs GPU to perform a DMA transfer.\nexport function readPixelsToBuffer(\n source: Framebuffer | Texture,\n options?: {\n sourceX?: number;\n sourceY?: number;\n sourceFormat?: number;\n target?: Buffer; // A new Buffer object is created when not provided.\n targetByteOffset?: number; // byte offset in buffer object\n // following parameters are auto deduced if not provided\n sourceWidth?: number;\n sourceHeight?: number;\n sourceType?: number;\n }\n): Buffer\n */\n\n/**\n * Copy a rectangle from a Framebuffer or Texture object into a texture (at an offset)\n */\n// eslint-disable-next-line complexity, max-statements\nfunction _copyTextureToTexture(device: WebGLDevice, options: CopyTextureToTextureOptions): void {\n const {\n /** Texture to copy to/from. */\n source,\n /** Mip-map level of the texture to copy to/from. (Default 0) */\n // mipLevel = 0,\n /** Defines which aspects of the texture to copy to/from. */\n // aspect = 'all',\n /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */\n origin = [0, 0],\n\n /** Texture to copy to/from. */\n destination,\n /** Mip-map level of the texture to copy to/from. (Default 0) */\n // destinationMipLevel = options.mipLevel,\n /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */\n // destinationOrigin = [0, 0],\n /** Defines which aspects of the texture to copy to/from. */\n // destinationAspect = options.aspect,\n\n } = options;\n\n let {\n width = options.destination.width,\n height = options.destination.width,\n // depthOrArrayLayers = 0\n } = options;\n\n const destinationMipmaplevel = 0;\n const destinationInternalFormat = GL.RGBA;\n\n const {framebuffer, destroyFramebuffer} = getFramebuffer(source);\n const [sourceX, sourceY] = origin;\n\n const isSubCopy = false;\n // typeof destinationX !== 'undefined' ||\n // typeof destinationY !== 'undefined' ||\n // typeof destinationZ !== 'undefined';\n\n // destinationX = destinationX || 0;\n // destinationY = destinationY || 0;\n // destinationZ = destinationZ || 0;\n device.gl.bindFramebuffer(GL.FRAMEBUFFER, framebuffer.handle);\n // TODO - support gl.readBuffer (WebGL2 only)\n // const prevBuffer = gl.readBuffer(attachment);\n\n let texture = null;\n let textureTarget: GL;\n if (destination instanceof WEBGLTexture) {\n texture = destination;\n width = Number.isFinite(width) ? width : texture.width;\n height = Number.isFinite(height) ? height : texture.height;\n texture.bind(0);\n textureTarget = texture.destination;\n } else {\n throw new Error('whoops');\n // textureTarget = destination;\n }\n\n if (!isSubCopy) {\n device.gl.copyTexImage2D(\n textureTarget,\n destinationMipmaplevel,\n destinationInternalFormat,\n sourceX,\n sourceY,\n width,\n height,\n 0 /* border must be 0 */\n );\n } else {\n // switch (textureTarget) {\n // case GL.TEXTURE_2D:\n // case GL.TEXTURE_CUBE_MAP:\n // device.gl.copyTexSubImage2D(\n // textureTarget,\n // destinationMipmaplevel,\n // destinationX,\n // destinationY,\n // sourceX,\n // sourceY,\n // width,\n // height\n // );\n // break;\n // case GL.TEXTURE_2D_ARRAY:\n // case GL.TEXTURE_3D:\n // const gl2 = device.assertWebGL2();\n // gl2.copyTexSubImage3D(\n // textureTarget,\n // destinationMipmaplevel,\n // destinationX,\n // destinationY,\n // destinationZ,\n // sourceX,\n // sourceY,\n // width,\n // height\n // );\n // break;\n // default:\n // }\n }\n if (texture) {\n texture.unbind();\n }\n // ts-expect-error\n // device.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);\n if (destroyFramebuffer) {\n framebuffer.destroy();\n }\n return texture;\n}\n\n// Returns number of components in a specific readPixels WebGL format\nexport function glFormatToComponents(format): 1 | 2 | 3 | 4 {\n switch (format) {\n case GL.ALPHA:\n case GL.R32F:\n case GL.RED:\n return 1;\n case GL.RG32F:\n case GL.RG:\n return 2;\n case GL.RGB:\n case GL.RGB32F:\n return 3;\n case GL.RGBA:\n case GL.RGBA32F:\n return 4;\n // TODO: Add support for additional WebGL2 formats\n default:\n throw new Error('GLFormat');\n }\n}\n\n// Return byte count for given readPixels WebGL type\nexport function glTypeToBytes(type: GL): 1 | 2 | 4 {\n switch (type) {\n case GL.UNSIGNED_BYTE:\n return 1;\n case GL.UNSIGNED_SHORT_5_6_5:\n case GL.UNSIGNED_SHORT_4_4_4_4:\n case GL.UNSIGNED_SHORT_5_5_5_1:\n return 2;\n case GL.FLOAT:\n return 4;\n // TODO: Add support for additional WebGL2 types\n default:\n throw new Error('GLType');\n }\n}\n\n// Helper methods\n\nfunction getFramebuffer(source: Texture | Framebuffer): {\n framebuffer: WEBGLFramebuffer;\n destroyFramebuffer: boolean;\n} {\n if (source instanceof Texture) {\n const {width, height, id} = source;\n const framebuffer = source.device.createFramebuffer({\n id: `framebuffer-for-${id}`,\n width,\n height,\n colorAttachments: [source]\n }) as unknown as WEBGLFramebuffer;\n\n return {framebuffer, destroyFramebuffer: true};\n }\n return {framebuffer: source as unknown as WEBGLFramebuffer, destroyFramebuffer: false};\n}\n"],"mappings":"AASA,SAAQA,aAAa,EAAEC,OAAO,QAAoB,eAAe;AAAC,SAK1DC,YAAY;AAAA,SAEZC,yBAAyB;AAEjC,SAASC,IAAIA,CAAIC,KAAc,EAAK;EAClC,OAAOA,KAAK;AACd;AA4BA,OAAO,MAAMC,kBAAkB,SAASN,aAAa,CAAC;EAIpDO,WAAWA,CAACC,MAAmB,EAAE;IAC/B,KAAK,CAACA,MAAM,EAAE,CAAC,CAAC,CAAC;IAAC,KAJpBA,MAAM;IAAA,KACNC,QAAQ,GAAc,EAAE;IAItB,IAAI,CAACD,MAAM,GAAGA,MAAM;EACtB;EAEAE,cAAcA,CAAA,EAAsC;IAAA,IAArCD,QAAmB,GAAAE,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI,CAACF,QAAQ;IAChD,KAAK,MAAMK,OAAO,IAAIL,QAAQ,EAAE;MAC9B,QAAQK,OAAO,CAACC,IAAI;QAClB,KAAK,uBAAuB;UAC1BC,mBAAmB,CAAC,IAAI,CAACR,MAAM,EAAEM,OAAO,CAACG,OAAO,CAAC;UACjD;QACF,KAAK,wBAAwB;UAC3BC,oBAAoB,CAAC,IAAI,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BA,EAAG,EAAC;MAC3BrC,KAAK;MACLC,MAAM;MACNsC,gBAAgB,EAAE,CAACtD,MAAM;IAC3B,CAAC,CAAgC;IAEjC,OAAO;MAACsB,WAAW;MAAEC,kBAAkB,EAAE;IAAI,CAAC;EAChD;EACA,OAAO;IAACD,WAAW,EAAEtB,MAAqC;IAAEuB,kBAAkB,EAAE;EAAK,CAAC;AACxF"}
@@ -1,5 +1,4 @@
1
1
  import { Framebuffer, assert } from '@luma.gl/core';
2
- import { GL } from '@luma.gl/constants';
3
2
  import { WEBGLTexture } from "./webgl-texture.js";
4
3
  import { WEBGLRenderbuffer } from "../objects/webgl-renderbuffer.js";
5
4
  import { getDepthStencilAttachmentWebGL } from "../converters/texture-formats.js";
@@ -22,10 +21,10 @@ export class WEBGLFramebuffer extends Framebuffer {
22
21
  props: this.props
23
22
  });
24
23
  this.autoCreateAttachmentTextures();
25
- this.gl.bindFramebuffer(GL.FRAMEBUFFER, this.handle);
24
+ this.gl.bindFramebuffer(36160, this.handle);
26
25
  for (let i = 0; i < this.colorAttachments.length; ++i) {
27
26
  const attachment = this.colorAttachments[i];
28
- const attachmentPoint = GL.COLOR_ATTACHMENT0 + i;
27
+ const attachmentPoint = 36064 + i;
29
28
  if (attachment) {
30
29
  this._attachOne(attachmentPoint, attachment);
31
30
  }
@@ -33,7 +32,7 @@ export class WEBGLFramebuffer extends Framebuffer {
33
32
  if (this.depthStencilAttachment) {
34
33
  this._attachOne(getDepthStencilAttachmentWebGL(this.depthStencilAttachment.format), this.depthStencilAttachment);
35
34
  }
36
- this.gl.bindFramebuffer(GL.FRAMEBUFFER, null);
35
+ this.gl.bindFramebuffer(36160, null);
37
36
  }
38
37
  if (props.check !== false) {
39
38
  this._checkStatus();
@@ -49,10 +48,10 @@ export class WEBGLFramebuffer extends Framebuffer {
49
48
  const {
50
49
  gl
51
50
  } = this;
52
- const prevHandle = gl.bindFramebuffer(GL.FRAMEBUFFER, this.handle);
53
- const status = gl.checkFramebufferStatus(GL.FRAMEBUFFER);
54
- gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
55
- if (status !== gl.FRAMEBUFFER_COMPLETE) {
51
+ const prevHandle = gl.bindFramebuffer(36160, this.handle);
52
+ const status = gl.checkFramebufferStatus(36160);
53
+ gl.bindFramebuffer(36160, prevHandle || null);
54
+ if (status !== 36053) {
56
55
  throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);
57
56
  }
58
57
  }
@@ -105,7 +104,7 @@ export class WEBGLFramebuffer extends Framebuffer {
105
104
  throw new Error('attach');
106
105
  }
107
106
  _attachWEBGLRenderbuffer(attachment, renderbuffer) {
108
- this.gl.framebufferRenderbuffer(GL.FRAMEBUFFER, attachment, GL.RENDERBUFFER, renderbuffer.handle);
107
+ this.gl.framebufferRenderbuffer(36160, attachment, 36161, renderbuffer.handle);
109
108
  }
110
109
  _attachTexture(attachment, texture, layer, level) {
111
110
  const {
@@ -114,17 +113,17 @@ export class WEBGLFramebuffer extends Framebuffer {
114
113
  } = this.device;
115
114
  gl.bindTexture(texture.target, texture.handle);
116
115
  switch (texture.target) {
117
- case GL.TEXTURE_2D_ARRAY:
118
- case GL.TEXTURE_3D:
116
+ case 35866:
117
+ case 32879:
119
118
  this.device.assertWebGL2();
120
- gl2 === null || gl2 === void 0 ? void 0 : gl2.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.target, level, layer);
119
+ gl2 === null || gl2 === void 0 ? void 0 : gl2.framebufferTextureLayer(36160, attachment, texture.target, level, layer);
121
120
  break;
122
- case GL.TEXTURE_CUBE_MAP:
121
+ case 34067:
123
122
  const face = mapIndexToCubeMapFace(layer);
124
- gl.framebufferTexture2D(GL.FRAMEBUFFER, attachment, face, texture.handle, level);
123
+ gl.framebufferTexture2D(36160, attachment, face, texture.handle, level);
125
124
  break;
126
- case GL.TEXTURE_2D:
127
- gl.framebufferTexture2D(GL.FRAMEBUFFER, attachment, GL.TEXTURE_2D, texture.handle, level);
125
+ case 3553:
126
+ gl.framebufferTexture2D(36160, attachment, 3553, texture.handle, level);
128
127
  break;
129
128
  default:
130
129
  assert(false, 'Illegal texture type');
@@ -133,21 +132,21 @@ export class WEBGLFramebuffer extends Framebuffer {
133
132
  }
134
133
  }
135
134
  function mapIndexToCubeMapFace(layer) {
136
- return layer < GL.TEXTURE_CUBE_MAP_POSITIVE_X ? layer + GL.TEXTURE_CUBE_MAP_POSITIVE_X : layer;
135
+ return layer < 34069 ? layer + 34069 : layer;
137
136
  }
138
137
  function _getFrameBufferStatus(status) {
139
138
  switch (status) {
140
- case GL.FRAMEBUFFER_COMPLETE:
139
+ case 36053:
141
140
  return 'success';
142
- case GL.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
141
+ case 36054:
143
142
  return 'Mismatched attachments';
144
- case GL.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
143
+ case 36055:
145
144
  return 'No attachments';
146
- case GL.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
145
+ case 36057:
147
146
  return 'Height/width mismatch';
148
- case GL.FRAMEBUFFER_UNSUPPORTED:
147
+ case 36061:
149
148
  return 'Unsupported or split attachments';
150
- case GL.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
149
+ case 36182:
151
150
  return 'Samples mismatch';
152
151
  default:
153
152
  return `${status}`;
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-framebuffer.js","names":["Framebuffer","assert","GL","WEBGLTexture","WEBGLRenderbuffer","getDepthStencilAttachmentWebGL","WEBGLFramebuffer","texture","colorAttachments","constructor","device","props","gl","handle","isDefaultFramebuffer","createFramebuffer","setSpectorMetadata","id","autoCreateAttachmentTextures","bindFramebuffer","FRAMEBUFFER","i","length","attachment","attachmentPoint","COLOR_ATTACHMENT0","_attachOne","depthStencilAttachment","format","check","_checkStatus","destroy","destroyed","deleteFramebuffer","prevHandle","status","checkFramebufferStatus","FRAMEBUFFER_COMPLETE","Error","_getFrameBufferStatus","createDepthStencilTexture","width","height","resizeAttachments","drawingBufferWidth","drawingBufferHeight","undefined","colorAttachment","resize","_attachWEBGLRenderbuffer","Array","isArray","layer","level","_attachTexture","renderbuffer","framebufferRenderbuffer","RENDERBUFFER","gl2","bindTexture","target","TEXTURE_2D_ARRAY","TEXTURE_3D","assertWebGL2","framebufferTextureLayer","TEXTURE_CUBE_MAP","face","mapIndexToCubeMapFace","framebufferTexture2D","TEXTURE_2D","TEXTURE_CUBE_MAP_POSITIVE_X","FRAMEBUFFER_INCOMPLETE_ATTACHMENT","FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT","FRAMEBUFFER_INCOMPLETE_DIMENSIONS","FRAMEBUFFER_UNSUPPORTED","FRAMEBUFFER_INCOMPLETE_MULTISAMPLE"],"sources":["../../../src/adapter/resources/webgl-framebuffer.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {FramebufferProps, TextureFormat} from '@luma.gl/core';\nimport {Framebuffer, Texture, assert} from '@luma.gl/core';\nimport {GL} from '@luma.gl/constants';\nimport {WebGLDevice} from '../webgl-device';\nimport {WEBGLTexture} from './webgl-texture';\nimport {WEBGLRenderbuffer} from '../objects/webgl-renderbuffer';\nimport {getDepthStencilAttachmentWebGL} from '../converters/texture-formats';\n\nexport type TextureAttachment = [Texture, number?, number?];\nexport type Attachment = WEBGLTexture | WEBGLRenderbuffer | TextureAttachment;\n\n/** luma.gl Framebuffer, WebGL implementation */\nexport class WEBGLFramebuffer extends Framebuffer {\n device: WebGLDevice;\n gl: WebGLRenderingContext;\n handle: WebGLFramebuffer;\n\n get texture() {\n return this.colorAttachments[0];\n }\n\n constructor(device: WebGLDevice, props: FramebufferProps) {\n super(device, props);\n\n // WebGL default framebuffer handle is null\n const isDefaultFramebuffer = props.handle === null;\n\n this.device = device;\n this.gl = device.gl;\n this.handle =\n this.props.handle || isDefaultFramebuffer ? this.props.handle : this.gl.createFramebuffer();\n\n if (!isDefaultFramebuffer) {\n // default framebuffer handle is null, so we can't set spector metadata...\n device.setSpectorMetadata(this.handle, {id: this.props.id, props: this.props});\n\n // Auto create textures for attachments if needed\n this.autoCreateAttachmentTextures();\n\n /** Attach from a map of attachments */\n this.gl.bindFramebuffer(GL.FRAMEBUFFER, this.handle);\n\n // Walk the attachments\n for (let i = 0; i < this.colorAttachments.length; ++i) {\n const attachment = this.colorAttachments[i];\n const attachmentPoint = GL.COLOR_ATTACHMENT0 + i;\n if (attachment) {\n this._attachOne(attachmentPoint, attachment as WEBGLTexture);\n }\n }\n\n if (this.depthStencilAttachment) {\n this._attachOne(\n getDepthStencilAttachmentWebGL(this.depthStencilAttachment.format),\n this.depthStencilAttachment as WEBGLTexture\n );\n }\n\n this.gl.bindFramebuffer(GL.FRAMEBUFFER, null);\n }\n\n // @ts-expect-error\n if (props.check !== false) {\n this._checkStatus();\n }\n }\n\n /** destroys any auto created resources etc. */\n override destroy(): void {\n super.destroy(); // destroys owned resources etc.\n if (!this.destroyed && this.handle !== null) {\n this.gl.deleteFramebuffer(this.handle);\n // this.handle = null;\n }\n }\n\n // PRIVATE\n\n /** Check the status */\n protected _checkStatus(): void {\n const {gl} = this;\n // TODO - should we really rely on this trick? \n const prevHandle = gl.bindFramebuffer(GL.FRAMEBUFFER, this.handle) as unknown as WebGLFramebuffer;\n const status = gl.checkFramebufferStatus(GL.FRAMEBUFFER);\n gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);\n if (status !== gl.FRAMEBUFFER_COMPLETE) {\n throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);\n }\n }\n\n /** In WebGL we must use renderbuffers for depth/stencil attachments (unless we have extensions) */\n protected override createDepthStencilTexture(format: TextureFormat): Texture {\n return new WEBGLRenderbuffer(this.device, {\n id: `${this.id}-depth-stencil`, // TODO misleading if not depth and stencil?\n format,\n // dataFormat: GL.DEPTH_STENCIL,\n // type: GL.UNSIGNED_INT_24_8,\n width: this.width,\n height: this.height\n }) as unknown as WEBGLTexture;\n }\n\n /** \n * Attachment resize is expected to be a noop if size is same \n */\n protected override resizeAttachments(width: number, height: number): this {\n // for default framebuffer, just update the stored size\n if (this.handle === null) {\n // assert(width === undefined && height === undefined);\n this.width = this.gl.drawingBufferWidth;\n this.height = this.gl.drawingBufferHeight;\n return this;\n }\n\n if (width === undefined) {\n width = this.gl.drawingBufferWidth;\n }\n if (height === undefined) {\n height = this.gl.drawingBufferHeight;\n }\n\n // TODO Not clear that this is better than default destroy/create implementation\n\n for (const colorAttachment of this.colorAttachments) {\n (colorAttachment as WEBGLTexture).resize({width, height});\n }\n if (this.depthStencilAttachment) {\n (this.depthStencilAttachment as WEBGLTexture).resize({width, height});\n }\n return this;\n }\n\n /** Attach one attachment */\n protected _attachOne(\n attachmentPoint: GL,\n attachment: Attachment\n ): WEBGLTexture | WEBGLRenderbuffer {\n if (attachment instanceof WEBGLRenderbuffer) {\n this._attachWEBGLRenderbuffer(attachmentPoint, attachment);\n return attachment;\n } else if (Array.isArray(attachment)) {\n const [texture, layer = 0, level = 0] = attachment;\n this._attachTexture(attachmentPoint, texture as unknown as WEBGLTexture, layer, level);\n return texture as unknown as WEBGLTexture;\n } else if (attachment instanceof WEBGLTexture) {\n this._attachTexture(attachmentPoint, attachment, 0, 0);\n return attachment;\n }\n throw new Error('attach');\n }\n\n protected _attachWEBGLRenderbuffer(attachment: GL, renderbuffer: WEBGLRenderbuffer): void {\n this.gl.framebufferRenderbuffer(\n GL.FRAMEBUFFER,\n attachment,\n GL.RENDERBUFFER,\n renderbuffer.handle\n );\n }\n\n /**\n * @param attachment\n * @param texture\n * @param layer = 0 - index into WEBGLTextureArray and Texture3D or face for `TextureCubeMap`\n * @param level = 0 - mipmapLevel (must be 0 in WebGL1)\n */\n protected _attachTexture(\n attachment: GL,\n texture: WEBGLTexture,\n layer: number,\n level: number\n ): void {\n const {gl, gl2} = this.device;\n gl.bindTexture(texture.target, texture.handle);\n\n switch (texture.target) {\n case GL.TEXTURE_2D_ARRAY:\n case GL.TEXTURE_3D:\n this.device.assertWebGL2();\n gl2?.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.target, level, layer);\n break;\n\n case GL.TEXTURE_CUBE_MAP:\n // layer must be a cubemap face (or if index, converted to cube map face)\n const face = mapIndexToCubeMapFace(layer);\n gl.framebufferTexture2D(GL.FRAMEBUFFER, attachment, face, texture.handle, level);\n break;\n\n case GL.TEXTURE_2D:\n gl.framebufferTexture2D(GL.FRAMEBUFFER, attachment, GL.TEXTURE_2D, texture.handle, level);\n break;\n\n default:\n assert(false, 'Illegal texture type');\n }\n\n gl.bindTexture(texture.target, null);\n }\n}\n\n// Helper functions\n\n// Map an index to a cube map face constant\nfunction mapIndexToCubeMapFace(layer: number | GL): GL {\n // TEXTURE_CUBE_MAP_POSITIVE_X is a big value (0x8515)\n // if smaller assume layer is index, otherwise assume it is already a cube map face constant\n return layer < GL.TEXTURE_CUBE_MAP_POSITIVE_X ? layer + GL.TEXTURE_CUBE_MAP_POSITIVE_X : layer;\n}\n\n// Helper METHODS\n// Get a string describing the framebuffer error if installed\nfunction _getFrameBufferStatus(status: GL) {\n switch (status) {\n case GL.FRAMEBUFFER_COMPLETE:\n return 'success';\n case GL.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:\n return 'Mismatched attachments';\n case GL.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:\n return 'No attachments';\n case GL.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:\n return 'Height/width mismatch';\n case GL.FRAMEBUFFER_UNSUPPORTED:\n return 'Unsupported or split attachments';\n // WebGL2\n case GL.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:\n return 'Samples mismatch';\n // OVR_multiview2 extension\n // case GL.FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_OVR: return 'baseViewIndex mismatch';\n default:\n return `${status}`;\n }\n}\n"],"mappings":"AAIA,SAAQA,WAAW,EAAWC,MAAM,QAAO,eAAe;AAC1D,SAAQC,EAAE,QAAO,oBAAoB;AAAC,SAE9BC,YAAY;AAAA,SACZC,iBAAiB;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AAE3D,OAAO,CAACM,MAAM,EAAEwC,KAAK,CAAC;QAChF;MAEF,KAAKnD,EAAE,CAACmE,UAAU;QAChBzD,EAAE,CAACwD,oBAAoB,CAAClE,EAAE,CAACkB,WAAW,EAAEG,UAAU,EAAErB,EAAE,CAACmE,UAAU,EAAE9D,OAAO,CAACM,MAAM,EAAEwC,KAAK,CAAC;QACzF;MAEF;QACEpD,MAAM,CAAC,KAAK,EAAE,sBAAsB,CAAC;IACzC;IAEAW,EAAE,CAAC+C,WAAW,CAACpD,OAAO,CAACqD,MAAM,EAAE,IAAI,CAAC;EACtC;AACF;AAKA,SAASO,qBAAqBA,CAACf,KAAkB,EAAM;EAGrD,OAAOA,KAAK,GAAGlD,EAAE,CAACoE,2BAA2B,GAAGlB,KAAK,GAAGlD,EAAE,CAACoE,2BAA2B,GAAGlB,KAAK;AAChG;AAIA,SAASb,qBAAqBA,CAACJ,MAAU,EAAE;EACzC,QAAQA,MAAM;IACZ,KAAKjC,EAAE,CAACmC,oBAAoB;MAC1B,OAAO,SAAS;IAClB,KAAKnC,EAAE,CAACqE,iCAAiC;MACvC,OAAO,wBAAwB;IACjC,KAAKrE,EAAE,CAACsE,yCAAyC;MAC/C,OAAO,gBAAgB;IACzB,KAAKtE,EAAE,CAACuE,iCAAiC;MACvC,OAAO,uBAAuB;IAChC,KAAKvE,EAAE,CAACwE,uBAAuB;MAC7B,OAAO,kCAAkC;IAE3C,KAAKxE,EAAE,CAACyE,kCAAkC;MACxC,OAAO,kBAAkB;IAG3B;MACE,OAAQ,GAAExC,MAAO,EAAC;EACtB;AACF"}
1
+ {"version":3,"file":"webgl-framebuffer.js","names":["Framebuffer","assert","WEBGLTexture","WEBGLRenderbuffer","getDepthStencilAttachmentWebGL","WEBGLFramebuffer","texture","colorAttachments","constructor","device","props","gl","handle","isDefaultFramebuffer","createFramebuffer","setSpectorMetadata","id","autoCreateAttachmentTextures","bindFramebuffer","i","length","attachment","attachmentPoint","_attachOne","depthStencilAttachment","format","check","_checkStatus","destroy","destroyed","deleteFramebuffer","prevHandle","status","checkFramebufferStatus","Error","_getFrameBufferStatus","createDepthStencilTexture","width","height","resizeAttachments","drawingBufferWidth","drawingBufferHeight","undefined","colorAttachment","resize","_attachWEBGLRenderbuffer","Array","isArray","layer","level","_attachTexture","renderbuffer","framebufferRenderbuffer","gl2","bindTexture","target","assertWebGL2","framebufferTextureLayer","face","mapIndexToCubeMapFace","framebufferTexture2D"],"sources":["../../../src/adapter/resources/webgl-framebuffer.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {FramebufferProps, TextureFormat} from '@luma.gl/core';\nimport {Framebuffer, Texture, assert} from '@luma.gl/core';\nimport {GL} from '@luma.gl/constants';\nimport {WebGLDevice} from '../webgl-device';\nimport {WEBGLTexture} from './webgl-texture';\nimport {WEBGLRenderbuffer} from '../objects/webgl-renderbuffer';\nimport {getDepthStencilAttachmentWebGL} from '../converters/texture-formats';\n\nexport type TextureAttachment = [Texture, number?, number?];\nexport type Attachment = WEBGLTexture | WEBGLRenderbuffer | TextureAttachment;\n\n/** luma.gl Framebuffer, WebGL implementation */\nexport class WEBGLFramebuffer extends Framebuffer {\n device: WebGLDevice;\n gl: WebGLRenderingContext;\n handle: WebGLFramebuffer;\n\n get texture() {\n return this.colorAttachments[0];\n }\n\n constructor(device: WebGLDevice, props: FramebufferProps) {\n super(device, props);\n\n // WebGL default framebuffer handle is null\n const isDefaultFramebuffer = props.handle === null;\n\n this.device = device;\n this.gl = device.gl;\n this.handle =\n this.props.handle || isDefaultFramebuffer ? this.props.handle : this.gl.createFramebuffer();\n\n if (!isDefaultFramebuffer) {\n // default framebuffer handle is null, so we can't set spector metadata...\n device.setSpectorMetadata(this.handle, {id: this.props.id, props: this.props});\n\n // Auto create textures for attachments if needed\n this.autoCreateAttachmentTextures();\n\n /** Attach from a map of attachments */\n this.gl.bindFramebuffer(GL.FRAMEBUFFER, this.handle);\n\n // Walk the attachments\n for (let i = 0; i < this.colorAttachments.length; ++i) {\n const attachment = this.colorAttachments[i];\n const attachmentPoint = GL.COLOR_ATTACHMENT0 + i;\n if (attachment) {\n this._attachOne(attachmentPoint, attachment as WEBGLTexture);\n }\n }\n\n if (this.depthStencilAttachment) {\n this._attachOne(\n getDepthStencilAttachmentWebGL(this.depthStencilAttachment.format),\n this.depthStencilAttachment as WEBGLTexture\n );\n }\n\n this.gl.bindFramebuffer(GL.FRAMEBUFFER, null);\n }\n\n // @ts-expect-error\n if (props.check !== false) {\n this._checkStatus();\n }\n }\n\n /** destroys any auto created resources etc. */\n override destroy(): void {\n super.destroy(); // destroys owned resources etc.\n if (!this.destroyed && this.handle !== null) {\n this.gl.deleteFramebuffer(this.handle);\n // this.handle = null;\n }\n }\n\n // PRIVATE\n\n /** Check the status */\n protected _checkStatus(): void {\n const {gl} = this;\n // TODO - should we really rely on this trick? \n const prevHandle = gl.bindFramebuffer(GL.FRAMEBUFFER, this.handle) as unknown as WebGLFramebuffer;\n const status = gl.checkFramebufferStatus(GL.FRAMEBUFFER);\n gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);\n if (status !== gl.FRAMEBUFFER_COMPLETE) {\n throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);\n }\n }\n\n /** In WebGL we must use renderbuffers for depth/stencil attachments (unless we have extensions) */\n protected override createDepthStencilTexture(format: TextureFormat): Texture {\n return new WEBGLRenderbuffer(this.device, {\n id: `${this.id}-depth-stencil`, // TODO misleading if not depth and stencil?\n format,\n // dataFormat: GL.DEPTH_STENCIL,\n // type: GL.UNSIGNED_INT_24_8,\n width: this.width,\n height: this.height\n }) as unknown as WEBGLTexture;\n }\n\n /** \n * Attachment resize is expected to be a noop if size is same \n */\n protected override resizeAttachments(width: number, height: number): this {\n // for default framebuffer, just update the stored size\n if (this.handle === null) {\n // assert(width === undefined && height === undefined);\n this.width = this.gl.drawingBufferWidth;\n this.height = this.gl.drawingBufferHeight;\n return this;\n }\n\n if (width === undefined) {\n width = this.gl.drawingBufferWidth;\n }\n if (height === undefined) {\n height = this.gl.drawingBufferHeight;\n }\n\n // TODO Not clear that this is better than default destroy/create implementation\n\n for (const colorAttachment of this.colorAttachments) {\n (colorAttachment as WEBGLTexture).resize({width, height});\n }\n if (this.depthStencilAttachment) {\n (this.depthStencilAttachment as WEBGLTexture).resize({width, height});\n }\n return this;\n }\n\n /** Attach one attachment */\n protected _attachOne(\n attachmentPoint: GL,\n attachment: Attachment\n ): WEBGLTexture | WEBGLRenderbuffer {\n if (attachment instanceof WEBGLRenderbuffer) {\n this._attachWEBGLRenderbuffer(attachmentPoint, attachment);\n return attachment;\n } else if (Array.isArray(attachment)) {\n const [texture, layer = 0, level = 0] = attachment;\n this._attachTexture(attachmentPoint, texture as unknown as WEBGLTexture, layer, level);\n return texture as unknown as WEBGLTexture;\n } else if (attachment instanceof WEBGLTexture) {\n this._attachTexture(attachmentPoint, attachment, 0, 0);\n return attachment;\n }\n throw new Error('attach');\n }\n\n protected _attachWEBGLRenderbuffer(attachment: GL, renderbuffer: WEBGLRenderbuffer): void {\n this.gl.framebufferRenderbuffer(\n GL.FRAMEBUFFER,\n attachment,\n GL.RENDERBUFFER,\n renderbuffer.handle\n );\n }\n\n /**\n * @param attachment\n * @param texture\n * @param layer = 0 - index into WEBGLTextureArray and Texture3D or face for `TextureCubeMap`\n * @param level = 0 - mipmapLevel (must be 0 in WebGL1)\n */\n protected _attachTexture(\n attachment: GL,\n texture: WEBGLTexture,\n layer: number,\n level: number\n ): void {\n const {gl, gl2} = this.device;\n gl.bindTexture(texture.target, texture.handle);\n\n switch (texture.target) {\n case GL.TEXTURE_2D_ARRAY:\n case GL.TEXTURE_3D:\n this.device.assertWebGL2();\n gl2?.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.target, level, layer);\n break;\n\n case GL.TEXTURE_CUBE_MAP:\n // layer must be a cubemap face (or if index, converted to cube map face)\n const face = mapIndexToCubeMapFace(layer);\n gl.framebufferTexture2D(GL.FRAMEBUFFER, attachment, face, texture.handle, level);\n break;\n\n case GL.TEXTURE_2D:\n gl.framebufferTexture2D(GL.FRAMEBUFFER, attachment, GL.TEXTURE_2D, texture.handle, level);\n break;\n\n default:\n assert(false, 'Illegal texture type');\n }\n\n gl.bindTexture(texture.target, null);\n }\n}\n\n// Helper functions\n\n// Map an index to a cube map face constant\nfunction mapIndexToCubeMapFace(layer: number | GL): GL {\n // TEXTURE_CUBE_MAP_POSITIVE_X is a big value (0x8515)\n // if smaller assume layer is index, otherwise assume it is already a cube map face constant\n return layer < GL.TEXTURE_CUBE_MAP_POSITIVE_X ? layer + GL.TEXTURE_CUBE_MAP_POSITIVE_X : layer;\n}\n\n// Helper METHODS\n// Get a string describing the framebuffer error if installed\nfunction _getFrameBufferStatus(status: GL) {\n switch (status) {\n case GL.FRAMEBUFFER_COMPLETE:\n return 'success';\n case GL.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:\n return 'Mismatched attachments';\n case GL.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:\n return 'No attachments';\n case GL.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:\n return 'Height/width mismatch';\n case GL.FRAMEBUFFER_UNSUPPORTED:\n return 'Unsupported or split attachments';\n // WebGL2\n case GL.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:\n return 'Samples mismatch';\n // OVR_multiview2 extension\n // case GL.FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_OVR: return 'baseViewIndex mismatch';\n default:\n return `${status}`;\n }\n}\n"],"mappings":"AAIA,SAAQA,WAAW,EAAWC,MAAM,QAAO,eAAe;AAAC,SAGnDC,YAAY;AAAA,SACZC,iBAAiB;AAAA,SACjBC,8BAA8B;AAMtC,OAAO,MAAMC,gBAAgB,SAASL,WAAW,CAAC;EAKhD,IAAIM,OAAOA,CAAA,EAAG;IACZ,OAAO,IAAI,CAACC,gBAAgB,CAAC,CAAC,CAAC;EACjC;EAEAC,WAAWA,CAACC,MAAmB,EAAEC,KAAuB,E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E,OAAO,kCAAkC;IAE3C;MACE,OAAO,kBAAkB;IAG3B;MACE,OAAQ,GAAEA,MAAO,EAAC;EACtB;AACF"}
@@ -1,5 +1,4 @@
1
1
  import { RenderPass } from '@luma.gl/core';
2
- import { GL } from '@luma.gl/constants';
3
2
  import { withGLParameters } from "../../context/state-tracker/with-parameters.js";
4
3
  import { setGLParameters } from "../../context/parameters/unified-parameter-api.js";
5
4
  import { pushContextState, popContextState } from "../../context/state-tracker/track-context-state.js";
@@ -38,7 +37,7 @@ export class WEBGLRenderPass extends RenderPass {
38
37
  glParameters.depthMask = !this.props.depthReadOnly;
39
38
  }
40
39
  glParameters.stencilMask = this.props.stencilReadOnly ? 0 : 1;
41
- glParameters[GL.RASTERIZER_DISCARD] = this.props.discard;
40
+ glParameters[35977] = this.props.discard;
42
41
  if (parameters.viewport) {
43
42
  if (parameters.viewport.length >= 6) {
44
43
  glParameters.viewport = parameters.viewport.slice(0, 4);
@@ -56,7 +55,7 @@ export class WEBGLRenderPass extends RenderPass {
56
55
  }
57
56
  if (parameters.stencilReference) {
58
57
  console.warn('RenderPassParameters.stencilReference not yet implemented in WebGL');
59
- parameters[GL.STENCIL_REF] = parameters.stencilReference;
58
+ parameters[2967] = parameters.stencilReference;
60
59
  }
61
60
  this.glParameters = glParameters;
62
61
  setGLParameters(this.device, glParameters);
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-render-pass.js","names":["RenderPass","GL","withGLParameters","setGLParameters","pushContextState","popContextState","GL_DEPTH_BUFFER_BIT","GL_STENCIL_BUFFER_BIT","GL_COLOR_BUFFER_BIT","GL_COLOR","WEBGLRenderPass","constructor","device","props","glParameters","gl","setParameters","parameters","clear","end","framebuffer","pushDebugGroup","groupLabel","popDebugGroup","insertDebugMarker","markerLabel","arguments","length","undefined","depthReadOnly","depthMask","stencilMask","stencilReadOnly","RASTERIZER_DISCARD","discard","viewport","slice","depthRange","scissorTest","Boolean","scissorRect","scissor","blendConstant","blendColor","stencilReference","console","warn","STENCIL_REF","clearMask","clearColor","clearDepth","clearStencil","clearColorBuffer","drawBuffer","value","gl2","Int32Array","clearBufferiv","Uint32Array","clearBufferuiv","Float32Array","clearBufferfv"],"sources":["../../../src/adapter/resources/webgl-render-pass.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {RenderPass, RenderPassProps, NumberArray, RenderPassParameters} from '@luma.gl/core';\nimport {WebGLDevice} from '../webgl-device';\nimport {GL, GLParameters} from '@luma.gl/constants';\nimport {withGLParameters} from '../../context/state-tracker/with-parameters';\nimport {setGLParameters} from '../../context/parameters/unified-parameter-api';\nimport {pushContextState, popContextState} from '../../context/state-tracker/track-context-state';\n\n// Should collapse during minification\nconst GL_DEPTH_BUFFER_BIT = 0x00000100;\nconst GL_STENCIL_BUFFER_BIT = 0x00000400;\nconst GL_COLOR_BUFFER_BIT = 0x00004000;\n\nconst GL_COLOR = 0x1800;\n\nexport class WEBGLRenderPass extends RenderPass {\n readonly device: WebGLDevice;\n\n /** Parameters that should be applied before each draw call */\n glParameters: GLParameters;\n\n constructor(device: WebGLDevice, props: RenderPassProps) {\n super(device, props);\n this.device = device;\n\n // TODO - do parameters (scissorRect) affect the clear operation?\n pushContextState(this.device.gl);\n this.setParameters(this.props.parameters);\n\n // Hack - for now WebGL draws in \"immediate mode\" (instead of queueing the operations)...\n this.clear();\n }\n\n end(): void {\n popContextState(this.device.gl);\n if (this.props.framebuffer) {\n setGLParameters(this.device, {framebuffer: null});\n }\n // should add commands to CommandEncoder.\n }\n\n pushDebugGroup(groupLabel: string): void {}\n popDebugGroup(): void {}\n insertDebugMarker(markerLabel: string): void {}\n\n // writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;\n\n // beginOcclusionQuery(queryIndex: number): void;\n // endOcclusionQuery(): void;\n\n // executeBundles(bundles: Iterable<GPURenderBundle>): void;\n\n /**\n * Maps RenderPass parameters to GL parameters\n */\n setParameters(parameters: RenderPassParameters = {}): void {\n const glParameters: GLParameters = {};\n\n // Framebuffers are specified using parameters in WebGL\n if (this.props.framebuffer) {\n glParameters.framebuffer = this.props.framebuffer;\n }\n\n if (this.props.depthReadOnly) {\n glParameters.depthMask = !this.props.depthReadOnly;\n }\n\n glParameters.stencilMask = this.props.stencilReadOnly ? 0 : 1;\n\n glParameters[GL.RASTERIZER_DISCARD] = this.props.discard;\n\n // Map the four renderpass parameters to WebGL parameters\n if (parameters.viewport) {\n // WebGPU viewports are 6 coordinates (X, Y, Z)\n if (parameters.viewport.length >= 6) {\n glParameters.viewport = parameters.viewport.slice(0, 4);\n glParameters.depthRange = [parameters.viewport[4], parameters.viewport[5]];\n } else {\n // WebGL viewports are 4 coordinates (X, Y)\n glParameters.viewport = parameters.viewport;\n }\n }\n glParameters.scissorTest = Boolean(parameters.scissorRect);\n if (parameters.scissorRect) {\n glParameters.scissor = parameters.scissorRect;\n }\n if (parameters.blendConstant) {\n glParameters.blendColor = parameters.blendConstant;\n }\n if (parameters.stencilReference) {\n // eslint-disable-next-line no-console\n console.warn('RenderPassParameters.stencilReference not yet implemented in WebGL');\n // parameters.stencilFunc = [func, ref, mask];\n // Does this work?\n parameters[GL.STENCIL_REF] = parameters.stencilReference;\n }\n\n this.glParameters = glParameters;\n\n setGLParameters(this.device, glParameters);\n }\n\n // Internal\n\n /**\n * Optionally clears depth, color and stencil buffers based on parameters\n */\n protected clear(): void {\n const glParameters: GLParameters = {...this.glParameters};\n\n let clearMask = 0;\n\n if (this.props.clearColor !== false) {\n clearMask |= GL_COLOR_BUFFER_BIT;\n glParameters.clearColor = this.props.clearColor;\n }\n if (this.props.clearDepth !== false) {\n clearMask |= GL_DEPTH_BUFFER_BIT;\n glParameters.clearDepth = this.props.clearDepth;\n }\n if (this.props.clearStencil !== false) {\n clearMask |= GL_STENCIL_BUFFER_BIT;\n glParameters.clearStencil = this.props.clearStencil;\n }\n\n if (clearMask !== 0) {\n // Temporarily set any clear \"colors\" and call clear\n withGLParameters(this.device, glParameters, () => {\n this.device.gl.clear(clearMask);\n });\n\n // TODO - clear multiple color attachments\n // for (attachment of this.framebuffer.colorAttachments) {\n // this.clearColorBuffer \n // }\n }\n }\n\n /** \n * WebGL2 - clear a specific color buffer \n */\n protected clearColorBuffer(drawBuffer: number = 0, value: NumberArray = [0, 0, 0, 0]) {\n withGLParameters(this.device.gl2, {framebuffer: this.props.framebuffer}, () => {\n // Method selection per OpenGL ES 3 docs\n switch (value.constructor) {\n case Int32Array:\n this.device.gl2.clearBufferiv(GL_COLOR, drawBuffer, value);\n break;\n case Uint32Array:\n this.device.gl2.clearBufferuiv(GL_COLOR, drawBuffer, value);\n break;\n case Float32Array:\n default:\n this.device.gl2.clearBufferfv(GL_COLOR, drawBuffer, value);\n break;\n }\n });\n }\n\n // clearDepthStencil() {\n // const GL_DEPTH = 0x1801;\n // const GL_STENCIL = 0x1802;\n // const GL_DEPTH_STENCIL = 0x84f9;\n\n // case GL_DEPTH:\n // this.device.gl2.clearBufferfv(GL_DEPTH, 0, [value]);\n // break;\n\n // case GL_STENCIL:\n // this.device.gl2.clearBufferiv(GL_STENCIL, 0, [value]);\n // break;\n\n // case GL_DEPTH_STENCIL:\n // const [depth, stencil] = value;\n // this.device.gl2.clearBufferfi(GL_DEPTH_STENCIL, 0, depth, stencil);\n // break;\n\n // default:\n // assert(false, ERR_ARGUMENTS);\n // }\n // });\n}\n\n"],"mappings":"AAGA,SAAQA,UAAU,QAA2D,eAAe;AAE5F,SAAQC,EAAE,QAAqB,oBAAoB;AAAC,SAC5CC,gBAAgB;AAAA,SAChBC,eAAe;AAAA,SACfC,gBAAgB,EAAEC,eAAe;AAGzC,MAAMC,mBAAmB,GAAG,UAAU;AACtC,MAAMC,qBAAqB,GAAG,UAAU;AACxC,MAAMC,mBAAmB,GAAG,UAAU;AAEtC,MAAMC,QAAQ,GAAG,MAAM;AAEvB,OAAO,MAAMC,eAAe,SAASV,UAAU,CAAC;EAM9CW,WAAWA,CAACC,MAAmB,EAAEC,KAAsB,EAAE;IACvD,KAAK,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C,KAAK,CAAC;UAC3D;QACF,KAAKM,YAAY;QACjB;UACE,IAAI,CAAChD,MAAM,CAAC2C,GAAG,CAACM,aAAa,CAACpD,QAAQ,EAAE4C,UAAU,EAAEC,KAAK,CAAC;UAC1D;MACJ;IACF,CAAC,CAAC;EACJ;AAwBF"}
1
+ {"version":3,"file":"webgl-render-pass.js","names":["RenderPass","withGLParameters","setGLParameters","pushContextState","popContextState","GL_DEPTH_BUFFER_BIT","GL_STENCIL_BUFFER_BIT","GL_COLOR_BUFFER_BIT","GL_COLOR","WEBGLRenderPass","constructor","device","props","glParameters","gl","setParameters","parameters","clear","end","framebuffer","pushDebugGroup","groupLabel","popDebugGroup","insertDebugMarker","markerLabel","arguments","length","undefined","depthReadOnly","depthMask","stencilMask","stencilReadOnly","discard","viewport","slice","depthRange","scissorTest","Boolean","scissorRect","scissor","blendConstant","blendColor","stencilReference","console","warn","clearMask","clearColor","clearDepth","clearStencil","clearColorBuffer","drawBuffer","value","gl2","Int32Array","clearBufferiv","Uint32Array","clearBufferuiv","Float32Array","clearBufferfv"],"sources":["../../../src/adapter/resources/webgl-render-pass.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {RenderPass, RenderPassProps, NumberArray, RenderPassParameters} from '@luma.gl/core';\nimport {WebGLDevice} from '../webgl-device';\nimport {GL, GLParameters} from '@luma.gl/constants';\nimport {withGLParameters} from '../../context/state-tracker/with-parameters';\nimport {setGLParameters} from '../../context/parameters/unified-parameter-api';\nimport {pushContextState, popContextState} from '../../context/state-tracker/track-context-state';\n\n// Should collapse during minification\nconst GL_DEPTH_BUFFER_BIT = 0x00000100;\nconst GL_STENCIL_BUFFER_BIT = 0x00000400;\nconst GL_COLOR_BUFFER_BIT = 0x00004000;\n\nconst GL_COLOR = 0x1800;\n\nexport class WEBGLRenderPass extends RenderPass {\n readonly device: WebGLDevice;\n\n /** Parameters that should be applied before each draw call */\n glParameters: GLParameters;\n\n constructor(device: WebGLDevice, props: RenderPassProps) {\n super(device, props);\n this.device = device;\n\n // TODO - do parameters (scissorRect) affect the clear operation?\n pushContextState(this.device.gl);\n this.setParameters(this.props.parameters);\n\n // Hack - for now WebGL draws in \"immediate mode\" (instead of queueing the operations)...\n this.clear();\n }\n\n end(): void {\n popContextState(this.device.gl);\n if (this.props.framebuffer) {\n setGLParameters(this.device, {framebuffer: null});\n }\n // should add commands to CommandEncoder.\n }\n\n pushDebugGroup(groupLabel: string): void {}\n popDebugGroup(): void {}\n insertDebugMarker(markerLabel: string): void {}\n\n // writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;\n\n // beginOcclusionQuery(queryIndex: number): void;\n // endOcclusionQuery(): void;\n\n // executeBundles(bundles: Iterable<GPURenderBundle>): void;\n\n /**\n * Maps RenderPass parameters to GL parameters\n */\n setParameters(parameters: RenderPassParameters = {}): void {\n const glParameters: GLParameters = {};\n\n // Framebuffers are specified using parameters in WebGL\n if (this.props.framebuffer) {\n glParameters.framebuffer = this.props.framebuffer;\n }\n\n if (this.props.depthReadOnly) {\n glParameters.depthMask = !this.props.depthReadOnly;\n }\n\n glParameters.stencilMask = this.props.stencilReadOnly ? 0 : 1;\n\n glParameters[GL.RASTERIZER_DISCARD] = this.props.discard;\n\n // Map the four renderpass parameters to WebGL parameters\n if (parameters.viewport) {\n // WebGPU viewports are 6 coordinates (X, Y, Z)\n if (parameters.viewport.length >= 6) {\n glParameters.viewport = parameters.viewport.slice(0, 4);\n glParameters.depthRange = [parameters.viewport[4], parameters.viewport[5]];\n } else {\n // WebGL viewports are 4 coordinates (X, Y)\n glParameters.viewport = parameters.viewport;\n }\n }\n glParameters.scissorTest = Boolean(parameters.scissorRect);\n if (parameters.scissorRect) {\n glParameters.scissor = parameters.scissorRect;\n }\n if (parameters.blendConstant) {\n glParameters.blendColor = parameters.blendConstant;\n }\n if (parameters.stencilReference) {\n // eslint-disable-next-line no-console\n console.warn('RenderPassParameters.stencilReference not yet implemented in WebGL');\n // parameters.stencilFunc = [func, ref, mask];\n // Does this work?\n parameters[GL.STENCIL_REF] = parameters.stencilReference;\n }\n\n this.glParameters = glParameters;\n\n setGLParameters(this.device, glParameters);\n }\n\n // Internal\n\n /**\n * Optionally clears depth, color and stencil buffers based on parameters\n */\n protected clear(): void {\n const glParameters: GLParameters = {...this.glParameters};\n\n let clearMask = 0;\n\n if (this.props.clearColor !== false) {\n clearMask |= GL_COLOR_BUFFER_BIT;\n glParameters.clearColor = this.props.clearColor;\n }\n if (this.props.clearDepth !== false) {\n clearMask |= GL_DEPTH_BUFFER_BIT;\n glParameters.clearDepth = this.props.clearDepth;\n }\n if (this.props.clearStencil !== false) {\n clearMask |= GL_STENCIL_BUFFER_BIT;\n glParameters.clearStencil = this.props.clearStencil;\n }\n\n if (clearMask !== 0) {\n // Temporarily set any clear \"colors\" and call clear\n withGLParameters(this.device, glParameters, () => {\n this.device.gl.clear(clearMask);\n });\n\n // TODO - clear multiple color attachments\n // for (attachment of this.framebuffer.colorAttachments) {\n // this.clearColorBuffer \n // }\n }\n }\n\n /** \n * WebGL2 - clear a specific color buffer \n */\n protected clearColorBuffer(drawBuffer: number = 0, value: NumberArray = [0, 0, 0, 0]) {\n withGLParameters(this.device.gl2, {framebuffer: this.props.framebuffer}, () => {\n // Method selection per OpenGL ES 3 docs\n switch (value.constructor) {\n case Int32Array:\n this.device.gl2.clearBufferiv(GL_COLOR, drawBuffer, value);\n break;\n case Uint32Array:\n this.device.gl2.clearBufferuiv(GL_COLOR, drawBuffer, value);\n break;\n case Float32Array:\n default:\n this.device.gl2.clearBufferfv(GL_COLOR, drawBuffer, value);\n break;\n }\n });\n }\n\n // clearDepthStencil() {\n // const GL_DEPTH = 0x1801;\n // const GL_STENCIL = 0x1802;\n // const GL_DEPTH_STENCIL = 0x84f9;\n\n // case GL_DEPTH:\n // this.device.gl2.clearBufferfv(GL_DEPTH, 0, [value]);\n // break;\n\n // case GL_STENCIL:\n // this.device.gl2.clearBufferiv(GL_STENCIL, 0, [value]);\n // break;\n\n // case GL_DEPTH_STENCIL:\n // const [depth, stencil] = value;\n // this.device.gl2.clearBufferfi(GL_DEPTH_STENCIL, 0, depth, stencil);\n // break;\n\n // default:\n // assert(false, ERR_ARGUMENTS);\n // }\n // });\n}\n\n"],"mappings":"AAGA,SAAQA,UAAU,QAA2D,eAAe;AAAC,SAGrFC,gBAAgB;AAAA,SAChBC,eAAe;AAAA,SACfC,gBAAgB,EAAEC,eAAe;AAGzC,MAAMC,mBAAmB,GAAG,UAAU;AACtC,MAAMC,qBAAqB,GAAG,UAAU;AACxC,MAAMC,mBAAmB,GAAG,UAAU;AAEtC,MAAMC,QAAQ,GAAG,MAAM;AAEvB,OAAO,MAAMC,eAAe,SAAST,UAAU,CAAC;EAM9CU,WAAWA,CAACC,MAAmB,EAAEC,KAAsB,EAAE;IACvD,KAAK,CAACD,MAAM,EAAEC,KAAK,CAAC;IAAC,KANdD,MAAM;IAAA,KAGfE,YAAY;IAIV,IAAI,CAACF,MAAM,GAAGA,MAAM;IAGpBR,gBAAgB,CAAC,IAAI,CAACQ,MAAM,CAACG,EAAE,CAAC;IAChC,IAAI,CAACC,aAAa,CAAC,IAAI,CAACH,KAAK,CAACI,UAAU,CAAC;IAGzC,IAAI,CAACC,KAAK,CAAC,CAAC;EACd;EAEAC,GAAGA,CAAA,EAAS;IACVd,eAAe,CAAC,IAAI,CAACO,MAAM,CAACG,EAAE,CAAC;IAC/B,IAAI,IAAI,CAACF,KAAK,CAACO,WAAW,EAAE;MAC1BjB,eAAe,CAAC,IAAI,CAACS,MAAM,EAAE;QAACQ,WAAW,EAAE;MAAI,CAAC,CAAC;IACnD;EAEF;EAEAC,cAAcA,CAACC,UAAkB,EAAQ,CAAC;EAC1CC,aAAaA,CAAA,EAAS,CAAC;EACvBC,iBAAiBA,CAACC,WAAmB,EAAQ,CAAC;EAY9CT,aAAaA,CAAA,EAA8C;IAAA,IAA7CC,UAAgC,GAAAS,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA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