@luma.gl/webgl 9.3.0-alpha.6 → 9.3.0-alpha.8

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 (202) 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 +4 -1
  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/shader-formats.d.ts +1 -64
  10. package/dist/adapter/converters/shader-formats.d.ts.map +1 -1
  11. package/dist/adapter/converters/shader-formats.js +1 -64
  12. package/dist/adapter/converters/shader-formats.js.map +1 -1
  13. package/dist/adapter/converters/webgl-shadertypes.d.ts +1 -3
  14. package/dist/adapter/converters/webgl-shadertypes.d.ts.map +1 -1
  15. package/dist/adapter/converters/webgl-shadertypes.js +1 -6
  16. package/dist/adapter/converters/webgl-shadertypes.js.map +1 -1
  17. package/dist/adapter/converters/webgl-texture-table.d.ts +1 -3
  18. package/dist/adapter/converters/webgl-texture-table.d.ts.map +1 -1
  19. package/dist/adapter/converters/webgl-texture-table.js +1 -15
  20. package/dist/adapter/converters/webgl-texture-table.js.map +1 -1
  21. package/dist/adapter/converters/webgl-vertex-formats.d.ts +1 -1
  22. package/dist/adapter/converters/webgl-vertex-formats.d.ts.map +1 -1
  23. package/dist/adapter/converters/webgl-vertex-formats.js +1 -1
  24. package/dist/adapter/converters/webgl-vertex-formats.js.map +1 -1
  25. package/dist/adapter/device-helpers/webgl-device-features.d.ts +1 -1
  26. package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
  27. package/dist/adapter/device-helpers/webgl-device-info.d.ts +1 -1
  28. package/dist/adapter/device-helpers/webgl-device-info.d.ts.map +1 -1
  29. package/dist/adapter/device-helpers/webgl-device-info.js +1 -1
  30. package/dist/adapter/device-helpers/webgl-device-info.js.map +1 -1
  31. package/dist/adapter/device-helpers/webgl-device-limits.d.ts +1 -1
  32. package/dist/adapter/device-helpers/webgl-device-limits.d.ts.map +1 -1
  33. package/dist/adapter/device-helpers/webgl-device-limits.js +1 -1
  34. package/dist/adapter/device-helpers/webgl-device-limits.js.map +1 -1
  35. package/dist/adapter/helpers/format-utils.d.ts +1 -1
  36. package/dist/adapter/helpers/format-utils.d.ts.map +1 -1
  37. package/dist/adapter/helpers/format-utils.js +1 -1
  38. package/dist/adapter/helpers/format-utils.js.map +1 -1
  39. package/dist/adapter/helpers/get-shader-layout-from-glsl.js +14 -2
  40. package/dist/adapter/helpers/get-shader-layout-from-glsl.js.map +1 -1
  41. package/dist/adapter/helpers/set-uniform.d.ts +1 -1
  42. package/dist/adapter/helpers/set-uniform.d.ts.map +1 -1
  43. package/dist/adapter/helpers/set-uniform.js +1 -1
  44. package/dist/adapter/helpers/set-uniform.js.map +1 -1
  45. package/dist/adapter/helpers/webgl-texture-utils.d.ts +1 -1
  46. package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -1
  47. package/dist/adapter/helpers/webgl-texture-utils.js +4 -4
  48. package/dist/adapter/helpers/webgl-texture-utils.js.map +1 -1
  49. package/dist/adapter/helpers/webgl-topology-utils.d.ts +1 -1
  50. package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
  51. package/dist/adapter/helpers/webgl-topology-utils.js +1 -1
  52. package/dist/adapter/helpers/webgl-topology-utils.js.map +1 -1
  53. package/dist/adapter/resources/webgl-buffer.d.ts +1 -1
  54. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  55. package/dist/adapter/resources/webgl-buffer.js +1 -1
  56. package/dist/adapter/resources/webgl-buffer.js.map +1 -1
  57. package/dist/adapter/resources/webgl-command-buffer.d.ts +1 -1
  58. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  59. package/dist/adapter/resources/webgl-command-buffer.js +20 -34
  60. package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
  61. package/dist/adapter/resources/webgl-command-encoder.d.ts +1 -1
  62. package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
  63. package/dist/adapter/resources/webgl-command-encoder.js +3 -1
  64. package/dist/adapter/resources/webgl-command-encoder.js.map +1 -1
  65. package/dist/adapter/resources/webgl-framebuffer.d.ts +3 -1
  66. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  67. package/dist/adapter/resources/webgl-framebuffer.js +10 -1
  68. package/dist/adapter/resources/webgl-framebuffer.js.map +1 -1
  69. package/dist/adapter/resources/webgl-query-set.d.ts +8 -0
  70. package/dist/adapter/resources/webgl-query-set.d.ts.map +1 -1
  71. package/dist/adapter/resources/webgl-query-set.js +59 -4
  72. package/dist/adapter/resources/webgl-query-set.js.map +1 -1
  73. package/dist/adapter/resources/webgl-render-pass.d.ts +1 -1
  74. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  75. package/dist/adapter/resources/webgl-render-pass.js +13 -11
  76. package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
  77. package/dist/adapter/resources/webgl-render-pipeline.d.ts +8 -6
  78. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  79. package/dist/adapter/resources/webgl-render-pipeline.js +39 -20
  80. package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
  81. package/dist/adapter/resources/webgl-sampler.d.ts +1 -1
  82. package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
  83. package/dist/adapter/resources/webgl-sampler.js +1 -1
  84. package/dist/adapter/resources/webgl-sampler.js.map +1 -1
  85. package/dist/adapter/resources/webgl-shader.d.ts +1 -1
  86. package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
  87. package/dist/adapter/resources/webgl-shader.js +15 -8
  88. package/dist/adapter/resources/webgl-shader.js.map +1 -1
  89. package/dist/adapter/resources/webgl-shared-render-pipeline.d.ts.map +1 -1
  90. package/dist/adapter/resources/webgl-shared-render-pipeline.js +4 -1
  91. package/dist/adapter/resources/webgl-shared-render-pipeline.js.map +1 -1
  92. package/dist/adapter/resources/webgl-texture.d.ts +4 -2
  93. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  94. package/dist/adapter/resources/webgl-texture.js +12 -17
  95. package/dist/adapter/resources/webgl-texture.js.map +1 -1
  96. package/dist/adapter/resources/webgl-transform-feedback.js +1 -1
  97. package/dist/adapter/resources/webgl-transform-feedback.js.map +1 -1
  98. package/dist/adapter/resources/webgl-vertex-array.d.ts +2 -2
  99. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
  100. package/dist/adapter/resources/webgl-vertex-array.js +1 -1
  101. package/dist/adapter/resources/webgl-vertex-array.js.map +1 -1
  102. package/dist/adapter/webgl-device.d.ts +2 -1
  103. package/dist/adapter/webgl-device.d.ts.map +1 -1
  104. package/dist/adapter/webgl-device.js +11 -7
  105. package/dist/adapter/webgl-device.js.map +1 -1
  106. package/dist/constants/index.d.ts +3 -0
  107. package/dist/constants/index.d.ts.map +1 -0
  108. package/dist/constants/index.js +5 -0
  109. package/dist/constants/index.js.map +1 -0
  110. package/dist/constants/webgl-constants.d.ts +822 -0
  111. package/dist/constants/webgl-constants.d.ts.map +1 -0
  112. package/dist/constants/webgl-constants.js +928 -0
  113. package/dist/constants/webgl-constants.js.map +1 -0
  114. package/dist/constants/webgl-types.d.ts +480 -0
  115. package/dist/constants/webgl-types.d.ts.map +1 -0
  116. package/dist/constants/webgl-types.js +6 -0
  117. package/dist/constants/webgl-types.js.map +1 -0
  118. package/dist/context/debug/webgl-developer-tools.js +1 -1
  119. package/dist/context/debug/webgl-developer-tools.js.map +1 -1
  120. package/dist/context/helpers/webgl-context-data.d.ts +1 -1
  121. package/dist/context/helpers/webgl-context-data.d.ts.map +1 -1
  122. package/dist/context/helpers/webgl-extensions.d.ts +1 -1
  123. package/dist/context/helpers/webgl-extensions.d.ts.map +1 -1
  124. package/dist/context/parameters/unified-parameter-api.d.ts +1 -1
  125. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  126. package/dist/context/parameters/webgl-parameter-tables.d.ts +1 -1
  127. package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
  128. package/dist/context/parameters/webgl-parameter-tables.js +1 -1
  129. package/dist/context/parameters/webgl-parameter-tables.js.map +1 -1
  130. package/dist/context/polyfills/polyfill-webgl1-extensions.js +1 -1
  131. package/dist/context/polyfills/polyfill-webgl1-extensions.js.map +1 -1
  132. package/dist/dist.dev.js +267 -162
  133. package/dist/dist.min.js +2 -2
  134. package/dist/index.cjs +3 -5941
  135. package/dist/index.cjs.map +4 -4
  136. package/dist/index.d.ts +2 -0
  137. package/dist/index.d.ts.map +1 -1
  138. package/dist/index.js +1 -0
  139. package/dist/index.js.map +1 -1
  140. package/dist/webgl-constants.d.ts +2 -0
  141. package/dist/webgl-constants.d.ts.map +1 -0
  142. package/dist/webgl-constants.js +5 -0
  143. package/dist/webgl-constants.js.map +1 -0
  144. package/dist/webgl-types.d.ts +2 -0
  145. package/dist/webgl-types.d.ts.map +1 -0
  146. package/dist/{types.js → webgl-types.js} +1 -1
  147. package/dist/webgl-types.js.map +1 -0
  148. package/package.json +18 -4
  149. package/src/adapter/converters/device-parameters.ts +6 -2
  150. package/src/adapter/converters/sampler-parameters.ts +1 -1
  151. package/src/adapter/converters/shader-formats.ts +1 -66
  152. package/src/adapter/converters/webgl-shadertypes.ts +1 -9
  153. package/src/adapter/converters/webgl-texture-table.ts +1 -21
  154. package/src/adapter/converters/webgl-vertex-formats.ts +1 -1
  155. package/src/adapter/device-helpers/webgl-device-features.ts +1 -1
  156. package/src/adapter/device-helpers/webgl-device-info.ts +1 -1
  157. package/src/adapter/device-helpers/webgl-device-limits.ts +1 -1
  158. package/src/adapter/helpers/format-utils.ts +1 -1
  159. package/src/adapter/helpers/get-shader-layout-from-glsl.ts +21 -2
  160. package/src/adapter/helpers/set-uniform.ts +1 -1
  161. package/src/adapter/helpers/webgl-texture-utils.ts +4 -4
  162. package/src/adapter/helpers/webgl-topology-utils.ts +1 -1
  163. package/src/adapter/resources/webgl-buffer.ts +1 -1
  164. package/src/adapter/resources/webgl-command-buffer.ts +25 -26
  165. package/src/adapter/resources/webgl-command-encoder.ts +6 -4
  166. package/src/adapter/resources/webgl-framebuffer.ts +12 -1
  167. package/src/adapter/resources/webgl-query-set.ts +71 -4
  168. package/src/adapter/resources/webgl-render-pass.ts +13 -13
  169. package/src/adapter/resources/webgl-render-pipeline.ts +65 -26
  170. package/src/adapter/resources/webgl-sampler.ts +1 -1
  171. package/src/adapter/resources/webgl-shader.ts +15 -8
  172. package/src/adapter/resources/webgl-shared-render-pipeline.ts +4 -1
  173. package/src/adapter/resources/webgl-texture.ts +15 -18
  174. package/src/adapter/resources/webgl-transform-feedback.ts +1 -1
  175. package/src/adapter/resources/webgl-vertex-array.ts +1 -1
  176. package/src/adapter/webgl-device.ts +16 -8
  177. package/src/constants/index.d.ts.map +1 -0
  178. package/src/constants/index.js.map +1 -0
  179. package/src/constants/index.ts +31 -0
  180. package/src/constants/webgl-constants.d.ts.map +1 -0
  181. package/src/constants/webgl-constants.js.map +1 -0
  182. package/src/constants/webgl-constants.ts +1051 -0
  183. package/src/constants/webgl-types.d.ts.map +1 -0
  184. package/src/constants/webgl-types.js.map +1 -0
  185. package/src/constants/webgl-types.ts +813 -0
  186. package/src/context/debug/webgl-developer-tools.ts +1 -1
  187. package/src/context/helpers/webgl-context-data.ts +1 -1
  188. package/src/context/helpers/webgl-extensions.ts +1 -1
  189. package/src/context/parameters/unified-parameter-api.ts +1 -1
  190. package/src/context/parameters/webgl-parameter-tables.ts +1 -1
  191. package/src/context/polyfills/polyfill-webgl1-extensions.ts +1 -1
  192. package/src/index.ts +26 -0
  193. package/src/webgl-constants.d.ts.map +1 -0
  194. package/src/webgl-constants.js.map +1 -0
  195. package/src/webgl-constants.ts +5 -0
  196. package/src/webgl-types.d.ts.map +1 -0
  197. package/src/webgl-types.js.map +1 -0
  198. package/src/webgl-types.ts +29 -0
  199. package/dist/types.d.ts +0 -11
  200. package/dist/types.d.ts.map +0 -1
  201. package/dist/types.js.map +0 -1
  202. package/src/types.ts +0 -14
