@luma.gl/webgl 9.0.0-beta.6 → 9.0.0-beta.7

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 (93) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  2. package/dist/adapter/converters/device-parameters.js +81 -84
  3. package/dist/adapter/converters/sampler-parameters.js +17 -17
  4. package/dist/adapter/converters/shader-formats.js +12 -12
  5. package/dist/adapter/converters/texture-formats.d.ts +10 -8
  6. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  7. package/dist/adapter/converters/texture-formats.js +175 -168
  8. package/dist/adapter/converters/vertex-formats.js +20 -20
  9. package/dist/adapter/device-helpers/webgl-device-features.d.ts +2 -1
  10. package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
  11. package/dist/adapter/device-helpers/webgl-device-features.js +14 -2
  12. package/dist/adapter/device-helpers/webgl-device-info.js +5 -5
  13. package/dist/adapter/device-helpers/webgl-device-limits.js +10 -10
  14. package/dist/adapter/helpers/decode-webgl-types.js +45 -45
  15. package/dist/adapter/helpers/get-shader-layout.js +29 -29
  16. package/dist/adapter/helpers/set-uniform.js +40 -40
  17. package/dist/adapter/helpers/webgl-topology-utils.js +38 -38
  18. package/dist/adapter/objects/webgl-renderbuffer.js +6 -6
  19. package/dist/adapter/objects/webgl-resource.js +1 -2
  20. package/dist/adapter/resources/webgl-buffer.js +14 -14
  21. package/dist/adapter/resources/webgl-command-buffer.js +25 -25
  22. package/dist/adapter/resources/webgl-external-texture.js +3 -3
  23. package/dist/adapter/resources/webgl-framebuffer.d.ts +2 -4
  24. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  25. package/dist/adapter/resources/webgl-framebuffer.js +41 -36
  26. package/dist/adapter/resources/webgl-query-set.js +6 -6
  27. package/dist/adapter/resources/webgl-render-pass.js +5 -5
  28. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  29. package/dist/adapter/resources/webgl-render-pipeline.js +19 -13
  30. package/dist/adapter/resources/webgl-sampler.js +2 -2
  31. package/dist/adapter/resources/webgl-shader.js +4 -4
  32. package/dist/adapter/resources/webgl-texture.d.ts +2 -1
  33. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  34. package/dist/adapter/resources/webgl-texture.js +29 -27
  35. package/dist/adapter/resources/webgl-transform-feedback.js +8 -8
  36. package/dist/adapter/resources/webgl-vertex-array.d.ts +1 -1
  37. package/dist/adapter/resources/webgl-vertex-array.js +5 -5
  38. package/dist/adapter/webgl-device.d.ts +6 -3
  39. package/dist/adapter/webgl-device.d.ts.map +1 -1
  40. package/dist/adapter/webgl-device.js +22 -17
  41. package/dist/classic/accessor.js +4 -4
  42. package/dist/classic/clear.js +2 -2
  43. package/dist/classic/copy-and-blit.js +15 -16
  44. package/dist/classic/format-utils.d.ts +2 -2
  45. package/dist/classic/format-utils.js +14 -14
  46. package/dist/classic/typed-array-utils.js +18 -18
  47. package/dist/context/parameters/unified-parameter-api.d.ts +3 -4
  48. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  49. package/dist/context/parameters/unified-parameter-api.js +4 -9
  50. package/dist/context/parameters/webgl-parameter-tables.d.ts +2 -13
  51. package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
  52. package/dist/context/parameters/webgl-parameter-tables.js +292 -298
  53. package/dist/context/state-tracker/with-parameters.d.ts +1 -2
  54. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  55. package/dist/context/state-tracker/with-parameters.js +2 -5
  56. package/dist/dist.dev.js +877 -840
  57. package/dist/index.cjs +1253 -1188
  58. package/dist/index.cjs.map +4 -4
  59. package/dist/index.d.ts +2 -2
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +1 -1
  62. package/dist.min.js +6 -6
  63. package/package.json +4 -4
  64. package/src/adapter/converters/device-parameters.ts +9 -11
  65. package/src/adapter/converters/texture-formats.ts +64 -61
  66. package/src/adapter/device-helpers/webgl-device-features.ts +22 -2
  67. package/src/adapter/objects/webgl-renderbuffer.ts +1 -1
  68. package/src/adapter/objects/webgl-resource.ts +1 -1
  69. package/src/adapter/resources/webgl-external-texture.ts +3 -3
  70. package/src/adapter/resources/webgl-framebuffer.ts +29 -26
  71. package/src/adapter/resources/webgl-render-pass.ts +3 -3
  72. package/src/adapter/resources/webgl-render-pipeline.ts +13 -6
  73. package/src/adapter/resources/webgl-texture.ts +7 -3
  74. package/src/adapter/webgl-device.ts +24 -19
  75. package/src/classic/clear.ts +2 -2
  76. package/src/context/parameters/unified-parameter-api.ts +4 -16
  77. package/src/context/state-tracker/with-parameters.ts +2 -7
  78. package/src/index.ts +4 -4
  79. package/dist/adapter/device-helpers/device-features.d.ts +0 -6
  80. package/dist/adapter/device-helpers/device-features.d.ts.map +0 -1
  81. package/dist/adapter/device-helpers/device-features.js +0 -65
  82. package/dist/adapter/device-helpers/device-limits.d.ts +0 -50
  83. package/dist/adapter/device-helpers/device-limits.d.ts.map +0 -1
  84. package/dist/adapter/device-helpers/device-limits.js +0 -92
  85. package/dist/adapter/device-helpers/get-device-info.d.ts +0 -4
  86. package/dist/adapter/device-helpers/get-device-info.d.ts.map +0 -1
  87. package/dist/adapter/device-helpers/get-device-info.js +0 -87
  88. package/dist/context/context/context-data.d.ts +0 -14
  89. package/dist/context/context/context-data.d.ts.map +0 -1
  90. package/dist/context/context/context-data.js +0 -33
  91. package/dist/context/context/create-browser-context.d.ts +0 -35
  92. package/dist/context/context/create-browser-context.d.ts.map +0 -1
  93. package/dist/context/context/create-browser-context.js +0 -66
