@luma.gl/webgl 9.1.0-alpha.10 → 9.1.0-alpha.12

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 (59) hide show
  1. package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
  2. package/dist/adapter/device-helpers/webgl-device-features.js +1 -2
  3. package/dist/adapter/helpers/format-utils.d.ts.map +1 -0
  4. package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
  5. package/dist/adapter/helpers/get-shader-layout.js +1 -3
  6. package/dist/adapter/helpers/typed-array-utils.d.ts.map +1 -0
  7. package/dist/adapter/helpers/webgl-texture-utils.d.ts +85 -18
  8. package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -1
  9. package/dist/adapter/helpers/webgl-texture-utils.js +210 -18
  10. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  11. package/dist/adapter/resources/webgl-render-pipeline.d.ts +1 -3
  12. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  13. package/dist/adapter/resources/webgl-texture.d.ts +1 -1
  14. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  15. package/dist/adapter/resources/webgl-texture.js +33 -8
  16. package/dist/adapter/webgl-device.d.ts +1 -2
  17. package/dist/adapter/webgl-device.d.ts.map +1 -1
  18. package/dist/adapter/webgl-device.js +2 -2
  19. package/dist/deprecated/accessor.d.ts.map +1 -0
  20. package/dist/{classic → deprecated}/accessor.js +36 -1
  21. package/dist/deprecated/clear.d.ts.map +1 -0
  22. package/dist/{classic → deprecated}/clear.js +2 -0
  23. package/dist/dist.dev.js +490 -432
  24. package/dist/dist.min.js +2 -2
  25. package/dist/index.cjs +491 -441
  26. package/dist/index.cjs.map +4 -4
  27. package/dist/index.d.ts +1 -1
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +1 -1
  30. package/dist/utils/fill-array.d.ts +4 -4
  31. package/dist/utils/fill-array.d.ts.map +1 -1
  32. package/package.json +5 -5
  33. package/src/adapter/device-helpers/webgl-device-features.ts +5 -2
  34. package/src/adapter/helpers/get-shader-layout.ts +1 -3
  35. package/src/adapter/helpers/webgl-texture-utils.ts +356 -37
  36. package/src/adapter/resources/webgl-render-pass.ts +3 -3
  37. package/src/adapter/resources/webgl-render-pipeline.ts +10 -3
  38. package/src/adapter/resources/webgl-texture.ts +41 -8
  39. package/src/adapter/webgl-device.ts +13 -4
  40. package/src/{classic → deprecated}/accessor.ts +44 -3
  41. package/src/{classic → deprecated}/clear.ts +3 -1
  42. package/src/index.ts +1 -1
  43. package/src/utils/fill-array.ts +4 -4
  44. package/dist/classic/accessor.d.ts.map +0 -1
  45. package/dist/classic/clear.d.ts.map +0 -1
  46. package/dist/classic/copy-and-blit.d.ts +0 -64
  47. package/dist/classic/copy-and-blit.d.ts.map +0 -1
  48. package/dist/classic/copy-and-blit.js +0 -194
  49. package/dist/classic/format-utils.d.ts.map +0 -1
  50. package/dist/classic/typed-array-utils.d.ts.map +0 -1
  51. package/src/classic/copy-and-blit.ts +0 -323
  52. /package/dist/{classic → adapter/helpers}/format-utils.d.ts +0 -0
  53. /package/dist/{classic → adapter/helpers}/format-utils.js +0 -0
  54. /package/dist/{classic → adapter/helpers}/typed-array-utils.d.ts +0 -0
  55. /package/dist/{classic → adapter/helpers}/typed-array-utils.js +0 -0
  56. /package/dist/{classic → deprecated}/accessor.d.ts +0 -0
  57. /package/dist/{classic → deprecated}/clear.d.ts +0 -0
  58. /package/src/{classic → adapter/helpers}/format-utils.ts +0 -0
  59. /package/src/{classic → adapter/helpers}/typed-array-utils.ts +0 -0
