@luma.gl/webgl 9.1.0-alpha.1 → 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 (109) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  2. package/dist/adapter/converters/device-parameters.js +18 -11
  3. package/dist/adapter/converters/texture-formats.d.ts +1 -1
  4. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  5. package/dist/adapter/converters/texture-formats.js +9 -16
  6. package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
  7. package/dist/adapter/device-helpers/webgl-device-features.js +1 -3
  8. package/dist/adapter/helpers/format-utils.d.ts.map +1 -0
  9. package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
  10. package/dist/adapter/helpers/get-shader-layout.js +1 -3
  11. package/dist/adapter/helpers/typed-array-utils.d.ts.map +1 -0
  12. package/dist/adapter/helpers/webgl-texture-utils.d.ts +89 -22
  13. package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -1
  14. package/dist/adapter/helpers/webgl-texture-utils.js +220 -26
  15. package/dist/adapter/resources/webgl-framebuffer.js +1 -1
  16. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  17. package/dist/adapter/resources/webgl-render-pass.js +17 -4
  18. package/dist/adapter/resources/webgl-render-pipeline.d.ts +1 -3
  19. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  20. package/dist/adapter/resources/webgl-render-pipeline.js +1 -1
  21. package/dist/adapter/resources/webgl-shader.js +1 -1
  22. package/dist/adapter/resources/webgl-texture.d.ts +21 -3
  23. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  24. package/dist/adapter/resources/webgl-texture.js +49 -30
  25. package/dist/adapter/resources/webgl-transform-feedback.js +1 -1
  26. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
  27. package/dist/adapter/resources/webgl-vertex-array.js +3 -0
  28. package/dist/adapter/webgl-adapter.d.ts +21 -0
  29. package/dist/adapter/webgl-adapter.d.ts.map +1 -0
  30. package/dist/adapter/webgl-adapter.js +91 -0
  31. package/dist/adapter/webgl-device.d.ts +16 -29
  32. package/dist/adapter/webgl-device.d.ts.map +1 -1
  33. package/dist/adapter/webgl-device.js +34 -114
  34. package/dist/context/debug/spector-types.d.ts +1108 -0
  35. package/dist/context/debug/spector-types.d.ts.map +1 -0
  36. package/dist/context/debug/spector-types.js +697 -0
  37. package/dist/context/debug/spector.d.ts +12 -8
  38. package/dist/context/debug/spector.d.ts.map +1 -1
  39. package/dist/context/debug/spector.js +23 -17
  40. package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts +9 -0
  41. package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts.map +1 -0
  42. package/dist/context/polyfills/polyfill-webgl1-extensions.js +181 -0
  43. package/dist/context/state-tracker/webgl-state-tracker.d.ts +43 -0
  44. package/dist/context/state-tracker/webgl-state-tracker.d.ts.map +1 -0
  45. package/dist/context/state-tracker/{track-context-state.js → webgl-state-tracker.js} +44 -74
  46. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  47. package/dist/context/state-tracker/with-parameters.js +5 -4
  48. package/dist/deprecated/accessor.d.ts.map +1 -0
  49. package/dist/{classic → deprecated}/accessor.js +36 -1
  50. package/dist/deprecated/clear.d.ts.map +1 -0
  51. package/dist/{classic → deprecated}/clear.js +2 -0
  52. package/dist/dist.dev.js +816 -642
  53. package/dist/dist.min.js +2 -2
  54. package/dist/index.cjs +815 -648
  55. package/dist/index.cjs.map +4 -4
  56. package/dist/index.d.ts +4 -2
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +4 -3
  59. package/dist/utils/fill-array.d.ts +4 -4
  60. package/dist/utils/fill-array.d.ts.map +1 -1
  61. package/dist/utils/split-uniforms-and-bindings.d.ts +1 -1
  62. package/dist/utils/split-uniforms-and-bindings.d.ts.map +1 -1
  63. package/dist/utils/uid.d.ts +7 -0
  64. package/dist/utils/uid.d.ts.map +1 -0
  65. package/dist/utils/uid.js +14 -0
  66. package/package.json +5 -5
  67. package/src/adapter/converters/device-parameters.ts +18 -12
  68. package/src/adapter/converters/texture-formats.ts +12 -20
  69. package/src/adapter/device-helpers/webgl-device-features.ts +5 -3
  70. package/src/adapter/helpers/get-shader-layout.ts +1 -3
  71. package/src/adapter/helpers/webgl-texture-utils.ts +366 -44
  72. package/src/adapter/resources/webgl-framebuffer.ts +1 -1
  73. package/src/adapter/resources/webgl-render-pass.ts +20 -7
  74. package/src/adapter/resources/webgl-render-pipeline.ts +12 -4
  75. package/src/adapter/resources/webgl-shader.ts +1 -1
  76. package/src/adapter/resources/webgl-texture.ts +76 -30
  77. package/src/adapter/resources/webgl-transform-feedback.ts +1 -1
  78. package/src/adapter/resources/webgl-vertex-array.ts +3 -0
  79. package/src/adapter/webgl-adapter.ts +113 -0
  80. package/src/adapter/webgl-device.ts +45 -139
  81. package/src/context/debug/spector-types.ts +1154 -0
  82. package/src/context/debug/spector.ts +38 -29
  83. package/src/context/polyfills/polyfill-webgl1-extensions.ts +202 -0
  84. package/src/context/state-tracker/{track-context-state.ts → webgl-state-tracker.ts} +55 -94
  85. package/src/context/state-tracker/with-parameters.ts +5 -4
  86. package/src/{classic → deprecated}/accessor.ts +44 -3
  87. package/src/{classic → deprecated}/clear.ts +3 -1
  88. package/src/index.ts +6 -8
  89. package/src/utils/fill-array.ts +4 -4
  90. package/src/utils/split-uniforms-and-bindings.ts +3 -3
  91. package/src/utils/uid.ts +16 -0
  92. package/dist/classic/accessor.d.ts.map +0 -1
  93. package/dist/classic/clear.d.ts.map +0 -1
  94. package/dist/classic/copy-and-blit.d.ts +0 -63
  95. package/dist/classic/copy-and-blit.d.ts.map +0 -1
  96. package/dist/classic/copy-and-blit.js +0 -193
  97. package/dist/classic/format-utils.d.ts.map +0 -1
  98. package/dist/classic/typed-array-utils.d.ts.map +0 -1
  99. package/dist/context/state-tracker/track-context-state.d.ts +0 -22
  100. package/dist/context/state-tracker/track-context-state.d.ts.map +0 -1
  101. package/src/classic/copy-and-blit.ts +0 -318
  102. /package/dist/{classic → adapter/helpers}/format-utils.d.ts +0 -0
  103. /package/dist/{classic → adapter/helpers}/format-utils.js +0 -0
  104. /package/dist/{classic → adapter/helpers}/typed-array-utils.d.ts +0 -0
  105. /package/dist/{classic → adapter/helpers}/typed-array-utils.js +0 -0
  106. /package/dist/{classic → deprecated}/accessor.d.ts +0 -0
  107. /package/dist/{classic → deprecated}/clear.d.ts +0 -0
  108. /package/src/{classic → adapter/helpers}/format-utils.ts +0 -0
  109. /package/src/{classic → adapter/helpers}/typed-array-utils.ts +0 -0