@@ -23,12 +23,12 @@ export const DEFAULT_WEBGL_TEXTURE_PROPS = {
23
23
  export class WEBGLTexture extends Texture {
24
24
  // TODO - remove?
25
25
  static FACES = [
26
- GL.TEXTURE_CUBE_MAP_POSITIVE_X,
27
- GL.TEXTURE_CUBE_MAP_NEGATIVE_X,
28
- GL.TEXTURE_CUBE_MAP_POSITIVE_Y,
29
- GL.TEXTURE_CUBE_MAP_NEGATIVE_Y,
30
- GL.TEXTURE_CUBE_MAP_POSITIVE_Z,
31
- GL.TEXTURE_CUBE_MAP_NEGATIVE_Z
26
+ 34069,
27
+ 34070,
28
+ 34071,
29
+ 34072,
30
+ 34073,
31
+ 34074
32
32
  ];
33
33
  MAX_ATTRIBUTES;
34
34
  device;
@@ -66,7 +66,7 @@ export class WEBGLTexture extends Texture {
66
66
  this.gl = this.device.gl;
67
67
  this.handle = this.props.handle || this.gl.createTexture();
68
68
  this.device.setSpectorMetadata(this.handle, { ...this.props, data: typeof this.props.data }); // {name: this.props.id};
69
- this.glFormat = GL.RGBA;
69
+ this.glFormat = 6408;
70
70
  this.target = getWebGLTextureTarget(this.props);
71
71
  // Program.draw() checks the loaded flag of all textures
72
72
  this.loaded = false;
@@ -89,6 +89,9 @@ export class WEBGLTexture extends Texture {
89
89
  toString() {
90
90
  return `Texture(${this.id},${this.width}x${this.height})`;
91
91
  }
92
+ createView(props) {
93
+ return new WEBGLTextureView(this.device, { ...props, texture: this });
94
+ }
92
95
  // eslint-disable-next-line max-statements
93
96
  initialize(props = {}) {
94
97
  // Cube textures
@@ -142,7 +145,7 @@ export class WEBGLTexture extends Texture {
142
145
  this.dataFormat = dataFormat;
143
146
  this.textureUnit = textureUnit;
144
147
  if (Number.isFinite(this.textureUnit)) {
145
- this.gl.activeTexture(GL.TEXTURE0 + this.textureUnit);
148
+ this.gl.activeTexture(33984 + this.textureUnit);
146
149
  this.gl.bindTexture(this.target, this.handle);
147
150
  }
148
151
  this.mipmaps = mipmaps;
@@ -161,9 +164,8 @@ export class WEBGLTexture extends Texture {
161
164
  // Set texture sampler parameters
162
165
  this.setSampler(props.sampler);
163
166
  this._setSamplerParameters(parameters);
164
- // @ts-ignore
165
- this.view = new WEBGLTextureView(this.device, { ...this.props, texture: this });
166
- if (mipmaps) {
167
+ this.view = this.createView({ ...this.props, mipLevelCount: 1, arrayLayerCount: 1 });
168
+ if (mipmaps && this.device.isTextureFormatFilterable(props.format)) {
167
169
  this.generateMipmap();
168
170
  }
169
171
  if (isVideo) {
@@ -309,9 +311,9 @@ export class WEBGLTexture extends Texture {
309
311
  break;
310
312
  case 'buffer':
311
313
  // WebGL2 enables creating textures directly from a WebGL buffer
312
- this.device.gl.bindBuffer(GL.PIXEL_UNPACK_BUFFER, data.handle || data);
314
+ this.device.gl.bindBuffer(35052, data.handle || data);
313
315
  this.device.gl.texImage2D(target, level, glFormat, width, height, 0 /* border*/, dataFormat, type, offset);
314
- this.device.gl.bindBuffer(GL.PIXEL_UNPACK_BUFFER, null);
316
+ this.device.gl.bindBuffer(35052, null);
315
317
  break;
316
318
  case 'browser-object':
317
319
  gl.texImage2D(target, level, glFormat, width, height, 0 /* border*/, dataFormat, type, data);
@@ -381,9 +383,9 @@ export class WEBGLTexture extends Texture {
381
383
  else if (typeof WebGLBuffer !== 'undefined' && data instanceof WebGLBuffer) {
382
384
  // WebGL2 allows us to create texture directly from a WebGL buffer
383
385
  // This texImage2D signature uses currently bound GL.PIXEL_UNPACK_BUFFER
384
- this.device.gl.bindBuffer(GL.PIXEL_UNPACK_BUFFER, data);
386
+ this.device.gl.bindBuffer(35052, data);
385
387
  this.device.gl.texSubImage2D(target, level, x, y, width, height, dataFormat, type, offset);
386
- this.device.gl.bindBuffer(GL.PIXEL_UNPACK_BUFFER, null);
388
+ this.device.gl.bindBuffer(35052, null);
387
389
  }
388
390
  else {
389
391
  // Assume data is a browser supported object (ImageData, Canvas, ...)
@@ -405,13 +407,13 @@ export class WEBGLTexture extends Texture {
405
407
  return null;
406
408
  }
407
409
  getActiveUnit() {
408
- return this.gl.getParameter(GL.ACTIVE_TEXTURE) - GL.TEXTURE0;
410
+ return this.gl.getParameter(34016) - 33984;
409
411
  }
410
412
  bind(textureUnit = this.textureUnit) {
411
413
  const { gl } = this;
412
414
  if (textureUnit !== undefined) {
413
415
  this.textureUnit = textureUnit;
414
- gl.activeTexture(gl.TEXTURE0 + textureUnit);
416
+ gl.activeTexture(33984 + textureUnit);
415
417
  }
416
418
  gl.bindTexture(this.target, this.handle);
417
419
  return textureUnit;
@@ -420,7 +422,7 @@ export class WEBGLTexture extends Texture {
420
422
  const { gl } = this;
421
423
  if (textureUnit !== undefined) {
422
424
  this.textureUnit = textureUnit;
423
- gl.activeTexture(gl.TEXTURE0 + textureUnit);
425
+ gl.activeTexture(33984 + textureUnit);
424
426
  }
425
427
  gl.bindTexture(this.target, null);
426
428
  return textureUnit;
@@ -491,7 +493,7 @@ export class WEBGLTexture extends Texture {
491
493
  /* eslint-disable max-statements, max-len */
492
494
  async setCubeMapImageData(options) {
493
495
  const { gl } = this;
494
- const { width, height, pixels, data, format = GL.RGBA, type = GL.UNSIGNED_BYTE } = options;
496
+ const { width, height, pixels, data, format = 6408, type = 5121 } = options;
495
497
  const imageDataMap = pixels || data;
496
498
  // pixel data (imageDataMap) is an Object from Face to Image or Promise.
497
499
  // For example:
@@ -530,7 +532,7 @@ export class WEBGLTexture extends Texture {
530
532
  }
531
533
  /** @todo update this method to accept LODs */
532
534
  setImageDataForFace(options) {
533
- const { face, width, height, pixels, data, format = GL.RGBA, type = GL.UNSIGNED_BYTE
535
+ const { face, width, height, pixels, data, format = 6408, type = 5121
534
536
  // generateMipmap = false // TODO
535
537
  } = options;
536
538
  const { gl } = this;
@@ -564,7 +566,7 @@ export class WEBGLTexture extends Texture {
564
566
  data);
565
567
  }
566
568
  if (data instanceof WEBGLBuffer) {
567
- this.gl.bindBuffer(GL.PIXEL_UNPACK_BUFFER, data.handle);
569
+ this.gl.bindBuffer(35052, data.handle);
568
570
  this.gl.texImage3D(this.target, level, dataFormat, width, height, depth, 0 /* border, must be 0 */, format, type, offset);
569
571
  }
570
572
  });
@@ -595,8 +597,8 @@ export class WEBGLTexture extends Texture {
595
597
  // Apparently there are integer/float conversion issues requires two parameter setting functions in JavaScript.
596
598
  // For now, pick the float version for parameters specified as GLfloat.
597
599
  switch (param) {
598
- case GL.TEXTURE_MIN_LOD:
599
- case GL.TEXTURE_MAX_LOD:
600
+ case 33082:
601
+ case 33083:
600
602
  this.gl.texParameterf(this.target, param, value);
601
603
  break;
602
604
  default:
@@ -613,14 +615,14 @@ function getWebGLTextureTarget(props) {
613
615
  switch (props.dimension) {
614
616
  // supported in WebGL
615
617
  case '2d':
616
- return GL.TEXTURE_2D;
618
+ return 3553;
617
619
  case 'cube':
618
- return GL.TEXTURE_CUBE_MAP;
620
+ return 34067;
619
621
  // supported in WebGL2
620
622
  case '2d-array':
621
- return GL.TEXTURE_2D_ARRAY;
623
+ return 35866;
622
624
  case '3d':
623
- return GL.TEXTURE_3D;
625
+ return 32879;
624
626
  // not supported in any WebGL version
625
627
  case '1d':
626
628
  case 'cube-array':
@@ -37,7 +37,7 @@ export class WEBGLTransformFeedback extends TransformFeedback {
37
37
  super.destroy();
38
38
  }
39
39
  begin(topology = 'point-list') {
40
- this.gl.bindTransformFeedback(GL.TRANSFORM_FEEDBACK, this.handle);
40
+ this.gl.bindTransformFeedback(36386, this.handle);
41
41
  if (this.bindOnUse) {
42
42
  this._bindBuffers();
43
43
  }
@@ -48,7 +48,7 @@ export class WEBGLTransformFeedback extends TransformFeedback {
48
48
  if (!this.bindOnUse) {
49
49
  this._unbindBuffers();
50
50
  }
51
- this.gl.bindTransformFeedback(GL.TRANSFORM_FEEDBACK, null);
51
+ this.gl.bindTransformFeedback(36386, null);
52
52
  }
53
53
  // SUBCLASS
54
54
  setBuffers(buffers) {
@@ -84,16 +84,16 @@ export class WEBGLTransformFeedback extends TransformFeedback {
84
84
  }
85
85
  bind(funcOrHandle = this.handle) {
86
86
  if (typeof funcOrHandle !== 'function') {
87
- this.gl.bindTransformFeedback(GL.TRANSFORM_FEEDBACK, funcOrHandle);
87
+ this.gl.bindTransformFeedback(36386, funcOrHandle);
88
88
  return this;
89
89
  }
90
90
  let value;
91
91
  if (!this._bound) {
92
- this.gl.bindTransformFeedback(GL.TRANSFORM_FEEDBACK, this.handle);
92
+ this.gl.bindTransformFeedback(36386, this.handle);
93
93
  this._bound = true;
94
94
  value = funcOrHandle();
95
95
  this._bound = false;
96
- this.gl.bindTransformFeedback(GL.TRANSFORM_FEEDBACK, null);
96
+ this.gl.bindTransformFeedback(36386, null);
97
97
  }
98
98
  else {
99
99
  value = funcOrHandle();
@@ -137,16 +137,16 @@ export class WEBGLTransformFeedback extends TransformFeedback {
137
137
  }
138
138
  _unbindBuffers() {
139
139
  for (const bufferIndex in this.buffers) {
140
- this.gl.bindBufferBase(GL.TRANSFORM_FEEDBACK_BUFFER, Number(bufferIndex), null);
140
+ this.gl.bindBufferBase(35982, Number(bufferIndex), null);
141
141
  }
142
142
  }
143
143
  _bindBuffer(index, buffer, byteOffset = 0, byteLength) {
144
144
  const handle = buffer && buffer.handle;
145
145
  if (!handle || byteLength === undefined) {
146
- this.gl.bindBufferBase(GL.TRANSFORM_FEEDBACK_BUFFER, index, handle);
146
+ this.gl.bindBufferBase(35982, index, handle);
147
147
  }
148
148
  else {
149
- this.gl.bindBufferRange(GL.TRANSFORM_FEEDBACK_BUFFER, index, handle, byteOffset, byteLength);
149
+ this.gl.bindBufferRange(35982, index, handle, byteOffset, byteLength);
150
150
  }
151
151
  }
152
152
  }
@@ -41,7 +41,7 @@ export declare class WEBGLVertexArray extends VertexArray {
41
41
  */
42
42
  /** Get an accessor from the */
43
43
  protected _getAccessor(location: number): {
44
- size: 1 | 2 | 3 | 4;
44
+ size: 4 | 1 | 2 | 3;
45
45
  type: GL.BYTE | GL.UNSIGNED_BYTE | GL.SHORT | GL.UNSIGNED_SHORT | GL.INT | GL.UNSIGNED_INT | GL.FLOAT | GL.HALF_FLOAT;
46
46
  stride: number;
47
47
  offset: number;
@@ -49,13 +49,13 @@ export class WEBGLVertexArray extends VertexArray {
49
49
  setIndexBuffer(indexBuffer) {
50
50
  const buffer = indexBuffer;
51
51
  // Explicitly allow `null` to support clearing the index buffer
52
- if (buffer && buffer.glTarget !== GL.ELEMENT_ARRAY_BUFFER) {
52
+ if (buffer && buffer.glTarget !== 34963) {
53
53
  throw new Error('Use .setBuffer()');
54
54
  }
55
55
  // In WebGL The GL.ELEMENT_ARRAY_BUFFER_BINDING is stored on the VertexArrayObject
56
56
  this.device.gl.bindVertexArray(this.handle);
57
57
  // TODO - this initial binding does not seem to take effect? see bindBeforeRender()
58
- this.device.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, buffer ? buffer.handle : null);
58
+ this.device.gl.bindBuffer(34963, buffer ? buffer.handle : null);
59
59
  // log.log(1, 'VertexArray.setIndexBuffer', indexBuffer)();
60
60
  // log.log(1, `Binding vertex array ${this.id}`, buffer?.id)();
61
61
  this.indexBuffer = buffer;
@@ -64,13 +64,13 @@ export class WEBGLVertexArray extends VertexArray {
64
64
  setBuffer(location, attributeBuffer) {
65
65
  const buffer = attributeBuffer;
66
66
  // Sanity check target
67
- if (buffer.glTarget === GL.ELEMENT_ARRAY_BUFFER) {
67
+ if (buffer.glTarget === 34963) {
68
68
  throw new Error('Use .setIndexBuffer()');
69
69
  }
70
70
  const { size, type, stride, offset, normalized, integer, divisor } = this._getAccessor(location);
71
71
  this.device.gl.bindVertexArray(this.handle);
72
72
  // A non-zero buffer object must be bound to the GL_ARRAY_BUFFER target
73
- this.device.gl.bindBuffer(GL.ARRAY_BUFFER, buffer.handle);
73
+ this.device.gl.bindBuffer(34962, buffer.handle);
74
74
  // WebGL2 supports *integer* data formats, i.e. GPU will see integer values
75
75
  if (integer) {
76
76
  this.device.gl.vertexAttribIPointer(location, size, type, stride, offset);
@@ -97,7 +97,7 @@ export class WEBGLVertexArray extends VertexArray {
97
97
  if (!this.init) {
98
98
  // log.log(1, `Binding vertex array ${this.id}`, this.indexBuffer?.id)();
99
99
  const webglBuffer = this.indexBuffer;
100
- this.device.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, webglBuffer?.handle || null);
100
+ this.device.gl.bindBuffer(34963, webglBuffer?.handle || null);
101
101
  this.init = true;
102
102
  }
103
103
  this._applyConstantAttributes();
@@ -17,8 +17,10 @@ import { WEBGLTransformFeedback } from "./resources/webgl-transform-feedback.js"
17
17
  import { WEBGLQuerySet } from "./resources/webgl-query-set.js";
18
18
  /** WebGPU style Device API for a WebGL context */
19
19
  export declare class WebGLDevice extends Device {
20
- static type: string;
21
- static isSupported(): boolean;
20
+ /** type of this device */
21
+ static readonly type: string;
22
+ /** type of this device */
23
+ readonly type = "webgl";
22
24
  /** The underlying WebGL context */
23
25
  readonly handle: WebGL2RenderingContext;
24
26
  features: WebGLDeviceFeatures;
@@ -30,6 +32,8 @@ export declare class WebGLDevice extends Device {
30
32
  message: string;
31
33
  }>;
32
34
  private _resolveContextLost?;
35
+ /** Check if WebGL 2 is available */
36
+ static isSupported(): boolean;
33
37
  /**
34
38
  * Get a device instance from a GL context
35
39
  * Creates and instruments the device if not already created
@@ -64,7 +68,6 @@ export declare class WebGLDevice extends Device {
64
68
  createComputePipeline(props?: ComputePipelineProps): ComputePipeline;
65
69
  beginComputePass(props: ComputePassProps): ComputePass;
66
70
  private renderPass;
67
- getDefaultRenderPass(): WEBGLRenderPass;
68
71
  createCommandEncoder(props?: CommandEncoderProps): WEBGLCommandEncoder;
69
72
  /**
70
73
  * Offscreen Canvas Support: Commit the frame
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-device.d.ts","sourceRoot":"","sources":["../../src/adapter/webgl-device.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,MAAM,EACN,OAAO,EACP,UAAU,EACX,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,MAAM,EAAE,aAAa,EAAmB,MAAM,eAAe,CAAC;AACtE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAQrD,OAAO,EAAC,mBAAmB,EAAC,kDAA+C;AAC3E,OAAO,EAAC,iBAAiB,EAAC,gDAA6C;AACvE,OAAO,EAAC,kBAAkB,EAAC,kCAA+B;AAU1D,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@ export class WebGLDevice extends Device {
33
33
  //
34
34
  // Public `Device` API
35
35
  //
36
+ /** type of this device */
36
37
  static type = 'webgl';
37
- static isSupported() {
38
- return typeof WebGL2RenderingContext !== 'undefined';
39
- }
38
+ /** type of this device */
39
+ type = 'webgl';
40
40
  /** The underlying WebGL context */
41
41
  handle;
42
42
  features;
@@ -48,6 +48,10 @@ export class WebGLDevice extends Device {
48
48
  //
49
49
  // Static methods, expected to be present by `luma.createDevice()`
50
50
  //
51
+ /** Check if WebGL 2 is available */
52
+ static isSupported() {
53
+ return typeof WebGL2RenderingContext !== 'undefined';
54
+ }
51
55
  /**
52
56
  * Get a device instance from a GL context
53
57
  * Creates and instruments the device if not already created
@@ -85,16 +89,22 @@ export class WebGLDevice extends Device {
85
89
  }
86
90
  // Wait for all the loads to settle before creating the context.
87
91
  // The Device.create() functions are async, so in contrast to the constructor, we can `await` here.
88
- await Promise.all(promises);
92
+ const results = await Promise.allSettled(promises);
93
+ for (const result of results) {
94
+ if (result.status === 'rejected') {
95
+ log.error(`Failed to initialize debug libraries ${result.reason}`)();
96
+ }
97
+ }
89
98
  log.probe(LOG_LEVEL + 1, 'DOM is loaded')();
90
99
  // @ts-expect-error
91
100
  if (props.gl?.device) {
101
+ log.warn('reattaching existing device')();
92
102
  return WebGLDevice.attach(props.gl);
93
103
  }
94
104
  const device = new WebGLDevice(props);
95
105
  // Log some debug info about the newly created context
96
106
  const message = `\
97
- Created ${device.info.type}${device.debug ? ' debug' : ''} context: \
107
+ Created ${device.type}${device.debug ? ' debug' : ''} context: \
98
108
  ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
99
109
  log.probe(LOG_LEVEL, message)();
100
110
  log.table(LOG_LEVEL, device.info)();
@@ -135,8 +145,11 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
135
145
  this.gl._version = 2; // Update GL context: Store WebGL version field on gl context (HACK to identify debug contexts)
136
146
  // luma Device fields
137
147
  this.info = getDeviceInfo(this.gl, this._extensions);
138
- this.features = new WebGLDeviceFeatures(this.gl, this._extensions);
139
148
  this.limits = new WebGLDeviceLimits(this.gl);
149
+ this.features = new WebGLDeviceFeatures(this.gl, this._extensions, this.props.disabledFeatures);
150
+ if (this.props.initalizeFeatures) {
151
+ this.features.initializeFeatures();
152
+ }
140
153
  this.canvasContext.resize();
141
154
  // Install context state tracking
142
155
  // @ts-expect-error - hidden parameters
@@ -222,14 +235,6 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
222
235
  throw new Error('ComputePass not supported in WebGL');
223
236
  }
224
237
  renderPass = null;
225
- getDefaultRenderPass() {
226
- this.renderPass =
227
- this.renderPass ||
228
- this.beginRenderPass({
229
- framebuffer: this.canvasContext.getCurrentFramebuffer()
230
- });
231
- return this.renderPass;
232
- }
233
238
  createCommandEncoder(props) {
234
239
  return new WEBGLCommandEncoder(this, props);
235
240
  }
@@ -255,13 +260,13 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
255
260
  return readPixelsToBuffer(source, options);
256
261
  }
257
262
  setParametersWebGL(parameters) {
258
- setGLParameters(this, parameters);
263
+ setGLParameters(this.gl, parameters);
259
264
  }
260
265
  getParametersWebGL(parameters) {
261
- return getGLParameters(this, parameters);
266
+ return getGLParameters(this.gl, parameters);
262
267
  }
263
268
  withParametersWebGL(parameters, func) {
264
- withGLParameters(this, parameters, func);
269
+ withGLParameters(this.gl, parameters, func);
265
270
  }
266
271
  clearWebGL(options) {
267
272
  clear(this, options);
@@ -7,7 +7,7 @@ import { getTypedArrayFromGLType } from "./typed-array-utils.js";
7
7
  const DEFAULT_ACCESSOR_VALUES = {
8
8
  offset: 0,
9
9
  stride: 0,
10
- type: GL.FLOAT,
10
+ type: 5126,
11
11
  size: 1,
12
12
  divisor: 0,
13
13
  normalized: false,
@@ -32,14 +32,14 @@ export class Accessor {
32
32
  static getBytesPerElement(accessor) {
33
33
  // TODO: using `FLOAT` when type is not specified,
34
34
  // ensure this assumption is valid or force API to specify type.
35
- const ArrayType = getTypedArrayFromGLType(accessor.type || GL.FLOAT);
35
+ const ArrayType = getTypedArrayFromGLType(accessor.type || 5126);
36
36
  return ArrayType.BYTES_PER_ELEMENT;
37
37
  }
38
38
  static getBytesPerVertex(accessor) {
39
39
  assert(accessor.size);
40
40
  // TODO: using `FLOAT` when type is not specified,
41
41
  // ensure this assumption is valid or force API to specify type.
42
- const ArrayType = getTypedArrayFromGLType(accessor.type || GL.FLOAT);
42
+ const ArrayType = getTypedArrayFromGLType(accessor.type || 5126);
43
43
  return ArrayType.BYTES_PER_ELEMENT * accessor.size;
44
44
  }
45
45
  // Combines (merges) a list of accessors. On top of default values
@@ -71,7 +71,7 @@ export class Accessor {
71
71
  if (props.type !== undefined) {
72
72
  this.type = props.type;
73
73
  // Auto-deduce integer type?
74
- if (props.type === GL.INT || props.type === GL.UNSIGNED_INT) {
74
+ if (props.type === 5124 || props.type === 5125) {
75
75
  this.integer = true;
76
76
  }
77
77
  }
@@ -44,8 +44,8 @@ export function clear(device, options) {
44
44
  }
45
45
  assert(clearFlags !== 0, ERR_ARGUMENTS);
46
46
  // Temporarily set any clear "colors" and call clear
47
- withGLParameters(device, parameters, () => {
48
- const gl = device.gl;
47
+ const gl = device.gl;
48
+ withGLParameters(gl, parameters, () => {
49
49
  gl.clear(clearFlags);
50
50
  });
51
51
  }
@@ -17,7 +17,7 @@ import { glFormatToComponents, glTypeToBytes } from "./format-utils.js";
17
17
  * @returns pixel array,
18
18
  */
19
19
  export function readPixelsToArray(source, options) {
20
- const { sourceX = 0, sourceY = 0, sourceFormat = GL.RGBA, sourceAttachment = GL.COLOR_ATTACHMENT0 // TODO - support gl.readBuffer
20
+ const { sourceX = 0, sourceY = 0, sourceFormat = 6408, sourceAttachment = 36064 // TODO - support gl.readBuffer
21
21
  } = options || {};
22
22
  let { target = null,
23
23
  // following parameters are auto deduced if not provided
@@ -31,21 +31,20 @@ export function readPixelsToArray(source, options) {
31
31
  // if (sourceAttachment === GL.COLOR_ATTACHMENT0 && handle === null) {
32
32
  // sourceAttachment = GL.FRONT;
33
33
  // }
34
- const attachment = sourceAttachment - GL.COLOR_ATTACHMENT0;
34
+ const attachment = sourceAttachment - 36064;
35
35
  // assert(attachments[sourceAttachment]);
36
36
  // Deduce the type from color attachment if not provided.
37
37
  sourceType =
38
38
  sourceType ||
39
- framebuffer.colorAttachments[attachment]?.texture?.type ||
40
- GL.UNSIGNED_BYTE;
39
+ framebuffer.colorAttachments[attachment]?.texture?.type || 5121;
41
40
  // Deduce type and allocated pixelArray if needed
42
41
  target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
43
42
  // Pixel array available, if necessary, deduce type from it.
44
43
  sourceType = sourceType || getGLTypeFromTypedArray(target);
45
- const prevHandle = gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
44
+ const prevHandle = gl.bindFramebuffer(36160, handle);
46
45
  gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
47
46
  // @ts-expect-error
48
- gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
47
+ gl.bindFramebuffer(36160, prevHandle || null);
49
48
  if (deleteFramebuffer) {
50
49
  framebuffer.destroy();
51
50
  }
@@ -59,7 +58,7 @@ export function readPixelsToArray(source, options) {
59
58
  * @param options
60
59
  */
61
60
  export function readPixelsToBuffer(source, options) {
62
- const { target, sourceX = 0, sourceY = 0, sourceFormat = GL.RGBA, targetByteOffset = 0 } = options || {};
61
+ const { target, sourceX = 0, sourceY = 0, sourceFormat = 6408, targetByteOffset = 0 } = options || {};
63
62
  // following parameters are auto deduced if not provided
64
63
  let { sourceWidth, sourceHeight, sourceType } = options || {};
65
64
  const { framebuffer, deleteFramebuffer } = getFramebuffer(source);
@@ -69,7 +68,7 @@ export function readPixelsToBuffer(source, options) {
69
68
  // Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature
70
69
  const webglFramebuffer = framebuffer;
71
70
  // deduce type if not available.
72
- sourceType = sourceType || GL.UNSIGNED_BYTE;
71
+ sourceType = sourceType || 5121;
73
72
  let webglBufferTarget = target;
74
73
  if (!webglBufferTarget) {
75
74
  // Create new buffer with enough size
@@ -102,7 +101,7 @@ export function readPixelsToBuffer(source, options) {
102
101
  export function copyToTexture(source, target, options) {
103
102
  const { sourceX = 0, sourceY = 0,
104
103
  // attachment = GL.COLOR_ATTACHMENT0, // TODO - support gl.readBuffer
105
- targetMipmaplevel = 0, targetInternalFormat = GL.RGBA } = options || {};
104
+ targetMipmaplevel = 0, targetInternalFormat = 6408 } = options || {};
106
105
  let { targetX, targetY, targetZ, width, // defaults to target width
107
106
  height // defaults to target height
108
107
  } = options || {};
@@ -116,7 +115,7 @@ export function copyToTexture(source, target, options) {
116
115
  targetX = targetX || 0;
117
116
  targetY = targetY || 0;
118
117
  targetZ = targetZ || 0;
119
- const prevHandle = device.gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
118
+ const prevHandle = device.gl.bindFramebuffer(36160, handle);
120
119
  // TODO - support gl.readBuffer (WebGL2 only)
121
120
  // const prevBuffer = gl.readBuffer(attachment);
122
121
  assert(target);
@@ -137,12 +136,12 @@ export function copyToTexture(source, target, options) {
137
136
  }
138
137
  else {
139
138
  switch (textureTarget) {
140
- case GL.TEXTURE_2D:
141
- case GL.TEXTURE_CUBE_MAP:
139
+ case 3553:
140
+ case 34067:
142
141
  device.gl.copyTexSubImage2D(textureTarget, targetMipmaplevel, targetX, targetY, sourceX, sourceY, width, height);
143
142
  break;
144
- case GL.TEXTURE_2D_ARRAY:
145
- case GL.TEXTURE_3D:
143
+ case 35866:
144
+ case 32879:
146
145
  device.gl.copyTexSubImage3D(textureTarget, targetMipmaplevel, targetX, targetY, targetZ, sourceX, sourceY, width, height);
147
146
  break;
148
147
  default:
@@ -152,7 +151,7 @@ export function copyToTexture(source, target, options) {
152
151
  texture.unbind();
153
152
  }
154
153
  // @ts-expect-error
155
- device.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
154
+ device.gl.bindFramebuffer(36160, prevHandle || null);
156
155
  if (deleteFramebuffer) {
157
156
  framebuffer.destroy();
158
157
  }
@@ -184,7 +183,7 @@ function getPixelArray(pixelArray, type, format, width, height) {
184
183
  return pixelArray;
185
184
  }
186
185
  // Allocate pixel array if not already available, using supplied type
187
- type = type || GL.UNSIGNED_BYTE;
186
+ type = type || 5121;
188
187
  const ArrayType = getTypedArrayFromGLType(type, { clamped: false });
189
188
  const components = glFormatToComponents(format);
190
189
  // TODO - check for composite type (components = 1).
@@ -1,3 +1,3 @@
1
- export declare function glFormatToComponents(format: any): 1 | 2 | 3 | 4 | 0;
2
- export declare function glTypeToBytes(type: any): 1 | 2 | 4 | 0;
1
+ export declare function glFormatToComponents(format: any): 0 | 1 | 4 | 2 | 3;
2
+ export declare function glTypeToBytes(type: any): 0 | 1 | 4 | 2;
3
3
  //# sourceMappingURL=format-utils.d.ts.map
@@ -6,18 +6,18 @@ import { GL } from '@luma.gl/constants';
6
6
  // Returns number of components in a specific readPixels WebGL format
7
7
  export function glFormatToComponents(format) {
8
8
  switch (format) {
9
- case GL.ALPHA:
10
- case GL.R32F:
11
- case GL.RED:
9
+ case 6406:
10
+ case 33326:
11
+ case 6403:
12
12
  return 1;
13
- case GL.RG32F:
14
- case GL.RG:
13
+ case 33328:
14
+ case 33319:
15
15
  return 2;
16
- case GL.RGB:
17
- case GL.RGB32F:
16
+ case 6407:
17
+ case 34837:
18
18
  return 3;
19
- case GL.RGBA:
20
- case GL.RGBA32F:
19
+ case 6408:
20
+ case 34836:
21
21
  return 4;
22
22
  // TODO: Add support for additional WebGL2 formats
23
23
  default:
@@ -28,13 +28,13 @@ export function glFormatToComponents(format) {
28
28
  // Return byte count for given readPixels WebGL type
29
29
  export function glTypeToBytes(type) {
30
30
  switch (type) {
31
- case GL.UNSIGNED_BYTE:
31
+ case 5121:
32
32
  return 1;
33
- case GL.UNSIGNED_SHORT_5_6_5:
34
- case GL.UNSIGNED_SHORT_4_4_4_4:
35
- case GL.UNSIGNED_SHORT_5_5_5_1:
33
+ case 33635:
34
+ case 32819:
35
+ case 32820:
36
36
  return 2;
37
- case GL.FLOAT:
37
+ case 5126:
38
38
  return 4;
39
39
  // TODO: Add support for additional WebGL2 types
40
40
  default: