@luma.gl/webgl 9.0.0-alpha.21 → 9.0.0-alpha.23

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 (134) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts +1 -1
  2. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  3. package/dist/adapter/converters/device-parameters.js +9 -9
  4. package/dist/adapter/converters/device-parameters.js.map +1 -1
  5. package/dist/adapter/converters/sampler-parameters.d.ts +1 -1
  6. package/dist/adapter/converters/sampler-parameters.d.ts.map +1 -1
  7. package/dist/adapter/converters/sampler-parameters.js +1 -1
  8. package/dist/adapter/converters/sampler-parameters.js.map +1 -1
  9. package/dist/adapter/converters/texture-formats.d.ts +27 -38
  10. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  11. package/dist/adapter/converters/texture-formats.js +152 -114
  12. package/dist/adapter/converters/texture-formats.js.map +1 -1
  13. package/dist/adapter/helpers/attribute-utils.d.ts +1 -1
  14. package/dist/adapter/helpers/attribute-utils.d.ts.map +1 -1
  15. package/dist/adapter/helpers/attribute-utils.js +1 -1
  16. package/dist/adapter/helpers/attribute-utils.js.map +1 -1
  17. package/dist/adapter/helpers/get-shader-info.d.ts.map +1 -1
  18. package/dist/adapter/helpers/get-shader-info.js.map +1 -1
  19. package/dist/adapter/helpers/uniforms.d.ts +7 -8
  20. package/dist/adapter/helpers/uniforms.d.ts.map +1 -1
  21. package/dist/adapter/helpers/uniforms.js +4 -4
  22. package/dist/adapter/helpers/uniforms.js.map +1 -1
  23. package/dist/adapter/objects/constants-to-keys.d.ts +0 -2
  24. package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
  25. package/dist/adapter/objects/constants-to-keys.js +0 -20
  26. package/dist/adapter/objects/constants-to-keys.js.map +1 -1
  27. package/dist/adapter/objects/webgl-renderbuffer.d.ts +11 -8
  28. package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +1 -1
  29. package/dist/adapter/objects/webgl-renderbuffer.js +29 -19
  30. package/dist/adapter/objects/webgl-renderbuffer.js.map +1 -1
  31. package/dist/adapter/objects/webgl-resource.d.ts +0 -1
  32. package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
  33. package/dist/adapter/objects/webgl-resource.js +4 -7
  34. package/dist/adapter/objects/webgl-resource.js.map +1 -1
  35. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  36. package/dist/adapter/resources/webgl-buffer.js +3 -2
  37. package/dist/adapter/resources/webgl-buffer.js.map +1 -1
  38. package/dist/adapter/resources/webgl-command-buffer.d.ts +8 -2
  39. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  40. package/dist/adapter/resources/webgl-command-buffer.js +168 -25
  41. package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
  42. package/dist/adapter/resources/webgl-command-encoder.d.ts +3 -2
  43. package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
  44. package/dist/adapter/resources/webgl-command-encoder.js +6 -2
  45. package/dist/adapter/resources/webgl-command-encoder.js.map +1 -1
  46. package/dist/adapter/resources/webgl-framebuffer.d.ts +9 -12
  47. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  48. package/dist/adapter/resources/webgl-framebuffer.js +29 -79
  49. package/dist/adapter/resources/webgl-framebuffer.js.map +1 -1
  50. package/dist/adapter/resources/webgl-render-pass.d.ts +16 -1
  51. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  52. package/dist/adapter/resources/webgl-render-pass.js +80 -0
  53. package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
  54. package/dist/adapter/resources/webgl-render-pipeline.d.ts +1 -1
  55. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  56. package/dist/adapter/resources/webgl-render-pipeline.js +3 -4
  57. package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
  58. package/dist/adapter/resources/webgl-sampler.d.ts +1 -1
  59. package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
  60. package/dist/adapter/resources/webgl-sampler.js +1 -1
  61. package/dist/adapter/resources/webgl-sampler.js.map +1 -1
  62. package/dist/adapter/resources/webgl-texture.d.ts +39 -19
  63. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  64. package/dist/adapter/resources/webgl-texture.js +32 -30
  65. package/dist/adapter/resources/webgl-texture.js.map +1 -1
  66. package/dist/adapter/webgl-canvas-context.d.ts +1 -2
  67. package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
  68. package/dist/adapter/webgl-canvas-context.js.map +1 -1
  69. package/dist/adapter/webgl-device.d.ts +13 -6
  70. package/dist/adapter/webgl-device.d.ts.map +1 -1
  71. package/dist/adapter/webgl-device.js +20 -2
  72. package/dist/adapter/webgl-device.js.map +1 -1
  73. package/dist/classic/buffer.d.ts +0 -1
  74. package/dist/classic/buffer.d.ts.map +1 -1
  75. package/dist/classic/buffer.js +0 -6
  76. package/dist/classic/buffer.js.map +1 -1
  77. package/dist/classic/typed-array-utils.d.ts +15 -17
  78. package/dist/classic/typed-array-utils.d.ts.map +1 -1
  79. package/dist/classic/typed-array-utils.js +1 -1
  80. package/dist/classic/typed-array-utils.js.map +1 -1
  81. package/dist/context/context/create-browser-context.js.map +1 -1
  82. package/dist/context/parameters/unified-parameter-api.d.ts +1 -1
  83. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  84. package/dist/context/parameters/unified-parameter-api.js.map +1 -1
  85. package/dist/context/parameters/webgl-parameter-tables.d.ts +1 -2
  86. package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
  87. package/dist/context/parameters/webgl-parameter-tables.js +1 -1
  88. package/dist/context/parameters/webgl-parameter-tables.js.map +1 -1
  89. package/dist/dist.dev.js +1102 -670
  90. package/dist/index.cjs +1085 -898
  91. package/dist/index.d.ts +3 -2
  92. package/dist/index.d.ts.map +1 -1
  93. package/dist/index.js +2 -1
  94. package/dist/index.js.map +1 -1
  95. package/dist.min.js +22 -21
  96. package/package.json +7 -4
  97. package/src/adapter/converters/device-parameters.ts +46 -22
  98. package/src/adapter/converters/sampler-parameters.ts +1 -2
  99. package/src/adapter/converters/texture-formats.ts +242 -161
  100. package/src/adapter/helpers/attribute-utils.ts +1 -2
  101. package/src/adapter/helpers/get-shader-info.ts +3 -0
  102. package/src/adapter/helpers/uniforms.ts +9 -10
  103. package/src/adapter/objects/constants-to-keys.ts +0 -25
  104. package/src/adapter/objects/webgl-renderbuffer.ts +32 -29
  105. package/src/adapter/objects/webgl-resource.ts +4 -8
  106. package/src/adapter/resources/webgl-buffer.ts +4 -5
  107. package/src/adapter/resources/webgl-command-buffer.ts +328 -21
  108. package/src/adapter/resources/webgl-command-encoder.ts +7 -2
  109. package/src/adapter/resources/webgl-framebuffer.ts +63 -111
  110. package/src/adapter/resources/webgl-render-pass.ts +146 -2
  111. package/src/adapter/resources/webgl-render-pipeline.ts +6 -3
  112. package/src/adapter/resources/webgl-sampler.ts +1 -2
  113. package/src/adapter/resources/webgl-texture.ts +61 -43
  114. package/src/adapter/webgl-canvas-context.ts +2 -2
  115. package/src/adapter/webgl-device.ts +37 -8
  116. package/src/classic/buffer.ts +3 -3
  117. package/src/classic/typed-array-utils.ts +15 -26
  118. package/src/context/context/create-browser-context.ts +2 -2
  119. package/src/context/parameters/unified-parameter-api.ts +1 -1
  120. package/src/context/parameters/webgl-parameter-tables.ts +2 -2
  121. package/src/index.ts +5 -3
  122. package/dist/adapter/converters/renderbuffer-formats.d.ts +0 -16
  123. package/dist/adapter/converters/renderbuffer-formats.d.ts.map +0 -1
  124. package/dist/adapter/converters/renderbuffer-formats.js +0 -180
  125. package/dist/adapter/converters/renderbuffer-formats.js.map +0 -1
  126. package/dist/types/webgl.d.ts +0 -145
  127. package/dist/types/webgl.d.ts.map +0 -1
  128. package/dist/types/webgl.js +0 -2
  129. package/dist/types/webgl.js.map +0 -1
  130. package/src/.DS_Store +0 -0
  131. package/src/adapter/.DS_Store +0 -0
  132. package/src/adapter/converters/renderbuffer-formats.ts +0 -90
  133. package/src/context/.DS_Store +0 -0
  134. package/src/types/webgl.ts +0 -286