@@ -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;
@@ -5,7 +5,7 @@
5
5
  import type {UniformValue, Binding} from '@luma.gl/core';
6
6
  import {isNumericArray} from '@math.gl/types';
7
7
 
8
- export function isUniformValue(value: unknown): boolean {
8
+ export function isUniformValue(value: unknown): value is UniformValue {
9
9
  return isNumericArray(value) !== null || typeof value === 'number' || typeof value === 'boolean';
10
10
  }
11
11
 
@@ -21,9 +21,9 @@ export function splitUniformsAndBindings(
21
21
  Object.keys(uniforms).forEach(name => {
22
22
  const uniform = uniforms[name];
23
23
  if (isUniformValue(uniform)) {
24
- result.uniforms[name] = uniform as UniformValue;
24
+ result.uniforms[name] = uniform;
25
25
  } else {
26
- result.bindings[name] = uniform as Binding;
26
+ result.bindings[name] = uniform;
27
27
  }
28
28
  });
29
29
 
@@ -0,0 +1,16 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ const uidCounters: Record<string, number> = {};
6
+
7
+ /**
8
+ * Returns a UID.
9
+ * @param id= - Identifier base name
10
+ * @return uid
11
+ **/
12
+ export function uid(id: string = 'id'): string {
13
+ uidCounters[id] = uidCounters[id] || 1;
14
+ const count = uidCounters[id]++;
15
+ return `${id}-${count}`;
16
+ }
@@ -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;AACrC,OAAO,EAAC,EAAE,EAAC,MAAM,oBAAoB,CAAC;AAGtC;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,MAAM,CAAC,EAAE,MAAM,CAAC;IAIhB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,sCAAsC;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,sCAAsC;IACtC,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,kBAAkB;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,QAAA,MAAM,uBAAuB;;;;;;;;CAQ5B,CAAC;AAEF,qBAAa,QAAS,YAAW,cAAc;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,MAAM,CAAC,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc,GAAG,MAAM;IAOtE,MAAM,CAAC,iBAAiB,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM;IAY1D,MAAM,CAAC,OAAO,CAAC,GAAG,SAAS,EAAE,cAAc,EAAE,GAAG,QAAQ;gBAI5C,GAAG,SAAS,EAAE,cAAc,EAAE;IAK1C,QAAQ,IAAI,MAAM;IAOlB,IAAI,iBAAiB,IAAI,MAAM,CAE9B;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,63 +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
- sourceType?: number;
25
- }): Uint8Array | Uint16Array | Float32Array;
26
- /**
27
- * Copies data from a Framebuffer or a Texture object into a Buffer object.
28
- * NOTE: doesn't wait for copy to be complete, it programs GPU to perform a DMA transffer.
29
- * @deprecated Use CommandEncoder
30
- * @param source
31
- * @param options
32
- */
33
- export declare function readPixelsToBuffer(source: Framebuffer | Texture, options?: {
34
- sourceX?: number;
35
- sourceY?: number;
36
- sourceFormat?: number;
37
- target?: Buffer;
38
- targetByteOffset?: number;
39
- sourceWidth?: number;
40
- sourceHeight?: number;
41
- sourceType?: number;
42
- }): WEBGLBuffer;
43
- /**
44
- * Copy a rectangle from a Framebuffer or Texture object into a texture (at an offset)
45
- * @deprecated Use CommandEncoder
46
- */
47
- export declare function copyToTexture(source: Framebuffer | Texture, target: Texture | GL, options?: {
48
- sourceX?: number;
49
- sourceY?: number;
50
- targetX?: number;
51
- targetY?: number;
52
- targetZ?: number;
53
- targetMipmaplevel?: number;
54
- targetInternalFormat?: number;
55
- width?: number;
56
- height?: number;
57
- }): Texture;
58
- /**
59
- * Wraps a given texture into a framebuffer object, that can be further used
60
- * to read data from the texture object.
61
- */
62
- export declare function toFramebuffer(texture: Texture, props?: FramebufferProps): WEBGLFramebuffer;
63
- //# 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,EAAC,WAAW,EAAC,6CAA0C;AAG9D;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,WAAW,GAAG,OAAO,EAC7B,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,UAAU,GAAG,WAAW,GAAG,YAAY,CAAC;IAEjD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACA,UAAU,GAAG,WAAW,GAAG,YAAY,CA+CzC;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,WAAW,GAAG,OAAO,EAC7B,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACA,WAAW,CA+Cb;AAED;;;GAGG;AAEH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,WAAW,GAAG,OAAO,EAC7B,MAAM,EAAE,OAAO,GAAG,EAAE,EACpB,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,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,193 +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, sourceFormat = 6408, sourceAttachment = 36064 // TODO - support gl.readBuffer
22
- } = options || {};
23
- let { target = null,
24
- // following parameters are auto deduced if not provided
25
- sourceWidth, sourceHeight, sourceType } = options || {};
26
- const { framebuffer, deleteFramebuffer } = getFramebuffer(source);
27
- // assert(framebuffer);
28
- const { gl, handle } = framebuffer;
29
- sourceWidth = sourceWidth || framebuffer.width;
30
- sourceHeight = sourceHeight || framebuffer.height;
31
- // TODO - Set and unset gl.readBuffer
32
- // if (sourceAttachment === GL.COLOR_ATTACHMENT0 && handle === null) {
33
- // sourceAttachment = GL.FRONT;
34
- // }
35
- const attachment = sourceAttachment - 36064;
36
- // assert(attachments[sourceAttachment]);
37
- // Deduce the type from color attachment if not provided.
38
- sourceType =
39
- sourceType || framebuffer.colorAttachments[attachment]?.texture?.glType || 5121;
40
- // Deduce type and allocated pixelArray if needed
41
- target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
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
- function getPixelArray(pixelArray, type, format, width, height) {
184
- if (pixelArray) {
185
- return pixelArray;
186
- }
187
- // Allocate pixel array if not already available, using supplied type
188
- type = type || 5121;
189
- const ArrayType = getTypedArrayFromGLType(type, { clamped: false });
190
- const components = glFormatToComponents(format);
191
- // TODO - check for composite type (components = 1).
192
- return new ArrayType(width * height * components);
193
- }
@@ -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"}
@@ -1,22 +0,0 @@
1
- /**
2
- * Initialize WebGL state caching on a context
3
- * can be called multiple times to enable/disable
4
- *
5
- * @note After calling this function, context state will be cached
6
- * gl.state.push() and gl.state.pop() will be available for saving,
7
- * temporarily modifying, and then restoring state.
8
- */
9
- export declare function trackContextState(gl: WebGL2RenderingContext, options?: {
10
- enable?: boolean;
11
- copyState?: boolean;
12
- log?: any;
13
- }): WebGL2RenderingContext;
14
- /**
15
- * Saves current WebGL context state onto an internal per-context stack
16
- */
17
- export declare function pushContextState(gl: WebGL2RenderingContext): void;
18
- /**
19
- * Restores previously saved WebGL context state
20
- */
21
- export declare function popContextState(gl: WebGL2RenderingContext): void;
22
- //# sourceMappingURL=track-context-state.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"track-context-state.d.ts","sourceRoot":"","sources":["../../../src/context/state-tracker/track-context-state.ts"],"names":[],"mappings":"AAkGA;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,sBAAsB,EAC1B,OAAO,CAAC,EAAE;IACR,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,GAAG,CAAC,EAAE,GAAG,CAAC;CACX,GACA,sBAAsB,CAgCxB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,sBAAsB,GAAG,IAAI,CAOjE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,sBAAsB,GAAG,IAAI,CAIhE"}
@@ -1,318 +0,0 @@
1
- // luma.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- import {Buffer, Texture, Framebuffer, FramebufferProps} from '@luma.gl/core';
6
- import {GL} from '@luma.gl/constants';
7
-
8
- import {WEBGLFramebuffer} from '../adapter/resources/webgl-framebuffer';
9
- import {getGLTypeFromTypedArray, getTypedArrayFromGLType} from './typed-array-utils';
10
- import {glFormatToComponents, glTypeToBytes} from './format-utils';
11
- import {WEBGLBuffer} from '../adapter/resources/webgl-buffer';
12
- import {WEBGLTexture} from '../adapter/resources/webgl-texture';
13
-
14
- /**
15
- * Copies data from a type or a Texture object into ArrayBuffer object.
16
- * App can provide targetPixelArray or have it auto allocated by this method
17
- * newly allocated by this method unless provided by app.
18
- * @deprecated Use CommandEncoder.copyTextureToBuffer and Buffer.read
19
- * @note Slow requires roundtrip to GPU
20
- *
21
- * @param source
22
- * @param options
23
- * @returns pixel array,
24
- */
25
- export function readPixelsToArray(
26
- source: Framebuffer | Texture,
27
- options?: {
28
- sourceX?: number;
29
- sourceY?: number;
30
- sourceFormat?: number;
31
- sourceAttachment?: number;
32
- target?: Uint8Array | Uint16Array | Float32Array;
33
- // following parameters are auto deduced if not provided
34
- sourceWidth?: number;
35
- sourceHeight?: number;
36
- sourceType?: number;
37
- }
38
- ): Uint8Array | Uint16Array | Float32Array {
39
- const {
40
- sourceX = 0,
41
- sourceY = 0,
42
- sourceFormat = GL.RGBA,
43
- sourceAttachment = GL.COLOR_ATTACHMENT0 // TODO - support gl.readBuffer
44
- } = options || {};
45
- let {
46
- target = null,
47
- // following parameters are auto deduced if not provided
48
- sourceWidth,
49
- sourceHeight,
50
- sourceType
51
- } = options || {};
52
-
53
- const {framebuffer, deleteFramebuffer} = getFramebuffer(source);
54
- // assert(framebuffer);
55
- const {gl, handle} = framebuffer;
56
- sourceWidth = sourceWidth || framebuffer.width;
57
- sourceHeight = sourceHeight || framebuffer.height;
58
-
59
- // TODO - Set and unset gl.readBuffer
60
- // if (sourceAttachment === GL.COLOR_ATTACHMENT0 && handle === null) {
61
- // sourceAttachment = GL.FRONT;
62
- // }
63
-
64
- const attachment = sourceAttachment - GL.COLOR_ATTACHMENT0;
65
- // assert(attachments[sourceAttachment]);
66
-
67
- // Deduce the type from color attachment if not provided.
68
- sourceType =
69
- sourceType || framebuffer.colorAttachments[attachment]?.texture?.glType || GL.UNSIGNED_BYTE;
70
-
71
- // Deduce type and allocated pixelArray if needed
72
- target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
73
-
74
- // Pixel array available, if necessary, deduce type from it.
75
- sourceType = sourceType || getGLTypeFromTypedArray(target);
76
-
77
- const prevHandle = gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
78
- gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
79
- // @ts-expect-error
80
- gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
81
- if (deleteFramebuffer) {
82
- framebuffer.destroy();
83
- }
84
- return target;
85
- }
86
-
87
- /**
88
- * Copies data from a Framebuffer or a Texture object into a Buffer object.
89
- * NOTE: doesn't wait for copy to be complete, it programs GPU to perform a DMA transffer.
90
- * @deprecated Use CommandEncoder
91
- * @param source
92
- * @param options
93
- */
94
- export function readPixelsToBuffer(
95
- source: Framebuffer | Texture,
96
- options?: {
97
- sourceX?: number;
98
- sourceY?: number;
99
- sourceFormat?: number;
100
- target?: Buffer; // A new Buffer object is created when not provided.
101
- targetByteOffset?: number; // byte offset in buffer object
102
- // following parameters are auto deduced if not provided
103
- sourceWidth?: number;
104
- sourceHeight?: number;
105
- sourceType?: number;
106
- }
107
- ): WEBGLBuffer {
108
- const {
109
- target,
110
- sourceX = 0,
111
- sourceY = 0,
112
- sourceFormat = GL.RGBA,
113
- targetByteOffset = 0
114
- } = options || {};
115
- // following parameters are auto deduced if not provided
116
- let {sourceWidth, sourceHeight, sourceType} = options || {};
117
- const {framebuffer, deleteFramebuffer} = getFramebuffer(source);
118
- // assert(framebuffer);
119
- sourceWidth = sourceWidth || framebuffer.width;
120
- sourceHeight = sourceHeight || framebuffer.height;
121
-
122
- // Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature
123
- const webglFramebuffer = framebuffer;
124
-
125
- // deduce type if not available.
126
- sourceType = sourceType || GL.UNSIGNED_BYTE;
127
-
128
- let webglBufferTarget = target as unknown as WEBGLBuffer | undefined;
129
- if (!webglBufferTarget) {
130
- // Create new buffer with enough size
131
- const components = glFormatToComponents(sourceFormat);
132
- const byteCount = glTypeToBytes(sourceType);
133
- const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;
134
- webglBufferTarget = webglFramebuffer.device.createBuffer({byteLength});
135
- }
136
-
137
- // TODO(donmccurdy): Do we have tests to confirm this is working?
138
- const commandEncoder = source.device.createCommandEncoder();
139
- commandEncoder.copyTextureToBuffer({
140
- source: source as Texture,
141
- width: sourceWidth,
142
- height: sourceHeight,
143
- origin: [sourceX, sourceY],
144
- destination: webglBufferTarget,
145
- byteOffset: targetByteOffset
146
- });
147
- commandEncoder.destroy();
148
-
149
- if (deleteFramebuffer) {
150
- framebuffer.destroy();
151
- }
152
-
153
- return webglBufferTarget;
154
- }
155
-
156
- /**
157
- * Copy a rectangle from a Framebuffer or Texture object into a texture (at an offset)
158
- * @deprecated Use CommandEncoder
159
- */
160
- // eslint-disable-next-line complexity, max-statements
161
- export function copyToTexture(
162
- source: Framebuffer | Texture,
163
- target: Texture | GL,
164
- options?: {
165
- sourceX?: number;
166
- sourceY?: number;
167
-
168
- targetX?: number;
169
- targetY?: number;
170
- targetZ?: number;
171
- targetMipmaplevel?: number;
172
- targetInternalFormat?: number;
173
-
174
- width?: number; // defaults to target width
175
- height?: number; // defaults to target height
176
- }
177
- ): Texture {
178
- const {
179
- sourceX = 0,
180
- sourceY = 0,
181
- // attachment = GL.COLOR_ATTACHMENT0, // TODO - support gl.readBuffer
182
- targetMipmaplevel = 0,
183
- targetInternalFormat = GL.RGBA
184
- } = options || {};
185
- let {
186
- targetX,
187
- targetY,
188
- targetZ,
189
- width, // defaults to target width
190
- height // defaults to target height
191
- } = options || {};
192
-
193
- const {framebuffer, deleteFramebuffer} = getFramebuffer(source);
194
- // assert(framebuffer);
195
- const webglFramebuffer = framebuffer;
196
- const {device, handle} = webglFramebuffer;
197
- const isSubCopy =
198
- typeof targetX !== 'undefined' ||
199
- typeof targetY !== 'undefined' ||
200
- typeof targetZ !== 'undefined';
201
- targetX = targetX || 0;
202
- targetY = targetY || 0;
203
- targetZ = targetZ || 0;
204
- const prevHandle = device.gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
205
- // TODO - support gl.readBuffer (WebGL2 only)
206
- // const prevBuffer = gl.readBuffer(attachment);
207
- // assert(target);
208
- let texture: WEBGLTexture | null = null;
209
- let textureTarget: GL;
210
- if (target instanceof WEBGLTexture) {
211
- texture = target;
212
- width = Number.isFinite(width) ? width : texture.width;
213
- height = Number.isFinite(height) ? height : texture.height;
214
- texture?.bind(0);
215
- // @ts-ignore
216
- textureTarget = texture.target;
217
- } else {
218
- // @ts-ignore
219
- textureTarget = target;
220
- }
221
-
222
- if (!isSubCopy) {
223
- device.gl.copyTexImage2D(
224
- textureTarget,
225
- targetMipmaplevel,
226
- targetInternalFormat,
227
- sourceX,
228
- sourceY,
229
- width,
230
- height,
231
- 0 /* border must be 0 */
232
- );
233
- } else {
234
- switch (textureTarget) {
235
- case GL.TEXTURE_2D:
236
- case GL.TEXTURE_CUBE_MAP:
237
- device.gl.copyTexSubImage2D(
238
- textureTarget,
239
- targetMipmaplevel,
240
- targetX,
241
- targetY,
242
- sourceX,
243
- sourceY,
244
- width,
245
- height
246
- );
247
- break;
248
- case GL.TEXTURE_2D_ARRAY:
249
- case GL.TEXTURE_3D:
250
- device.gl.copyTexSubImage3D(
251
- textureTarget,
252
- targetMipmaplevel,
253
- targetX,
254
- targetY,
255
- targetZ,
256
- sourceX,
257
- sourceY,
258
- width,
259
- height
260
- );
261
- break;
262
- default:
263
- }
264
- }
265
- if (texture) {
266
- texture.unbind();
267
- }
268
- // @ts-expect-error
269
- device.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
270
- if (deleteFramebuffer) {
271
- framebuffer.destroy();
272
- }
273
- return texture;
274
- }
275
-
276
- function getFramebuffer(source: Texture | Framebuffer): {
277
- framebuffer: WEBGLFramebuffer;
278
- deleteFramebuffer: boolean;
279
- } {
280
- if (!(source instanceof Framebuffer)) {
281
- return {framebuffer: toFramebuffer(source), deleteFramebuffer: true};
282
- }
283
- return {framebuffer: source as WEBGLFramebuffer, deleteFramebuffer: false};
284
- }
285
-
286
- /**
287
- * Wraps a given texture into a framebuffer object, that can be further used
288
- * to read data from the texture object.
289
- */
290
- export function toFramebuffer(texture: Texture, props?: FramebufferProps): WEBGLFramebuffer {
291
- const {device, width, height, id} = texture;
292
- const framebuffer = device.createFramebuffer({
293
- ...props,
294
- id: `framebuffer-for-${id}`,
295
- width,
296
- height,
297
- colorAttachments: [texture]
298
- });
299
- return framebuffer as WEBGLFramebuffer;
300
- }
301
-
302
- function getPixelArray(
303
- pixelArray,
304
- type,
305
- format,
306
- width: number,
307
- height: number
308
- ): Uint8Array | Uint16Array | Float32Array {
309
- if (pixelArray) {
310
- return pixelArray;
311
- }
312
- // Allocate pixel array if not already available, using supplied type
313
- type = type || GL.UNSIGNED_BYTE;
314
- const ArrayType = getTypedArrayFromGLType(type, {clamped: false});
315
- const components = glFormatToComponents(format);
316
- // TODO - check for composite type (components = 1).
317
- return new ArrayType(width * height * components) as Uint8Array | Uint16Array | Float32Array;
318
- }