@@ -52,7 +52,7 @@ import {WEBGLTextureView} from './webgl-texture-view';
52
52
  import {
53
53
  initializeTextureStorage,
54
54
  // clearMipLevel,
55
- copyCPUImageToMipLevel,
55
+ copyExternalImageToMipLevel,
56
56
  copyCPUDataToMipLevel,
57
57
  // copyGPUBufferToMipLevel,
58
58
  getWebGLTextureTarget
@@ -350,10 +350,38 @@ export class WEBGLTexture extends Texture {
350
350
  }): {width: number; height: number} {
351
351
  const size = Texture.getExternalImageSize(options.image);
352
352
  const opts = {...Texture.defaultCopyExternalImageOptions, ...size, ...options};
353
- const {depth, mipLevel: lodLevel, image} = opts;
354
- this.bind();
355
- this._setMipLevel(depth, lodLevel, image);
356
- this.unbind();
353
+
354
+ const {image, depth, mipLevel, x, y, z} = opts;
355
+ let {width, height} = opts;
356
+ const {dimension, glTarget, glFormat, glInternalFormat, glType} = this;
357
+
358
+ // WebGL will error if we try to copy outside the bounds of the texture
359
+ width = Math.min(width, size.width - x);
360
+ height = Math.min(height, size.height - y);
361
+
362
+ // WebGL does not yet support sourceX/sourceY in copyExternalImage; requires copyTexSubImage2D from a framebuffer'
363
+
364
+ if (options.sourceX || options.sourceY) {
365
+ throw new Error(
366
+ 'WebGL does not yet support sourceX/sourceY in copyExternalImage; requires copyTexSubImage2D from a framebuffer'
367
+ );
368
+ }
369
+
370
+ copyExternalImageToMipLevel(this.device.gl, this.handle, image, {
371
+ dimension,
372
+ mipLevel,
373
+ x,
374
+ y,
375
+ z,
376
+ width,
377
+ height,
378
+ depth,
379
+ glFormat,
380
+ glInternalFormat,
381
+ glType,
382
+ glTarget
383
+ });
384
+
357
385
  return {width: opts.width, height: opts.height};
358
386
  }
359
387
 
