@luma.gl/webgl 9.0.11 → 9.1.0-alpha.2

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 (123) 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 +12 -1
  4. package/dist/adapter/converters/texture-formats.d.ts +22 -16
  5. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  6. package/dist/adapter/converters/texture-formats.js +31 -32
  7. package/dist/adapter/device-helpers/webgl-device-features.js +1 -1
  8. package/dist/adapter/device-helpers/webgl-device-limits.js +1 -1
  9. package/dist/adapter/helpers/webgl-texture-utils.d.ts +300 -0
  10. package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -0
  11. package/dist/adapter/helpers/webgl-texture-utils.js +368 -0
  12. package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
  13. package/dist/adapter/helpers/webgl-topology-utils.js +0 -4
  14. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  15. package/dist/adapter/resources/webgl-buffer.js +2 -2
  16. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  17. package/dist/adapter/resources/webgl-command-buffer.js +6 -9
  18. package/dist/adapter/resources/webgl-framebuffer.d.ts +32 -5
  19. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  20. package/dist/adapter/resources/webgl-framebuffer.js +42 -60
  21. package/dist/adapter/resources/webgl-render-pass.d.ts +3 -2
  22. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  23. package/dist/adapter/resources/webgl-render-pass.js +1 -3
  24. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  25. package/dist/adapter/resources/webgl-render-pipeline.js +45 -20
  26. package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
  27. package/dist/adapter/resources/webgl-shader.js +2 -2
  28. package/dist/adapter/resources/webgl-texture-view.d.ts +1 -1
  29. package/dist/adapter/resources/webgl-texture-view.d.ts.map +1 -1
  30. package/dist/adapter/resources/webgl-texture-view.js +1 -1
  31. package/dist/adapter/resources/webgl-texture.d.ts +58 -172
  32. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  33. package/dist/adapter/resources/webgl-texture.js +402 -510
  34. package/dist/adapter/resources/webgl-transform-feedback.js +1 -1
  35. package/dist/adapter/resources/webgl-vertex-array.d.ts +3 -2
  36. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
  37. package/dist/adapter/resources/webgl-vertex-array.js +5 -2
  38. package/dist/adapter/webgl-canvas-context.d.ts +3 -1
  39. package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
  40. package/dist/adapter/webgl-canvas-context.js +2 -0
  41. package/dist/adapter/webgl-device.d.ts +4 -3
  42. package/dist/adapter/webgl-device.d.ts.map +1 -1
  43. package/dist/adapter/webgl-device.js +6 -5
  44. package/dist/classic/accessor.d.ts +22 -1
  45. package/dist/classic/accessor.d.ts.map +1 -1
  46. package/dist/classic/accessor.js +1 -9
  47. package/dist/classic/clear.d.ts.map +1 -1
  48. package/dist/classic/clear.js +2 -5
  49. package/dist/classic/copy-and-blit.d.ts +2 -1
  50. package/dist/classic/copy-and-blit.d.ts.map +1 -1
  51. package/dist/classic/copy-and-blit.js +11 -9
  52. package/dist/classic/format-utils.d.ts.map +1 -1
  53. package/dist/classic/format-utils.js +0 -3
  54. package/dist/classic/typed-array-utils.d.ts +1 -1
  55. package/dist/classic/typed-array-utils.d.ts.map +1 -1
  56. package/dist/context/debug/spector.d.ts.map +1 -1
  57. package/dist/context/debug/spector.js +2 -1
  58. package/dist/context/debug/webgl-developer-tools.d.ts +1 -1
  59. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  60. package/dist/context/debug/webgl-developer-tools.js +2 -5
  61. package/dist/context/parameters/webgl-parameter-tables.js +1 -1
  62. package/dist/context/state-tracker/track-context-state.d.ts.map +1 -1
  63. package/dist/context/state-tracker/track-context-state.js +5 -6
  64. package/dist/dist.dev.js +872 -1262
  65. package/dist/dist.min.js +2 -2
  66. package/dist/index.cjs +861 -1138
  67. package/dist/index.cjs.map +4 -4
  68. package/dist/index.d.ts +0 -4
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +0 -3
  71. package/dist/utils/fill-array.d.ts +8 -0
  72. package/dist/utils/fill-array.d.ts.map +1 -0
  73. package/dist/utils/fill-array.js +26 -0
  74. package/dist/utils/load-script.d.ts +8 -0
  75. package/dist/utils/load-script.d.ts.map +1 -0
  76. package/dist/utils/load-script.js +26 -0
  77. package/dist/utils/split-uniforms-and-bindings.d.ts +9 -0
  78. package/dist/utils/split-uniforms-and-bindings.d.ts.map +1 -0
  79. package/dist/utils/split-uniforms-and-bindings.js +20 -0
  80. package/package.json +6 -5
  81. package/src/adapter/converters/device-parameters.ts +13 -1
  82. package/src/adapter/converters/texture-formats.ts +45 -42
  83. package/src/adapter/device-helpers/webgl-device-features.ts +1 -1
  84. package/src/adapter/device-helpers/webgl-device-limits.ts +1 -1
  85. package/src/adapter/helpers/webgl-texture-utils.ts +481 -0
  86. package/src/adapter/helpers/webgl-topology-utils.ts +0 -4
  87. package/src/adapter/resources/webgl-buffer.ts +2 -2
  88. package/src/adapter/resources/webgl-command-buffer.ts +8 -10
  89. package/src/adapter/resources/webgl-framebuffer.ts +22 -56
  90. package/src/adapter/resources/webgl-render-pass.ts +4 -5
  91. package/src/adapter/resources/webgl-render-pipeline.ts +48 -23
  92. package/src/adapter/resources/webgl-shader.ts +3 -3
  93. package/src/adapter/resources/webgl-texture-view.ts +1 -3
  94. package/src/adapter/resources/webgl-texture.ts +432 -784
  95. package/src/adapter/resources/webgl-transform-feedback.ts +1 -1
  96. package/src/adapter/resources/webgl-vertex-array.ts +11 -7
  97. package/src/adapter/webgl-canvas-context.ts +4 -1
  98. package/src/adapter/webgl-device.ts +10 -18
  99. package/src/classic/accessor.ts +31 -11
  100. package/src/classic/clear.ts +3 -6
  101. package/src/classic/copy-and-blit.ts +19 -19
  102. package/src/classic/format-utils.ts +0 -3
  103. package/src/classic/typed-array-utils.ts +1 -1
  104. package/src/context/debug/spector.ts +2 -1
  105. package/src/context/debug/webgl-developer-tools.ts +3 -7
  106. package/src/context/parameters/webgl-parameter-tables.ts +3 -3
  107. package/src/context/state-tracker/track-context-state.ts +5 -6
  108. package/src/index.ts +0 -6
  109. package/src/utils/fill-array.ts +35 -0
  110. package/src/utils/load-script.ts +30 -0
  111. package/src/utils/split-uniforms-and-bindings.ts +31 -0
  112. package/dist/adapter/objects/constants-to-keys.d.ts +0 -3
  113. package/dist/adapter/objects/constants-to-keys.d.ts.map +0 -1
  114. package/dist/adapter/objects/constants-to-keys.js +0 -22
  115. package/dist/adapter/objects/webgl-renderbuffer.d.ts +0 -43
  116. package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +0 -1
  117. package/dist/adapter/objects/webgl-renderbuffer.js +0 -95
  118. package/dist/adapter/objects/webgl-resource.d.ts +0 -32
  119. package/dist/adapter/objects/webgl-resource.d.ts.map +0 -1
  120. package/dist/adapter/objects/webgl-resource.js +0 -114
  121. package/src/adapter/objects/constants-to-keys.ts +0 -27
  122. package/src/adapter/objects/webgl-renderbuffer.ts +0 -132
  123. package/src/adapter/objects/webgl-resource.ts +0 -183