@@ -14,11 +14,10 @@ import {
14
14
  isObjectEmpty
15
15
  } from '@luma.gl/api';
16
16
  import {Texture, cast, log, assert, isPowerOfTwo, loadImage} from '@luma.gl/api';
17
- import GL from '@luma.gl/constants';
18
- import type {GLSamplerParameters} from '../../types/webgl';
17
+ import {GL, GLSamplerParameters} from '@luma.gl/constants';
19
18
  import {withParameters} from '../../context/state-tracker/with-parameters';
20
19
  import {
21
- getWebGLTextureFormat,
20
+ convertTextureFormatToGL,
22
21
  getWebGLTextureParameters,
23
22
  getTextureFormatBytesPerPixel
24
23
  } from '../converters/texture-formats';
@@ -30,7 +29,33 @@ import {WebGLDevice} from '../webgl-device';
30
29
  import {WEBGLBuffer} from './webgl-buffer';
31
30
  import {WEBGLSampler} from './webgl-sampler';
32
31
 
33
- export type {TextureProps};
32
+ export type WEBGLTextureProps = TextureProps & {
33
+ /** @deprecated use props.sampler */
34
+ parameters?: Record<number, number>;
35
+ /** @deprecated use props.data */
36
+ pixels?: any;
37
+ /** @deprecated use props.format */
38
+ dataFormat?: number | null;
39
+ /** @deprecated rarely supported */
40
+ border?: number;
41
+ /** @deprecated WebGL only. */
42
+ pixelStore?: object;
43
+ /** @deprecated WebGL only. */
44
+ textureUnit?: number;
45
+ /** @deprecated WebGL only. Use dimension. */
46
+ target?: number;
47
+ };
48
+
49
+ export const DEFAULT_WEBGL_TEXTURE_PROPS = {
50
+ // deprecated
51
+ parameters: {},
52
+ pixelStore: {},
53
+ pixels: null,
54
+ border: 0,
55
+ dataFormat: undefined!,
56
+ textureUnit: undefined!,
57
+ target: undefined!,
58
+ };
34
59
 