package/dist/dist.dev.js CHANGED
@@ -48,10 +48,10 @@ var __exports__ = (() => {
48
48
  }
49
49
  });
50
50
 
51
- // ../constants/src/webgl-constants.ts
51
+ // src/constants/webgl-constants.ts
52
52
  var GLEnum;
53
53
  var init_webgl_constants = __esm({
54
- "../constants/src/webgl-constants.ts"() {
54
+ "src/constants/webgl-constants.ts"() {
55
55
  "use strict";
56
56
  GLEnum = /* @__PURE__ */ ((GLEnum2) => {
57
57
  GLEnum2[GLEnum2["DEPTH_BUFFER_BIT"] = 256] = "DEPTH_BUFFER_BIT";
@@ -705,9 +705,9 @@ var __exports__ = (() => {
705
705
  }
706
706
  });
707
707
 
708
- // ../constants/src/index.ts
709
- var init_src = __esm({
710
- "../constants/src/index.ts"() {
708
+ // src/constants/index.ts
709
+ var init_constants = __esm({
710
+ "src/constants/index.ts"() {
711
711
  "use strict";
712
712
  init_webgl_constants();
713
713
  }
@@ -1111,7 +1111,7 @@ var __exports__ = (() => {
1111
1111
  "src/context/debug/webgl-developer-tools.ts"() {
1112
1112
  "use strict";
1113
1113
  import_core2 = __toESM(require_core(), 1);
1114
- init_src();
1114
+ init_constants();
1115
1115
  init_dist();
1116
1116
  init_load_script();
1117
1117
  WEBGL_DEBUG_CDN_URL = "https://unpkg.com/webgl-debug@2.0.1/index.js";
@@ -2704,6 +2704,15 @@ var __exports__ = (() => {
2704
2704
  }
2705
2705
  gl.bindTexture(texture.glTarget, null);
2706
2706
  }
2707
+ /** Default framebuffer resize is managed by canvas size and should be a no-op. */
2708
+ resizeAttachments(width, height) {
2709
+ if (this.handle === null) {
2710
+ this.width = width;
2711
+ this.height = height;
2712
+ return;
2713
+ }
2714
+ super.resizeAttachments(width, height);
2715
+ }
2707
2716
  };
2708
2717
  }
2709
2718
  });
@@ -3066,7 +3075,12 @@ var __exports__ = (() => {
3066
3075
  throw new Error(this.props.stage);
3067
3076
  }
3068
3077
  device._setWebGLDebugMetadata(this.handle, this, { spector: this.props });
3069
- this._compile(this.source);
3078
+ const compilationStatus = this._compile(this.source);
3079
+ if (compilationStatus && typeof compilationStatus.catch === "function") {
3080
+ compilationStatus.catch(() => {
3081
+ this.compilationStatus = "error";
3082
+ });
3083
+ }
3070
3084
  }
3071
3085
  destroy() {
3072
3086
  if (this.handle) {
@@ -3097,7 +3111,7 @@ var __exports__ = (() => {
3097
3111
  }
3098
3112
  // PRIVATE METHODS
3099
3113
  /** Compile a shader and get compilation status */
3100
- async _compile(source) {
3114
+ _compile(source) {
3101
3115
  source = source.startsWith("#version ") ? source : `#version 300 es
3102
3116
  ${source}`;
3103
3117
  const { gl } = this.device;
@@ -3116,10 +3130,11 @@ ${source}`;
3116
3130
  return;
3117
3131
  }
3118
3132
  import_core10.log.once(1, "Shader compilation is asynchronous")();
3119
- await this._waitForCompilationComplete();
3120
- import_core10.log.info(2, `Shader ${this.id} - async compilation complete: ${this.compilationStatus}`)();
3121
- this._getCompilationStatus();
3122
- this.debugShader();
3133
+ return this._waitForCompilationComplete().then(() => {
3134
+ import_core10.log.info(2, `Shader ${this.id} - async compilation complete: ${this.compilationStatus}`)();
3135
+ this._getCompilationStatus();
3136
+ this.debugShader();
3137
+ });
3123
3138
  }
3124
3139
  /** Use KHR_parallel_shader_compile extension if available */
3125
3140
  async _waitForCompilationComplete() {
@@ -3278,6 +3293,9 @@ ${source}`;
3278
3293
  parameters.depthCompare !== "always" ? gl.enable(2929 /* DEPTH_TEST */) : gl.disable(2929 /* DEPTH_TEST */);
3279
3294
  gl.depthFunc(convertCompareFunction("depthCompare", parameters.depthCompare));
3280
3295
  }
3296
+ if (parameters.clearDepth !== void 0) {
3297
+ gl.clearDepth(parameters.clearDepth);
3298
+ }
3281
3299
  if (parameters.stencilWriteMask) {
3282
3300
  const mask = parameters.stencilWriteMask;
3283
3301
  gl.stencilMaskSeparate(1028 /* FRONT */, mask);
@@ -3687,7 +3705,7 @@ ${source}`;
3687
3705
  function getWebGLCubeFaceTarget(glTarget, dimension, level) {
3688
3706
  return dimension === "cube" ? 34069 /* TEXTURE_CUBE_MAP_POSITIVE_X */ + level : glTarget;
3689
3707
  }
3690
- var import_core14, import_core15, WEBGLTexture;
3708
+ var import_core14, WEBGLTexture;
3691
3709
  var init_webgl_texture = __esm({
3692
3710
  "src/adapter/resources/webgl-texture.ts"() {
3693
3711
  "use strict";
@@ -3697,7 +3715,6 @@ ${source}`;
3697
3715
  init_with_parameters();
3698
3716
  init_webgl_texture_view();
3699
3717
  init_shader_formats();
3700
- import_core15 = __toESM(require_core(), 1);
3701
3718
  WEBGLTexture = class extends import_core14.Texture {
3702
3719
  // readonly MAX_ATTRIBUTES: number;
3703
3720
  device;
@@ -3829,18 +3846,18 @@ ${source}`;
3829
3846
  * before any WebGL calls are issued.
3830
3847
  */
3831
3848
  readBuffer(options = {}, buffer) {
3849
+ if (!buffer) {
3850
+ throw new Error(`${this} readBuffer requires a destination buffer`);
3851
+ }
3832
3852
  const normalizedOptions = this._getSupportedColorReadOptions(options);
3853
+ const byteOffset = options.byteOffset ?? 0;
3833
3854
  const memoryLayout = this.computeMemoryLayout(normalizedOptions);
3834
- const readBuffer = buffer || this.device.createBuffer({
3835
- byteLength: memoryLayout.byteLength,
3836
- usage: import_core14.Buffer.COPY_DST | import_core14.Buffer.MAP_READ
3837
- });
3838
- if (readBuffer.byteLength < memoryLayout.byteLength) {
3855
+ if (buffer.byteLength < byteOffset + memoryLayout.byteLength) {
3839
3856
  throw new Error(
3840
- `${this} readBuffer target is too small (${readBuffer.byteLength} < ${memoryLayout.byteLength})`
3857
+ `${this} readBuffer target is too small (${buffer.byteLength} < ${byteOffset + memoryLayout.byteLength})`
3841
3858
  );
3842
3859
  }
3843
- const webglBuffer = readBuffer;
3860
+ const webglBuffer = buffer;
3844
3861
  this.gl.bindBuffer(35051 /* PIXEL_PACK_BUFFER */, webglBuffer.handle);
3845
3862
  try {
3846
3863
  this._readColorTextureLayers(normalizedOptions, memoryLayout, (destinationByteOffset) => {
@@ -3851,19 +3868,18 @@ ${source}`;
3851
3868
  normalizedOptions.height,
3852
3869
  this.glFormat,
3853
3870
  this.glType,
3854
- destinationByteOffset
3871
+ byteOffset + destinationByteOffset
3855
3872
  );
3856
3873
  });
3857
3874
  } finally {
3858
3875
  this.gl.bindBuffer(35051 /* PIXEL_PACK_BUFFER */, null);
3859
3876
  }
3860
- return readBuffer;
3877
+ return buffer;
3861
3878
  }
3862
3879
  async readDataAsync(options = {}) {
3863
- const buffer = this.readBuffer(options);
3864
- const data = await buffer.readAsync();
3865
- buffer.destroy();
3866
- return data.buffer;
3880
+ throw new Error(
3881
+ `${this} readDataAsync is deprecated; use readBuffer() with an explicit destination buffer or DynamicTexture.readAsync()`
3882
+ );
3867
3883
  }
3868
3884
  writeBuffer(buffer, options_ = {}) {
3869
3885
  const options = this._normalizeTextureWriteOptions(options_);
@@ -4018,7 +4034,7 @@ ${source}`;
4018
4034
  const options = this._getSupportedColorReadOptions(options_);
4019
4035
  const memoryLayout = this.computeMemoryLayout(options);
4020
4036
  const shaderType = convertGLDataTypeToDataType(this.glType);
4021
- const ArrayType = (0, import_core15.getTypedArrayConstructor)(shaderType);
4037
+ const ArrayType = (0, import_core14.getTypedArrayConstructor)(shaderType);
4022
4038
  const targetArray = new ArrayType(memoryLayout.byteLength / ArrayType.BYTES_PER_ELEMENT);
4023
4039
  this._readColorTextureLayers(options, memoryLayout, (destinationByteOffset) => {
4024
4040
  const layerView = new ArrayType(
@@ -4332,24 +4348,41 @@ ${source}`;
4332
4348
  function mergeShaderLayout(baseLayout, overrideLayout) {
4333
4349
  const mergedLayout = {
4334
4350
  ...baseLayout,
4335
- attributes: baseLayout.attributes.map((attribute) => ({ ...attribute }))
4351
+ attributes: baseLayout.attributes.map((attribute) => ({ ...attribute })),
4352
+ bindings: baseLayout.bindings.map((binding) => ({ ...binding }))
4336
4353
  };
4337
4354
  for (const attribute of overrideLayout?.attributes || []) {
4338
4355
  const baseAttribute = mergedLayout.attributes.find((attr) => attr.name === attribute.name);
4339
4356
  if (!baseAttribute) {
4340
- import_core16.log.warn(`shader layout attribute ${attribute.name} not present in shader`);
4357
+ import_core15.log.warn(`shader layout attribute ${attribute.name} not present in shader`);
4341
4358
  } else {
4342
4359
  baseAttribute.type = attribute.type || baseAttribute.type;
4343
4360
  baseAttribute.stepMode = attribute.stepMode || baseAttribute.stepMode;
4344
4361
  }
4345
4362
  }
4363
+ for (const binding of overrideLayout?.bindings || []) {
4364
+ const baseBinding = getShaderLayoutBindingByName(mergedLayout, binding.name);
4365
+ if (!baseBinding) {
4366
+ import_core15.log.warn(`shader layout binding ${binding.name} not present in shader`);
4367
+ continue;
4368
+ }
4369
+ Object.assign(baseBinding, binding);
4370
+ }
4346
4371
  return mergedLayout;
4347
4372
  }
4348
- var import_core16, WEBGLRenderPipeline;
4373
+ function getShaderLayoutBindingByName(shaderLayout, bindingName) {
4374
+ return shaderLayout.bindings.find(
4375
+ (binding) => binding.name === bindingName || binding.name === `${bindingName}Uniforms` || `${binding.name}Uniforms` === bindingName
4376
+ );
4377
+ }
4378
+ function getBindingValueForLayoutBinding(bindings, bindingName) {
4379
+ return bindings[bindingName] || bindings[`${bindingName}Uniforms`] || bindings[bindingName.replace(/Uniforms$/, "")];
4380
+ }
4381
+ var import_core15, WEBGLRenderPipeline;
4349
4382
  var init_webgl_render_pipeline = __esm({
4350
4383
  "src/adapter/resources/webgl-render-pipeline.ts"() {
4351
4384
  "use strict";
4352
- import_core16 = __toESM(require_core(), 1);
4385
+ import_core15 = __toESM(require_core(), 1);
4353
4386
  init_device_parameters();
4354
4387
  init_set_uniform();
4355
4388
  init_webgl_buffer();
@@ -4357,7 +4390,7 @@ ${source}`;
4357
4390
  init_webgl_texture();
4358
4391
  init_webgl_texture_view();
4359
4392
  init_webgl_topology_utils();
4360
- WEBGLRenderPipeline = class extends import_core16.RenderPipeline {
4393
+ WEBGLRenderPipeline = class extends import_core15.RenderPipeline {
4361
4394
  /** The WebGL device that created this render pipeline */
4362
4395
  device;
4363
4396
  /** Handle to underlying WebGL program */
@@ -4407,12 +4440,15 @@ ${source}`;
4407
4440
  * Shared-model draws pass bindings per draw and do not rely on this state.
4408
4441
  */
4409
4442
  setBindings(bindings, options) {
4410
- for (const [name, value] of Object.entries(bindings)) {
4411
- const binding = this.shaderLayout.bindings.find((binding_) => binding_.name === name) || this.shaderLayout.bindings.find((binding_) => binding_.name === `${name}Uniforms`);
4443
+ const flatBindings = (0, import_core15.flattenBindingsByGroup)(
4444
+ (0, import_core15.normalizeBindingsByGroup)(this.shaderLayout, bindings)
4445
+ );
4446
+ for (const [name, value] of Object.entries(flatBindings)) {
4447
+ const binding = getShaderLayoutBindingByName(this.shaderLayout, name);
4412
4448
  if (!binding) {
4413
4449
  const validBindings = this.shaderLayout.bindings.map((binding_) => `"${binding_.name}"`).join(", ");
4414
4450
  if (!options?.disableWarnings) {
4415
- import_core16.log.warn(
4451
+ import_core15.log.warn(
4416
4452
  `No binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`,
4417
4453
  value
4418
4454
  )();
@@ -4420,7 +4456,7 @@ ${source}`;
4420
4456
  continue;
4421
4457
  }
4422
4458
  if (!value) {
4423
- import_core16.log.warn(`Unsetting binding "${name}" in render pipeline "${this.id}"`)();
4459
+ import_core15.log.warn(`Unsetting binding "${name}" in render pipeline "${this.id}"`)();
4424
4460
  }
4425
4461
  switch (binding.type) {
4426
4462
  case "uniform":
@@ -4434,7 +4470,7 @@ ${source}`;
4434
4470
  }
4435
4471
  break;
4436
4472
  case "sampler":
4437
- import_core16.log.warn(`Ignoring sampler ${name}`)();
4473
+ import_core15.log.warn(`Ignoring sampler ${name}`)();
4438
4474
  break;
4439
4475
  default:
4440
4476
  throw new Error(binding.type);
@@ -4448,6 +4484,7 @@ ${source}`;
4448
4484
  */
4449
4485
  draw(options) {
4450
4486
  this._syncLinkStatus();
4487
+ const drawBindings = options.bindGroups ? (0, import_core15.flattenBindingsByGroup)(options.bindGroups) : options.bindings || this.bindings;
4451
4488
  const {
4452
4489
  renderPass,
4453
4490
  parameters = this.props.parameters,
@@ -4462,18 +4499,17 @@ ${source}`;
4462
4499
  // firstInstance,
4463
4500
  // baseVertex,
4464
4501
  transformFeedback,
4465
- bindings = this.bindings,
4466
4502
  uniforms = this.uniforms
4467
4503
  } = options;
4468
4504
  const glDrawMode = getGLDrawMode(topology);
4469
4505
  const isIndexed = Boolean(vertexArray.indexBuffer);
4470
4506
  const glIndexType = vertexArray.indexBuffer?.glIndexType;
4471
4507
  if (this.linkStatus !== "success") {
4472
- import_core16.log.info(2, `RenderPipeline:${this.id}.draw() aborted - waiting for shader linking`)();
4508
+ import_core15.log.info(2, `RenderPipeline:${this.id}.draw() aborted - waiting for shader linking`)();
4473
4509
  return false;
4474
4510
  }
4475
- if (!this._areTexturesRenderable(bindings)) {
4476
- import_core16.log.info(2, `RenderPipeline:${this.id}.draw() aborted - textures not yet loaded`)();
4511
+ if (!this._areTexturesRenderable(drawBindings)) {
4512
+ import_core15.log.info(2, `RenderPipeline:${this.id}.draw() aborted - textures not yet loaded`)();
4477
4513
  return false;
4478
4514
  }
4479
4515
  this.device.gl.useProgram(this.handle);
@@ -4481,7 +4517,7 @@ ${source}`;
4481
4517
  if (transformFeedback) {
4482
4518
  transformFeedback.begin(this.props.topology);
4483
4519
  }
4484
- this._applyBindings(bindings, { disableWarnings: this.props.disableWarnings });
4520
+ this._applyBindings(drawBindings, { disableWarnings: this.props.disableWarnings });
4485
4521
  this._applyUniforms(uniforms);
4486
4522
  const webglRenderPass = renderPass;
4487
4523
  withDeviceAndGLParameters(this.device, parameters, webglRenderPass.glParameters, () => {
@@ -4521,8 +4557,8 @@ ${source}`;
4521
4557
  _areTexturesRenderable(bindings) {
4522
4558
  let texturesRenderable = true;
4523
4559
  for (const bindingInfo of this.shaderLayout.bindings) {
4524
- if (!bindings[bindingInfo.name] && !bindings[bindingInfo.name.replace(/Uniforms$/, "")]) {
4525
- import_core16.log.warn(`Binding ${bindingInfo.name} not found in ${this.id}`)();
4560
+ if (!getBindingValueForLayoutBinding(bindings, bindingInfo.name)) {
4561
+ import_core15.log.warn(`Binding ${bindingInfo.name} not found in ${this.id}`)();
4526
4562
  texturesRenderable = false;
4527
4563
  }
4528
4564
  }
@@ -4539,7 +4575,7 @@ ${source}`;
4539
4575
  let textureUnit = 0;
4540
4576
  let uniformBufferIndex = 0;
4541
4577
  for (const binding of this.shaderLayout.bindings) {
4542
- const value = bindings[binding.name] || bindings[binding.name.replace(/Uniforms$/, "")];
4578
+ const value = getBindingValueForLayoutBinding(bindings, binding.name);
4543
4579
  if (!value) {
4544
4580
  throw new Error(`No value for binding ${binding.name} in ${this.id}`);
4545
4581
  }
@@ -4554,15 +4590,13 @@ ${source}`;
4554
4590
  if (value instanceof WEBGLBuffer) {
4555
4591
  gl.bindBufferBase(35345 /* UNIFORM_BUFFER */, uniformBufferIndex, value.handle);
4556
4592
  } else {
4593
+ const bufferBinding = value;
4557
4594
  gl.bindBufferRange(
4558
4595
  35345 /* UNIFORM_BUFFER */,
4559
4596
  uniformBufferIndex,
4560
- // @ts-expect-error
4561
- value.buffer.handle,
4562
- // @ts-expect-error
4563
- value.offset || 0,
4564
- // @ts-expect-error
4565
- value.size || value.buffer.byteLength - value.offset
4597
+ bufferBinding.buffer.handle,
4598
+ bufferBinding.offset || 0,
4599
+ bufferBinding.size || bufferBinding.buffer.byteLength - (bufferBinding.offset || 0)
4566
4600
  );
4567
4601
  }
4568
4602
  uniformBufferIndex += 1;
@@ -4577,7 +4611,7 @@ ${source}`;
4577
4611
  } else if (value instanceof WEBGLTexture) {
4578
4612
  texture = value;
4579
4613
  } else if (value instanceof WEBGLFramebuffer && value.colorAttachments[0] instanceof WEBGLTextureView) {
4580
- import_core16.log.warn(
4614
+ import_core15.log.warn(
4581
4615
  "Passing framebuffer in texture binding may be deprecated. Use fbo.colorAttachments[0] instead"
4582
4616
  )();
4583
4617
  texture = value.colorAttachments[0].texture;
@@ -4799,7 +4833,7 @@ ${source}`;
4799
4833
  }
4800
4834
  const { name, type: glUniformType, size } = activeInfo;
4801
4835
  const uniformType = convertGLUniformTypeToShaderVariableType(glUniformType);
4802
- const { type, components } = (0, import_core17.getVariableShaderTypeInfo)(uniformType);
4836
+ const { type, components } = (0, import_core16.getVariableShaderTypeInfo)(uniformType);
4803
4837
  varyings.push({ location, name, type, size: size * components });
4804
4838
  }
4805
4839
  varyings.sort((a, b) => a.location - b.location);
@@ -4879,6 +4913,16 @@ ${source}`;
4879
4913
  });
4880
4914
  }
4881
4915
  }
4916
+ const uniformInstancePrefixes = new Set(
4917
+ blockInfo.uniforms.map((uniform) => uniform.name.split(".")[0]).filter((instanceName) => Boolean(instanceName))
4918
+ );
4919
+ const blockAlias = blockInfo.name.replace(/Uniforms$/, "");
4920
+ if (uniformInstancePrefixes.size === 1 && !uniformInstancePrefixes.has(blockInfo.name) && !uniformInstancePrefixes.has(blockAlias)) {
4921
+ const [instanceName] = uniformInstancePrefixes;
4922
+ import_core16.log.warn(
4923
+ `Uniform block "${blockInfo.name}" uses GLSL instance "${instanceName}". luma.gl binds uniform buffers by block name ("${blockInfo.name}") and alias ("${blockAlias}"). Prefer matching the instance name to one of those to avoid confusing silent mismatches.`
4924
+ )();
4925
+ }
4882
4926
  uniformBlocks.push(blockInfo);
4883
4927
  }
4884
4928
  uniformBlocks.sort((a, b) => a.location - b.location);
@@ -4894,7 +4938,7 @@ ${source}`;
4894
4938
  }
4895
4939
  const UNIFORM_NAME_REGEXP = /([^[]*)(\[[0-9]+\])?/;
4896
4940
  const matches = UNIFORM_NAME_REGEXP.exec(name);
4897
- const uniformName = (0, import_core17.assertDefined)(matches?.[1], `Failed to parse GLSL uniform name ${name}`);
4941
+ const uniformName = (0, import_core16.assertDefined)(matches?.[1], `Failed to parse GLSL uniform name ${name}`);
4898
4942
  return {
4899
4943
  name: uniformName,
4900
4944
  // TODO - is this a bug, shouldn't we return the value?
@@ -4902,25 +4946,25 @@ ${source}`;
4902
4946
  isArray: Boolean(matches?.[2])
4903
4947
  };
4904
4948
  }
4905
- var import_core17;
4949
+ var import_core16;
4906
4950
  var init_get_shader_layout_from_glsl = __esm({
4907
4951
  "src/adapter/helpers/get-shader-layout-from-glsl.ts"() {
4908
4952
  "use strict";
4909
- import_core17 = __toESM(require_core(), 1);
4953
+ import_core16 = __toESM(require_core(), 1);
4910
4954
  init_webgl_shadertypes();
4911
4955
  }
4912
4956
  });
4913
4957
 
4914
4958
  // src/adapter/resources/webgl-shared-render-pipeline.ts
4915
- var import_core18, LOG_PROGRAM_PERF_PRIORITY, WEBGLSharedRenderPipeline;
4959
+ var import_core17, LOG_PROGRAM_PERF_PRIORITY, WEBGLSharedRenderPipeline;
4916
4960
  var init_webgl_shared_render_pipeline = __esm({
4917
4961
  "src/adapter/resources/webgl-shared-render-pipeline.ts"() {
4918
4962
  "use strict";
4919
- import_core18 = __toESM(require_core(), 1);
4963
+ import_core17 = __toESM(require_core(), 1);
4920
4964
  init_get_shader_layout_from_glsl();
4921
4965
  init_webgl_shadertypes();
4922
4966
  LOG_PROGRAM_PERF_PRIORITY = 4;
4923
- WEBGLSharedRenderPipeline = class extends import_core18.SharedRenderPipeline {
4967
+ WEBGLSharedRenderPipeline = class extends import_core17.SharedRenderPipeline {
4924
4968
  device;
4925
4969
  handle;
4926
4970
  vs;
@@ -4941,9 +4985,9 @@ ${source}`;
4941
4985
  );
4942
4986
  }
4943
4987
  this._linkShaders();
4944
- import_core18.log.time(3, `RenderPipeline ${this.id} - shaderLayout introspection`)();
4988
+ import_core17.log.time(3, `RenderPipeline ${this.id} - shaderLayout introspection`)();
4945
4989
  this.introspectedLayout = getShaderLayoutFromGLSL(this.device.gl, this.handle);
4946
- import_core18.log.timeEnd(3, `RenderPipeline ${this.id} - shaderLayout introspection`)();
4990
+ import_core17.log.timeEnd(3, `RenderPipeline ${this.id} - shaderLayout introspection`)();
4947
4991
  }
4948
4992
  destroy() {
4949
4993
  if (this.destroyed) {
@@ -4958,17 +5002,17 @@ ${source}`;
4958
5002
  const { gl } = this.device;
4959
5003
  gl.attachShader(this.handle, this.vs.handle);
4960
5004
  gl.attachShader(this.handle, this.fs.handle);
4961
- import_core18.log.time(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
5005
+ import_core17.log.time(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
4962
5006
  gl.linkProgram(this.handle);
4963
- import_core18.log.timeEnd(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
5007
+ import_core17.log.timeEnd(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
4964
5008
  if (!this.device.features.has("compilation-status-async-webgl")) {
4965
5009
  const status2 = this._getLinkStatus();
4966
5010
  this._reportLinkStatus(status2);
4967
5011
  return;
4968
5012
  }
4969
- import_core18.log.once(1, "RenderPipeline linking is asynchronous")();
5013
+ import_core17.log.once(1, "RenderPipeline linking is asynchronous")();
4970
5014
  await this._waitForLinkComplete();
4971
- import_core18.log.info(2, `RenderPipeline ${this.id} - async linking complete: ${this.linkStatus}`)();
5015
+ import_core17.log.info(2, `RenderPipeline ${this.id} - async linking complete: ${this.linkStatus}`)();
4972
5016
  const status = this._getLinkStatus();
4973
5017
  this._reportLinkStatus(status);
4974
5018
  }
@@ -5091,44 +5135,44 @@ ${source}`;
5091
5135
  device.gl.bindBuffer(36662 /* COPY_READ_BUFFER */, null);
5092
5136
  device.gl.bindBuffer(36663 /* COPY_WRITE_BUFFER */, null);
5093
5137
  }
5094
- function _copyBufferToTexture(device, options) {
5095
- throw new Error("Not implemented");
5138
+ function _copyBufferToTexture(_device, _options) {
5139
+ throw new Error("copyBufferToTexture is not supported in WebGL");
5096
5140
  }
5097
5141
  function _copyTextureToBuffer(device, options) {
5098
5142
  const {
5099
- /** Texture to copy to/from. */
5100
5143
  sourceTexture,
5101
- /** Mip-map level of the texture to copy to/from. (Default 0) */
5102
5144
  mipLevel = 0,
5103
- /** Defines which aspects of the texture to copy to/from. */
5104
5145
  aspect = "all",
5105
- /** Width to copy */
5106
5146
  width = options.sourceTexture.width,
5107
- /** Height to copy */
5108
5147
  height = options.sourceTexture.height,
5109
- depthOrArrayLayers = 0,
5110
- /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
5148
+ depthOrArrayLayers,
5111
5149
  origin = [0, 0, 0],
5112
- /** Destination buffer */
5113
5150
  destinationBuffer,
5114
- /** Offset, in bytes, from the beginning of the buffer to the start of the image data (default 0) */
5115
5151
  byteOffset = 0,
5116
- /**
5117
- * The stride, in bytes, between the beginning of each block row and the subsequent block row.
5118
- * Required if there are multiple block rows (i.e. the copy height or depth is more than one block).
5119
- */
5120
5152
  bytesPerRow,
5121
- /**
5122
- * Number of block rows per single image of the texture.
5123
- * rowsPerImage &times; bytesPerRow is the stride, in bytes, between the beginning of each image of data and the subsequent image.
5124
- * Required if there are multiple images (i.e. the copy depth is more than one).
5125
- */
5126
5153
  rowsPerImage
5127
5154
  } = options;
5155
+ if (sourceTexture instanceof import_core18.Texture) {
5156
+ sourceTexture.readBuffer(
5157
+ {
5158
+ x: origin[0] ?? 0,
5159
+ y: origin[1] ?? 0,
5160
+ z: origin[2] ?? 0,
5161
+ width,
5162
+ height,
5163
+ depthOrArrayLayers,
5164
+ mipLevel,
5165
+ aspect,
5166
+ byteOffset
5167
+ },
5168
+ destinationBuffer
5169
+ );
5170
+ return;
5171
+ }
5128
5172
  if (aspect !== "all") {
5129
5173
  throw new Error("aspect not supported in WebGL");
5130
5174
  }
5131
- if (mipLevel !== 0 || depthOrArrayLayers !== 0 || bytesPerRow || rowsPerImage) {
5175
+ if (mipLevel !== 0 || depthOrArrayLayers !== void 0 || bytesPerRow || rowsPerImage) {
5132
5176
  throw new Error("not implemented");
5133
5177
  }
5134
5178
  const { framebuffer, destroyFramebuffer } = getFramebuffer(sourceTexture);
@@ -5137,7 +5181,7 @@ ${source}`;
5137
5181
  const webglBuffer = destinationBuffer;
5138
5182
  const sourceWidth = width || framebuffer.width;
5139
5183
  const sourceHeight = height || framebuffer.height;
5140
- const colorAttachment0 = (0, import_core19.assertDefined)(framebuffer.colorAttachments[0]);
5184
+ const colorAttachment0 = (0, import_core18.assertDefined)(framebuffer.colorAttachments[0]);
5141
5185
  const sourceParams = getTextureFormatWebGL(colorAttachment0.texture.props.format);
5142
5186
  const sourceFormat = sourceParams.format;
5143
5187
  const sourceType = sourceParams.type;
@@ -5245,7 +5289,7 @@ ${source}`;
5245
5289
  }
5246
5290
  }
5247
5291
  function getFramebuffer(source) {
5248
- if (source instanceof import_core19.Texture) {
5292
+ if (source instanceof import_core18.Texture) {
5249
5293
  const { width, height, id } = source;
5250
5294
  const framebuffer = source.device.createFramebuffer({
5251
5295
  id: `framebuffer-for-${id}`,
@@ -5257,14 +5301,14 @@ ${source}`;
5257
5301
  }
5258
5302
  return { framebuffer: source, destroyFramebuffer: false };
5259
5303
  }
5260
- var import_core19, WEBGLCommandBuffer;
5304
+ var import_core18, WEBGLCommandBuffer;
5261
5305
  var init_webgl_command_buffer = __esm({
5262
5306
  "src/adapter/resources/webgl-command-buffer.ts"() {
5263
5307
  "use strict";
5264
- import_core19 = __toESM(require_core(), 1);
5265
- init_webgl_texture();
5308
+ import_core18 = __toESM(require_core(), 1);
5266
5309
  init_webgl_texture_table();
5267
- WEBGLCommandBuffer = class extends import_core19.CommandBuffer {
5310
+ init_webgl_texture();
5311
+ WEBGLCommandBuffer = class extends import_core18.CommandBuffer {
5268
5312
  device;
5269
5313
  handle = null;
5270
5314
  commands = [];
@@ -5297,15 +5341,15 @@ ${source}`;
5297
5341
  });
5298
5342
 
5299
5343
  // src/adapter/resources/webgl-render-pass.ts
5300
- var import_core20, COLOR_CHANNELS, WEBGLRenderPass;
5344
+ var import_core19, COLOR_CHANNELS, WEBGLRenderPass;
5301
5345
  var init_webgl_render_pass = __esm({
5302
5346
  "src/adapter/resources/webgl-render-pass.ts"() {
5303
5347
  "use strict";
5304
- import_core20 = __toESM(require_core(), 1);
5348
+ import_core19 = __toESM(require_core(), 1);
5305
5349
  init_with_parameters();
5306
5350
  init_unified_parameter_api();
5307
5351
  COLOR_CHANNELS = [1, 2, 4, 8];
5308
- WEBGLRenderPass = class extends import_core20.RenderPass {
5352
+ WEBGLRenderPass = class extends import_core19.RenderPass {
5309
5353
  device;
5310
5354
  handle = null;
5311
5355
  /** Parameters that should be applied before each draw call */
@@ -5313,13 +5357,15 @@ ${source}`;
5313
5357
  constructor(device, props) {
5314
5358
  super(device, props);
5315
5359
  this.device = device;
5316
- if (!props?.framebuffer) {
5360
+ const webglFramebuffer = this.props.framebuffer;
5361
+ const isDefaultFramebuffer = !webglFramebuffer || webglFramebuffer.handle === null;
5362
+ if (isDefaultFramebuffer) {
5317
5363
  device.getDefaultCanvasContext()._resizeDrawingBufferIfNeeded();
5318
5364
  }
5319
5365
  let viewport;
5320
5366
  if (!props?.parameters?.viewport) {
5321
- if (props?.framebuffer) {
5322
- const { width, height } = props.framebuffer;
5367
+ if (!isDefaultFramebuffer) {
5368
+ const { width, height } = webglFramebuffer;
5323
5369
  viewport = [0, 0, width, height];
5324
5370
  } else {
5325
5371
  const [width, height] = device.getDefaultCanvasContext().getDrawingBufferSize();
@@ -5328,13 +5374,10 @@ ${source}`;
5328
5374
  }
5329
5375
  this.device.pushState();
5330
5376
  this.setParameters({ viewport, ...this.props.parameters });
5331
- const webglFramebuffer = this.props.framebuffer;
5332
- if (this.props.framebuffer && webglFramebuffer?.handle) {
5333
- const drawBuffers = this.props.framebuffer.colorAttachments.map(
5334
- (_, i) => 36064 /* COLOR_ATTACHMENT0 */ + i
5335
- );
5377
+ if (!isDefaultFramebuffer) {
5378
+ const drawBuffers = webglFramebuffer.colorAttachments.map((_, i) => 36064 /* COLOR_ATTACHMENT0 */ + i);
5336
5379
  this.device.gl.drawBuffers(drawBuffers);
5337
- } else if (!this.props.framebuffer) {
5380
+ } else {
5338
5381
  this.device.gl.drawBuffers([1029 /* BACK */]);
5339
5382
  }
5340
5383
  this.clear();
@@ -5494,14 +5537,14 @@ ${source}`;
5494
5537
  });
5495
5538
 
5496
5539
  // src/adapter/resources/webgl-command-encoder.ts
5497
- var import_core21, WEBGLCommandEncoder;
5540
+ var import_core20, WEBGLCommandEncoder;
5498
5541
  var init_webgl_command_encoder = __esm({
5499
5542
  "src/adapter/resources/webgl-command-encoder.ts"() {
5500
5543
  "use strict";
5501
- import_core21 = __toESM(require_core(), 1);
5544
+ import_core20 = __toESM(require_core(), 1);
5502
5545
  init_webgl_command_buffer();
5503
5546
  init_webgl_render_pass();
5504
- WEBGLCommandEncoder = class extends import_core21.CommandEncoder {
5547
+ WEBGLCommandEncoder = class extends import_core20.CommandEncoder {
5505
5548
  device;
5506
5549
  handle = null;
5507
5550
  commandBuffer;
@@ -5550,7 +5593,8 @@ ${source}`;
5550
5593
  }
5551
5594
  insertDebugMarker(markerLabel) {
5552
5595
  }
5553
- resolveQuerySet(querySet, destination, options) {
5596
+ resolveQuerySet(_querySet, _destination, _options) {
5597
+ throw new Error("resolveQuerySet is not supported in WebGL");
5554
5598
  }
5555
5599
  writeTimestamp(querySet, queryIndex) {
5556
5600
  const webglQuerySet = querySet;
@@ -5604,15 +5648,15 @@ ${source}`;
5604
5648
  }
5605
5649
  return true;
5606
5650
  }
5607
- var import_core22, WEBGLVertexArray;
5651
+ var import_core21, WEBGLVertexArray;
5608
5652
  var init_webgl_vertex_array = __esm({
5609
5653
  "src/adapter/resources/webgl-vertex-array.ts"() {
5610
5654
  "use strict";
5611
- import_core22 = __toESM(require_core(), 1);
5655
+ import_core21 = __toESM(require_core(), 1);
5612
5656
  init_dist();
5613
5657
  init_webgl_vertex_formats();
5614
5658
  init_fill_array();
5615
- WEBGLVertexArray = class extends import_core22.VertexArray {
5659
+ WEBGLVertexArray = class extends import_core21.VertexArray {
5616
5660
  get [Symbol.toStringTag]() {
5617
5661
  return "VertexArray";
5618
5662
  }
@@ -5780,7 +5824,7 @@ ${source}`;
5780
5824
  this.buffer = this.buffer || this.device.createBuffer({ byteLength });
5781
5825
  updateNeeded ||= !compareConstantArrayValues(constantValue, this.bufferValue);
5782
5826
  if (updateNeeded) {
5783
- const typedArray = (0, import_core22.getScratchArray)(value.constructor, length);
5827
+ const typedArray = (0, import_core21.getScratchArray)(value.constructor, length);
5784
5828
  fillArray({ target: typedArray, source: constantValue, start: 0, count: length });
5785
5829
  this.buffer.write(typedArray);
5786
5830
  this.bufferValue = value;
@@ -5798,14 +5842,14 @@ ${source}`;
5798
5842
  }
5799
5843
  return /^\d+$/.test(value);
5800
5844
  }
5801
- var import_core23, WEBGLTransformFeedback;
5845
+ var import_core22, WEBGLTransformFeedback;
5802
5846
  var init_webgl_transform_feedback = __esm({
5803
5847
  "src/adapter/resources/webgl-transform-feedback.ts"() {
5804
5848
  "use strict";
5805
- import_core23 = __toESM(require_core(), 1);
5806
- init_src2();
5849
+ import_core22 = __toESM(require_core(), 1);
5850
+ init_src();
5807
5851
  init_webgl_topology_utils();
5808
- WEBGLTransformFeedback = class extends import_core23.TransformFeedback {
5852
+ WEBGLTransformFeedback = class extends import_core22.TransformFeedback {
5809
5853
  device;
5810
5854
  gl;
5811
5855
  handle;
@@ -5868,7 +5912,7 @@ ${source}`;
5868
5912
  const { buffer, byteLength, byteOffset } = this._getBufferRange(bufferOrRange);
5869
5913
  if (location < 0) {
5870
5914
  this.unusedBuffers[locationOrName] = buffer;
5871
- import_core23.log.warn(`${this.id} unusedBuffers varying buffer ${locationOrName}`)();
5915
+ import_core22.log.warn(`${this.id} unusedBuffers varying buffer ${locationOrName}`)();
5872
5916
  return;
5873
5917
  }
5874
5918
  this.buffers[location] = { buffer, byteLength, byteOffset };
@@ -5951,15 +5995,16 @@ ${source}`;
5951
5995
  });
5952
5996
 
5953
5997
  // src/adapter/resources/webgl-query-set.ts
5954
- var import_core24, WEBGLQuerySet;
5998
+ var import_core23, WEBGLQuerySet;
5955
5999
  var init_webgl_query_set = __esm({
5956
6000
  "src/adapter/resources/webgl-query-set.ts"() {
5957
6001
  "use strict";
5958
- import_core24 = __toESM(require_core(), 1);
5959
- WEBGLQuerySet = class extends import_core24.QuerySet {
6002
+ import_core23 = __toESM(require_core(), 1);
6003
+ WEBGLQuerySet = class extends import_core23.QuerySet {
5960
6004
  device;
5961
6005
  handle;
5962
6006
  _timestampPairs = [];
6007
+ _pendingReads = /* @__PURE__ */ new Set();
5963
6008
  _occlusionQuery = null;
5964
6009
  _occlusionActive = false;
5965
6010
  get [Symbol.toStringTag]() {
@@ -5995,15 +6040,21 @@ ${source}`;
5995
6040
  }
5996
6041
  for (const pair of this._timestampPairs) {
5997
6042
  if (pair.activeQuery) {
6043
+ this._cancelPendingQuery(pair.activeQuery);
5998
6044
  this.device.gl.deleteQuery(pair.activeQuery.handle);
5999
6045
  }
6000
6046
  for (const query of pair.completedQueries) {
6047
+ this._cancelPendingQuery(query);
6001
6048
  this.device.gl.deleteQuery(query.handle);
6002
6049
  }
6003
6050
  }
6004
6051
  if (this._occlusionQuery) {
6052
+ this._cancelPendingQuery(this._occlusionQuery);
6005
6053
  this.device.gl.deleteQuery(this._occlusionQuery.handle);
6006
6054
  }
6055
+ for (const query of Array.from(this._pendingReads)) {
6056
+ this._cancelPendingQuery(query);
6057
+ }
6007
6058
  this.destroyResource();
6008
6059
  }
6009
6060
  isResultAvailable(queryIndex) {
@@ -6074,7 +6125,11 @@ ${source}`;
6074
6125
  handle: this.handle,
6075
6126
  promise: null,
6076
6127
  result: null,
6077
- disjoint: false
6128
+ disjoint: false,
6129
+ cancelled: false,
6130
+ pollRequestId: null,
6131
+ resolve: null,
6132
+ reject: null
6078
6133
  };
6079
6134
  this._occlusionActive = true;
6080
6135
  }
@@ -6103,7 +6158,11 @@ ${source}`;
6103
6158
  handle,
6104
6159
  promise: null,
6105
6160
  result: null,
6106
- disjoint: false
6161
+ disjoint: false,
6162
+ cancelled: false,
6163
+ pollRequestId: null,
6164
+ resolve: null,
6165
+ reject: null
6107
6166
  };
6108
6167
  this.device.gl.beginQuery(35007 /* TIME_ELAPSED_EXT */, handle);
6109
6168
  pair.activeQuery = query;
@@ -6135,6 +6194,10 @@ ${source}`;
6135
6194
  return this._pollQueryAvailability(pair.completedQueries[0]);
6136
6195
  }
6137
6196
  _pollQueryAvailability(query) {
6197
+ if (query.cancelled || this.destroyed) {
6198
+ query.result = 0n;
6199
+ return true;
6200
+ }
6138
6201
  if (query.result !== null || query.disjoint) {
6139
6202
  return true;
6140
6203
  }
@@ -6166,13 +6229,28 @@ ${source}`;
6166
6229
  if (query.promise) {
6167
6230
  return query.promise;
6168
6231
  }
6232
+ this._pendingReads.add(query);
6169
6233
  query.promise = new Promise((resolve, reject) => {
6234
+ query.resolve = resolve;
6235
+ query.reject = reject;
6170
6236
  const poll = () => {
6237
+ query.pollRequestId = null;
6238
+ if (query.cancelled || this.destroyed) {
6239
+ this._pendingReads.delete(query);
6240
+ query.promise = null;
6241
+ query.resolve = null;
6242
+ query.reject = null;
6243
+ resolve(0n);
6244
+ return;
6245
+ }
6171
6246
  if (!this._pollQueryAvailability(query)) {
6172
- requestAnimationFrame(poll);
6247
+ query.pollRequestId = this._requestAnimationFrame(poll);
6173
6248
  return;
6174
6249
  }
6250
+ this._pendingReads.delete(query);
6175
6251
  query.promise = null;
6252
+ query.resolve = null;
6253
+ query.reject = null;
6176
6254
  if (query.disjoint) {
6177
6255
  reject(new Error("GPU timestamp query was invalidated by a disjoint event"));
6178
6256
  } else {
@@ -6183,17 +6261,38 @@ ${source}`;
6183
6261
  });
6184
6262
  return query.promise;
6185
6263
  }
6264
+ _cancelPendingQuery(query) {
6265
+ this._pendingReads.delete(query);
6266
+ query.cancelled = true;
6267
+ if (query.pollRequestId !== null) {
6268
+ this._cancelAnimationFrame(query.pollRequestId);
6269
+ query.pollRequestId = null;
6270
+ }
6271
+ if (query.resolve) {
6272
+ const resolve = query.resolve;
6273
+ query.promise = null;
6274
+ query.resolve = null;
6275
+ query.reject = null;
6276
+ resolve(0n);
6277
+ }
6278
+ }
6279
+ _requestAnimationFrame(callback) {
6280
+ return requestAnimationFrame(callback);
6281
+ }
6282
+ _cancelAnimationFrame(requestId) {
6283
+ cancelAnimationFrame(requestId);
6284
+ }
6186
6285
  };
6187
6286
  }
6188
6287
  });
6189
6288
 
6190
6289
  // src/adapter/resources/webgl-fence.ts
6191
- var import_core25, WEBGLFence;
6290
+ var import_core24, WEBGLFence;
6192
6291
  var init_webgl_fence = __esm({
6193
6292
  "src/adapter/resources/webgl-fence.ts"() {
6194
6293
  "use strict";
6195
- import_core25 = __toESM(require_core(), 1);
6196
- WEBGLFence = class extends import_core25.Fence {
6294
+ import_core24 = __toESM(require_core(), 1);
6295
+ WEBGLFence = class extends import_core24.Fence {
6197
6296
  device;
6198
6297
  gl;
6199
6298
  handle;
@@ -6313,7 +6412,7 @@ ${source}`;
6313
6412
  sourceFormat ||= texture?.glFormat || 6408 /* RGBA */;
6314
6413
  sourceType ||= texture?.glType || 5121 /* UNSIGNED_BYTE */;
6315
6414
  target2 = getPixelArray(target2, sourceType, sourceFormat, sourceWidth, sourceHeight, sourceDepth);
6316
- const signedType = (0, import_core26.getDataType)(target2);
6415
+ const signedType = import_core25.dataTypeDecoder.getDataType(target2);
6317
6416
  sourceType = sourceType || convertDataTypeToGLDataType(signedType);
6318
6417
  const prevHandle = gl.bindFramebuffer(
6319
6418
  36160 /* FRAMEBUFFER */,
@@ -6365,7 +6464,7 @@ ${source}`;
6365
6464
  return webglBufferTarget;
6366
6465
  }
6367
6466
  function getFramebuffer2(source) {
6368
- if (!(source instanceof import_core26.Framebuffer)) {
6467
+ if (!(source instanceof import_core25.Framebuffer)) {
6369
6468
  return { framebuffer: toFramebuffer(source), deleteFramebuffer: true };
6370
6469
  }
6371
6470
  return { framebuffer: source, deleteFramebuffer: false };
@@ -6387,15 +6486,15 @@ ${source}`;
6387
6486
  }
6388
6487
  glType ||= 5121 /* UNSIGNED_BYTE */;
6389
6488
  const shaderType = convertGLDataTypeToDataType(glType);
6390
- const ArrayType = (0, import_core26.getTypedArrayConstructor)(shaderType);
6489
+ const ArrayType = import_core25.dataTypeDecoder.getTypedArrayConstructor(shaderType);
6391
6490
  const components = glFormatToComponents(glFormat);
6392
6491
  return new ArrayType(width * height * components);
6393
6492
  }
6394
- var import_core26;
6493
+ var import_core25;
6395
6494
  var init_webgl_texture_utils = __esm({
6396
6495
  "src/adapter/helpers/webgl-texture-utils.ts"() {
6397
6496
  "use strict";
6398
- import_core26 = __toESM(require_core(), 1);
6497
+ import_core25 = __toESM(require_core(), 1);
6399
6498
  init_webgl_shadertypes();
6400
6499
  init_format_utils();
6401
6500
  init_shader_formats();
@@ -6441,11 +6540,11 @@ ${source}`;
6441
6540
  }
6442
6541
  return true;
6443
6542
  }
6444
- var import_core27, WebGLDevice;
6543
+ var import_core26, WebGLDevice;
6445
6544
  var init_webgl_device = __esm({
6446
6545
  "src/adapter/webgl-device.ts"() {
6447
6546
  "use strict";
6448
- import_core27 = __toESM(require_core(), 1);
6547
+ import_core26 = __toESM(require_core(), 1);
6449
6548
  init_webgl_state_tracker();
6450
6549
  init_create_browser_context();
6451
6550
  init_webgl_context_data();
@@ -6474,7 +6573,7 @@ ${source}`;
6474
6573
  init_unified_parameter_api();
6475
6574
  init_with_parameters();
6476
6575
  init_webgl_extensions();
6477
- WebGLDevice = class extends import_core27.Device {
6576
+ WebGLDevice = class extends import_core26.Device {
6478
6577
  static getDeviceFromContext(gl) {
6479
6578
  if (!gl) {
6480
6579
  return null;
@@ -6525,7 +6624,7 @@ ${source}`;
6525
6624
  }
6526
6625
  constructor(props) {
6527
6626
  super({ ...props, id: props.id || uid("webgl-device") });
6528
- const canvasContextProps = import_core27.Device._getCanvasContextProps(props);
6627
+ const canvasContextProps = import_core26.Device._getCanvasContextProps(props);
6529
6628
  if (!canvasContextProps) {
6530
6629
  throw new Error("WebGLDevice requires props.createCanvasContext to be set");
6531
6630
  }
@@ -6567,7 +6666,7 @@ ${source}`;
6567
6666
  device = WebGLDevice.getDeviceFromContext(gl);
6568
6667
  if (device) {
6569
6668
  if (props._reuseDevices) {
6570
- import_core27.log.log(
6669
+ import_core26.log.log(
6571
6670
  1,
6572
6671
  `Not creating a new Device, instead returning a reference to Device ${device.id} already attached to WebGL context`,
6573
6672
  device
@@ -6591,15 +6690,15 @@ ${source}`;
6591
6690
  this.features.initializeFeatures();
6592
6691
  }
6593
6692
  const glState = new WebGLStateTracker(this.gl, {
6594
- log: (...args) => import_core27.log.log(1, ...args)()
6693
+ log: (...args) => import_core26.log.log(1, ...args)()
6595
6694
  });
6596
6695
  glState.trackState(this.gl, { copyState: false });
6597
6696
  if (props.debug || props.debugWebGL) {
6598
6697
  this.gl = makeDebugContext(this.gl, { debugWebGL: true, traceWebGL: props.debugWebGL });
6599
- import_core27.log.warn("WebGL debug mode activated. Performance reduced.")();
6698
+ import_core26.log.warn("WebGL debug mode activated. Performance reduced.")();
6600
6699
  }
6601
6700
  if (props.debugWebGL) {
6602
- import_core27.log.level = Math.max(import_core27.log.level, 1);
6701
+ import_core26.log.level = Math.max(import_core26.log.level, 1);
6603
6702
  }
6604
6703
  this.commandEncoder = new WEBGLCommandEncoder(this, { id: `${this}-command-encoder` });
6605
6704
  this.canvasContext._startObservers();
@@ -6685,13 +6784,7 @@ ${source}`;
6685
6784
  submit(commandBuffer) {
6686
6785
  let submittedCommandEncoder = null;
6687
6786
  if (!commandBuffer) {
6688
- submittedCommandEncoder = this.commandEncoder;
6689
- commandBuffer = submittedCommandEncoder.finish();
6690
- this.commandEncoder.destroy();
6691
- this.commandEncoder = this.createCommandEncoder({
6692
- id: submittedCommandEncoder.props.id,
6693
- timeProfilingQuerySet: submittedCommandEncoder.getTimeProfilingQuerySet()
6694
- });
6787
+ ({ submittedCommandEncoder, commandBuffer } = this._finalizeDefaultCommandEncoderForSubmit());
6695
6788
  }
6696
6789
  try {
6697
6790
  commandBuffer._executeCommands();
@@ -6705,6 +6798,16 @@ ${source}`;
6705
6798
  commandBuffer.destroy();
6706
6799
  }
6707
6800
  }
6801
+ _finalizeDefaultCommandEncoderForSubmit() {
6802
+ const submittedCommandEncoder = this.commandEncoder;
6803
+ const commandBuffer = submittedCommandEncoder.finish();
6804
+ this.commandEncoder.destroy();
6805
+ this.commandEncoder = this.createCommandEncoder({
6806
+ id: submittedCommandEncoder.props.id,
6807
+ timeProfilingQuerySet: submittedCommandEncoder.getTimeProfilingQuerySet()
6808
+ });
6809
+ return { submittedCommandEncoder, commandBuffer };
6810
+ }
6708
6811
  //
6709
6812
  // TEMPORARY HACKS - will be removed in v9.1
6710
6813
  //
@@ -6726,7 +6829,7 @@ ${source}`;
6726
6829
  return withGLParameters(this.gl, parameters, func);
6727
6830
  }
6728
6831
  resetWebGL() {
6729
- import_core27.log.warn("WebGLDevice.resetWebGL is deprecated, use only for debugging")();
6832
+ import_core26.log.warn("WebGLDevice.resetWebGL is deprecated, use only for debugging")();
6730
6833
  resetGLParameters(this.gl);
6731
6834
  }
6732
6835
  _getDeviceSpecificTextureFormatCapabilities(capabilities) {
@@ -6798,7 +6901,7 @@ ${source}`;
6798
6901
  this._constants = this._constants || new Array(maxVertexAttributes).fill(null);
6799
6902
  const currentConstant = this._constants[location];
6800
6903
  if (currentConstant && compareConstantArrayValues2(currentConstant, constant)) {
6801
- import_core27.log.info(
6904
+ import_core26.log.info(
6802
6905
  1,
6803
6906
  `setConstantAttributeWebGL(${location}) could have been skipped, value unchanged`
6804
6907
  )();
@@ -6844,21 +6947,21 @@ ${source}`;
6844
6947
  }
6845
6948
  return Boolean(gl && typeof gl.createVertexArray === "function");
6846
6949
  }
6847
- var import_core28, LOG_LEVEL2, WebGLAdapter, webgl2Adapter;
6950
+ var import_core27, LOG_LEVEL2, WebGLAdapter, webgl2Adapter;
6848
6951
  var init_webgl_adapter = __esm({
6849
6952
  "src/adapter/webgl-adapter.ts"() {
6850
6953
  "use strict";
6851
- import_core28 = __toESM(require_core(), 1);
6954
+ import_core27 = __toESM(require_core(), 1);
6852
6955
  init_polyfill_webgl1_extensions();
6853
6956
  init_spector();
6854
6957
  init_webgl_developer_tools();
6855
6958
  LOG_LEVEL2 = 1;
6856
- WebGLAdapter = class extends import_core28.Adapter {
6959
+ WebGLAdapter = class extends import_core27.Adapter {
6857
6960
  /** type of device's created by this adapter */
6858
6961
  type = "webgl";
6859
6962
  constructor() {
6860
6963
  super();
6861
- import_core28.Device.defaultProps = { ...import_core28.Device.defaultProps, ...DEFAULT_SPECTOR_PROPS };
6964
+ import_core27.Device.defaultProps = { ...import_core27.Device.defaultProps, ...DEFAULT_SPECTOR_PROPS };
6862
6965
  }
6863
6966
  /** Force any created WebGL contexts to be WebGL2 contexts, polyfilled with WebGL1 extensions */
6864
6967
  enforceWebGL2(enable2) {
@@ -6873,7 +6976,7 @@ ${source}`;
6873
6976
  return true;
6874
6977
  }
6875
6978
  if (typeof WebGLRenderingContext !== "undefined" && handle instanceof WebGLRenderingContext) {
6876
- import_core28.log.warn("WebGL1 is not supported", handle)();
6979
+ import_core27.log.warn("WebGL1 is not supported", handle)();
6877
6980
  }
6878
6981
  return false;
6879
6982
  }
@@ -6915,19 +7018,19 @@ ${source}`;
6915
7018
  const results = await Promise.allSettled(promises);
6916
7019
  for (const result of results) {
6917
7020
  if (result.status === "rejected") {
6918
- import_core28.log.error(`Failed to initialize debug libraries ${result.reason}`)();
7021
+ import_core27.log.error(`Failed to initialize debug libraries ${result.reason}`)();
6919
7022
  }
6920
7023
  }
6921
7024
  try {
6922
7025
  const device = new WebGLDevice2(props);
6923
- import_core28.log.groupCollapsed(LOG_LEVEL2, `WebGLDevice ${device.id} created`)();
7026
+ import_core27.log.groupCollapsed(LOG_LEVEL2, `WebGLDevice ${device.id} created`)();
6924
7027
  const message2 = `${device._reused ? "Reusing" : "Created"} device with WebGL2 ${device.props.debug ? "debug " : ""}context: ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
6925
- import_core28.log.probe(LOG_LEVEL2, message2)();
6926
- import_core28.log.table(LOG_LEVEL2, device.info)();
7028
+ import_core27.log.probe(LOG_LEVEL2, message2)();
7029
+ import_core27.log.table(LOG_LEVEL2, device.info)();
6927
7030
  return device;
6928
7031
  } finally {
6929
- import_core28.log.groupEnd(LOG_LEVEL2)();
6930
- import_core28.log.info(
7032
+ import_core27.log.groupEnd(LOG_LEVEL2)();
7033
+ import_core27.log.info(
6931
7034
  LOG_LEVEL2,
6932
7035
  `%cWebGL call tracing: luma.log.set('debug-webgl') `,
6933
7036
  "color: white; background: blue; padding: 2px 6px; border-radius: 3px;"
@@ -6940,9 +7043,10 @@ ${source}`;
6940
7043
  });
6941
7044
 
6942
7045
  // src/index.ts
6943
- var init_src2 = __esm({
7046
+ var init_src = __esm({
6944
7047
  "src/index.ts"() {
6945
7048
  "use strict";
7049
+ init_webgl_constants();
6946
7050
  init_webgl_adapter();
6947
7051
  init_webgl_device();
6948
7052
  init_webgl_canvas_context();
@@ -6968,6 +7072,7 @@ ${source}`;
6968
7072
  // bundle.ts
6969
7073
  var bundle_exports = {};
6970
7074
  __export(bundle_exports, {
7075
+ GL: () => GLEnum,
6971
7076
  WEBGLBuffer: () => WEBGLBuffer,
6972
7077
  WEBGLCommandEncoder: () => WEBGLCommandEncoder,
6973
7078
  WEBGLFence: () => WEBGLFence,
@@ -6992,7 +7097,7 @@ ${source}`;
6992
7097
  withGLParameters: () => withGLParameters
6993
7098
  });
6994
7099
  __reExport(bundle_exports, __toESM(require_core(), 1));
6995
- init_src2();
7100
+ init_src();
6996
7101
  return __toCommonJS(bundle_exports);
6997
7102
  })();
6998
7103
  return __exports__;