@@ -56,7 +56,7 @@ export class WEBGLTransformFeedback extends TransformFeedback {
56
56
 
57
57
  end(): void {
58
58
  this.gl.endTransformFeedback();
59
- if (!this.bindOnUse) {
59
+ if (this.bindOnUse) {
60
60
  this._unbindBuffers();
61
61
  }
62
62
  this.gl.bindTransformFeedback(GL.TRANSFORM_FEEDBACK, null);
@@ -2,8 +2,9 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {Device, Buffer, VertexArrayProps, TypedArray, NumberArray} from '@luma.gl/core';
6
- import {VertexArray, getScratchArray, fillArray} from '@luma.gl/core';
5
+ import type {TypedArray, NumericArray} from '@math.gl/types';
6
+ import type {Device, Buffer, VertexArrayProps} from '@luma.gl/core';
7
+ import {VertexArray, getScratchArray} from '@luma.gl/core';
7
8
  import {GL} from '@luma.gl/constants';
8
9
  import {getBrowser} from '@probe.gl/env';
9
10
 
@@ -11,7 +12,7 @@ import {WebGLDevice} from '../webgl-device';
11
12
  import {WEBGLBuffer} from '../resources/webgl-buffer';
12
13
 
13
14
  import {getGLFromVertexType} from '../converters/vertex-formats';
14
- // import {getGLFromVertexType} from '../converters/vertex-formats';
15
+ import {fillArray} from '../../utils/fill-array';
15
16
 
16
17
  /** VertexArrayObject wrapper */
17
18
  export class WEBGLVertexArray extends VertexArray {
@@ -32,10 +33,10 @@ export class WEBGLVertexArray extends VertexArray {
32
33
  }
33
34
 
34
35
  // Create a VertexArray
35
- constructor(device: WebGLDevice, props?: VertexArrayProps) {
36
+ constructor(device: WebGLDevice, props: VertexArrayProps) {
36
37
  super(device, props);
37
38
  this.device = device;
38
- this.handle = this.device.gl.createVertexArray();
39
+ this.handle = this.device.gl.createVertexArray()!;
39
40
  }
40
41
 
41
42
  override destroy(): void {
@@ -96,6 +97,9 @@ export class WEBGLVertexArray extends VertexArray {
96
97
  // Attaches ARRAY_BUFFER with specified buffer format to location
97
98
  this.device.gl.vertexAttribPointer(location, size, type, normalized, stride, offset);
98
99
  }
100
+ // Clear binding - keeping it may cause [.WebGL-0x12804417100]
101
+ // GL_INVALID_OPERATION: A transform feedback buffer that would be written to is also bound to a non-transform-feedback target
102
+ this.device.gl.bindBuffer(GL.ARRAY_BUFFER, null);
99
103
 
100
104
  // Mark as non-constant
101
105
  this.device.gl.enableVertexAttribArray(location);
@@ -249,7 +253,7 @@ export class WEBGLVertexArray extends VertexArray {
249
253
  * TODO - convert Arrays based on known type? (read type from accessor, don't assume Float32Array)
250
254
  * TODO - handle single values for size 1 attributes?
251
255
  */
252
- function normalizeConstantArrayValue(arrayValue: NumberArray) {
256
+ function normalizeConstantArrayValue(arrayValue: NumericArray) {
253
257
  if (Array.isArray(arrayValue)) {
254
258
  return new Float32Array(arrayValue);
255
259
  }
@@ -259,7 +263,7 @@ function normalizeConstantArrayValue(arrayValue: NumberArray) {
259
263
  /**
260
264
  *
261
265
  */
262
- function compareConstantArrayValues(v1: NumberArray, v2: NumberArray): boolean {
266
+ function compareConstantArrayValues(v1: NumericArray, v2: NumericArray): boolean {
263
267
  if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {
264
268
  return false;
265
269
  }
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {CanvasContextProps} from '@luma.gl/core';
5
+ import type {CanvasContextProps, TextureFormat} from '@luma.gl/core';
6
6
  import {CanvasContext} from '@luma.gl/core';
7
7
  import {WebGLDevice} from './webgl-device';
8
8
  import {WEBGLFramebuffer} from './resources/webgl-framebuffer';
@@ -12,6 +12,9 @@ import {WEBGLFramebuffer} from './resources/webgl-framebuffer';
12
12
  */
13
13
  export class WebGLCanvasContext extends CanvasContext {
14
14
  readonly device: WebGLDevice;
15
+ readonly format: TextureFormat = 'rgba8unorm';
16
+ readonly depthStencilFormat: TextureFormat = 'depth24plus';
17
+
15
18
  presentationSize: [number, number];
16
19
  private _framebuffer: WEBGLFramebuffer | null = null;
17
20
 
@@ -2,19 +2,10 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {
6
- DeviceProps,
7
- DeviceInfo,
8
- CanvasContextProps,
9
- TextureFormat,
10
- VertexArray,
11
- VertexArrayProps,
12
- Framebuffer,
13
- Buffer,
14
- Texture,
15
- TypedArray
16
- } from '@luma.gl/core';
17
- import {Device, CanvasContext, log, uid, assert} from '@luma.gl/core';
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';
8
+ import {Device, CanvasContext, log} from '@luma.gl/core';
18
9
  import type {GLExtensions} from '@luma.gl/constants';
19
10
  import {
20
11
  popContextState,
@@ -192,7 +183,7 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
192
183
  //
193
184
 
194
185
  constructor(props: DeviceProps) {
195
- super({...props, id: props.id || uid('webgl-device')});
186
+ super({...props, id: props.id || 'webgl-device'});
196
187
 
197
188
  // If attaching to an already attached context, return the attached device
198
189
  // @ts-expect-error device is attached to context
@@ -298,7 +289,8 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
298
289
  return new WEBGLBuffer(this, newProps);
299
290
  }
300
291
 
301
- _createTexture(props: TextureProps): WEBGLTexture {
292
+ // _createTexture(props: TextureProps): WEBGLTexture {
293
+ _createTexture(props: TextureProps): Texture {
302
294
  return new WEBGLTexture(this, props);
303
295
  }
304
296
 
@@ -348,7 +340,7 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
348
340
 
349
341
  private renderPass: WEBGLRenderPass | null = null;
350
342
 
351
- override createCommandEncoder(props?: CommandEncoderProps): WEBGLCommandEncoder {
343
+ override createCommandEncoder(props: CommandEncoderProps = {}): WEBGLCommandEncoder {
352
344
  return new WEBGLCommandEncoder(this, props);
353
345
  }
354
346
 
@@ -538,7 +530,7 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
538
530
  setConstantUintArray(this, location, constant as Uint32Array);
539
531
  break;
540
532
  default:
541
- assert(false);
533
+ throw new Error('constant');
542
534
  }
543
535
  }
544
536
 
@@ -574,7 +566,7 @@ function setConstantFloatArray(device: WebGLDevice, location: number, array: Flo
574
566
  device.gl.vertexAttrib4fv(location, array);
575
567
  break;
576
568
  default:
577
- assert(false);
569
+ // assert(false);
578
570
  }
579
571
  }
580
572
 
@@ -2,10 +2,39 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {assert, checkProps, Buffer, AccessorObject} from '@luma.gl/core';
5
+ import {Buffer} from '@luma.gl/core';
6
6
  import {GL} from '@luma.gl/constants';
7
7
  import {getTypedArrayFromGLType} from './typed-array-utils';
8
8
 
9
+ /**
10
+ * Attribute descriptor object
11
+ * @deprecated Use ShaderLayout
12
+ */
13
+ export interface AccessorObject {
14
+ buffer?: Buffer;
15
+ // format: VertexFormat;
16
+ offset?: number;
17
+ // can now be described with single WebGPU-style `format` string
18
+
19
+ //
20
+ stride?: number;
21
+
22
+ /** @deprecated - Use accessor.stepMode */
23
+ divisor?: number;
24
+
25
+ /** @deprecated - Infer from format */
26
+ type?: number;
27
+ /** @deprecated - Infer from format */
28
+ size?: number;
29
+ /** @deprecated - Infer from format */
30
+ normalized?: boolean;
31
+ /** @deprecated - Infer from format */
32
+ integer?: boolean;
33
+
34
+ /** @deprecated */
35
+ index?: number;
36
+ }
37
+
9
38
  const DEFAULT_ACCESSOR_VALUES = {
10
39
  offset: 0,
11
40
  stride: 0,
@@ -16,13 +45,6 @@ const DEFAULT_ACCESSOR_VALUES = {
16
45
  integer: false
17
46
  };
18
47
 
19
- const PROP_CHECKS = {
20
- deprecatedProps: {
21
- instanced: 'divisor',
22
- isInstanced: 'divisor'
23
- }
24
- };
25
-
26
48
  export class Accessor implements AccessorObject {
27
49
  offset?: number;
28
50
  stride?: number;
@@ -43,7 +65,7 @@ export class Accessor implements AccessorObject {
43
65
  }
44
66
 
45
67
  static getBytesPerVertex(accessor: AccessorObject): number {
46
- assert(accessor.size);
68
+ // assert(accessor.size);
47
69
  // TODO: using `FLOAT` when type is not specified,
48
70
  // ensure this assumption is valid or force API to specify type.
49
71
  const ArrayType = getTypedArrayFromGLType(accessor.type || GL.FLOAT);
@@ -82,8 +104,6 @@ export class Accessor implements AccessorObject {
82
104
 
83
105
  // eslint-disable-next-line complexity, max-statements
84
106
  _assign(props: AccessorObject = {}): this {
85
- props = checkProps('Accessor', props, PROP_CHECKS);
86
-
87
107
  if (props.type !== undefined) {
88
108
  this.type = props.type;
89
109
 
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {Device, Framebuffer, assert} from '@luma.gl/core';
5
+ import {Device, Framebuffer} from '@luma.gl/core';
6
6
  import {WebGLDevice} from '../adapter/webgl-device';
7
7
  import {withGLParameters} from '../context/state-tracker/with-parameters';
8
8
 
@@ -16,9 +16,6 @@ const GL_DEPTH = 0x1801;
16
16
  const GL_STENCIL = 0x1802;
17
17
  const GL_DEPTH_STENCIL = 0x84f9;
18
18
 
19
- // Should disappear if asserts are removed
20
- const ERR_ARGUMENTS = 'clear: bad arguments';
21
-
22
19
  /**
23
20
  * Optionally clears depth, color and stencil buffers
24
21
  * @deprecated Set clear color when creating a RenderPass.
@@ -57,7 +54,7 @@ export function clear(
57
54
  }
58
55
  }
59
56
 
60
- assert(clearFlags !== 0, ERR_ARGUMENTS);
57
+ // assert(clearFlags !== 0, ERR_ARGUMENTS);
61
58
 
62
59
  // Temporarily set any clear "colors" and call clear
63
60
  const gl = (device as WebGLDevice).gl;
@@ -112,7 +109,7 @@ export function clearBuffer(
112
109
  break;
113
110
 
114
111
  default:
115
- assert(false, ERR_ARGUMENTS);
112
+ // assert(false, ERR_ARGUMENTS);
116
113
  }
117
114
  });
118
115
  }
@@ -2,14 +2,14 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {assert, Buffer, Texture, Framebuffer, FramebufferProps} from '@luma.gl/core';
5
+ import {Buffer, Texture, Framebuffer, FramebufferProps} from '@luma.gl/core';
6
6
  import {GL} from '@luma.gl/constants';
7
7
 
8
- import {WEBGLTextureView} from '../adapter/resources/webgl-texture-view';
9
8
  import {WEBGLFramebuffer} from '../adapter/resources/webgl-framebuffer';
10
9
  import {getGLTypeFromTypedArray, getTypedArrayFromGLType} from './typed-array-utils';
11
10
  import {glFormatToComponents, glTypeToBytes} from './format-utils';
12
11
  import {WEBGLBuffer} from '../adapter/resources/webgl-buffer';
12
+ import {WEBGLTexture} from '../adapter/resources/webgl-texture';
13
13
 
14
14
  /**
15
15
  * Copies data from a type or a Texture object into ArrayBuffer object.
@@ -51,8 +51,8 @@ export function readPixelsToArray(
51
51
  } = options || {};
52
52
 
53
53
  const {framebuffer, deleteFramebuffer} = getFramebuffer(source);
54
- assert(framebuffer);
55
- const {gl, handle} = framebuffer as WEBGLFramebuffer;
54
+ // assert(framebuffer);
55
+ const {gl, handle} = framebuffer;
56
56
  sourceWidth = sourceWidth || framebuffer.width;
57
57
  sourceHeight = sourceHeight || framebuffer.height;
58
58
 
@@ -66,9 +66,7 @@ export function readPixelsToArray(
66
66
 
67
67
  // Deduce the type from color attachment if not provided.
68
68
  sourceType =
69
- sourceType ||
70
- (framebuffer.colorAttachments[attachment] as WEBGLTextureView)?.texture?.type ||
71
- GL.UNSIGNED_BYTE;
69
+ sourceType || framebuffer.colorAttachments[attachment]?.texture?.glType || GL.UNSIGNED_BYTE;
72
70
 
73
71
  // Deduce type and allocated pixelArray if needed
74
72
  target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
@@ -117,12 +115,12 @@ export function readPixelsToBuffer(
117
115
  // following parameters are auto deduced if not provided
118
116
  let {sourceWidth, sourceHeight, sourceType} = options || {};
119
117
  const {framebuffer, deleteFramebuffer} = getFramebuffer(source);
120
- assert(framebuffer);
118
+ // assert(framebuffer);
121
119
  sourceWidth = sourceWidth || framebuffer.width;
122
120
  sourceHeight = sourceHeight || framebuffer.height;
123
121
 
124
122
  // Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature
125
- const webglFramebuffer = framebuffer as WEBGLFramebuffer;
123
+ const webglFramebuffer = framebuffer;
126
124
 
127
125
  // deduce type if not available.
128
126
  sourceType = sourceType || GL.UNSIGNED_BYTE;
@@ -193,8 +191,8 @@ export function copyToTexture(
193
191
  } = options || {};
194
192
 
195
193
  const {framebuffer, deleteFramebuffer} = getFramebuffer(source);
196
- assert(framebuffer);
197
- const webglFramebuffer = framebuffer as WEBGLFramebuffer;
194
+ // assert(framebuffer);
195
+ const webglFramebuffer = framebuffer;
198
196
  const {device, handle} = webglFramebuffer;
199
197
  const isSubCopy =
200
198
  typeof targetX !== 'undefined' ||
@@ -206,16 +204,18 @@ export function copyToTexture(
206
204
  const prevHandle = device.gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
207
205
  // TODO - support gl.readBuffer (WebGL2 only)
208
206
  // const prevBuffer = gl.readBuffer(attachment);
209
- assert(target);
210
- let texture = null;
207
+ // assert(target);
208
+ let texture: WEBGLTexture | null = null;
211
209
  let textureTarget: GL;
212
- if (target instanceof Texture) {
210
+ if (target instanceof WEBGLTexture) {
213
211
  texture = target;
214
212
  width = Number.isFinite(width) ? width : texture.width;
215
213
  height = Number.isFinite(height) ? height : texture.height;
216
- texture.bind(0);
214
+ texture?.bind(0);
215
+ // @ts-ignore
217
216
  textureTarget = texture.target;
218
217
  } else {
218
+ // @ts-ignore
219
219
  textureTarget = target;
220
220
  }
221
221
 
@@ -274,20 +274,20 @@ export function copyToTexture(
274
274
  }
275
275
 
276
276
  function getFramebuffer(source: Texture | Framebuffer): {
277
- framebuffer: Framebuffer;
277
+ framebuffer: WEBGLFramebuffer;
278
278
  deleteFramebuffer: boolean;
279
279
  } {
280
280
  if (!(source instanceof Framebuffer)) {
281
281
  return {framebuffer: toFramebuffer(source), deleteFramebuffer: true};
282
282
  }
283
- return {framebuffer: source, deleteFramebuffer: false};
283
+ return {framebuffer: source as WEBGLFramebuffer, deleteFramebuffer: false};
284
284
  }
285
285
 
286
286
  /**
287
287
  * Wraps a given texture into a framebuffer object, that can be further used
288
288
  * to read data from the texture object.
289
289
  */
290
- export function toFramebuffer(texture: Texture, props?: FramebufferProps): Framebuffer {
290
+ export function toFramebuffer(texture: Texture, props?: FramebufferProps): WEBGLFramebuffer {
291
291
  const {device, width, height, id} = texture;
292
292
  const framebuffer = device.createFramebuffer({
293
293
  ...props,
@@ -296,7 +296,7 @@ export function toFramebuffer(texture: Texture, props?: FramebufferProps): Frame
296
296
  height,
297
297
  colorAttachments: [texture]
298
298
  });
299
- return framebuffer;
299
+ return framebuffer as WEBGLFramebuffer;
300
300
  }
301
301
 
302
302
  function getPixelArray(
@@ -2,7 +2,6 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {assert} from '@luma.gl/core';
6
5
  import {GL} from '@luma.gl/constants';
7
6
 
8
7
  // Returns number of components in a specific readPixels WebGL format
@@ -23,7 +22,6 @@ export function glFormatToComponents(format) {
23
22
  return 4;
24
23
  // TODO: Add support for additional WebGL2 formats
25
24
  default:
26
- assert(false);
27
25
  return 0;
28
26
  }
29
27
  }
@@ -41,7 +39,6 @@ export function glTypeToBytes(type) {
41
39
  return 4;
42
40
  // TODO: Add support for additional WebGL2 types
43
41
  default:
44
- assert(false);
45
42
  return 0;
46
43
  }
47
44
  }
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {TypedArray, TypedArrayConstructor} from '@luma.gl/core';
5
+ import {TypedArray, TypedArrayConstructor} from '@math.gl/types';
6
6
  import {GL, GLDataType, GLPixelType} from '@luma.gl/constants';
7
7
 
8
8
  const ERR_TYPE_DEDUCTION = 'Failed to deduce GL constant from typed array';
@@ -2,7 +2,8 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {log, loadScript} from '@luma.gl/core';
5
+ import {log} from '@luma.gl/core';
6
+ import {loadScript} from '../../utils/load-script';
6
7
 
7
8
  /** Spector debug initialization options */
8
9
  type SpectorProps = {
@@ -2,10 +2,11 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {log, loadScript} from '@luma.gl/core';
5
+ import {log} from '@luma.gl/core';
6
6
  // Rename constant to prevent inlining. We need the full set of constants for generating debug strings.
7
7
  import {GL as GLEnum} from '@luma.gl/constants';
8
8
  import {isBrowser} from '@probe.gl/env';
9
+ import {loadScript} from '../../utils/load-script';
9
10
 
10
11
  const WEBGL_DEBUG_CDN_URL = 'https://unpkg.com/webgl-debug@2.0.1/index.js';
11
12
 
@@ -58,12 +59,7 @@ export async function loadWebGLDeveloperTools(): Promise<void> {
58
59
  export function makeDebugContext(
59
60
  gl: WebGL2RenderingContext,
60
61
  props: DebugContextProps = {}
61
- ): WebGL2RenderingContext | null {
62
- // Return null to ensure we don't try to create a context in this case (TODO what case is that?)
63
- if (!gl) {
64
- return null;
65
- }
66
-
62
+ ): WebGL2RenderingContext {
67
63
  return props.debug ? getDebugContext(gl, props) : getRealContext(gl);
68
64
  }
69
65
 
@@ -100,7 +100,7 @@ const pixelStorei = (gl: WebGL2RenderingContext, value: number | boolean, key: G
100
100
 
101
101
  const bindFramebuffer = (gl: WebGL2RenderingContext, value: unknown, key: GL) => {
102
102
  const target = key === GL.FRAMEBUFFER_BINDING ? GL.DRAW_FRAMEBUFFER : GL.READ_FRAMEBUFFER;
103
- return gl.bindFramebuffer(target, value);
103
+ return gl.bindFramebuffer(target, value as WebGLFramebuffer);
104
104
  };
105
105
 
106
106
  const bindBuffer = (gl: WebGL2RenderingContext, value: unknown, key: GL) => {
@@ -113,7 +113,7 @@ const bindBuffer = (gl: WebGL2RenderingContext, value: unknown, key: GL) => {
113
113
  };
114
114
  const glTarget = bindingMap[key];
115
115
 
116
- gl.bindBuffer(glTarget, value);
116
+ gl.bindBuffer(glTarget as number, value as WebGLBuffer | null);
117
117
  };
118
118
 
119
119
  // Utility
@@ -304,7 +304,7 @@ export const GL_PARAMETER_SETTERS = {
304
304
  gl.polygonOffset(...value),
305
305
 
306
306
  sampleCoverage: (gl: WebGL2RenderingContext, value: [number, boolean?]) =>
307
- gl.sampleCoverage(...value),
307
+ gl.sampleCoverage(value[0], value[1] || false),
308
308
 
309
309
  scissorTest: (gl: WebGL2RenderingContext, value) =>
310
310
  value ? gl.enable(GL.SCISSOR_TEST) : gl.disable(GL.SCISSOR_TEST),
@@ -4,7 +4,6 @@
4
4
 
5
5
  // Support for listening to context state changes and intercepting state queries
6
6
  // NOTE: this system does not handle buffer bindings
7
- import {assert} from '@luma.gl/core';
8
7
  import {
9
8
  GL_PARAMETER_DEFAULTS,
10
9
  GL_HOOKED_SETTERS,
@@ -44,7 +43,7 @@ class GLState {
44
43
  }
45
44
 
46
45
  pop() {
47
- assert(this.stateStack.length > 0);
46
+ // assert(this.stateStack.length > 0);
48
47
  // Use the saved values in the state stack to restore parameters
49
48
  const oldValues = this.stateStack[this.stateStack.length - 1];
50
49
  setGLParameters(this.gl, oldValues);
@@ -66,7 +65,7 @@ class GLState {
66
65
  this.stateStack.length > 0 ? this.stateStack[this.stateStack.length - 1] : null;
67
66
 
68
67
  for (const key in values) {
69
- assert(key !== undefined);
68
+ // assert(key !== undefined);
70
69
  const value = values[key];
71
70
  const cached = this.cache[key];
72
71
  // Check that value hasn't already been shadowed
@@ -113,8 +112,8 @@ export function trackContextState(
113
112
  log?: any;
114
113
  }
115
114
  ): WebGL2RenderingContext {
116
- const {enable = true, copyState} = options;
117
- assert(copyState !== undefined);
115
+ const {enable = true, copyState} = options || {};
116
+ // assert(copyState !== undefined);
118
117
  // @ts-expect-error
119
118
  if (!gl.state) {
120
119
  // @ts-ignore
@@ -163,7 +162,7 @@ export function pushContextState(gl: WebGL2RenderingContext): void {
163
162
  */
164
163
  export function popContextState(gl: WebGL2RenderingContext): void {
165
164
  const glState = getContextState(gl);
166
- assert(glState);
165
+ // assert(glState);
167
166
  glState.pop();
168
167
  }
169
168
 
package/src/index.ts CHANGED
@@ -16,7 +16,6 @@ export {WebGLDevice} from './adapter/webgl-device';
16
16
  export {WebGLCanvasContext} from './adapter/webgl-canvas-context';
17
17
 
18
18
  // WebGL Resource classes
19
- export {WebGLResource, WebGLResource as WEBGLResource} from './adapter/objects/webgl-resource';
20
19
  export {WEBGLBuffer} from './adapter/resources/webgl-buffer';
21
20
  export {WEBGLTexture} from './adapter/resources/webgl-texture';
22
21
  // export {WEBGLExternalTexture} from './adapter/resources/webgl-external-texture';
@@ -44,11 +43,6 @@ export {setDeviceParameters, withDeviceParameters} from './adapter/converters/de
44
43
 
45
44
  // HELPERS - EXPERIMENTAL
46
45
  export {getShaderLayout} from './adapter/helpers/get-shader-layout';
47
- export {convertGLToTextureFormat} from './adapter/converters/texture-formats';
48
-
49
- // Internal WebGL classes
50
- export type {RenderbufferProps as _RenderbufferProps} from './adapter/objects/webgl-renderbuffer';
51
- export {WEBGLRenderbuffer as _WEBGLRenderbuffer} from './adapter/objects/webgl-renderbuffer';
52
46
 
53
47
  // TEST EXPORTS
54
48
  export {TEXTURE_FORMATS as _TEXTURE_FORMATS} from './adapter/converters/texture-formats';
@@ -0,0 +1,35 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {NumberArray} from '@math.gl/types';
6
+
7
+ // Uses copyWithin to significantly speed up typed array value filling
8
+ export function fillArray(options: {
9
+ target: NumberArray;
10
+ source: NumberArray;
11
+ start?: number;
12
+ count?: number;
13
+ }): NumberArray {
14
+ const {target, source, start = 0, count = 1} = options;
15
+ const length = source.length;
16
+ const total = count * length;
17
+ let copied = 0;
18
+ for (let i = start; copied < length; copied++) {
19
+ target[i++] = source[copied];
20
+ }
21
+
22
+ while (copied < total) {
23
+ // If we have copied less than half, copy everything we got
24
+ // else copy remaining in one operation
25
+ if (copied < total - copied) {
26
+ target.copyWithin(start + copied, start, start + copied);
27
+ copied *= 2;
28
+ } else {
29
+ target.copyWithin(start + copied, start, start + total - copied);
30
+ copied = total;
31
+ }
32
+ }
33
+
34
+ return options.target;
35
+ }
@@ -0,0 +1,30 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ /**
6
+ * Load a script (identified by an url). When the url returns, the
7
+ * content of this file is added into a new script element, attached to the DOM (body element)
8
+ * @param scriptUrl defines the url of the script to laod
9
+ * @param scriptId defines the id of the script element
10
+ */
11
+ export async function loadScript(scriptUrl: string, scriptId?: string): Promise<Event> {
12
+ const head = document.getElementsByTagName('head')[0];
13
+ if (!head) {
14
+ throw new Error('loadScript');
15
+ }
16
+
17
+ const script = document.createElement('script');
18
+ script.setAttribute('type', 'text/javascript');
19
+ script.setAttribute('src', scriptUrl);
20
+ if (scriptId) {
21
+ script.id = scriptId;
22
+ }
23
+
24
+ return new Promise((resolve, reject) => {
25
+ script.onload = resolve;
26
+ script.onerror = error =>
27
+ reject(new Error(`Unable to load script '${scriptUrl}': ${error as string}`));
28
+ head.appendChild(script);
29
+ });
30
+ }
@@ -0,0 +1,31 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {UniformValue, Binding} from '@luma.gl/core';
6
+ import {isNumericArray} from '@math.gl/types';
7
+
8
+ export function isUniformValue(value: unknown): boolean {
9
+ return isNumericArray(value) !== null || typeof value === 'number' || typeof value === 'boolean';
10
+ }
11
+
12
+ type UniformsAndBindings = {
13
+ bindings: Record<string, Binding>;
14
+ uniforms: Record<string, UniformValue>;
15
+ };
16
+
17
+ export function splitUniformsAndBindings(
18
+ uniforms: Record<string, Binding | UniformValue>
19
+ ): UniformsAndBindings {
20
+ const result: UniformsAndBindings = {bindings: {}, uniforms: {}};
21
+ Object.keys(uniforms).forEach(name => {
22
+ const uniform = uniforms[name];
23
+ if (isUniformValue(uniform)) {
24
+ result.uniforms[name] = uniform as UniformValue;
25
+ } else {
26
+ result.bindings[name] = uniform as Binding;
27
+ }
28
+ });
29
+
30
+ return result;
31
+ }
@@ -1,3 +0,0 @@
1
- import { GL } from '@luma.gl/constants';
2
- export declare function getKeyValue(gl: WebGL2RenderingContext, name: string | GL): GL;
3
- //# sourceMappingURL=constants-to-keys.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants-to-keys.d.ts","sourceRoot":"","sources":["../../../src/adapter/objects/constants-to-keys.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,EAAE,EAAC,MAAM,oBAAoB,CAAC;AAGtC,wBAAgB,WAAW,CAAC,EAAE,EAAE,sBAAsB,EAAE,IAAI,EAAE,MAAM,GAAG,EAAE,GAAG,EAAE,CAkB7E"}