@@ -601,7 +629,7 @@ export class WEBGLTexture extends Texture {
601
629
  */
602
630
  protected _setMipLevel(
603
631
  depth: number,
604
- level: number,
632
+ mipLevel: number,
605
633
  textureData: Texture2DData,
606
634
  glTarget: GL = this.glTarget
607
635
  ) {
@@ -611,7 +639,12 @@ export class WEBGLTexture extends Texture {
611
639
  // }
612
640
 
613
641
  if (Texture.isExternalImage(textureData)) {
614
- copyCPUImageToMipLevel(this.device.gl, textureData, {...this, depth, level, glTarget});
642
+ copyExternalImageToMipLevel(this.device.gl, this.handle, textureData, {
643
+ ...this,
644
+ depth,
645
+ mipLevel,
646
+ glTarget
647
+ });
615
648
  return;
616
649
  }
617
650
 
@@ -620,7 +653,7 @@ export class WEBGLTexture extends Texture {
620
653
  copyCPUDataToMipLevel(this.device.gl, textureData.data, {
621
654
  ...this,
622
655
  depth,
623
- level,
656
+ mipLevel,
624
657
  glTarget
625
658
  });
626
659
  return;
@@ -3,8 +3,17 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {TypedArray} from '@math.gl/types';
6
- import type {DeviceProps, DeviceInfo, CanvasContextProps, TextureFormat} from '@luma.gl/core';
7
- import type {Buffer, Texture, Framebuffer, VertexArray, VertexArrayProps} from '@luma.gl/core';
6
+ import type {
7
+ DeviceProps,
8
+ DeviceInfo,
9
+ CanvasContextProps,
10
+ TextureFormat,
11
+ Buffer,
12
+ Texture,
13
+ Framebuffer,
14
+ VertexArray,
15
+ VertexArrayProps
16
+ } from '@luma.gl/core';
8
17
  import {Device, CanvasContext, log} from '@luma.gl/core';
9
18
  import type {GLExtensions} from '@luma.gl/constants';
10
19
  import {WebGLStateTracker} from '../context/state-tracker/webgl-state-tracker';
@@ -59,14 +68,14 @@ import {WEBGLVertexArray} from './resources/webgl-vertex-array';
59
68
  import {WEBGLTransformFeedback} from './resources/webgl-transform-feedback';
60
69
  import {WEBGLQuerySet} from './resources/webgl-query-set';
61
70
 
62
- import {readPixelsToArray, readPixelsToBuffer} from '../classic/copy-and-blit';
71
+ import {readPixelsToArray, readPixelsToBuffer} from './helpers/webgl-texture-utils';
63
72
  import {
64
73
  setGLParameters,
65
74
  getGLParameters,
66
75
  resetGLParameters
67
76
  } from '../context/parameters/unified-parameter-api';
68
77
  import {withGLParameters} from '../context/state-tracker/with-parameters';
69
- import {clear} from '../classic/clear';
78
+ import {clear} from '../deprecated/clear';
70
79
  import {getWebGLExtension} from '../context/helpers/webgl-extensions';
71
80
 
72
81
  /** WebGPU style Device API for a WebGL context */
@@ -2,9 +2,9 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {Buffer} from '@luma.gl/core';
6
- import {GL} from '@luma.gl/constants';
7
- import {getTypedArrayFromGLType} from './typed-array-utils';
5
+ import {Buffer, log} from '@luma.gl/core';
6
+ import {GL, GLDataType, GLPixelType} from '@luma.gl/constants';
7
+ import {TypedArrayConstructor} from '@math.gl/types';
8
8
 
9
9
  /**
10
10
  * Attribute descriptor object
@@ -81,6 +81,7 @@ export class Accessor implements AccessorObject {
81
81
  }
82
82
 
83
83
  constructor(...accessors: AccessorObject[]) {
84
+ log.warn('Accessor will be removed in next minor release');
84
85
  accessors.forEach(accessor => this._assign(accessor)); // Merge in sequence
85
86
  Object.freeze(this);
86
87
  }
@@ -180,5 +181,45 @@ export class Accessor implements AccessorObject {
180
181
  }
181
182
  }
182
183
 
184
+ /**
185
+ * Converts GL constant to corresponding TYPED ARRAY
186
+ * Used to auto deduce gl parameter types
187
+ * @deprecated Use getTypedArrayFromDataType
188
+ * @param glType
189
+ * @param param1
190
+ * @returns
191
+ */
192
+ // eslint-disable-next-line complexity
193
+ function getTypedArrayFromGLType(
194
+ glType: GLDataType | GLPixelType,
195
+ options?: {
196
+ clamped?: boolean;
197
+ }
198
+ ): TypedArrayConstructor {
199
+ const {clamped = true} = options || {};
200
+ // Sorted in some order of likelihood to reduce amount of comparisons
201
+ switch (glType) {
202
+ case GL.FLOAT:
203
+ return Float32Array;
204
+ case GL.UNSIGNED_SHORT:
205
+ case GL.UNSIGNED_SHORT_5_6_5:
206
+ case GL.UNSIGNED_SHORT_4_4_4_4:
207
+ case GL.UNSIGNED_SHORT_5_5_5_1:
208
+ return Uint16Array;
209
+ case GL.UNSIGNED_INT:
210
+ return Uint32Array;
211
+ case GL.UNSIGNED_BYTE:
212
+ return clamped ? Uint8ClampedArray : Uint8Array;
213
+ case GL.BYTE:
214
+ return Int8Array;
215
+ case GL.SHORT:
216
+ return Int16Array;
217
+ case GL.INT:
218
+ return Int32Array;
219
+ default:
220
+ throw new Error('Failed to deduce typed array type from GL constant');
221
+ }
222
+ }
223
+
183
224
  // TEST EXPORTS
184
225
  export {DEFAULT_ACCESSOR_VALUES};
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {Device, Framebuffer} from '@luma.gl/core';
5
+ import {Device, Framebuffer, log} from '@luma.gl/core';
6
6
  import {WebGLDevice} from '../adapter/webgl-device';
7
7
  import {withGLParameters} from '../context/state-tracker/with-parameters';
8
8
 
@@ -24,6 +24,8 @@ export function clear(
24
24
  device: Device,
25
25
  options?: {framebuffer?: Framebuffer; color?: any; depth?: any; stencil?: any}
26
26
  ): void {
27
+ log.warn('clear will be removed in next minor release');
28
+
27
29
  const {framebuffer = null, color = null, depth = null, stencil = null} = options || {};
28
30
  const parameters: any = {};
29
31
 
package/src/index.ts CHANGED
@@ -38,7 +38,7 @@ export {WEBGLVertexArray} from './adapter/resources/webgl-vertex-array';
38
38
  export {WEBGLTransformFeedback} from './adapter/resources/webgl-transform-feedback';
39
39
 
40
40
  // WebGL adapter classes
41
- export {Accessor} from './classic/accessor';
41
+ export {Accessor} from './deprecated/accessor';
42
42
  export type {AccessorObject} from './types';
43
43
 
44
44
  // Unified parameter API
@@ -2,15 +2,15 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {NumberArray} from '@math.gl/types';
5
+ import type {NumericArray} from '@math.gl/types';
6
6
 
7
7
  // Uses copyWithin to significantly speed up typed array value filling
8
8
  export function fillArray(options: {
9
- target: NumberArray;
10
- source: NumberArray;
9
+ target: NumericArray;
10
+ source: NumericArray;
11
11
  start?: number;
12
12
  count?: number;
13
- }): NumberArray {
13
+ }): NumericArray {
14
14
  const {target, source, start = 0, count = 1} = options;
15
15
  const length = source.length;
16
16
  const total = count * length;
@@ -1 +0,0 @@
1
- {"version":3,"file":"accessor.d.ts","sourceRoot":"","sources":["../../src/classic/accessor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;A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9B;IAED,IAAI,gBAAgB,IAAI,MAAM,CAE7B;IAKD,OAAO,CAAC,KAAK,GAAE,cAAmB,GAAG,IAAI;CA2E1C;AAGD,OAAO,EAAC,uBAAuB,EAAC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"clear.d.ts","sourceRoot":"","sources":["../../src/classic/clear.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAE,WAAW,EAAC,MAAM,eAAe,CAAC;AAclD;;;GAGG;AACH,wBAAgB,KAAK,CACnB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IAAC,WAAW,CAAC,EAAE,WAAW,CAAC;IAAC,KAAK,CAAC,EAAE,GAAG,CAAC;IAAC,KAAK,CAAC,EAAE,GAAG,CAAC;IAAC,OAAO,CAAC,EAAE,GAAG,CAAA;CAAC,GAC7E,IAAI,CAsCN;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IAAC,WAAW,CAAC,EAAE,WAAW,CAAC;IAAC,MAAM,CAAC,EAAE,GAAG,CAAC;IAAC,UAAU,CAAC,EAAE,GAAG,CAAC;IAAC,KAAK,CAAC,EAAE,GAAG,CAAA;CAAC,QA2CnF"}
@@ -1,64 +0,0 @@
1
- import { Buffer, Texture, Framebuffer, FramebufferProps } from '@luma.gl/core';
2
- import { GL } from '@luma.gl/constants';
3
- import { WEBGLFramebuffer } from "../adapter/resources/webgl-framebuffer.js";
4
- import { WEBGLBuffer } from "../adapter/resources/webgl-buffer.js";
5
- /**
6
- * Copies data from a type or a Texture object into ArrayBuffer object.
7
- * App can provide targetPixelArray or have it auto allocated by this method
8
- * newly allocated by this method unless provided by app.
9
- * @deprecated Use CommandEncoder.copyTextureToBuffer and Buffer.read
10
- * @note Slow requires roundtrip to GPU
11
- *
12
- * @param source
13
- * @param options
14
- * @returns pixel array,
15
- */
16
- export declare function readPixelsToArray(source: Framebuffer | Texture, options?: {
17
- sourceX?: number;
18
- sourceY?: number;
19
- sourceFormat?: number;
20
- sourceAttachment?: number;
21
- target?: Uint8Array | Uint16Array | Float32Array;
22
- sourceWidth?: number;
23
- sourceHeight?: number;
24
- sourceDepth?: number;
25
- sourceType?: number;
26
- }): Uint8Array | Uint16Array | Float32Array;
27
- /**
28
- * Copies data from a Framebuffer or a Texture object into a Buffer object.
29
- * NOTE: doesn't wait for copy to be complete, it programs GPU to perform a DMA transffer.
30
- * @deprecated Use CommandEncoder
31
- * @param source
32
- * @param options
33
- */
34
- export declare function readPixelsToBuffer(source: Framebuffer | Texture, options?: {
35
- sourceX?: number;
36
- sourceY?: number;
37
- sourceFormat?: number;
38
- target?: Buffer;
39
- targetByteOffset?: number;
40
- sourceWidth?: number;
41
- sourceHeight?: number;
42
- sourceType?: number;
43
- }): WEBGLBuffer;
44
- /**
45
- * Copy a rectangle from a Framebuffer or Texture object into a texture (at an offset)
46
- * @deprecated Use CommandEncoder
47
- */
48
- export declare function copyToTexture(source: Framebuffer | Texture, target: Texture | GL, options?: {
49
- sourceX?: number;
50
- sourceY?: number;
51
- targetX?: number;
52
- targetY?: number;
53
- targetZ?: number;
54
- targetMipmaplevel?: number;
55
- targetInternalFormat?: number;
56
- width?: number;
57
- height?: number;
58
- }): Texture;
59
- /**
60
- * Wraps a given texture into a framebuffer object, that can be further used
61
- * to read data from the texture object.
62
- */
63
- export declare function toFramebuffer(texture: Texture, props?: FramebufferProps): WEBGLFramebuffer;
64
- //# sourceMappingURL=copy-and-blit.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"copy-and-blit.d.ts","sourceRoot":"","sources":["../../src/classic/copy-and-blit.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAC,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAC,EAAE,EAAC,MAAM,oBAAoB,CAAC;AAEtC,OAAO,EAAC,gBAAgB,EAAC,kDAA+C;AAGxE,OAAO,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jB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GACA,OAAO,CAiGT;AAYD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,gBAAgB,GAAG,gBAAgB,CAU1F"}
@@ -1,194 +0,0 @@
1
- // luma.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- import { Framebuffer } from '@luma.gl/core';
5
- import { GL } from '@luma.gl/constants';
6
- import { getGLTypeFromTypedArray, getTypedArrayFromGLType } from "./typed-array-utils.js";
7
- import { glFormatToComponents, glTypeToBytes } from "./format-utils.js";
8
- import { WEBGLTexture } from "../adapter/resources/webgl-texture.js";
9
- /**
10
- * Copies data from a type or a Texture object into ArrayBuffer object.
11
- * App can provide targetPixelArray or have it auto allocated by this method
12
- * newly allocated by this method unless provided by app.
13
- * @deprecated Use CommandEncoder.copyTextureToBuffer and Buffer.read
14
- * @note Slow requires roundtrip to GPU
15
- *
16
- * @param source
17
- * @param options
18
- * @returns pixel array,
19
- */
20
- export function readPixelsToArray(source, options) {
21
- const { sourceX = 0, sourceY = 0, sourceAttachment = 36064 // TODO - support gl.readBuffer
22
- } = options || {};
23
- let { target = null,
24
- // following parameters are auto deduced if not provided
25
- sourceWidth, sourceHeight, sourceDepth, sourceFormat, sourceType } = options || {};
26
- const { framebuffer, deleteFramebuffer } = getFramebuffer(source);
27
- // assert(framebuffer);
28
- const { gl, handle } = framebuffer;
29
- const attachment = sourceAttachment - 36064;
30
- sourceWidth ||= framebuffer.width;
31
- sourceHeight ||= framebuffer.height;
32
- // TODO - Set and unset gl.readBuffer
33
- // if (sourceAttachment === GL.COLOR_ATTACHMENT0 && handle === null) {
34
- // sourceAttachment = GL.FRONT;
35
- // }
36
- sourceDepth = framebuffer.colorAttachments[attachment]?.texture?.depth || 1;
37
- sourceFormat ||= framebuffer.colorAttachments[attachment]?.texture?.glFormat || 6408;
38
- // Deduce the type from color attachment if not provided.
39
- sourceType ||= framebuffer.colorAttachments[attachment]?.texture?.glType || 5121;
40
- // Deduce type and allocated pixelArray if needed
41
- target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight, sourceDepth);
42
- // Pixel array available, if necessary, deduce type from it.
43
- sourceType = sourceType || getGLTypeFromTypedArray(target);
44
- const prevHandle = gl.bindFramebuffer(36160, handle);
45
- gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
46
- // @ts-expect-error
47
- gl.bindFramebuffer(36160, prevHandle || null);
48
- if (deleteFramebuffer) {
49
- framebuffer.destroy();
50
- }
51
- return target;
52
- }
53
- /**
54
- * Copies data from a Framebuffer or a Texture object into a Buffer object.
55
- * NOTE: doesn't wait for copy to be complete, it programs GPU to perform a DMA transffer.
56
- * @deprecated Use CommandEncoder
57
- * @param source
58
- * @param options
59
- */
60
- export function readPixelsToBuffer(source, options) {
61
- const { target, sourceX = 0, sourceY = 0, sourceFormat = 6408, targetByteOffset = 0 } = options || {};
62
- // following parameters are auto deduced if not provided
63
- let { sourceWidth, sourceHeight, sourceType } = options || {};
64
- const { framebuffer, deleteFramebuffer } = getFramebuffer(source);
65
- // assert(framebuffer);
66
- sourceWidth = sourceWidth || framebuffer.width;
67
- sourceHeight = sourceHeight || framebuffer.height;
68
- // Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature
69
- const webglFramebuffer = framebuffer;
70
- // deduce type if not available.
71
- sourceType = sourceType || 5121;
72
- let webglBufferTarget = target;
73
- if (!webglBufferTarget) {
74
- // Create new buffer with enough size
75
- const components = glFormatToComponents(sourceFormat);
76
- const byteCount = glTypeToBytes(sourceType);
77
- const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;
78
- webglBufferTarget = webglFramebuffer.device.createBuffer({ byteLength });
79
- }
80
- // TODO(donmccurdy): Do we have tests to confirm this is working?
81
- const commandEncoder = source.device.createCommandEncoder();
82
- commandEncoder.copyTextureToBuffer({
83
- source: source,
84
- width: sourceWidth,
85
- height: sourceHeight,
86
- origin: [sourceX, sourceY],
87
- destination: webglBufferTarget,
88
- byteOffset: targetByteOffset
89
- });
90
- commandEncoder.destroy();
91
- if (deleteFramebuffer) {
92
- framebuffer.destroy();
93
- }
94
- return webglBufferTarget;
95
- }
96
- /**
97
- * Copy a rectangle from a Framebuffer or Texture object into a texture (at an offset)
98
- * @deprecated Use CommandEncoder
99
- */
100
- // eslint-disable-next-line complexity, max-statements
101
- export function copyToTexture(source, target, options) {
102
- const { sourceX = 0, sourceY = 0,
103
- // attachment = GL.COLOR_ATTACHMENT0, // TODO - support gl.readBuffer
104
- targetMipmaplevel = 0, targetInternalFormat = 6408 } = options || {};
105
- let { targetX, targetY, targetZ, width, // defaults to target width
106
- height // defaults to target height
107
- } = options || {};
108
- const { framebuffer, deleteFramebuffer } = getFramebuffer(source);
109
- // assert(framebuffer);
110
- const webglFramebuffer = framebuffer;
111
- const { device, handle } = webglFramebuffer;
112
- const isSubCopy = typeof targetX !== 'undefined' ||
113
- typeof targetY !== 'undefined' ||
114
- typeof targetZ !== 'undefined';
115
- targetX = targetX || 0;
116
- targetY = targetY || 0;
117
- targetZ = targetZ || 0;
118
- const prevHandle = device.gl.bindFramebuffer(36160, handle);
119
- // TODO - support gl.readBuffer (WebGL2 only)
120
- // const prevBuffer = gl.readBuffer(attachment);
121
- // assert(target);
122
- let texture = null;
123
- let textureTarget;
124
- if (target instanceof WEBGLTexture) {
125
- texture = target;
126
- width = Number.isFinite(width) ? width : texture.width;
127
- height = Number.isFinite(height) ? height : texture.height;
128
- texture?.bind(0);
129
- // @ts-ignore
130
- textureTarget = texture.target;
131
- }
132
- else {
133
- // @ts-ignore
134
- textureTarget = target;
135
- }
136
- if (!isSubCopy) {
137
- device.gl.copyTexImage2D(textureTarget, targetMipmaplevel, targetInternalFormat, sourceX, sourceY, width, height, 0 /* border must be 0 */);
138
- }
139
- else {
140
- switch (textureTarget) {
141
- case 3553:
142
- case 34067:
143
- device.gl.copyTexSubImage2D(textureTarget, targetMipmaplevel, targetX, targetY, sourceX, sourceY, width, height);
144
- break;
145
- case 35866:
146
- case 32879:
147
- device.gl.copyTexSubImage3D(textureTarget, targetMipmaplevel, targetX, targetY, targetZ, sourceX, sourceY, width, height);
148
- break;
149
- default:
150
- }
151
- }
152
- if (texture) {
153
- texture.unbind();
154
- }
155
- // @ts-expect-error
156
- device.gl.bindFramebuffer(36160, prevHandle || null);
157
- if (deleteFramebuffer) {
158
- framebuffer.destroy();
159
- }
160
- return texture;
161
- }
162
- function getFramebuffer(source) {
163
- if (!(source instanceof Framebuffer)) {
164
- return { framebuffer: toFramebuffer(source), deleteFramebuffer: true };
165
- }
166
- return { framebuffer: source, deleteFramebuffer: false };
167
- }
168
- /**
169
- * Wraps a given texture into a framebuffer object, that can be further used
170
- * to read data from the texture object.
171
- */
172
- export function toFramebuffer(texture, props) {
173
- const { device, width, height, id } = texture;
174
- const framebuffer = device.createFramebuffer({
175
- ...props,
176
- id: `framebuffer-for-${id}`,
177
- width,
178
- height,
179
- colorAttachments: [texture]
180
- });
181
- return framebuffer;
182
- }
183
- // eslint-disable-next-line max-params
184
- function getPixelArray(pixelArray, type, format, width, height, depth) {
185
- if (pixelArray) {
186
- return pixelArray;
187
- }
188
- // Allocate pixel array if not already available, using supplied type
189
- type = type || 5121;
190
- const ArrayType = getTypedArrayFromGLType(type, { clamped: false });
191
- const components = glFormatToComponents(format);
192
- // TODO - check for composite type (components = 1).
193
- return new ArrayType(width * height * components);
194
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"format-utils.d.ts","sourceRoot":"","sources":["../../src/classic/format-utils.ts"],"names":[],"mappings":"AAOA,wBAAgB,oBAAoB,CAAC,MAAM,KAAA,qBAmB1C;AAGD,wBAAgB,aAAa,CAAC,IAAI,KAAA,iBAcjC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"typed-array-utils.d.ts","sourceRoot":"","sources":["../../src/classic/typed-array-utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,UAAU,EAAE,qBAAqB,EAAC,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAK,UAAU,EAAE,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAI/D;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,UAAU,GAAG,UAAU,CAuB3E;AAED;;;;;;;GAOG;AAEH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,UAAU,GAAG,WAAW,EAChC,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GACA,qBAAqB,CAwBvB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE;IAChC,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB,GAAG,IAAI,CAgBP;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE;IAAC,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAC,GAAG;IACvF,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAaA"}