35
60
  export type TextureSourceData =
36
61
  TypedArray |
@@ -48,7 +73,7 @@ type SetImageDataOptions = {
48
73
  width?: number;
49
74
  height?: number;
50
75
  depth?: number;
51
- format?: any;
76
+ glFormat?: GL;
52
77
  type?: any;
53
78
  offset?: number;
54
79
  data: any; // TextureSourceData;
@@ -87,7 +112,7 @@ type SetSubImageDataOptions = {
87
112
  width?: number;
88
113
  height?: number;
89
114
  depth?: number;
90
- format?: any;
115
+ glFormat?: any;
91
116
  type?: any;
92
117
  offset?: number;
93
118
  data: any;
@@ -114,7 +139,7 @@ type SetImageData3DOptions = {
114
139
 
115
140
 
116
141
  // Polyfill
117
- export class WEBGLTexture extends Texture {
142
+ export class WEBGLTexture extends Texture<WEBGLTextureProps> {
118
143
  // TODO - remove?
119
144
  static FACES: number[] = [
120
145
  GL.TEXTURE_CUBE_MAP_POSITIVE_X,
@@ -131,13 +156,12 @@ export class WEBGLTexture extends Texture {
131
156
  readonly gl2: WebGL2RenderingContext | null;
132
157
  readonly handle: WebGLTexture;
133
158
 
134
- data;
159
+ /** Sampler object (currently unused) */
160
+ sampler: WEBGLSampler = undefined;
135
161
 
136
- width: number = undefined;
137
- height: number = undefined;
138
- depth: number = undefined;
162
+ // data;
139
163
 
140
- format: GL = undefined;
164
+ glFormat: GL = undefined;
141
165
  type: GL = undefined;
142
166
  dataFormat: GL = undefined;
143
167
  mipmaps: boolean = undefined;
@@ -154,9 +178,6 @@ export class WEBGLTexture extends Texture {
154
178
  target: GL;
155
179
  textureUnit: number = undefined;
156
180
 
157
- /** Sampler object (currently unused) */
158
- sampler: WEBGLSampler = undefined;
159
-
160
181
  /**
161
182
  * Program.draw() checks the loaded flag of all textures to avoid
162
183
  * Textures that are still loading from promises
@@ -169,8 +190,8 @@ export class WEBGLTexture extends Texture {
169
190
  lastTime: number;
170
191
  };
171
192
 
172
- constructor(device: Device, props: TextureProps) {
173
- super(device, {format: GL.RGBA, ...props});
193
+ constructor(device: Device, props: WEBGLTextureProps) {
194
+ super(device, {...DEFAULT_WEBGL_TEXTURE_PROPS, format: 'rgba8unorm', ...props});
174
195
 
175
196
  this.device = cast<WebGLDevice>(device);
176
197
  this.gl = this.device.gl;
@@ -178,6 +199,7 @@ export class WEBGLTexture extends Texture {
178
199
  this.handle = this.props.handle || this.gl.createTexture();
179
200
  this.device.setSpectorMetadata(this.handle, {...this.props, data: typeof this.props.data}); // {name: this.props.id};
180
201
 
202
+ this.glFormat = GL.RGBA;
181
203
  this.target = getWebGLTextureTarget(this.props);
182
204
 
183
205
  // Program.draw() checks the loaded flag of all textures
@@ -208,7 +230,7 @@ export class WEBGLTexture extends Texture {
208
230
  }
209
231
 
210
232
  // eslint-disable-next-line max-statements
211
- initialize(props: TextureProps = {}): this {
233
+ initialize(props: WEBGLTextureProps = {}): this {
212
234
  // Cube textures
213
235
  if (this.props.dimension === 'cube') {
214
236
  return this.initializeCube(props);
@@ -240,7 +262,7 @@ export class WEBGLTexture extends Texture {
240
262
  const {parameters = {} as Record<GL, any>} = props;
241
263
 
242
264
  const {
243
- pixels = null, recreate = false, pixelStore = {}, textureUnit = undefined} = props;
265
+ pixels = null, pixelStore = {}, textureUnit = undefined} = props;
244
266
 
245
267
  // pixels variable is for API compatibility purpose
246
268
  if (!data) {
@@ -253,6 +275,8 @@ export class WEBGLTexture extends Texture {
253
275
  let {width, height, dataFormat, type, compressed = false, mipmaps = true} = props;
254
276
  const {depth = 0} = props;
255
277
 
278
+ const glFormat = convertTextureFormatToGL(props.format, this.device.isWebGL2);
279
+
256
280
  // Deduce width and height
257
281
  ({width, height, compressed, dataFormat, type} = this._deduceParameters({
258
282
  format: props.format,
@@ -264,13 +288,11 @@ export class WEBGLTexture extends Texture {
264
288
  height
265
289
  }));
266
290
 
267
- const format = getWebGLTextureFormat(this.gl, props.format);
268
-
269
291
  // Store opts for accessors
270
292
  this.width = width;
271
293
  this.height = height;
272
- this.depth = depth;
273
- this.format = format;
294
+ // this.depth = depth;
295
+ this.glFormat = glFormat;
274
296
  this.type = type;
275
297
  this.dataFormat = dataFormat;
276
298
  this.textureUnit = textureUnit;
@@ -292,7 +314,7 @@ export class WEBGLTexture extends Texture {
292
314
  width,
293
315
  height,
294
316
  depth,
295
- format,
317
+ format: glFormat,
296
318
  type,
297
319
  dataFormat,
298
320
  // @ts-expect-error
@@ -308,10 +330,6 @@ export class WEBGLTexture extends Texture {
308
330
  this.generateMipmap();
309
331
  }
310
332
 
311
- // TODO - Store data to enable auto recreate on context loss
312
- if (recreate) {
313
- this.data = data;
314
- }
315
333
  if (isVideo) {
316
334
  this._video = {
317
335
  video: data as HTMLVideoElement,
@@ -324,7 +342,7 @@ export class WEBGLTexture extends Texture {
324
342
  return this;
325
343
  }
326
344
 
327
- initializeCube(props?: TextureProps): this {
345
+ initializeCube(props?: WEBGLTextureProps): this {
328
346
  const {mipmaps = true, parameters = {} as Record<GL, any>} = props;
329
347
 
330
348
  // Store props for accessors
@@ -439,7 +457,7 @@ export class WEBGLTexture extends Texture {
439
457
  */
440
458
  // eslint-disable-next-line max-statements, complexity
441
459
  setImageData(options: SetImageDataOptions) {
442
- if (this.props.dimension === '3d') {
460
+ if (this.props.dimension === '3d' || this.props.dimension === '2d-array') {
443
461
  return this.setImageData3D(options);
444
462
  }
445
463
 
@@ -449,7 +467,7 @@ export class WEBGLTexture extends Texture {
449
467
  target = this.target,
450
468
  pixels = null,
451
469
  level = 0,
452
- format = this.format,
470
+ glFormat = this.glFormat,
453
471
  offset = 0,
454
472
  parameters = {} as Record<GL, any>
455
473
  } = options;
@@ -489,7 +507,7 @@ export class WEBGLTexture extends Texture {
489
507
  withParameters(this.gl, parameters, () => {
490
508
  switch (dataType) {
491
509
  case 'null':
492
- gl.texImage2D(target, level, format, width, height, 0 /* border*/, dataFormat, type, data);
510
+ gl.texImage2D(target, level, glFormat, width, height, 0 /* border*/, dataFormat, type, data);
493
511
  break;
494
512
  case 'typed-array':
495
513
  // Looks like this assert is not necessary, as offset is ignored under WebGL1
@@ -497,7 +515,7 @@ export class WEBGLTexture extends Texture {
497
515
  gl.texImage2D(
498
516
  target,
499
517
  level,
500
- format,
518
+ glFormat,
501
519
  width,
502
520
  height,
503
521
  0, // border (must be 0)
@@ -515,7 +533,7 @@ export class WEBGLTexture extends Texture {
515
533
  gl2.texImage2D(
516
534
  target,
517
535
  level,
518
- format,
536
+ glFormat,
519
537
  width,
520
538
  height,
521
539
  0 /* border*/,
@@ -530,7 +548,7 @@ export class WEBGLTexture extends Texture {
530
548
  gl.texImage2D(
531
549
  target,
532
550
  level,
533
- format,
551
+ glFormat,
534
552
  width,
535
553
  height,
536
554
  0 /* border*/,
@@ -539,7 +557,7 @@ export class WEBGLTexture extends Texture {
539
557
  data
540
558
  );
541
559
  } else {
542
- gl.texImage2D(target, level, format, dataFormat, type, data);
560
+ gl.texImage2D(target, level, glFormat, dataFormat, type, data);
543
561
  }
544
562
  break;
545
563
  case 'compressed':
@@ -564,7 +582,7 @@ export class WEBGLTexture extends Texture {
564
582
  if (data && data.byteLength) {
565
583
  this.trackAllocatedMemory(data.byteLength, 'Texture');
566
584
  } else {
567
- const bytesPerPixel = getTextureFormatBytesPerPixel(this.gl, this.props.format);
585
+ const bytesPerPixel = getTextureFormatBytesPerPixel(this.props.format, this.device.isWebGL2);
568
586
  this.trackAllocatedMemory(this.width * this.height * bytesPerPixel, 'Texture');
569
587
  }
570
588
 
@@ -587,7 +605,7 @@ export class WEBGLTexture extends Texture {
587
605
  width = this.width,
588
606
  height = this.height,
589
607
  level = 0,
590
- format = this.format,
608
+ glFormat = this.glFormat,
591
609
  type = this.type,
592
610
  dataFormat = this.dataFormat,
593
611
  compressed = false,
@@ -629,7 +647,7 @@ export class WEBGLTexture extends Texture {
629
647
  withParameters(this.gl, parameters, () => {
630
648
  // TODO - x,y parameters
631
649
  if (compressed) {
632
- this.gl.compressedTexSubImage2D(target, level, x, y, width, height, format, data);
650
+ this.gl.compressedTexSubImage2D(target, level, x, y, width, height, glFormat, data);
633
651
  } else if (data === null) {
634
652
  this.gl.texSubImage2D(target, level, x, y, width, height, dataFormat, type, null);
635
653
  } else if (ArrayBuffer.isView(data)) {
@@ -723,12 +741,12 @@ export class WEBGLTexture extends Texture {
723
741
 
724
742
  // HELPER METHODS
725
743
 
726
- _deduceParameters(opts: TextureProps) {
744
+ _deduceParameters(opts: WEBGLTextureProps) {
727
745
  const {format, data} = opts;
728
746
  let {width, height, dataFormat, type, compressed} = opts;
729
747
 
730
748
  // Deduce format and type from format
731
- const parameters = getWebGLTextureParameters(this.gl, format);
749
+ const parameters = getWebGLTextureParameters(format, this.device.isWebGL2);
732
750
  dataFormat = dataFormat || parameters.dataFormat;
733
751
  type = type || parameters.type;
734
752
  compressed = compressed || parameters.compressed;
@@ -884,7 +902,7 @@ export class WEBGLTexture extends Texture {
884
902
 
885
903
  this.gl.bindTexture(this.target, this.handle);
886
904
 
887
- const webglTextureFormat = getWebGLTextureParameters(this.gl, format);
905
+ const webglTextureFormat = getWebGLTextureParameters(format, this.device.isWebGL2);
888
906
 
889
907
  withParameters(this.gl, parameters, () => {
890
908
  if (ArrayBuffer.isView(data)) {
@@ -924,7 +942,7 @@ export class WEBGLTexture extends Texture {
924
942
  if (data && data.byteLength) {
925
943
  this.trackAllocatedMemory(data.byteLength, 'Texture');
926
944
  } else {
927
- const bytesPerPixel = getTextureFormatBytesPerPixel(this.gl, this.props.format);
945
+ const bytesPerPixel = getTextureFormatBytesPerPixel(this.props.format, this.device.isWebGL2);
928
946
  this.trackAllocatedMemory(this.width * this.height * this.depth * bytesPerPixel, 'Texture');
929
947
  }
930
948
 
@@ -5,8 +5,7 @@ import {WebGLDevice} from './webgl-device';
5
5
  import {WEBGLFramebuffer} from './resources/webgl-framebuffer';
6
6
 
7
7
  /**
8
- * Holds a WebGL Canvas Context which will handle drawing buffer resizing etc
9
- * @todo This class is WIP, intended to replace the old gltools-based context size tracking
8
+ * A WebGL Canvas Context which manages the canvas and handles drawing buffer resizing etc
10
9
  */
11
10
  export class WebGLCanvasContext extends CanvasContext {
12
11
  readonly device: WebGLDevice;
@@ -24,6 +23,7 @@ export class WebGLCanvasContext extends CanvasContext {
24
23
 
25
24
  getCurrentFramebuffer(): WEBGLFramebuffer {
26
25
  this.update();
26
+ // Setting handle to null returns a reference to the default framebuffer
27
27
  this._framebuffer = this._framebuffer || new WEBGLFramebuffer(this.device, {handle: null});
28
28
  return this._framebuffer;
29
29
  }
@@ -45,7 +45,9 @@ import type {
45
45
  // RenderPass,
46
46
  RenderPassProps,
47
47
  ComputePass,
48
- ComputePassProps
48
+ ComputePassProps,
49
+ // CommandEncoder,
50
+ CommandEncoderProps
49
51
  } from '@luma.gl/api';
50
52
 
51
53
  import {ClassicBuffer} from '../classic/buffer';
@@ -56,6 +58,7 @@ import {WEBGLTexture} from './resources/webgl-texture';
56
58
  import {WEBGLFramebuffer} from './resources/webgl-framebuffer';
57
59
  import {WEBGLRenderPass} from './resources/webgl-render-pass';
58
60
  import {WEBGLRenderPipeline} from './resources/webgl-render-pipeline';
61
+ import {WEBGLCommandEncoder} from './resources/webgl-command-encoder';
59
62
 
60
63
  const LOG_LEVEL = 1;
61
64
 
@@ -279,8 +282,9 @@ ${this.info.vendor}, ${this.info.renderer} for canvas: ${this.canvasContext.id}`
279
282
  throw new Error('WebGL only supports a single canvas');
280
283
  }
281
284
 
282
- _createBuffer(props: BufferProps): WEBGLBuffer {
283
- return new ClassicBuffer(this, props);
285
+ createBuffer(props: BufferProps | ArrayBuffer | ArrayBufferView): WEBGLBuffer {
286
+ const newProps = this._getBufferProps(props);
287
+ return new ClassicBuffer(this, newProps);
284
288
  }
285
289
 
286
290
  _createTexture(props: TextureProps): WEBGLTexture {
@@ -330,6 +334,10 @@ ${this.info.vendor}, ${this.info.renderer} for canvas: ${this.canvasContext.id}`
330
334
  return this.renderPass;
331
335
  }
332
336
 
337
+ override createCommandEncoder(props: CommandEncoderProps): WEBGLCommandEncoder {
338
+ return new WEBGLCommandEncoder(this, props);
339
+ }
340
+
333
341
  /**
334
342
  * Offscreen Canvas Support: Commit the frame
335
343
  * https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/commit
@@ -375,20 +383,22 @@ ${this.info.vendor}, ${this.info.renderer} for canvas: ${this.canvasContext.id}`
375
383
  }
376
384
 
377
385
  /**
378
- * Loses the context
379
- * @note Triggers context loss, mainly for testing
380
- * @todo Promote to `Device` API?
386
+ * Triggers device (or WebGL context) loss.
387
+ * @note primarily intended for testing how application reacts to device loss
381
388
  */
382
- loseDevice(): void {
389
+ override loseDevice(): boolean {
390
+ let deviceLossTriggered = false;
383
391
  const ext = this.gl.getExtension('WEBGL_lose_context');
384
392
  if (ext) {
393
+ deviceLossTriggered = true;
385
394
  ext.loseContext();
395
+ // ext.loseContext should trigger context loss callback but the platform may not do this, so do it explicitly
386
396
  }
387
- // loseContext should trigger context loss callback but
388
397
  this._resolveContextLost?.({
389
398
  reason: 'destroyed',
390
399
  message: 'Application triggered context loss'
391
400
  });
401
+ return deviceLossTriggered;
392
402
  }
393
403
 
394
404
  /** Save current WebGL context state onto an internal stack */
@@ -410,6 +420,25 @@ ${this.info.vendor}, ${this.info.renderer} for canvas: ${this.canvasContext.id}`
410
420
  // eslint-disable-next-line camelcase
411
421
  handle.__SPECTOR_Metadata = props;
412
422
  }
423
+
424
+ /**
425
+ * Returns the GL.<KEY> constant that corresponds to a numeric value of a GL constant
426
+ * Be aware that there are some duplicates especially for constants that are 0,
427
+ * so this isn't guaranteed to return the right key in all cases.
428
+ */
429
+ getGLKey(value: unknown, gl?: WebGLRenderingContext): string {
430
+ // @ts-ignore expect-error depends on settings
431
+ gl = gl || this.gl2 || this.gl;
432
+ const number = Number(value);
433
+ for (const key in gl) {
434
+ // @ts-ignore expect-error depends on settings
435
+ if (gl[key] === number) {
436
+ return `GL.${key}`;
437
+ }
438
+ }
439
+ // No constant found. Stringify the value and return it.
440
+ return String(value);
441
+ }
413
442
  }
414
443
 
415
444
  /** Check if supplied parameter is a WebGLRenderingContext */
@@ -108,9 +108,9 @@ export class ClassicBuffer extends WEBGLBuffer {
108
108
  Object.seal(this);
109
109
  }
110
110
 
111
- override write(data: TypedArray, byteOffset?: number): void {
112
- this.subData({data, offset: byteOffset});
113
- }
111
+ // override write(data: TypedArray, byteOffset: number = 0): void {
112
+ // this.subData({data, offset: byteOffset});
113
+ // }
114
114
 
115
115
  // returns number of elements in the buffer (assuming that the full buffer is used)
116
116
  getElementCount(accessor: AccessorObject = this.accessor): number {
@@ -1,28 +1,17 @@
1
1
  // luma.gl, MIT license
2
2
 
3
- import {TypedArray} from '@luma.gl/api';
4
- import GL from '@luma.gl/constants';
5
- import {GLType} from '../types/webgl'
3
+ import {TypedArray, TypedArrayConstructor} from '@luma.gl/api';
4
+ import {GL, GLDataType, GLPixelType} from '@luma.gl/constants';
6
5
 
7
6
  const ERR_TYPE_DEDUCTION = 'Failed to deduce GL constant from typed array';
8
7
 
9
- type TypedArrayConstructor =
10
- | Float32ArrayConstructor
11
- | Uint16ArrayConstructor
12
- | Uint32ArrayConstructor
13
- | Uint8ArrayConstructor
14
- | Uint8ClampedArrayConstructor
15
- | Int8ArrayConstructor
16
- | Int16ArrayConstructor
17
- | Int32ArrayConstructor;
18
-
19
8
  /**
20
9
  * Converts TYPED ARRAYS to corresponding GL constant
21
10
  * Used to auto deduce gl parameter types
22
- * @param {*} arrayOrType
11
+ * @param arrayOrType
23
12
  * @returns
24
13
  */
25
- export function getGLTypeFromTypedArray(arrayOrType: TypedArray): GLType {
14
+ export function getGLTypeFromTypedArray(arrayOrType: TypedArray): GLDataType {
26
15
  // If typed array, look up constructor
27
16
  const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
28
17
  switch (type) {
@@ -50,13 +39,13 @@ export function getGLTypeFromTypedArray(arrayOrType: TypedArray): GLType {
50
39
  /**
51
40
  * Converts GL constant to corresponding TYPED ARRAY
52
41
  * Used to auto deduce gl parameter types
53
- * @param {*} glType
54
- * @param {*} param1
42
+ * @param glType
43
+ * @param param1
55
44
  * @returns
56
45
  */
57
46
  // eslint-disable-next-line complexity
58
47
  export function getTypedArrayFromGLType(
59
- glType: any,
48
+ glType: GLDataType | GLPixelType,
60
49
  options?: {
61
50
  clamped?: boolean;
62
51
  }
@@ -90,14 +79,14 @@ export function getTypedArrayFromGLType(
90
79
  * Flip rows (can be used on arrays returned from `Framebuffer.readPixels`)
91
80
  * https: *stackoverflow.com/questions/41969562/
92
81
  * how-can-i-flip-the-result-of-webglrenderingcontext-readpixels
93
- * @param {*} param0
82
+ * @param param0
94
83
  */
95
84
  export function flipRows(options: {
96
- data: any;
97
- width: any;
98
- height: any;
85
+ data: TypedArray;
86
+ width: number;
87
+ height: number;
99
88
  bytesPerPixel?: number;
100
- temp?: any;
89
+ temp?: Uint8Array;
101
90
  }): void {
102
91
  const {data, width, height, bytesPerPixel = 4, temp} = options;
103
92
  const bytesPerRow = width * bytesPerPixel;
@@ -118,9 +107,9 @@ export function flipRows(options: {
118
107
 
119
108
 
120
109
  export function scalePixels(options: {
121
- data: any;
122
- width: any;
123
- height: any;
110
+ data: TypedArray;
111
+ width: number;
112
+ height: number;
124
113
  }): {
125
114
  data: Uint8Array;
126
115
  width: number;
@@ -68,10 +68,10 @@ export function createBrowserContext(canvas: HTMLCanvasElement | OffscreenCanvas
68
68
 
69
69
  // Prefer webgl2 over webgl1 if both are acceptable
70
70
  if (props.webgl2) {
71
- gl = gl || canvas.getContext('webgl2', props) as WebGL2RenderingContext | null;
71
+ gl = gl || canvas.getContext('webgl2', props) ;
72
72
  }
73
73
  if (props.webgl1) {
74
- gl = gl || canvas.getContext('webgl', props) as WebGLRenderingContext | null;
74
+ gl = gl || canvas.getContext('webgl', props) ;
75
75
  }
76
76
 
77
77
  // TODO are we removing this listener before giving it a chance to fire?
@@ -2,7 +2,7 @@
2
2
  // Also knows default values of all parameters, enabling fast cache initialization
3
3
  // Provides base functionality for the state caching.
4
4
  import {Device} from '@luma.gl/api';
5
- import type {GLParameters} from '../../types/webgl';
5
+ import type {GLParameters} from '@luma.gl/constants';
6
6
  import {
7
7
  GL_PARAMETER_DEFAULTS,
8
8
  GL_PARAMETER_SETTERS,
@@ -1,7 +1,7 @@
1
1
  // Tables describing WebGL parameters
2
- import GL from '@luma.gl/constants';
2
+ import {GL, GLParameters} from '@luma.gl/constants';
3
3
  import {isWebGL2} from '../context/webgl-checks';
4
- import type {GLParameters} from '../../types/webgl';
4
+
5
5
  // DEFAULT SETTINGS - FOR FAST CACHE INITIALIZATION AND CONTEXT RESETS
6
6
 
7
7
  /* eslint-disable no-shadow */
package/src/index.ts CHANGED
@@ -33,7 +33,7 @@ export type {RenderbufferProps} from './adapter/objects/webgl-renderbuffer';
33
33
  export {WEBGLRenderbuffer} from './adapter/objects/webgl-renderbuffer';
34
34
  export {WEBGLVertexArrayObject} from './adapter/objects/webgl-vertex-array-object';
35
35
 
36
- // WebGL adapter classes (Legacy, will be moved to gltools)
36
+ // WebGL adapter classes (Legacy, will be moved to webgl-legacy)
37
37
  export {Accessor} from './classic/accessor';
38
38
  export type {AccessorObject} from './types';
39
39
  export type {ClassicBufferProps, ClassicBufferProps as BufferProps} from './classic/buffer';
@@ -51,7 +51,7 @@ export {
51
51
 
52
52
  export {setDeviceParameters, withDeviceParameters} from './adapter/converters/device-parameters';
53
53
 
54
- export type {GLParameters} from './types/webgl';
54
+ export type {GLParameters} from '@luma.gl/constants';
55
55
  export {
56
56
  getParameters,
57
57
  setParameters,
@@ -74,4 +74,6 @@ export {polyfillContext} from './context/polyfill/polyfill-context';
74
74
 
75
75
  // HELPERS - EXPERIMENTAL
76
76
  export {getShaderLayout, getProgramBindings} from './adapter/helpers/get-shader-layout';
77
- export {_checkFloat32ColorAttachment} from './adapter/converters/texture-formats';
77
+ export {convertGLToTextureFormat, _checkFloat32ColorAttachment} from './adapter/converters/texture-formats';
78
+
79
+ export {TEXTURE_FORMATS as _TEXTURE_FORMATS} from './adapter/converters/texture-formats';
@@ -1,16 +0,0 @@
1
- import GL from '@luma.gl/constants';
2
- export declare function isRenderbufferFormatSupported(gl: WebGLRenderingContext, format: GL): boolean;
3
- export declare function getRenderbufferFormatBytesPerPixel(format: GL): number;
4
- /**
5
- * @param bpp "bytes per pixel", used for memory usage calculations.
6
- * @param gl2 requires WebGL2
7
- * @param ext requires extension
8
- */
9
- declare type RenderbufferFormat = {
10
- bpp: number;
11
- gl2?: boolean;
12
- ext?: string;
13
- };
14
- export declare const RENDERBUFFER_FORMATS: Record<string, RenderbufferFormat>;
15
- export {};
16
- //# sourceMappingURL=renderbuffer-formats.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"renderbuffer-formats.d.ts","sourceRoot":"","sources":["../../../src/adapter/converters/renderbuffer-formats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGpC,wBAAgB,6BAA6B,CAAC,EAAE,EAAE,qBAAqB,EAAE,MAAM,EAAE,EAAE,GAAG,OAAO,CAa5F;AAED,wBAAgB,kCAAkC,CAAC,MAAM,EAAE,EAAE,GAAG,MAAM,CAErE;AAKD;;;;GAIG;AACH,aAAK,kBAAkB,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAqDnE,CAAC"}