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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/LICENSE +34 -0
  2. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  3. package/dist/adapter/converters/device-parameters.js +12 -1
  4. package/dist/adapter/converters/texture-formats.d.ts +22 -16
  5. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  6. package/dist/adapter/converters/texture-formats.js +31 -32
  7. package/dist/adapter/device-helpers/webgl-device-features.js +1 -1
  8. package/dist/adapter/device-helpers/webgl-device-limits.js +1 -1
  9. package/dist/adapter/helpers/webgl-texture-utils.d.ts +300 -0
  10. package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -0
  11. package/dist/adapter/helpers/webgl-texture-utils.js +368 -0
  12. package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
  13. package/dist/adapter/helpers/webgl-topology-utils.js +0 -4
  14. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  15. package/dist/adapter/resources/webgl-buffer.js +2 -2
  16. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  17. package/dist/adapter/resources/webgl-command-buffer.js +6 -9
  18. package/dist/adapter/resources/webgl-framebuffer.d.ts +32 -5
  19. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  20. package/dist/adapter/resources/webgl-framebuffer.js +42 -60
  21. package/dist/adapter/resources/webgl-render-pass.d.ts +3 -2
  22. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  23. package/dist/adapter/resources/webgl-render-pass.js +1 -3
  24. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  25. package/dist/adapter/resources/webgl-render-pipeline.js +45 -20
  26. package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
  27. package/dist/adapter/resources/webgl-shader.js +2 -2
  28. package/dist/adapter/resources/webgl-texture-view.d.ts +1 -1
  29. package/dist/adapter/resources/webgl-texture-view.d.ts.map +1 -1
  30. package/dist/adapter/resources/webgl-texture-view.js +1 -1
  31. package/dist/adapter/resources/webgl-texture.d.ts +58 -172
  32. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  33. package/dist/adapter/resources/webgl-texture.js +402 -510
  34. package/dist/adapter/resources/webgl-transform-feedback.js +1 -1
  35. package/dist/adapter/resources/webgl-vertex-array.d.ts +3 -2
  36. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
  37. package/dist/adapter/resources/webgl-vertex-array.js +5 -2
  38. package/dist/adapter/webgl-canvas-context.d.ts +3 -1
  39. package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
  40. package/dist/adapter/webgl-canvas-context.js +2 -0
  41. package/dist/adapter/webgl-device.d.ts +4 -3
  42. package/dist/adapter/webgl-device.d.ts.map +1 -1
  43. package/dist/adapter/webgl-device.js +6 -5
  44. package/dist/classic/accessor.d.ts +22 -1
  45. package/dist/classic/accessor.d.ts.map +1 -1
  46. package/dist/classic/accessor.js +1 -9
  47. package/dist/classic/clear.d.ts.map +1 -1
  48. package/dist/classic/clear.js +2 -5
  49. package/dist/classic/copy-and-blit.d.ts +2 -1
  50. package/dist/classic/copy-and-blit.d.ts.map +1 -1
  51. package/dist/classic/copy-and-blit.js +11 -9
  52. package/dist/classic/format-utils.d.ts.map +1 -1
  53. package/dist/classic/format-utils.js +0 -3
  54. package/dist/classic/typed-array-utils.d.ts +1 -1
  55. package/dist/classic/typed-array-utils.d.ts.map +1 -1
  56. package/dist/context/debug/spector.d.ts.map +1 -1
  57. package/dist/context/debug/spector.js +2 -1
  58. package/dist/context/debug/webgl-developer-tools.d.ts +1 -1
  59. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  60. package/dist/context/debug/webgl-developer-tools.js +2 -5
  61. package/dist/context/parameters/webgl-parameter-tables.js +1 -1
  62. package/dist/context/state-tracker/track-context-state.d.ts.map +1 -1
  63. package/dist/context/state-tracker/track-context-state.js +5 -6
  64. package/dist/dist.dev.js +872 -1262
  65. package/dist/dist.min.js +2 -2
  66. package/dist/index.cjs +861 -1138
  67. package/dist/index.cjs.map +4 -4
  68. package/dist/index.d.ts +0 -4
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +0 -3
  71. package/dist/utils/fill-array.d.ts +8 -0
  72. package/dist/utils/fill-array.d.ts.map +1 -0
  73. package/dist/utils/fill-array.js +26 -0
  74. package/dist/utils/load-script.d.ts +8 -0
  75. package/dist/utils/load-script.d.ts.map +1 -0
  76. package/dist/utils/load-script.js +26 -0
  77. package/dist/utils/split-uniforms-and-bindings.d.ts +9 -0
  78. package/dist/utils/split-uniforms-and-bindings.d.ts.map +1 -0
  79. package/dist/utils/split-uniforms-and-bindings.js +20 -0
  80. package/package.json +6 -5
  81. package/src/adapter/converters/device-parameters.ts +13 -1
  82. package/src/adapter/converters/texture-formats.ts +45 -42
  83. package/src/adapter/device-helpers/webgl-device-features.ts +1 -1
  84. package/src/adapter/device-helpers/webgl-device-limits.ts +1 -1
  85. package/src/adapter/helpers/webgl-texture-utils.ts +481 -0
  86. package/src/adapter/helpers/webgl-topology-utils.ts +0 -4
  87. package/src/adapter/resources/webgl-buffer.ts +2 -2
  88. package/src/adapter/resources/webgl-command-buffer.ts +8 -10
  89. package/src/adapter/resources/webgl-framebuffer.ts +22 -56
  90. package/src/adapter/resources/webgl-render-pass.ts +4 -5
  91. package/src/adapter/resources/webgl-render-pipeline.ts +48 -23
  92. package/src/adapter/resources/webgl-shader.ts +3 -3
  93. package/src/adapter/resources/webgl-texture-view.ts +1 -3
  94. package/src/adapter/resources/webgl-texture.ts +432 -784
  95. package/src/adapter/resources/webgl-transform-feedback.ts +1 -1
  96. package/src/adapter/resources/webgl-vertex-array.ts +11 -7
  97. package/src/adapter/webgl-canvas-context.ts +4 -1
  98. package/src/adapter/webgl-device.ts +10 -18
  99. package/src/classic/accessor.ts +31 -11
  100. package/src/classic/clear.ts +3 -6
  101. package/src/classic/copy-and-blit.ts +19 -19
  102. package/src/classic/format-utils.ts +0 -3
  103. package/src/classic/typed-array-utils.ts +1 -1
  104. package/src/context/debug/spector.ts +2 -1
  105. package/src/context/debug/webgl-developer-tools.ts +3 -7
  106. package/src/context/parameters/webgl-parameter-tables.ts +3 -3
  107. package/src/context/state-tracker/track-context-state.ts +5 -6
  108. package/src/index.ts +0 -6
  109. package/src/utils/fill-array.ts +35 -0
  110. package/src/utils/load-script.ts +30 -0
  111. package/src/utils/split-uniforms-and-bindings.ts +31 -0
  112. package/dist/adapter/objects/constants-to-keys.d.ts +0 -3
  113. package/dist/adapter/objects/constants-to-keys.d.ts.map +0 -1
  114. package/dist/adapter/objects/constants-to-keys.js +0 -22
  115. package/dist/adapter/objects/webgl-renderbuffer.d.ts +0 -43
  116. package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +0 -1
  117. package/dist/adapter/objects/webgl-renderbuffer.js +0 -95
  118. package/dist/adapter/objects/webgl-resource.d.ts +0 -32
  119. package/dist/adapter/objects/webgl-resource.d.ts.map +0 -1
  120. package/dist/adapter/objects/webgl-resource.js +0 -114
  121. package/src/adapter/objects/constants-to-keys.ts +0 -27
  122. package/src/adapter/objects/webgl-renderbuffer.ts +0 -132
  123. package/src/adapter/objects/webgl-resource.ts +0 -183
package/dist/index.cjs CHANGED
@@ -30,7 +30,6 @@ __export(dist_exports, {
30
30
  WEBGLFramebuffer: () => WEBGLFramebuffer,
31
31
  WEBGLRenderPass: () => WEBGLRenderPass,
32
32
  WEBGLRenderPipeline: () => WEBGLRenderPipeline,
33
- WEBGLResource: () => WebGLResource,
34
33
  WEBGLSampler: () => WEBGLSampler,
35
34
  WEBGLShader: () => WEBGLShader,
36
35
  WEBGLTexture: () => WEBGLTexture,
@@ -38,10 +37,7 @@ __export(dist_exports, {
38
37
  WEBGLVertexArray: () => WEBGLVertexArray,
39
38
  WebGLCanvasContext: () => WebGLCanvasContext,
40
39
  WebGLDevice: () => WebGLDevice,
41
- WebGLResource: () => WebGLResource,
42
40
  _TEXTURE_FORMATS: () => TEXTURE_FORMATS,
43
- _WEBGLRenderbuffer: () => WEBGLRenderbuffer,
44
- convertGLToTextureFormat: () => convertGLToTextureFormat,
45
41
  getGLParameters: () => getGLParameters,
46
42
  getShaderLayout: () => getShaderLayout,
47
43
  popContextState: () => popContextState,
@@ -56,10 +52,7 @@ __export(dist_exports, {
56
52
  module.exports = __toCommonJS(dist_exports);
57
53
 
58
54
  // dist/adapter/webgl-device.js
59
- var import_core27 = require("@luma.gl/core");
60
-
61
- // dist/context/state-tracker/track-context-state.js
62
- var import_core = require("@luma.gl/core");
55
+ var import_core22 = require("@luma.gl/core");
63
56
 
64
57
  // dist/context/parameters/webgl-parameter-tables.js
65
58
  var import_constants = require("@luma.gl/constants");
@@ -295,7 +288,7 @@ var GL_PARAMETER_SETTERS = {
295
288
  lineWidth: (gl, value) => gl.lineWidth(value),
296
289
  polygonOffsetFill: (gl, value) => value ? gl.enable(32823) : gl.disable(32823),
297
290
  polygonOffset: (gl, value) => gl.polygonOffset(...value),
298
- sampleCoverage: (gl, value) => gl.sampleCoverage(...value),
291
+ sampleCoverage: (gl, value) => gl.sampleCoverage(value[0], value[1] || false),
299
292
  scissorTest: (gl, value) => value ? gl.enable(3089) : gl.disable(3089),
300
293
  scissor: (gl, value) => gl.scissor(...value),
301
294
  stencilTest: (gl, value) => value ? gl.enable(2960) : gl.disable(2960),
@@ -626,7 +619,6 @@ var GLState = class {
626
619
  this.stateStack.push({});
627
620
  }
628
621
  pop() {
629
- (0, import_core.assert)(this.stateStack.length > 0);
630
622
  const oldValues = this.stateStack[this.stateStack.length - 1];
631
623
  setGLParameters(this.gl, oldValues);
632
624
  this.stateStack.pop();
@@ -642,7 +634,6 @@ var GLState = class {
642
634
  let oldValue;
643
635
  const oldValues = this.stateStack.length > 0 ? this.stateStack[this.stateStack.length - 1] : null;
644
636
  for (const key in values) {
645
- (0, import_core.assert)(key !== void 0);
646
637
  const value = values[key];
647
638
  const cached = this.cache[key];
648
639
  if (!deepArrayEqual(value, cached)) {
@@ -661,8 +652,7 @@ function getContextState(gl) {
661
652
  return gl.state;
662
653
  }
663
654
  function trackContextState(gl, options) {
664
- const { enable: enable2 = true, copyState } = options;
665
- (0, import_core.assert)(copyState !== void 0);
655
+ const { enable: enable2 = true, copyState } = options || {};
666
656
  if (!gl.state) {
667
657
  gl.state = new GLState(gl, { copyState });
668
658
  installProgramSpy(gl);
@@ -687,7 +677,6 @@ function pushContextState(gl) {
687
677
  }
688
678
  function popContextState(gl) {
689
679
  const glState = getContextState(gl);
690
- (0, import_core.assert)(glState);
691
680
  glState.pop();
692
681
  }
693
682
  function installGetterOverride(gl, functionName) {
@@ -857,10 +846,10 @@ function identifyGPUType(vendor, renderer) {
857
846
  }
858
847
 
859
848
  // dist/adapter/device-helpers/webgl-device-features.js
860
- var import_core3 = require("@luma.gl/core");
849
+ var import_core2 = require("@luma.gl/core");
861
850
 
862
851
  // dist/adapter/converters/texture-formats.js
863
- var import_core2 = require("@luma.gl/core");
852
+ var import_core = require("@luma.gl/core");
864
853
  var import_constants4 = require("@luma.gl/constants");
865
854
 
866
855
  // dist/adapter/converters/vertex-formats.js
@@ -1005,7 +994,6 @@ var TEXTURE_FORMATS = {
1005
994
  "bgra8unorm-srgb": { b: 4, c: 4 },
1006
995
  "rg16uint": { gl: 33338, b: 4, c: 1, bpp: 4 },
1007
996
  "rg16sint": { gl: 33337, b: 4, c: 2, bpp: 4 },
1008
- // When using a WebGL 2 context and the EXT_color_buffer_float WebGL2 extension
1009
997
  "rg16float": { gl: 33327, bpp: 4, b: 4, c: 2, render: float16_renderable, filter: float16_filterable, rb: true },
1010
998
  "rg16unorm-webgl": { gl: 33324, b: 2, c: 2, render: norm16_renderable },
1011
999
  "rg16snorm-webgl": { gl: 36761, b: 2, c: 2, render: snorm16_renderable },
@@ -1179,31 +1167,6 @@ var TEXTURE_FORMATS = {
1179
1167
  "atc-rgba-unorm-webgl": { gl: 35986, f: texture_compression_atc_webgl },
1180
1168
  "atc-rgbai-unorm-webgl": { gl: 34798, f: texture_compression_atc_webgl }
1181
1169
  };
1182
- var DATA_FORMAT_CHANNELS = {
1183
- [6403]: 1,
1184
- [36244]: 1,
1185
- [33319]: 2,
1186
- [33320]: 2,
1187
- [6407]: 3,
1188
- [36248]: 3,
1189
- [6408]: 4,
1190
- [36249]: 4,
1191
- [6402]: 1,
1192
- [34041]: 1,
1193
- [6406]: 1,
1194
- [6409]: 1,
1195
- [6410]: 2
1196
- };
1197
- var TYPE_SIZES = {
1198
- [5126]: 4,
1199
- [5125]: 4,
1200
- [5124]: 4,
1201
- [5123]: 2,
1202
- [5122]: 2,
1203
- [5131]: 2,
1204
- [5120]: 1,
1205
- [5121]: 1
1206
- };
1207
1170
  function isTextureFormatSupported(gl, format, extensions) {
1208
1171
  const info = TEXTURE_FORMATS[format];
1209
1172
  if (!info) {
@@ -1218,28 +1181,6 @@ function isTextureFormatSupported(gl, format, extensions) {
1218
1181
  }
1219
1182
  return true;
1220
1183
  }
1221
- function isRenderbufferFormatSupported(gl, format, extensions) {
1222
- var _a;
1223
- return isTextureFormatSupported(gl, format, extensions) && ((_a = TEXTURE_FORMATS[format]) == null ? void 0 : _a.rb);
1224
- }
1225
- function convertGLToTextureFormat(format) {
1226
- if (typeof format === "string") {
1227
- return format;
1228
- }
1229
- const entry = Object.entries(TEXTURE_FORMATS).find(([, entry2]) => entry2.gl === format);
1230
- if (!entry) {
1231
- throw new Error(`Unknown texture format ${format}`);
1232
- }
1233
- return entry[0];
1234
- }
1235
- function convertTextureFormatToGL(format) {
1236
- const formatInfo = TEXTURE_FORMATS[format];
1237
- const webglFormat = formatInfo == null ? void 0 : formatInfo.gl;
1238
- if (webglFormat === void 0) {
1239
- throw new Error(`Unsupported texture format ${format}`);
1240
- }
1241
- return webglFormat;
1242
- }
1243
1184
  function isTextureFormatFilterable(gl, format, extensions) {
1244
1185
  if (!isTextureFormatSupported(gl, format, extensions)) {
1245
1186
  return false;
@@ -1248,7 +1189,7 @@ function isTextureFormatFilterable(gl, format, extensions) {
1248
1189
  return false;
1249
1190
  }
1250
1191
  try {
1251
- const decoded = (0, import_core2.decodeTextureFormat)(format);
1192
+ const decoded = (0, import_core.decodeTextureFormat)(format);
1252
1193
  if (decoded.signed) {
1253
1194
  return false;
1254
1195
  }
@@ -1272,14 +1213,14 @@ function isTextureFormatRenderable(gl, format, extensions) {
1272
1213
  }
1273
1214
  return true;
1274
1215
  }
1275
- function getWebGLTextureParameters(format) {
1216
+ function getTextureFormatWebGL(format) {
1276
1217
  var _a;
1277
1218
  const formatData = TEXTURE_FORMATS[format];
1278
1219
  const webglFormat = convertTextureFormatToGL(format);
1279
- const decoded = (0, import_core2.decodeTextureFormat)(format);
1220
+ const decoded = (0, import_core.decodeTextureFormat)(format);
1280
1221
  return {
1281
- format: webglFormat,
1282
- dataFormat: (formatData == null ? void 0 : formatData.dataFormat) || getWebGLPixelDataFormat(decoded.format, decoded.integer, decoded.normalized, webglFormat),
1222
+ internalFormat: webglFormat,
1223
+ format: (formatData == null ? void 0 : formatData.dataFormat) || getWebGLPixelDataFormat(decoded.format, decoded.integer, decoded.normalized, webglFormat),
1283
1224
  // depth formats don't have a type
1284
1225
  type: decoded.dataType ? getGLFromVertexType(decoded.dataType) : ((_a = formatData == null ? void 0 : formatData.types) == null ? void 0 : _a[0]) || 5121,
1285
1226
  // @ts-expect-error
@@ -1293,12 +1234,6 @@ function getDepthStencilAttachmentWebGL(format) {
1293
1234
  }
1294
1235
  return info.attachment;
1295
1236
  }
1296
- function getTextureFormatBytesPerPixel(format) {
1297
- const params = getWebGLTextureParameters(format);
1298
- const channels = DATA_FORMAT_CHANNELS[params.dataFormat] || 4;
1299
- const channelSize = TYPE_SIZES[params.type] || 1;
1300
- return channels * channelSize;
1301
- }
1302
1237
  function getWebGLPixelDataFormat(dataFormat, integer, normalized, format) {
1303
1238
  if (format === 6408 || format === 6407) {
1304
1239
  return format;
@@ -1316,6 +1251,14 @@ function getWebGLPixelDataFormat(dataFormat, integer, normalized, format) {
1316
1251
  return 6408;
1317
1252
  }
1318
1253
  }
1254
+ function convertTextureFormatToGL(format) {
1255
+ const formatInfo = TEXTURE_FORMATS[format];
1256
+ const webglFormat = formatInfo == null ? void 0 : formatInfo.gl;
1257
+ if (webglFormat === void 0) {
1258
+ throw new Error(`Unsupported texture format ${format}`);
1259
+ }
1260
+ return webglFormat;
1261
+ }
1319
1262
 
1320
1263
  // dist/adapter/device-helpers/webgl-device-features.js
1321
1264
  var WEBGL_FEATURES = {
@@ -1337,7 +1280,7 @@ var WEBGL_FEATURES = {
1337
1280
  "shader-conservative-depth-webgl": "EXT_conservative_depth"
1338
1281
  // Textures are handled by getTextureFeatures()
1339
1282
  };
1340
- var WebGLDeviceFeatures = class extends import_core3.DeviceFeatures {
1283
+ var WebGLDeviceFeatures = class extends import_core2.DeviceFeatures {
1341
1284
  gl;
1342
1285
  extensions;
1343
1286
  testedFeatures = /* @__PURE__ */ new Set();
@@ -1357,7 +1300,8 @@ var WebGLDeviceFeatures = class extends import_core3.DeviceFeatures {
1357
1300
  return [];
1358
1301
  }
1359
1302
  has(feature) {
1360
- if (this.disabledFeatures[feature]) {
1303
+ var _a;
1304
+ if ((_a = this.disabledFeatures) == null ? void 0 : _a[feature]) {
1361
1305
  return false;
1362
1306
  }
1363
1307
  if (!this.testedFeatures.has(feature)) {
@@ -1391,9 +1335,9 @@ var WebGLDeviceFeatures = class extends import_core3.DeviceFeatures {
1391
1335
  };
1392
1336
 
1393
1337
  // dist/adapter/device-helpers/webgl-device-limits.js
1394
- var import_core4 = require("@luma.gl/core");
1338
+ var import_core3 = require("@luma.gl/core");
1395
1339
  var import_constants5 = require("@luma.gl/constants");
1396
- var WebGLDeviceLimits = class extends import_core4.DeviceLimits {
1340
+ var WebGLDeviceLimits = class extends import_core3.DeviceLimits {
1397
1341
  get maxTextureDimension1D() {
1398
1342
  return 0;
1399
1343
  }
@@ -1497,19 +1441,19 @@ var WebGLDeviceLimits = class extends import_core4.DeviceLimits {
1497
1441
  if (this.limits[parameter] === void 0) {
1498
1442
  this.limits[parameter] = this.gl.getParameter(parameter);
1499
1443
  }
1500
- return this.limits[parameter];
1444
+ return this.limits[parameter] || 0;
1501
1445
  }
1502
1446
  };
1503
1447
 
1504
1448
  // dist/adapter/webgl-canvas-context.js
1505
- var import_core11 = require("@luma.gl/core");
1449
+ var import_core9 = require("@luma.gl/core");
1506
1450
 
1507
1451
  // dist/adapter/resources/webgl-framebuffer.js
1508
- var import_core10 = require("@luma.gl/core");
1452
+ var import_core8 = require("@luma.gl/core");
1509
1453
  var import_constants11 = require("@luma.gl/constants");
1510
1454
 
1511
1455
  // dist/adapter/resources/webgl-texture.js
1512
- var import_core9 = require("@luma.gl/core");
1456
+ var import_core7 = require("@luma.gl/core");
1513
1457
  var import_constants10 = require("@luma.gl/constants");
1514
1458
 
1515
1459
  // dist/context/state-tracker/with-parameters.js
@@ -1544,10 +1488,10 @@ function isObjectEmpty2(object) {
1544
1488
  var import_constants7 = require("@luma.gl/constants");
1545
1489
 
1546
1490
  // dist/adapter/converters/device-parameters.js
1547
- var import_core5 = require("@luma.gl/core");
1491
+ var import_core4 = require("@luma.gl/core");
1548
1492
  var import_constants6 = require("@luma.gl/constants");
1549
1493
  function withDeviceAndGLParameters(device, parameters, glParameters, func) {
1550
- if ((0, import_core5.isObjectEmpty)(parameters)) {
1494
+ if (isObjectEmpty3(parameters)) {
1551
1495
  return func(device);
1552
1496
  }
1553
1497
  const webglDevice = device;
@@ -1561,7 +1505,7 @@ function withDeviceAndGLParameters(device, parameters, glParameters, func) {
1561
1505
  }
1562
1506
  }
1563
1507
  function withDeviceParameters(device, parameters, func) {
1564
- if ((0, import_core5.isObjectEmpty)(parameters)) {
1508
+ if (isObjectEmpty3(parameters)) {
1565
1509
  return func(device);
1566
1510
  }
1567
1511
  pushContextState(device.gl);
@@ -1672,7 +1616,7 @@ function setDeviceParameters(device, parameters) {
1672
1616
  gl.stencilMaskSeparate(1029, mask);
1673
1617
  }
1674
1618
  if (parameters.stencilReadMask) {
1675
- import_core5.log.warn("stencilReadMask not supported under WebGL");
1619
+ import_core4.log.warn("stencilReadMask not supported under WebGL");
1676
1620
  }
1677
1621
  if (parameters.stencilCompare) {
1678
1622
  const mask = parameters.stencilReadMask || 4294967295;
@@ -1764,6 +1708,14 @@ function map(parameter, value, valueMap) {
1764
1708
  function mapBoolean(parameter, value) {
1765
1709
  return value;
1766
1710
  }
1711
+ function isObjectEmpty3(obj) {
1712
+ let isEmpty = true;
1713
+ for (const key in obj) {
1714
+ isEmpty = false;
1715
+ break;
1716
+ }
1717
+ return isEmpty;
1718
+ }
1767
1719
 
1768
1720
  // dist/adapter/converters/sampler-parameters.js
1769
1721
  function convertSamplerParametersToWebGL(props) {
@@ -1830,136 +1782,10 @@ function convertMinFilterMode(minFilter, mipmapFilter) {
1830
1782
  }
1831
1783
  }
1832
1784
 
1833
- // dist/adapter/resources/webgl-buffer.js
1834
- var import_core6 = require("@luma.gl/core");
1835
- var import_constants8 = require("@luma.gl/constants");
1836
- var WEBGLBuffer = class extends import_core6.Buffer {
1837
- device;
1838
- gl;
1839
- handle;
1840
- /** Target in OpenGL defines the type of buffer */
1841
- glTarget;
1842
- /** Usage is a hint on how frequently the buffer will be updates */
1843
- glUsage;
1844
- /** Index type is needed when issuing draw calls, so we pre-compute it */
1845
- glIndexType = 5123;
1846
- /** Number of bytes allocated on the GPU for this buffer */
1847
- byteLength;
1848
- /** Number of bytes used */
1849
- bytesUsed;
1850
- constructor(device, props = {}) {
1851
- super(device, props);
1852
- this.device = device;
1853
- this.gl = this.device.gl;
1854
- const handle = typeof props === "object" ? props.handle : void 0;
1855
- this.handle = handle || this.gl.createBuffer();
1856
- device.setSpectorMetadata(this.handle, { ...this.props, data: typeof this.props.data });
1857
- this.glTarget = getWebGLTarget(this.props.usage);
1858
- this.glUsage = getWebGLUsage(this.props.usage);
1859
- this.glIndexType = this.props.indexType === "uint32" ? 5125 : 5123;
1860
- if (props.data) {
1861
- this._initWithData(props.data, props.byteOffset, props.byteLength);
1862
- } else {
1863
- this._initWithByteLength(props.byteLength || 0);
1864
- }
1865
- }
1866
- // PRIVATE METHODS
1867
- /** Allocate a new buffer and initialize to contents of typed array */
1868
- _initWithData(data, byteOffset = 0, byteLength = data.byteLength + byteOffset) {
1869
- const glTarget = this.glTarget;
1870
- this.gl.bindBuffer(glTarget, this.handle);
1871
- this.gl.bufferData(glTarget, byteLength, this.glUsage);
1872
- this.gl.bufferSubData(glTarget, byteOffset, data);
1873
- this.gl.bindBuffer(glTarget, null);
1874
- this.bytesUsed = byteLength;
1875
- this.byteLength = byteLength;
1876
- this._setDebugData(data, byteOffset, byteLength);
1877
- this.trackAllocatedMemory(byteLength);
1878
- }
1879
- // Allocate a GPU buffer of specified size.
1880
- _initWithByteLength(byteLength) {
1881
- (0, import_core6.assert)(byteLength >= 0);
1882
- let data = byteLength;
1883
- if (byteLength === 0) {
1884
- data = new Float32Array(0);
1885
- }
1886
- const glTarget = this.glTarget;
1887
- this.gl.bindBuffer(glTarget, this.handle);
1888
- this.gl.bufferData(glTarget, data, this.glUsage);
1889
- this.gl.bindBuffer(glTarget, null);
1890
- this.bytesUsed = byteLength;
1891
- this.byteLength = byteLength;
1892
- this._setDebugData(null, 0, byteLength);
1893
- this.trackAllocatedMemory(byteLength);
1894
- return this;
1895
- }
1896
- destroy() {
1897
- if (!this.destroyed && this.handle) {
1898
- this.removeStats();
1899
- this.trackDeallocatedMemory();
1900
- this.gl.deleteBuffer(this.handle);
1901
- this.destroyed = true;
1902
- this.handle = null;
1903
- }
1904
- }
1905
- write(data, byteOffset = 0) {
1906
- const srcOffset = 0;
1907
- const byteLength = void 0;
1908
- const glTarget = 36663;
1909
- this.gl.bindBuffer(glTarget, this.handle);
1910
- if (srcOffset !== 0 || byteLength !== void 0) {
1911
- this.gl.bufferSubData(glTarget, byteOffset, data, srcOffset, byteLength);
1912
- } else {
1913
- this.gl.bufferSubData(glTarget, byteOffset, data);
1914
- }
1915
- this.gl.bindBuffer(glTarget, null);
1916
- this._setDebugData(data, byteOffset, data.byteLength);
1917
- }
1918
- /** Asynchronously read data from the buffer */
1919
- async readAsync(byteOffset = 0, byteLength) {
1920
- return this.readSyncWebGL(byteOffset, byteLength);
1921
- }
1922
- /** Synchronously read data from the buffer. WebGL only. */
1923
- readSyncWebGL(byteOffset = 0, byteLength) {
1924
- byteLength = byteLength ?? this.byteLength - byteOffset;
1925
- const data = new Uint8Array(byteLength);
1926
- const dstOffset = 0;
1927
- this.gl.bindBuffer(36662, this.handle);
1928
- this.gl.getBufferSubData(36662, byteOffset, data, dstOffset, byteLength);
1929
- this.gl.bindBuffer(36662, null);
1930
- this._setDebugData(data, byteOffset, byteLength);
1931
- return data;
1932
- }
1933
- };
1934
- function getWebGLTarget(usage) {
1935
- if (usage & import_core6.Buffer.INDEX) {
1936
- return 34963;
1937
- }
1938
- if (usage & import_core6.Buffer.VERTEX) {
1939
- return 34962;
1940
- }
1941
- if (usage & import_core6.Buffer.UNIFORM) {
1942
- return 35345;
1943
- }
1944
- return 34962;
1945
- }
1946
- function getWebGLUsage(usage) {
1947
- if (usage & import_core6.Buffer.INDEX) {
1948
- return 35044;
1949
- }
1950
- if (usage & import_core6.Buffer.VERTEX) {
1951
- return 35044;
1952
- }
1953
- if (usage & import_core6.Buffer.UNIFORM) {
1954
- return 35048;
1955
- }
1956
- return 35044;
1957
- }
1958
-
1959
1785
  // dist/adapter/resources/webgl-sampler.js
1960
- var import_core7 = require("@luma.gl/core");
1961
- var import_constants9 = require("@luma.gl/constants");
1962
- var WEBGLSampler = class extends import_core7.Sampler {
1786
+ var import_core5 = require("@luma.gl/core");
1787
+ var import_constants8 = require("@luma.gl/constants");
1788
+ var WEBGLSampler = class extends import_core5.Sampler {
1963
1789
  device;
1964
1790
  handle;
1965
1791
  parameters;
@@ -1997,14 +1823,15 @@ var WEBGLSampler = class extends import_core7.Sampler {
1997
1823
  };
1998
1824
 
1999
1825
  // dist/adapter/resources/webgl-texture-view.js
2000
- var import_core8 = require("@luma.gl/core");
2001
- var WEBGLTextureView = class extends import_core8.TextureView {
1826
+ var import_core6 = require("@luma.gl/core");
1827
+ var WEBGLTextureView = class extends import_core6.TextureView {
2002
1828
  device;
2003
1829
  gl;
2004
1830
  handle;
1831
+ // Does not have a WebGL representation
2005
1832
  texture;
2006
1833
  constructor(device, props) {
2007
- super(device, { ...import_core8.Texture.defaultProps, ...props });
1834
+ super(device, { ...import_core6.Texture.defaultProps, ...props });
2008
1835
  this.device = device;
2009
1836
  this.gl = this.device.gl;
2010
1837
  this.handle = null;
@@ -2012,164 +1839,253 @@ var WEBGLTextureView = class extends import_core8.TextureView {
2012
1839
  }
2013
1840
  };
2014
1841
 
1842
+ // dist/adapter/helpers/webgl-texture-utils.js
1843
+ var import_constants9 = require("@luma.gl/constants");
1844
+ function initializeTextureStorage(gl, levels, options) {
1845
+ const { dimension, width, height, depth = 0 } = options;
1846
+ const { glInternalFormat } = options;
1847
+ const glTarget = options.glTarget;
1848
+ switch (dimension) {
1849
+ case "2d-array":
1850
+ case "3d":
1851
+ gl.texStorage3D(glTarget, levels, glInternalFormat, width, height, depth);
1852
+ break;
1853
+ default:
1854
+ gl.texStorage2D(glTarget, levels, glInternalFormat, width, height);
1855
+ }
1856
+ }
1857
+ function copyCPUImageToMipLevel(gl, image, options) {
1858
+ const { dimension, width, height, depth = 0, level = 0 } = options;
1859
+ const { x = 0, y = 0, z = 0 } = options;
1860
+ const { glFormat, glType } = options;
1861
+ const glTarget = getCubeTargetWebGL(options.glTarget, dimension, depth);
1862
+ switch (dimension) {
1863
+ case "2d-array":
1864
+ case "3d":
1865
+ gl.texSubImage3D(glTarget, level, x, y, z, width, height, depth, glFormat, glType, image);
1866
+ break;
1867
+ case "2d":
1868
+ case "cube":
1869
+ gl.texSubImage2D(glTarget, level, x, y, width, height, glFormat, glType, image);
1870
+ break;
1871
+ default:
1872
+ throw new Error(dimension);
1873
+ }
1874
+ }
1875
+ function copyCPUDataToMipLevel(gl, typedArray, options) {
1876
+ const { dimension, width, height, depth = 0, level = 0, byteOffset = 0 } = options;
1877
+ const { x = 0, y = 0, z = 0 } = options;
1878
+ const { glFormat, glType, compressed } = options;
1879
+ const glTarget = getCubeTargetWebGL(options.glTarget, dimension, depth);
1880
+ switch (dimension) {
1881
+ case "2d-array":
1882
+ case "3d":
1883
+ if (compressed) {
1884
+ gl.compressedTexSubImage3D(glTarget, level, x, y, z, width, height, depth, glFormat, typedArray, byteOffset);
1885
+ } else {
1886
+ gl.texSubImage3D(glTarget, level, x, y, z, width, height, depth, glFormat, glType, typedArray, byteOffset);
1887
+ }
1888
+ break;
1889
+ case "2d":
1890
+ case "cube":
1891
+ if (compressed) {
1892
+ gl.compressedTexSubImage2D(glTarget, level, x, y, width, height, glFormat, typedArray, byteOffset);
1893
+ } else {
1894
+ gl.texSubImage2D(glTarget, level, x, y, width, height, glFormat, glType, typedArray, byteOffset);
1895
+ }
1896
+ break;
1897
+ default:
1898
+ throw new Error(dimension);
1899
+ }
1900
+ }
1901
+ function getWebGLTextureTarget(dimension) {
1902
+ switch (dimension) {
1903
+ case "1d":
1904
+ break;
1905
+ case "2d":
1906
+ return 3553;
1907
+ case "3d":
1908
+ return 32879;
1909
+ case "cube":
1910
+ return 34067;
1911
+ case "2d-array":
1912
+ return 35866;
1913
+ case "cube-array":
1914
+ break;
1915
+ }
1916
+ throw new Error(dimension);
1917
+ }
1918
+ function getCubeTargetWebGL(glTarget, dimension, level) {
1919
+ return dimension === "cube" ? 34069 + level : glTarget;
1920
+ }
1921
+
2015
1922
  // dist/adapter/resources/webgl-texture.js
2016
- var DEFAULT_WEBGL_TEXTURE_PROPS = {
2017
- // deprecated
2018
- parameters: {},
2019
- pixelStore: {},
2020
- pixels: null,
2021
- border: 0,
2022
- dataFormat: void 0,
2023
- textureUnit: void 0,
2024
- target: void 0
2025
- };
2026
- var _WEBGLTexture = class extends import_core9.Texture {
1923
+ function normalizeTextureData(data, options) {
1924
+ let lodArray;
1925
+ if (ArrayBuffer.isView(data)) {
1926
+ lodArray = [
1927
+ {
1928
+ // ts-expect-error does data really need to be Uint8ClampedArray?
1929
+ data,
1930
+ width: options.width,
1931
+ height: options.height
1932
+ // depth: options.depth
1933
+ }
1934
+ ];
1935
+ } else if (!Array.isArray(data)) {
1936
+ lodArray = [data];
1937
+ } else {
1938
+ lodArray = data;
1939
+ }
1940
+ return lodArray;
1941
+ }
1942
+ var WEBGLTexture = class extends import_core7.Texture {
2027
1943
  MAX_ATTRIBUTES;
2028
1944
  device;
2029
1945
  gl;
2030
1946
  handle;
2031
- // (TODO - currently unused in WebGL, but WebGL 2 does support sampler objects) */
2032
1947
  sampler = void 0;
1948
+ // TODO - currently unused in WebGL. Create dummy sampler?
2033
1949
  view = void 0;
2034
- // data;
2035
- glFormat = void 0;
2036
- type = void 0;
2037
- dataFormat = void 0;
2038
- mipmaps = void 0;
1950
+ // TODO - currently unused in WebGL. Create dummy view?
1951
+ mipmaps = false;
2039
1952
  /**
2040
1953
  * @note `target` cannot be modified by bind:
2041
1954
  * textures are special because when you first bind them to a target,
2042
- * they get special information. When you first bind a texture as a
2043
- * GL_TEXTURE_2D, you are saying that this texture is a 2D texture.
1955
+ * When you first bind a texture as a GL_TEXTURE_2D, you are saying that this texture is a 2D texture.
2044
1956
  * And it will always be a 2D texture; this state cannot be changed ever.
2045
1957
  * A texture that was first bound as a GL_TEXTURE_2D, must always be bound as a GL_TEXTURE_2D;
2046
1958
  * attempting to bind it as GL_TEXTURE_3D will give rise to a run-time error
2047
- * */
2048
- target;
2049
- textureUnit = void 0;
2050
- /**
2051
- * Program.draw() checks the loaded flag of all textures to avoid
2052
- * Textures that are still loading from promises
2053
- * Set to true as soon as texture has been initialized with valid data
2054
1959
  */
2055
- loaded = false;
2056
- _video;
1960
+ glTarget;
1961
+ // Texture type
1962
+ /** The WebGL format - essentially channel structure */
1963
+ glFormat;
1964
+ /** The WebGL data format - the type of each channel */
1965
+ glType;
1966
+ /** The WebGL constant corresponding to the WebGPU style constant in format */
1967
+ glInternalFormat;
1968
+ /** Whether the internal format is compressed */
1969
+ compressed;
1970
+ // data;
1971
+ // inherited props
1972
+ // dimension: ...
1973
+ // format: GLTextureTarget;
1974
+ // width: number = undefined;
1975
+ // height: number = undefined;
1976
+ // depth: number = undefined;
1977
+ // state
1978
+ /** Texture binding slot */
1979
+ textureUnit = 0;
1980
+ /** For automatically updating video */
1981
+ _video = null;
2057
1982
  constructor(device, props) {
2058
- var _a;
2059
- super(device, { ...DEFAULT_WEBGL_TEXTURE_PROPS, format: "rgba8unorm", ...props });
1983
+ super(device, { ...import_core7.Texture.defaultProps, ...props, data: void 0 });
2060
1984
  this.device = device;
2061
1985
  this.gl = this.device.gl;
2062
- this.handle = this.props.handle || this.gl.createTexture();
2063
- this.device.setSpectorMetadata(this.handle, { ...this.props, data: typeof this.props.data });
2064
- this.glFormat = 6408;
2065
- this.target = getWebGLTextureTarget(this.props);
2066
- this.loaded = false;
2067
- if (typeof ((_a = this.props) == null ? void 0 : _a.data) === "string") {
2068
- Object.assign(this.props, { data: (0, import_core9.loadImage)(this.props.data) });
1986
+ this.glTarget = getWebGLTextureTarget(this.props.dimension);
1987
+ const format = getTextureFormatWebGL(this.props.format);
1988
+ this.glInternalFormat = format.internalFormat;
1989
+ this.glFormat = format.format;
1990
+ this.glType = format.type;
1991
+ this.compressed = format.compressed;
1992
+ if (typeof HTMLVideoElement !== "undefined" && props.data instanceof HTMLVideoElement && // @ts-expect-error
1993
+ props.data.readyState < HTMLVideoElement.HAVE_METADATA) {
1994
+ const video = props.data;
1995
+ this._video = null;
1996
+ video.addEventListener("loadeddata", () => this.initialize(props));
2069
1997
  }
2070
- this.initialize(this.props);
1998
+ this.initialize({ ...this.props, data: props.data });
2071
1999
  Object.seal(this);
2072
2000
  }
2073
- destroy() {
2074
- if (this.handle) {
2075
- this.gl.deleteTexture(this.handle);
2076
- this.removeStats();
2077
- this.trackDeallocatedMemory("Texture");
2078
- this.destroyed = true;
2079
- }
2080
- }
2081
- toString() {
2082
- return `Texture(${this.id},${this.width}x${this.height})`;
2083
- }
2084
- createView(props) {
2085
- return new WEBGLTextureView(this.device, { ...props, texture: this });
2086
- }
2001
+ /**
2002
+ * Initialize texture with supplied props
2003
+ */
2087
2004
  // eslint-disable-next-line max-statements
2088
2005
  initialize(props = {}) {
2089
- if (this.props.dimension === "cube") {
2090
- return this.initializeCube(props);
2091
- }
2092
- let data = props.data;
2093
- if (data instanceof Promise) {
2094
- data.then((resolvedImageData) => this.initialize(Object.assign({}, props, {
2095
- pixels: resolvedImageData,
2096
- data: resolvedImageData
2097
- })));
2098
- return this;
2099
- }
2100
- const isVideo = typeof HTMLVideoElement !== "undefined" && data instanceof HTMLVideoElement;
2101
- if (isVideo && data.readyState < HTMLVideoElement.HAVE_METADATA) {
2102
- this._video = null;
2103
- data.addEventListener("loadeddata", () => this.initialize(props));
2104
- return this;
2105
- }
2106
- const { parameters = {} } = props;
2107
- const { pixels = null, pixelStore = {}, textureUnit = void 0, mipmaps = true } = props;
2108
- if (!data) {
2109
- data = pixels;
2006
+ this.handle = this.props.handle || this.gl.createTexture();
2007
+ this.device.setSpectorMetadata(this.handle, { ...this.props, data: typeof this.props.data });
2008
+ const data = props.data;
2009
+ let { width, height } = props;
2010
+ if (!width || !height) {
2011
+ const textureSize = this.getTextureDataSize(data);
2012
+ width = (textureSize == null ? void 0 : textureSize.width) || 1;
2013
+ height = (textureSize == null ? void 0 : textureSize.height) || 1;
2110
2014
  }
2111
- let { width, height, dataFormat, type, compressed = false } = props;
2112
- const { depth = 0 } = props;
2113
- const glFormat = convertTextureFormatToGL(props.format);
2114
- ({ width, height, compressed, dataFormat, type } = this._deduceParameters({
2115
- format: props.format,
2116
- type,
2117
- dataFormat,
2118
- compressed,
2119
- data,
2120
- width,
2121
- height
2122
- }));
2123
2015
  this.width = width;
2124
2016
  this.height = height;
2125
- this.glFormat = glFormat;
2126
- this.type = type;
2127
- this.dataFormat = dataFormat;
2128
- this.textureUnit = textureUnit;
2129
- if (Number.isFinite(this.textureUnit)) {
2130
- this.gl.activeTexture(33984 + this.textureUnit);
2131
- this.gl.bindTexture(this.target, this.handle);
2132
- }
2133
- this.mipmaps = mipmaps;
2134
- this.setImageData({
2135
- data,
2136
- width,
2137
- height,
2138
- depth,
2139
- format: glFormat,
2140
- type,
2141
- dataFormat,
2142
- // @ts-expect-error
2143
- parameters: pixelStore,
2144
- compressed
2145
- });
2017
+ this.depth = props.depth;
2146
2018
  this.setSampler(props.sampler);
2147
- this._setSamplerParameters(parameters);
2148
- this.view = this.createView({ ...this.props, mipLevelCount: 1, arrayLayerCount: 1 });
2149
- if (mipmaps && this.device.isTextureFormatFilterable(props.format)) {
2019
+ this.view = new WEBGLTextureView(this.device, { ...this.props, texture: this });
2020
+ this.bind();
2021
+ if (!this.props.data) {
2022
+ initializeTextureStorage(this.gl, this.mipLevels, this);
2023
+ }
2024
+ if (props.data) {
2025
+ switch (props.dimension) {
2026
+ case "1d":
2027
+ this.setTexture1DData(props.data);
2028
+ break;
2029
+ case "2d":
2030
+ this.setTexture2DData(props.data);
2031
+ break;
2032
+ case "3d":
2033
+ this.setTexture3DData(props.data);
2034
+ break;
2035
+ case "cube":
2036
+ this.setTextureCubeData(props.data);
2037
+ break;
2038
+ case "2d-array":
2039
+ this.setTextureArrayData(props.data);
2040
+ break;
2041
+ case "cube-array":
2042
+ this.setTextureCubeArrayData(props.data);
2043
+ break;
2044
+ default:
2045
+ throw new Error(props.dimension);
2046
+ }
2047
+ }
2048
+ this.mipmaps = Boolean(props.mipmaps);
2049
+ if (this.mipmaps) {
2150
2050
  this.generateMipmap();
2151
2051
  }
2152
- if (isVideo) {
2153
- this._video = {
2154
- video: data,
2155
- parameters,
2156
- // @ts-expect-error
2157
- lastTime: data.readyState >= HTMLVideoElement.HAVE_CURRENT_DATA ? data.currentTime : -1
2158
- };
2052
+ }
2053
+ /*
2054
+ initializeCube(props?: TextureProps): void {
2055
+ const {mipmaps = true} = props; // , parameters = {} as Record<GL, any>} = props;
2056
+
2057
+ // Store props for accessors
2058
+ // this.props = props;
2059
+
2060
+ // @ts-expect-error
2061
+ this.setCubeMapData(props).then(() => {
2062
+ // TODO - should genMipmap() be called on the cubemap or on the faces?
2063
+ // TODO - without generateMipmap() cube textures do not work at all!!! Why?
2064
+ if (mipmaps) {
2065
+ this.generateMipmap(props);
2066
+ }
2067
+
2068
+ this.setSampler(props.sampler);
2069
+
2070
+ // v8 compatibility?
2071
+ // const {parameters = {} as Record<GL, any>} = props;
2072
+ // this._setSamplerParameters(parameters);
2073
+ });
2074
+ }
2075
+ */
2076
+ destroy() {
2077
+ if (this.handle) {
2078
+ this.gl.deleteTexture(this.handle);
2079
+ this.removeStats();
2080
+ this.trackDeallocatedMemory("Texture");
2081
+ this.destroyed = true;
2159
2082
  }
2160
- return this;
2161
2083
  }
2162
- initializeCube(props) {
2163
- const { mipmaps = true, parameters = {} } = props;
2164
- this.setCubeMapImageData(props).then(() => {
2165
- this.loaded = true;
2166
- if (mipmaps) {
2167
- this.generateMipmap(props);
2168
- }
2169
- this.setSampler(props.sampler);
2170
- this._setSamplerParameters(parameters);
2171
- });
2172
- return this;
2084
+ toString() {
2085
+ return `Texture(${this.id},${this.width}x${this.height})`;
2086
+ }
2087
+ createView(props) {
2088
+ return new WEBGLTextureView(this.device, { ...props, texture: this });
2173
2089
  }
2174
2090
  setSampler(sampler = {}) {
2175
2091
  let samplerProps;
@@ -2182,300 +2098,88 @@ var _WEBGLTexture = class extends import_core9.Texture {
2182
2098
  }
2183
2099
  const parameters = convertSamplerParametersToWebGL(samplerProps);
2184
2100
  this._setSamplerParameters(parameters);
2185
- return this;
2186
2101
  }
2187
- /**
2188
- * If size has changed, reinitializes with current format
2189
- * @note note clears image and mipmaps
2190
- */
2191
- resize(options) {
2192
- const { height, width, mipmaps = false } = options;
2193
- if (width !== this.width || height !== this.height) {
2194
- return this.initialize({
2195
- width,
2196
- height,
2197
- format: this.format,
2198
- type: this.type,
2199
- dataFormat: this.dataFormat,
2200
- mipmaps
2201
- });
2202
- }
2203
- return this;
2204
- }
2205
- /** Update external texture (video frame) */
2102
+ /** Update external texture (video frame or canvas) */
2206
2103
  update() {
2207
- if (this._video) {
2208
- const { video, parameters, lastTime } = this._video;
2209
- if (lastTime === video.currentTime || video.readyState < HTMLVideoElement.HAVE_CURRENT_DATA) {
2210
- return;
2211
- }
2212
- this.setSubImageData({
2213
- data: video,
2214
- parameters
2215
- });
2216
- if (this.mipmaps) {
2217
- this.generateMipmap();
2218
- }
2219
- this._video.lastTime = video.currentTime;
2220
- }
2104
+ import_core7.log.warn("Texture.update() not implemented");
2221
2105
  }
2222
2106
  // Call to regenerate mipmaps after modifying texture(s)
2223
2107
  generateMipmap(params = {}) {
2108
+ if (!this.props.data) {
2109
+ return;
2110
+ }
2224
2111
  this.mipmaps = true;
2225
- this.gl.bindTexture(this.target, this.handle);
2112
+ this.gl.bindTexture(this.glTarget, this.handle);
2226
2113
  withGLParameters(this.gl, params, () => {
2227
- this.gl.generateMipmap(this.target);
2114
+ this.gl.generateMipmap(this.glTarget);
2228
2115
  });
2229
- this.gl.bindTexture(this.target, null);
2230
- return this;
2116
+ this.gl.bindTexture(this.glTarget, null);
2231
2117
  }
2232
- /*
2233
- * Allocates storage
2234
- * @param {*} pixels -
2235
- * null - create empty texture of specified format
2236
- * Typed array - init from image data in typed array
2237
- * Buffer|WebGLBuffer - (WEBGL2) init from image data in WebGLBuffer
2238
- * HTMLImageElement|Image - Inits with content of image. Auto width/height
2239
- * HTMLCanvasElement - Inits with contents of canvas. Auto width/height
2240
- * HTMLVideoElement - Creates video texture. Auto width/height
2241
- *
2242
- * @param width -
2243
- * @param height -
2244
- * @param mipMapLevel -
2245
- * @param {GLenum} format - format of image data.
2246
- * @param {GLenum} type
2247
- * - format of array (autodetect from type) or
2248
- * - (WEBGL2) format of buffer
2249
- * @param {Number} offset - (WEBGL2) offset from start of buffer
2250
- * @parameters - temporary settings to be applied, can be used to supply pixel store settings.
2251
- */
2252
- // eslint-disable-next-line max-statements, complexity
2253
- setImageData(options) {
2254
- if (this.props.dimension === "3d" || this.props.dimension === "2d-array") {
2255
- return this.setImageData3D(options);
2256
- }
2257
- this.trackDeallocatedMemory("Texture");
2258
- const { target = this.target, pixels = null, level = 0, glFormat = this.glFormat, offset = 0, parameters = {} } = options;
2259
- let { data = null, type = this.type, width = this.width, height = this.height, dataFormat = this.dataFormat, compressed = false } = options;
2260
- if (!data) {
2261
- data = pixels;
2262
- }
2263
- ({ type, dataFormat, compressed, width, height } = this._deduceParameters({
2264
- format: this.props.format,
2265
- type,
2266
- dataFormat,
2267
- compressed,
2268
- data,
2269
- width,
2270
- height
2271
- }));
2272
- const { gl } = this;
2273
- gl.bindTexture(this.target, this.handle);
2274
- let dataType = null;
2275
- ({ data, dataType } = this._getDataType({ data, compressed }));
2276
- withGLParameters(this.gl, parameters, () => {
2277
- switch (dataType) {
2278
- case "null":
2279
- gl.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
2280
- break;
2281
- case "typed-array":
2282
- gl.texImage2D(
2283
- target,
2284
- level,
2285
- glFormat,
2286
- width,
2287
- height,
2288
- 0,
2289
- // border (must be 0)
2290
- dataFormat,
2291
- type,
2292
- data,
2293
- offset
2294
- );
2295
- break;
2296
- case "buffer":
2297
- this.device.gl.bindBuffer(35052, data.handle || data);
2298
- this.device.gl.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, offset);
2299
- this.device.gl.bindBuffer(35052, null);
2300
- break;
2301
- case "browser-object":
2302
- gl.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
2303
- break;
2304
- case "compressed":
2305
- for (const [levelIndex, levelData] of data.entries()) {
2306
- gl.compressedTexImage2D(target, levelIndex, levelData.format, levelData.width, levelData.height, 0, levelData.data);
2307
- }
2308
- break;
2309
- default:
2310
- (0, import_core9.assert)(false, "Unknown image data type");
2311
- }
2312
- });
2313
- if (data && data.byteLength) {
2314
- this.trackAllocatedMemory(data.byteLength, "Texture");
2315
- } else {
2316
- const bytesPerPixel = getTextureFormatBytesPerPixel(this.props.format);
2317
- this.trackAllocatedMemory(this.width * this.height * bytesPerPixel, "Texture");
2118
+ // Image Data Setters
2119
+ setTexture1DData(data) {
2120
+ throw new Error("setTexture1DData not supported in WebGL.");
2121
+ }
2122
+ /** Set a simple texture */
2123
+ setTexture2DData(lodData, depth = 0, glTarget = this.glTarget) {
2124
+ this.bind();
2125
+ const lodArray = normalizeTextureData(lodData, this);
2126
+ if (lodArray.length > 1 && this.props.mipmaps !== false) {
2127
+ import_core7.log.warn(`Texture ${this.id} mipmap and multiple LODs.`)();
2318
2128
  }
2319
- this.loaded = true;
2320
- return this;
2129
+ for (let lodLevel = 0; lodLevel < lodArray.length; lodLevel++) {
2130
+ const imageData = lodArray[lodLevel];
2131
+ this._setMipLevel(depth, lodLevel, imageData);
2132
+ }
2133
+ this.unbind();
2321
2134
  }
2322
2135
  /**
2323
- * Redefines an area of an existing texture
2324
- * Note: does not allocate storage
2325
- * Redefines an area of an existing texture
2136
+ * Sets a 3D texture
2137
+ * @param data
2326
2138
  */
2327
- setSubImageData({ target = this.target, pixels = null, data = null, x = 0, y = 0, width = this.width, height = this.height, level = 0, glFormat = this.glFormat, type = this.type, dataFormat = this.dataFormat, compressed = false, offset = 0, parameters = {} }) {
2328
- ({ type, dataFormat, compressed, width, height } = this._deduceParameters({
2329
- format: this.props.format,
2330
- type,
2331
- dataFormat,
2332
- compressed,
2333
- data,
2334
- width,
2335
- height
2336
- }));
2337
- (0, import_core9.assert)(this.depth === 1, "texSubImage not supported for 3D textures");
2338
- if (!data) {
2339
- data = pixels;
2139
+ setTexture3DData(data) {
2140
+ if (this.props.dimension !== "3d") {
2141
+ throw new Error(this.id);
2340
2142
  }
2341
- if (data && data.data) {
2342
- const ndarray = data;
2343
- data = ndarray.data;
2344
- width = ndarray.shape[0];
2345
- height = ndarray.shape[1];
2346
- }
2347
- if (data instanceof WEBGLBuffer) {
2348
- data = data.handle;
2143
+ if (ArrayBuffer.isView(data)) {
2144
+ copyCPUDataToMipLevel(this.device.gl, data, this);
2349
2145
  }
2350
- this.gl.bindTexture(this.target, this.handle);
2351
- withGLParameters(this.gl, parameters, () => {
2352
- if (compressed) {
2353
- this.gl.compressedTexSubImage2D(target, level, x, y, width, height, glFormat, data);
2354
- } else if (data === null) {
2355
- this.gl.texSubImage2D(target, level, x, y, width, height, dataFormat, type, null);
2356
- } else if (ArrayBuffer.isView(data)) {
2357
- this.gl.texSubImage2D(target, level, x, y, width, height, dataFormat, type, data, offset);
2358
- } else if (typeof WebGLBuffer !== "undefined" && data instanceof WebGLBuffer) {
2359
- this.device.gl.bindBuffer(35052, data);
2360
- this.device.gl.texSubImage2D(target, level, x, y, width, height, dataFormat, type, offset);
2361
- this.device.gl.bindBuffer(35052, null);
2362
- } else {
2363
- this.device.gl.texSubImage2D(target, level, x, y, width, height, dataFormat, type, data);
2364
- }
2365
- });
2366
- this.gl.bindTexture(this.target, null);
2367
2146
  }
2368
2147
  /**
2369
- * Defines a two-dimensional texture image or cube-map texture image with
2370
- * pixels from the current framebuffer (rather than from client memory).
2371
- * (gl.copyTexImage2D wrapper)
2372
- *
2373
- * Note that binding a texture into a Framebuffer's color buffer and
2374
- * rendering can be faster.
2148
+ * Set a Texture Cube Data
2149
+ * @todo - could support TextureCubeArray with depth
2150
+ * @param data
2151
+ * @param index
2375
2152
  */
2376
- copyFramebuffer(opts = {}) {
2377
- import_core9.log.error("Texture.copyFramebuffer({...}) is no logner supported, use copyToTexture(source, target, opts})")();
2378
- return null;
2379
- }
2380
- getActiveUnit() {
2381
- return this.gl.getParameter(34016) - 33984;
2382
- }
2383
- bind(textureUnit = this.textureUnit) {
2384
- const { gl } = this;
2385
- if (textureUnit !== void 0) {
2386
- this.textureUnit = textureUnit;
2387
- gl.activeTexture(33984 + textureUnit);
2153
+ setTextureCubeData(data, depth = 0) {
2154
+ if (this.props.dimension !== "cube") {
2155
+ throw new Error(this.id);
2388
2156
  }
2389
- gl.bindTexture(this.target, this.handle);
2390
- return textureUnit;
2391
2157
  }
2392
- unbind(textureUnit = this.textureUnit) {
2393
- const { gl } = this;
2394
- if (textureUnit !== void 0) {
2395
- this.textureUnit = textureUnit;
2396
- gl.activeTexture(33984 + textureUnit);
2158
+ /**
2159
+ * Sets an entire texture array
2160
+ * @param data
2161
+ */
2162
+ setTextureArrayData(data) {
2163
+ if (this.props.dimension !== "2d-array") {
2164
+ throw new Error(this.id);
2397
2165
  }
2398
- gl.bindTexture(this.target, null);
2399
- return textureUnit;
2166
+ throw new Error("setTextureArrayData not implemented.");
2400
2167
  }
2401
- // PRIVATE METHODS
2402
- _getDataType({ data, compressed = false }) {
2403
- if (compressed) {
2404
- return { data, dataType: "compressed" };
2405
- }
2406
- if (data === null) {
2407
- return { data, dataType: "null" };
2408
- }
2409
- if (ArrayBuffer.isView(data)) {
2410
- return { data, dataType: "typed-array" };
2411
- }
2412
- if (data instanceof WEBGLBuffer) {
2413
- return { data: data.handle, dataType: "buffer" };
2414
- }
2415
- if (typeof WebGLBuffer !== "undefined" && data instanceof WebGLBuffer) {
2416
- return { data, dataType: "buffer" };
2417
- }
2418
- return { data, dataType: "browser-object" };
2419
- }
2420
- // HELPER METHODS
2421
- _deduceParameters(opts) {
2422
- const { format, data } = opts;
2423
- let { width, height, dataFormat, type, compressed } = opts;
2424
- const parameters = getWebGLTextureParameters(format);
2425
- dataFormat = dataFormat || parameters.dataFormat;
2426
- type = type || parameters.type;
2427
- compressed = compressed || parameters.compressed;
2428
- ({ width, height } = this._deduceImageSize(data, width, height));
2429
- return { dataFormat, type, compressed, width, height, format, data };
2430
- }
2431
- // eslint-disable-next-line complexity
2432
- _deduceImageSize(data, width, height) {
2433
- let size;
2434
- if (typeof ImageData !== "undefined" && data instanceof ImageData) {
2435
- size = { width: data.width, height: data.height };
2436
- } else if (typeof HTMLImageElement !== "undefined" && data instanceof HTMLImageElement) {
2437
- size = { width: data.naturalWidth, height: data.naturalHeight };
2438
- } else if (typeof HTMLCanvasElement !== "undefined" && data instanceof HTMLCanvasElement) {
2439
- size = { width: data.width, height: data.height };
2440
- } else if (typeof ImageBitmap !== "undefined" && data instanceof ImageBitmap) {
2441
- size = { width: data.width, height: data.height };
2442
- } else if (typeof HTMLVideoElement !== "undefined" && data instanceof HTMLVideoElement) {
2443
- size = { width: data.videoWidth, height: data.videoHeight };
2444
- } else if (!data) {
2445
- size = { width: width >= 0 ? width : 1, height: height >= 0 ? height : 1 };
2446
- } else {
2447
- size = { width, height };
2448
- }
2449
- (0, import_core9.assert)(size, "Could not deduced texture size");
2450
- (0, import_core9.assert)(width === void 0 || size.width === width, "Deduced texture width does not match supplied width");
2451
- (0, import_core9.assert)(height === void 0 || size.height === height, "Deduced texture height does not match supplied height");
2452
- return size;
2168
+ /**
2169
+ * Sets an entire texture cube array
2170
+ * @param data
2171
+ */
2172
+ setTextureCubeArrayData(data) {
2173
+ throw new Error("setTextureCubeArrayData not supported in WebGL2.");
2453
2174
  }
2454
- // CUBE MAP METHODS
2455
- /* eslint-disable max-statements, max-len */
2456
- async setCubeMapImageData(options) {
2457
- const { gl } = this;
2458
- const { width, height, pixels, data, format = 6408, type = 5121 } = options;
2459
- const imageDataMap = pixels || data;
2460
- const resolvedFaces = await Promise.all(_WEBGLTexture.FACES.map((face) => {
2461
- const facePixels = imageDataMap[face];
2462
- return Promise.all(Array.isArray(facePixels) ? facePixels : [facePixels]);
2463
- }));
2175
+ setTextureCubeFaceData(lodData, face, depth = 0) {
2176
+ if (Array.isArray(lodData) && lodData.length > 1 && this.props.mipmaps !== false) {
2177
+ import_core7.log.warn(`${this.id} has mipmap and multiple LODs.`)();
2178
+ }
2464
2179
  this.bind();
2465
- _WEBGLTexture.FACES.forEach((face, index) => {
2466
- if (resolvedFaces[index].length > 1 && this.props.mipmaps !== false) {
2467
- import_core9.log.warn(`${this.id} has mipmap and multiple LODs.`)();
2468
- }
2469
- resolvedFaces[index].forEach((image, lodLevel) => {
2470
- if (width && height) {
2471
- gl.texImage2D(face, lodLevel, format, width, height, 0, format, type, image);
2472
- } else {
2473
- gl.texImage2D(face, lodLevel, format, format, type, image);
2474
- }
2475
- });
2476
- });
2477
2180
  this.unbind();
2478
2181
  }
2182
+ // INTERNAL METHODS
2479
2183
  /** @todo update this method to accept LODs */
2480
2184
  setImageDataForFace(options) {
2481
2185
  const {
@@ -2502,121 +2206,157 @@ var _WEBGLTexture = class extends import_core9.Texture {
2502
2206
  } else {
2503
2207
  gl.texImage2D(face, 0, format, format, type, imageData);
2504
2208
  }
2505
- return this;
2506
2209
  }
2507
- /** Image 3D copies from Typed Array or WebGLBuffer */
2508
- setImageData3D(options) {
2509
- const {
2510
- level = 0,
2511
- dataFormat,
2512
- format,
2513
- type,
2514
- // = GL.UNSIGNED_BYTE,
2515
- width,
2516
- height,
2517
- depth = 1,
2518
- offset = 0,
2519
- data,
2520
- parameters = {}
2521
- } = options;
2522
- this.trackDeallocatedMemory("Texture");
2523
- this.gl.bindTexture(this.target, this.handle);
2524
- const webglTextureFormat = getWebGLTextureParameters(format);
2525
- withGLParameters(this.gl, parameters, () => {
2526
- if (ArrayBuffer.isView(data)) {
2527
- this.gl.texImage3D(
2528
- this.target,
2529
- level,
2530
- webglTextureFormat.format,
2531
- width,
2532
- height,
2533
- depth,
2534
- 0,
2535
- webglTextureFormat.dataFormat,
2536
- webglTextureFormat.type,
2537
- // dataType: getWebGL,
2538
- data
2539
- );
2540
- }
2541
- if (data instanceof WEBGLBuffer) {
2542
- this.gl.bindBuffer(35052, data.handle);
2543
- this.gl.texImage3D(this.target, level, dataFormat, width, height, depth, 0, format, type, offset);
2210
+ _getImageDataMap(faceData) {
2211
+ for (let i = 0; i < import_core7.Texture.CubeFaces.length; ++i) {
2212
+ const faceName = import_core7.Texture.CubeFaces[i];
2213
+ if (faceData[faceName]) {
2214
+ faceData[34069 + i] = faceData[faceName];
2215
+ delete faceData[faceName];
2544
2216
  }
2545
- });
2546
- if (data && data.byteLength) {
2547
- this.trackAllocatedMemory(data.byteLength, "Texture");
2548
- } else {
2549
- const bytesPerPixel = getTextureFormatBytesPerPixel(this.props.format);
2550
- this.trackAllocatedMemory(this.width * this.height * this.depth * bytesPerPixel, "Texture");
2551
2217
  }
2552
- this.loaded = true;
2553
- return this;
2218
+ return faceData;
2554
2219
  }
2555
2220
  // RESOURCE METHODS
2556
2221
  /**
2557
2222
  * Sets sampler parameters on texture
2558
2223
  */
2559
2224
  _setSamplerParameters(parameters) {
2560
- if ((0, import_core9.isObjectEmpty)(parameters)) {
2561
- return;
2562
- }
2563
- logParameters(parameters);
2564
- this.gl.bindTexture(this.target, this.handle);
2225
+ import_core7.log.log(1, "texture sampler parameters", parameters)();
2226
+ this.gl.bindTexture(this.glTarget, this.handle);
2565
2227
  for (const [pname, pvalue] of Object.entries(parameters)) {
2566
2228
  const param = Number(pname);
2567
2229
  const value = pvalue;
2568
2230
  switch (param) {
2569
2231
  case 33082:
2570
2232
  case 33083:
2571
- this.gl.texParameterf(this.target, param, value);
2233
+ this.gl.texParameterf(this.glTarget, param, value);
2234
+ break;
2235
+ case 10241:
2236
+ this.gl.texParameteri(this.glTarget, param, value);
2237
+ break;
2238
+ case 10242:
2239
+ case 10243:
2240
+ this.gl.texParameteri(this.glTarget, param, value);
2241
+ break;
2242
+ case 34046:
2243
+ if (this.device.features.has("texture-filterable-anisotropic-webgl")) {
2244
+ this.gl.texParameteri(this.glTarget, param, value);
2245
+ }
2572
2246
  break;
2573
2247
  default:
2574
- this.gl.texParameteri(this.target, param, value);
2248
+ this.gl.texParameteri(this.glTarget, param, value);
2575
2249
  break;
2576
2250
  }
2577
2251
  }
2578
- this.gl.bindTexture(this.target, null);
2579
- return;
2252
+ this.gl.bindTexture(this.glTarget, null);
2580
2253
  }
2581
- };
2582
- var WEBGLTexture = _WEBGLTexture;
2583
- // TODO - remove?
2584
- __publicField(WEBGLTexture, "FACES", [
2585
- 34069,
2586
- 34070,
2587
- 34071,
2588
- 34072,
2589
- 34073,
2590
- 34074
2591
- ]);
2592
- function getWebGLTextureTarget(props) {
2593
- switch (props.dimension) {
2594
- case "2d":
2595
- return 3553;
2596
- case "cube":
2597
- return 34067;
2598
- case "2d-array":
2599
- return 35866;
2600
- case "3d":
2601
- return 32879;
2602
- case "1d":
2603
- case "cube-array":
2604
- default:
2605
- throw new Error(props.dimension);
2254
+ // CLASSIC
2255
+ /*
2256
+ setCubeMapData(options: {
2257
+ width: number;
2258
+ height: number;
2259
+ data: Record<GL, Texture2DData> | Record<TextureCubeFace, Texture2DData>;
2260
+ format?: any;
2261
+ type?: any;
2262
+ /** @deprecated Use .data *
2263
+ pixels: any;
2264
+ }): void {
2265
+ const {gl} = this;
2266
+
2267
+ const {width, height, pixels, data, format = GL.RGBA, type = GL.UNSIGNED_BYTE} = options;
2268
+
2269
+ // pixel data (imageDataMap) is an Object from Face to Image or Promise.
2270
+ // For example:
2271
+ // {
2272
+ // GL.TEXTURE_CUBE_MAP_POSITIVE_X : Image-or-Promise,
2273
+ // GL.TEXTURE_CUBE_MAP_NEGATIVE_X : Image-or-Promise,
2274
+ // ... }
2275
+ // To provide multiple level-of-details (LODs) this can be Face to Array
2276
+ // of Image or Promise, like this
2277
+ // {
2278
+ // GL.TEXTURE_CUBE_MAP_POSITIVE_X : [Image-or-Promise-LOD-0, Image-or-Promise-LOD-1],
2279
+ // GL.TEXTURE_CUBE_MAP_NEGATIVE_X : [Image-or-Promise-LOD-0, Image-or-Promise-LOD-1],
2280
+ // ... }
2281
+
2282
+ const imageDataMap = this._getImageDataMap(pixels || data);
2283
+
2284
+ const resolvedFaces = WEBGLTexture.FACES.map(face => {
2285
+ const facePixels = imageDataMap[face];
2286
+ return Array.isArray(facePixels) ? facePixels : [facePixels];
2287
+ });
2288
+ this.bind();
2289
+
2290
+ WEBGLTexture.FACES.forEach((face, index) => {
2291
+ if (resolvedFaces[index].length > 1 && this.props.mipmaps !== false) {
2292
+ // If the user provides multiple LODs, then automatic mipmap
2293
+ // generation generateMipmap() should be disabled to avoid overwritting them.
2294
+ log.warn(`${this.id} has mipmap and multiple LODs.`)();
2295
+ }
2296
+ resolvedFaces[index].forEach((image, lodLevel) => {
2297
+ // TODO: adjust width & height for LOD!
2298
+ if (width && height) {
2299
+ gl.texImage2D(face, lodLevel, format, width, height, 0 /* border*, format, type, image);
2300
+ } else {
2301
+ gl.texImage2D(face, lodLevel, format, format, type, image);
2302
+ }
2303
+ });
2304
+ });
2305
+
2306
+ this.unbind();
2307
+ }
2308
+ */
2309
+ // INTERNAL SETTERS
2310
+ /**
2311
+ * Copy a region of data from a CPU memory buffer into this texture.
2312
+ * @todo - GLUnpackParameters parameters
2313
+ */
2314
+ _setMipLevel(depth, level, textureData, offset = 0) {
2315
+ if (import_core7.Texture.isExternalImage(textureData)) {
2316
+ copyCPUImageToMipLevel(this.device.gl, textureData, { ...this, depth, level });
2317
+ return;
2318
+ }
2319
+ if (this.isTextureLevelData(textureData)) {
2320
+ copyCPUDataToMipLevel(this.device.gl, textureData.data, {
2321
+ ...this,
2322
+ depth,
2323
+ level
2324
+ });
2325
+ return;
2326
+ }
2327
+ throw new Error("Texture: invalid image data");
2606
2328
  }
2607
- }
2608
- function logParameters(parameters) {
2609
- import_core9.log.log(1, "texture sampler parameters", parameters)();
2610
- }
2329
+ // HELPERS
2330
+ getActiveUnit() {
2331
+ return this.gl.getParameter(34016) - 33984;
2332
+ }
2333
+ bind(textureUnit) {
2334
+ const { gl } = this;
2335
+ if (textureUnit !== void 0) {
2336
+ this.textureUnit = textureUnit;
2337
+ gl.activeTexture(33984 + textureUnit);
2338
+ }
2339
+ gl.bindTexture(this.glTarget, this.handle);
2340
+ return textureUnit;
2341
+ }
2342
+ unbind(textureUnit) {
2343
+ const { gl } = this;
2344
+ if (textureUnit !== void 0) {
2345
+ this.textureUnit = textureUnit;
2346
+ gl.activeTexture(33984 + textureUnit);
2347
+ }
2348
+ gl.bindTexture(this.glTarget, null);
2349
+ return textureUnit;
2350
+ }
2351
+ };
2611
2352
 
2612
2353
  // dist/adapter/resources/webgl-framebuffer.js
2613
- var WEBGLFramebuffer = class extends import_core10.Framebuffer {
2354
+ var WEBGLFramebuffer = class extends import_core8.Framebuffer {
2614
2355
  device;
2615
2356
  gl;
2616
2357
  handle;
2617
- get texture() {
2618
- return this.colorAttachments[0];
2619
- }
2358
+ colorAttachments = [];
2359
+ depthStencilAttachment = null;
2620
2360
  constructor(device, props) {
2621
2361
  super(device, props);
2622
2362
  const isDefaultFramebuffer = props.handle === null;
@@ -2631,11 +2371,11 @@ var WEBGLFramebuffer = class extends import_core10.Framebuffer {
2631
2371
  const attachment = this.colorAttachments[i];
2632
2372
  const attachmentPoint = 36064 + i;
2633
2373
  if (attachment) {
2634
- this._attachOne(attachmentPoint, attachment);
2374
+ this._attachTexture(attachmentPoint, attachment);
2635
2375
  }
2636
2376
  }
2637
2377
  if (this.depthStencilAttachment) {
2638
- this._attachOne(getDepthStencilAttachmentWebGL(this.depthStencilAttachment.props.format), this.depthStencilAttachment);
2378
+ this._attachTexture(getDepthStencilAttachmentWebGL(this.depthStencilAttachment.props.format), this.depthStencilAttachment);
2639
2379
  }
2640
2380
  if (props.check !== false) {
2641
2381
  const status = this.gl.checkFramebufferStatus(36160);
@@ -2665,68 +2405,55 @@ var WEBGLFramebuffer = class extends import_core10.Framebuffer {
2665
2405
  });
2666
2406
  }
2667
2407
  /**
2668
- * Attachment resize is expected to be a noop if size is same
2669
- */
2670
- resizeAttachments(width, height) {
2671
- if (this.handle === null) {
2672
- this.width = this.gl.drawingBufferWidth;
2673
- this.height = this.gl.drawingBufferHeight;
2408
+ * Attachment resize is expected to be a noop if size is same
2409
+ *
2410
+ protected override resizeAttachments(width: number, height: number): this {
2411
+ // for default framebuffer, just update the stored size
2412
+ if (this.handle === null) {
2413
+ // assert(width === undefined && height === undefined);
2414
+ this.width = this.gl.drawingBufferWidth;
2415
+ this.height = this.gl.drawingBufferHeight;
2416
+ return this;
2417
+ }
2418
+
2419
+ if (width === undefined) {
2420
+ width = this.gl.drawingBufferWidth;
2421
+ }
2422
+ if (height === undefined) {
2423
+ height = this.gl.drawingBufferHeight;
2424
+ }
2425
+
2426
+ // TODO Not clear that this is better than default destroy/create implementation
2427
+
2428
+ for (const colorAttachment of this.colorAttachments) {
2429
+ colorAttachment.texture.clone({width, height});
2430
+ }
2431
+ if (this.depthStencilAttachment) {
2432
+ this.depthStencilAttachment.texture.resize({width, height});
2433
+ }
2674
2434
  return this;
2675
2435
  }
2676
- if (width === void 0) {
2677
- width = this.gl.drawingBufferWidth;
2678
- }
2679
- if (height === void 0) {
2680
- height = this.gl.drawingBufferHeight;
2681
- }
2682
- for (const colorAttachment of this.colorAttachments) {
2683
- colorAttachment.texture.resize({ width, height });
2684
- }
2685
- if (this.depthStencilAttachment) {
2686
- this.depthStencilAttachment.texture.resize({ width, height });
2687
- }
2688
- return this;
2689
- }
2436
+ */
2690
2437
  /** Attach one attachment */
2691
- _attachOne(attachmentPoint, attachment) {
2692
- if (Array.isArray(attachment)) {
2693
- const [texture, layer = 0, level = 0] = attachment;
2694
- this._attachTexture(attachmentPoint, texture, layer, level);
2695
- return texture;
2696
- }
2697
- if (attachment instanceof WEBGLTexture) {
2698
- this._attachTexture(attachmentPoint, attachment, 0, 0);
2699
- return attachment;
2700
- }
2701
- if (attachment instanceof WEBGLTextureView) {
2702
- const textureView = attachment;
2703
- this._attachTexture(attachmentPoint, textureView.texture, textureView.props.baseMipLevel, textureView.props.baseArrayLayer);
2704
- return attachment.texture;
2705
- }
2706
- throw new Error("attach");
2707
- }
2708
- // TODO - we do not seem to need render buffers in WebGL 2
2709
- // protected _attachWEBGLRenderbuffer(attachment: GL, renderbuffer: WEBGLRenderbuffer): void {
2710
- // this.gl.framebufferRenderbuffer(
2711
- // GL.FRAMEBUFFER,
2712
- // attachment,
2713
- // GL.RENDERBUFFER,
2714
- // renderbuffer.handle
2715
- // );
2716
- // }
2438
+ _attachTexture(attachmentPoint, textureView) {
2439
+ this._attachTextureView(attachmentPoint, textureView);
2440
+ }
2717
2441
  /**
2718
2442
  * @param attachment
2719
2443
  * @param texture
2720
2444
  * @param layer = 0 - index into WEBGLTextureArray and Texture3D or face for `TextureCubeMap`
2721
2445
  * @param level = 0 - mipmapLevel
2722
2446
  */
2723
- _attachTexture(attachment, texture, layer, level) {
2447
+ _attachTextureView(attachment, textureView) {
2724
2448
  const { gl } = this.device;
2725
- gl.bindTexture(texture.target, texture.handle);
2726
- switch (texture.target) {
2449
+ const { texture } = textureView;
2450
+ const level = textureView.props.baseMipLevel;
2451
+ const layer = textureView.props.baseArrayLayer;
2452
+ gl.bindTexture(texture.glTarget, texture.handle);
2453
+ switch (texture.glTarget) {
2727
2454
  case 35866:
2728
2455
  case 32879:
2729
- gl.framebufferTextureLayer(36160, attachment, texture.target, level, layer);
2456
+ gl.framebufferTextureLayer(36160, attachment, texture.glTarget, level, layer);
2730
2457
  break;
2731
2458
  case 34067:
2732
2459
  const face = mapIndexToCubeMapFace(layer);
@@ -2736,9 +2463,9 @@ var WEBGLFramebuffer = class extends import_core10.Framebuffer {
2736
2463
  gl.framebufferTexture2D(36160, attachment, 3553, texture.handle, level);
2737
2464
  break;
2738
2465
  default:
2739
- (0, import_core10.assert)(false, "Illegal texture type");
2466
+ throw new Error("Illegal texture type");
2740
2467
  }
2741
- gl.bindTexture(texture.target, null);
2468
+ gl.bindTexture(texture.glTarget, null);
2742
2469
  }
2743
2470
  };
2744
2471
  function mapIndexToCubeMapFace(layer) {
@@ -2764,8 +2491,10 @@ function _getFrameBufferStatus(status) {
2764
2491
  }
2765
2492
 
2766
2493
  // dist/adapter/webgl-canvas-context.js
2767
- var WebGLCanvasContext = class extends import_core11.CanvasContext {
2494
+ var WebGLCanvasContext = class extends import_core9.CanvasContext {
2768
2495
  device;
2496
+ format = "rgba8unorm";
2497
+ depthStencilFormat = "depth24plus";
2769
2498
  presentationSize;
2770
2499
  _framebuffer = null;
2771
2500
  constructor(device, props) {
@@ -2815,9 +2544,30 @@ var WebGLCanvasContext = class extends import_core11.CanvasContext {
2815
2544
  };
2816
2545
 
2817
2546
  // dist/context/debug/spector.js
2818
- var import_core12 = require("@luma.gl/core");
2547
+ var import_core10 = require("@luma.gl/core");
2548
+
2549
+ // dist/utils/load-script.js
2550
+ async function loadScript(scriptUrl, scriptId) {
2551
+ const head = document.getElementsByTagName("head")[0];
2552
+ if (!head) {
2553
+ throw new Error("loadScript");
2554
+ }
2555
+ const script = document.createElement("script");
2556
+ script.setAttribute("type", "text/javascript");
2557
+ script.setAttribute("src", scriptUrl);
2558
+ if (scriptId) {
2559
+ script.id = scriptId;
2560
+ }
2561
+ return new Promise((resolve, reject) => {
2562
+ script.onload = resolve;
2563
+ script.onerror = (error) => reject(new Error(`Unable to load script '${scriptUrl}': ${error}`));
2564
+ head.appendChild(script);
2565
+ });
2566
+ }
2567
+
2568
+ // dist/context/debug/spector.js
2819
2569
  var DEFAULT_SPECTOR_PROPS = {
2820
- spector: import_core12.log.get("spector") || import_core12.log.get("inspect")
2570
+ spector: import_core10.log.get("spector") || import_core10.log.get("inspect")
2821
2571
  };
2822
2572
  var SPECTOR_CDN_URL = "https://spectorcdn.babylonjs.com/spector.bundle.js";
2823
2573
  var LOG_LEVEL = 1;
@@ -2826,9 +2576,9 @@ var initialized = false;
2826
2576
  async function loadSpectorJS(props) {
2827
2577
  if (!globalThis.SPECTOR) {
2828
2578
  try {
2829
- await (0, import_core12.loadScript)(SPECTOR_CDN_URL);
2579
+ await loadScript(SPECTOR_CDN_URL);
2830
2580
  } catch (error) {
2831
- import_core12.log.warn(String(error));
2581
+ import_core10.log.warn(String(error));
2832
2582
  }
2833
2583
  }
2834
2584
  }
@@ -2838,7 +2588,7 @@ function initializeSpectorJS(props) {
2838
2588
  return null;
2839
2589
  }
2840
2590
  if (!spector && globalThis.SPECTOR) {
2841
- import_core12.log.probe(LOG_LEVEL, "SPECTOR found and initialized")();
2591
+ import_core10.log.probe(LOG_LEVEL, "SPECTOR found and initialized")();
2842
2592
  spector = new globalThis.SPECTOR.Spector();
2843
2593
  if (globalThis.luma) {
2844
2594
  globalThis.luma.spector = spector;
@@ -2850,9 +2600,9 @@ function initializeSpectorJS(props) {
2850
2600
  if (!initialized) {
2851
2601
  initialized = true;
2852
2602
  spector.spyCanvases();
2853
- spector == null ? void 0 : spector.onCaptureStarted.add((capture) => import_core12.log.info("Spector capture started:", capture)());
2603
+ spector == null ? void 0 : spector.onCaptureStarted.add((capture) => import_core10.log.info("Spector capture started:", capture)());
2854
2604
  spector == null ? void 0 : spector.onCapture.add((capture) => {
2855
- import_core12.log.info("Spector capture complete:", capture)();
2605
+ import_core10.log.info("Spector capture complete:", capture)();
2856
2606
  spector == null ? void 0 : spector.getResultUI();
2857
2607
  spector == null ? void 0 : spector.resultView.display();
2858
2608
  spector == null ? void 0 : spector.resultView.addCapture(capture);
@@ -2864,7 +2614,7 @@ function initializeSpectorJS(props) {
2864
2614
  }
2865
2615
  spector == null ? void 0 : spector.startCapture(props == null ? void 0 : props.canvas, 500);
2866
2616
  new Promise((resolve) => setTimeout(resolve, 2e3)).then((_) => {
2867
- import_core12.log.info("Spector capture stopped after 2 seconds")();
2617
+ import_core10.log.info("Spector capture stopped after 2 seconds")();
2868
2618
  spector == null ? void 0 : spector.stopCapture();
2869
2619
  });
2870
2620
  }
@@ -2872,7 +2622,7 @@ function initializeSpectorJS(props) {
2872
2622
  }
2873
2623
 
2874
2624
  // dist/context/debug/webgl-developer-tools.js
2875
- var import_core13 = require("@luma.gl/core");
2625
+ var import_core11 = require("@luma.gl/core");
2876
2626
  var import_constants12 = require("@luma.gl/constants");
2877
2627
  var import_env = require("@probe.gl/env");
2878
2628
  var WEBGL_DEBUG_CDN_URL = "https://unpkg.com/webgl-debug@2.0.1/index.js";
@@ -2884,91 +2634,213 @@ async function loadWebGLDeveloperTools() {
2884
2634
  if ((0, import_env.isBrowser)() && !globalThis.WebGLDebugUtils) {
2885
2635
  globalThis.global = globalThis.global || globalThis;
2886
2636
  globalThis.global.module = {};
2887
- await (0, import_core13.loadScript)(WEBGL_DEBUG_CDN_URL);
2637
+ await loadScript(WEBGL_DEBUG_CDN_URL);
2638
+ }
2639
+ }
2640
+ function makeDebugContext(gl, props = {}) {
2641
+ return props.debug ? getDebugContext(gl, props) : getRealContext(gl);
2642
+ }
2643
+ function getRealContext(gl) {
2644
+ const data = getWebGLContextData(gl);
2645
+ return data.realContext ? data.realContext : gl;
2646
+ }
2647
+ function getDebugContext(gl, props) {
2648
+ if (!globalThis.WebGLDebugUtils) {
2649
+ import_core11.log.warn("webgl-debug not loaded")();
2650
+ return gl;
2651
+ }
2652
+ const data = getWebGLContextData(gl);
2653
+ if (data.debugContext) {
2654
+ return data.debugContext;
2655
+ }
2656
+ globalThis.WebGLDebugUtils.init({ ...import_constants12.GL, ...gl });
2657
+ const glDebug = globalThis.WebGLDebugUtils.makeDebugContext(gl, onGLError.bind(null, props), onValidateGLFunc.bind(null, props));
2658
+ for (const key in import_constants12.GL) {
2659
+ if (!(key in glDebug) && typeof import_constants12.GL[key] === "number") {
2660
+ glDebug[key] = import_constants12.GL[key];
2661
+ }
2662
+ }
2663
+ class WebGLDebugContext {
2664
+ }
2665
+ Object.setPrototypeOf(glDebug, Object.getPrototypeOf(gl));
2666
+ Object.setPrototypeOf(WebGLDebugContext, glDebug);
2667
+ const debugContext = Object.create(WebGLDebugContext);
2668
+ data.realContext = gl;
2669
+ data.debugContext = debugContext;
2670
+ debugContext.debug = true;
2671
+ return debugContext;
2672
+ }
2673
+ function getFunctionString(functionName, functionArgs) {
2674
+ functionArgs = Array.from(functionArgs).map((arg) => arg === void 0 ? "undefined" : arg);
2675
+ let args = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, functionArgs);
2676
+ args = `${args.slice(0, 100)}${args.length > 100 ? "..." : ""}`;
2677
+ return `gl.${functionName}(${args})`;
2678
+ }
2679
+ function onGLError(props, err, functionName, args) {
2680
+ args = Array.from(args).map((arg) => arg === void 0 ? "undefined" : arg);
2681
+ const errorMessage = globalThis.WebGLDebugUtils.glEnumToString(err);
2682
+ const functionArgs = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, args);
2683
+ const message2 = `${errorMessage} in gl.${functionName}(${functionArgs})`;
2684
+ import_core11.log.error(message2)();
2685
+ debugger;
2686
+ if (props.throwOnError) {
2687
+ throw new Error(message2);
2688
+ }
2689
+ }
2690
+ function onValidateGLFunc(props, functionName, functionArgs) {
2691
+ let functionString = "";
2692
+ if (import_core11.log.level >= 1) {
2693
+ functionString = getFunctionString(functionName, functionArgs);
2694
+ import_core11.log.log(1, functionString)();
2695
+ }
2696
+ if (props.break && props.break.length > 0) {
2697
+ functionString = functionString || getFunctionString(functionName, functionArgs);
2698
+ const isBreakpoint = props.break.every((breakOn) => functionString.indexOf(breakOn) !== -1);
2699
+ if (isBreakpoint) {
2700
+ debugger;
2701
+ }
2702
+ }
2703
+ for (const arg of functionArgs) {
2704
+ if (arg === void 0) {
2705
+ functionString = functionString || getFunctionString(functionName, functionArgs);
2706
+ if (props.throwOnError) {
2707
+ throw new Error(`Undefined argument: ${functionString}`);
2708
+ } else {
2709
+ import_core11.log.error(`Undefined argument: ${functionString}`)();
2710
+ debugger;
2711
+ }
2712
+ }
2713
+ }
2714
+ }
2715
+
2716
+ // dist/adapter/resources/webgl-buffer.js
2717
+ var import_core12 = require("@luma.gl/core");
2718
+ var import_constants13 = require("@luma.gl/constants");
2719
+ var WEBGLBuffer = class extends import_core12.Buffer {
2720
+ device;
2721
+ gl;
2722
+ handle;
2723
+ /** Target in OpenGL defines the type of buffer */
2724
+ glTarget;
2725
+ /** Usage is a hint on how frequently the buffer will be updates */
2726
+ glUsage;
2727
+ /** Index type is needed when issuing draw calls, so we pre-compute it */
2728
+ glIndexType = 5123;
2729
+ /** Number of bytes allocated on the GPU for this buffer */
2730
+ byteLength;
2731
+ /** Number of bytes used */
2732
+ bytesUsed;
2733
+ constructor(device, props = {}) {
2734
+ super(device, props);
2735
+ this.device = device;
2736
+ this.gl = this.device.gl;
2737
+ const handle = typeof props === "object" ? props.handle : void 0;
2738
+ this.handle = handle || this.gl.createBuffer();
2739
+ device.setSpectorMetadata(this.handle, { ...this.props, data: typeof this.props.data });
2740
+ this.glTarget = getWebGLTarget(this.props.usage);
2741
+ this.glUsage = getWebGLUsage(this.props.usage);
2742
+ this.glIndexType = this.props.indexType === "uint32" ? 5125 : 5123;
2743
+ if (props.data) {
2744
+ this._initWithData(props.data, props.byteOffset, props.byteLength);
2745
+ } else {
2746
+ this._initWithByteLength(props.byteLength || 0);
2747
+ }
2748
+ }
2749
+ // PRIVATE METHODS
2750
+ /** Allocate a new buffer and initialize to contents of typed array */
2751
+ _initWithData(data, byteOffset = 0, byteLength = data.byteLength + byteOffset) {
2752
+ const glTarget = this.glTarget;
2753
+ this.gl.bindBuffer(glTarget, this.handle);
2754
+ this.gl.bufferData(glTarget, byteLength, this.glUsage);
2755
+ this.gl.bufferSubData(glTarget, byteOffset, data);
2756
+ this.gl.bindBuffer(glTarget, null);
2757
+ this.bytesUsed = byteLength;
2758
+ this.byteLength = byteLength;
2759
+ this._setDebugData(data, byteOffset, byteLength);
2760
+ this.trackAllocatedMemory(byteLength);
2761
+ }
2762
+ // Allocate a GPU buffer of specified size.
2763
+ _initWithByteLength(byteLength) {
2764
+ let data = byteLength;
2765
+ if (byteLength === 0) {
2766
+ data = new Float32Array(0);
2767
+ }
2768
+ const glTarget = this.glTarget;
2769
+ this.gl.bindBuffer(glTarget, this.handle);
2770
+ this.gl.bufferData(glTarget, data, this.glUsage);
2771
+ this.gl.bindBuffer(glTarget, null);
2772
+ this.bytesUsed = byteLength;
2773
+ this.byteLength = byteLength;
2774
+ this._setDebugData(null, 0, byteLength);
2775
+ this.trackAllocatedMemory(byteLength);
2776
+ return this;
2777
+ }
2778
+ destroy() {
2779
+ if (!this.destroyed && this.handle) {
2780
+ this.removeStats();
2781
+ this.trackDeallocatedMemory();
2782
+ this.gl.deleteBuffer(this.handle);
2783
+ this.destroyed = true;
2784
+ this.handle = null;
2785
+ }
2888
2786
  }
2889
- }
2890
- function makeDebugContext(gl, props = {}) {
2891
- if (!gl) {
2892
- return null;
2787
+ write(data, byteOffset = 0) {
2788
+ const srcOffset = 0;
2789
+ const byteLength = void 0;
2790
+ const glTarget = 36663;
2791
+ this.gl.bindBuffer(glTarget, this.handle);
2792
+ if (srcOffset !== 0 || byteLength !== void 0) {
2793
+ this.gl.bufferSubData(glTarget, byteOffset, data, srcOffset, byteLength);
2794
+ } else {
2795
+ this.gl.bufferSubData(glTarget, byteOffset, data);
2796
+ }
2797
+ this.gl.bindBuffer(glTarget, null);
2798
+ this._setDebugData(data, byteOffset, data.byteLength);
2893
2799
  }
2894
- return props.debug ? getDebugContext(gl, props) : getRealContext(gl);
2895
- }
2896
- function getRealContext(gl) {
2897
- const data = getWebGLContextData(gl);
2898
- return data.realContext ? data.realContext : gl;
2899
- }
2900
- function getDebugContext(gl, props) {
2901
- if (!globalThis.WebGLDebugUtils) {
2902
- import_core13.log.warn("webgl-debug not loaded")();
2903
- return gl;
2800
+ /** Asynchronously read data from the buffer */
2801
+ async readAsync(byteOffset = 0, byteLength) {
2802
+ return this.readSyncWebGL(byteOffset, byteLength);
2904
2803
  }
2905
- const data = getWebGLContextData(gl);
2906
- if (data.debugContext) {
2907
- return data.debugContext;
2804
+ /** Synchronously read data from the buffer. WebGL only. */
2805
+ readSyncWebGL(byteOffset = 0, byteLength) {
2806
+ byteLength = byteLength ?? this.byteLength - byteOffset;
2807
+ const data = new Uint8Array(byteLength);
2808
+ const dstOffset = 0;
2809
+ this.gl.bindBuffer(36662, this.handle);
2810
+ this.gl.getBufferSubData(36662, byteOffset, data, dstOffset, byteLength);
2811
+ this.gl.bindBuffer(36662, null);
2812
+ this._setDebugData(data, byteOffset, byteLength);
2813
+ return data;
2908
2814
  }
2909
- globalThis.WebGLDebugUtils.init({ ...import_constants12.GL, ...gl });
2910
- const glDebug = globalThis.WebGLDebugUtils.makeDebugContext(gl, onGLError.bind(null, props), onValidateGLFunc.bind(null, props));
2911
- for (const key in import_constants12.GL) {
2912
- if (!(key in glDebug) && typeof import_constants12.GL[key] === "number") {
2913
- glDebug[key] = import_constants12.GL[key];
2914
- }
2815
+ };
2816
+ function getWebGLTarget(usage) {
2817
+ if (usage & import_core12.Buffer.INDEX) {
2818
+ return 34963;
2915
2819
  }
2916
- class WebGLDebugContext {
2820
+ if (usage & import_core12.Buffer.VERTEX) {
2821
+ return 34962;
2917
2822
  }
2918
- Object.setPrototypeOf(glDebug, Object.getPrototypeOf(gl));
2919
- Object.setPrototypeOf(WebGLDebugContext, glDebug);
2920
- const debugContext = Object.create(WebGLDebugContext);
2921
- data.realContext = gl;
2922
- data.debugContext = debugContext;
2923
- debugContext.debug = true;
2924
- return debugContext;
2925
- }
2926
- function getFunctionString(functionName, functionArgs) {
2927
- functionArgs = Array.from(functionArgs).map((arg) => arg === void 0 ? "undefined" : arg);
2928
- let args = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, functionArgs);
2929
- args = `${args.slice(0, 100)}${args.length > 100 ? "..." : ""}`;
2930
- return `gl.${functionName}(${args})`;
2931
- }
2932
- function onGLError(props, err, functionName, args) {
2933
- args = Array.from(args).map((arg) => arg === void 0 ? "undefined" : arg);
2934
- const errorMessage = globalThis.WebGLDebugUtils.glEnumToString(err);
2935
- const functionArgs = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, args);
2936
- const message2 = `${errorMessage} in gl.${functionName}(${functionArgs})`;
2937
- import_core13.log.error(message2)();
2938
- debugger;
2939
- if (props.throwOnError) {
2940
- throw new Error(message2);
2823
+ if (usage & import_core12.Buffer.UNIFORM) {
2824
+ return 35345;
2941
2825
  }
2826
+ return 34962;
2942
2827
  }
2943
- function onValidateGLFunc(props, functionName, functionArgs) {
2944
- let functionString = "";
2945
- if (import_core13.log.level >= 1) {
2946
- functionString = getFunctionString(functionName, functionArgs);
2947
- import_core13.log.log(1, functionString)();
2828
+ function getWebGLUsage(usage) {
2829
+ if (usage & import_core12.Buffer.INDEX) {
2830
+ return 35044;
2948
2831
  }
2949
- if (props.break && props.break.length > 0) {
2950
- functionString = functionString || getFunctionString(functionName, functionArgs);
2951
- const isBreakpoint = props.break.every((breakOn) => functionString.indexOf(breakOn) !== -1);
2952
- if (isBreakpoint) {
2953
- debugger;
2954
- }
2832
+ if (usage & import_core12.Buffer.VERTEX) {
2833
+ return 35044;
2955
2834
  }
2956
- for (const arg of functionArgs) {
2957
- if (arg === void 0) {
2958
- functionString = functionString || getFunctionString(functionName, functionArgs);
2959
- if (props.throwOnError) {
2960
- throw new Error(`Undefined argument: ${functionString}`);
2961
- } else {
2962
- import_core13.log.error(`Undefined argument: ${functionString}`)();
2963
- debugger;
2964
- }
2965
- }
2835
+ if (usage & import_core12.Buffer.UNIFORM) {
2836
+ return 35048;
2966
2837
  }
2838
+ return 35044;
2967
2839
  }
2968
2840
 
2969
2841
  // dist/adapter/resources/webgl-shader.js
2970
- var import_core14 = require("@luma.gl/core");
2971
- var import_constants13 = require("@luma.gl/constants");
2842
+ var import_core13 = require("@luma.gl/core");
2843
+ var import_constants14 = require("@luma.gl/constants");
2972
2844
 
2973
2845
  // dist/adapter/helpers/parse-shader-compiler-log.js
2974
2846
  function parseShaderCompilerLog(errLog) {
@@ -3015,7 +2887,7 @@ function getMessageType(messageType) {
3015
2887
  }
3016
2888
 
3017
2889
  // dist/adapter/resources/webgl-shader.js
3018
- var WEBGLShader = class extends import_core14.Shader {
2890
+ var WEBGLShader = class extends import_core13.Shader {
3019
2891
  device;
3020
2892
  handle;
3021
2893
  constructor(device, props) {
@@ -3046,12 +2918,12 @@ var WEBGLShader = class extends import_core14.Shader {
3046
2918
  }
3047
2919
  getCompilationInfoSync() {
3048
2920
  const log9 = this.device.gl.getShaderInfoLog(this.handle);
3049
- return parseShaderCompilerLog(log9);
2921
+ return log9 ? parseShaderCompilerLog(log9) : [];
3050
2922
  }
3051
2923
  getTranslatedSource() {
3052
2924
  const extensions = this.device.getExtension("WEBGL_debug_shaders");
3053
2925
  const ext = extensions.WEBGL_debug_shaders;
3054
- return ext == null ? void 0 : ext.getTranslatedShaderSource(this.handle);
2926
+ return (ext == null ? void 0 : ext.getTranslatedShaderSource(this.handle)) || null;
3055
2927
  }
3056
2928
  // PRIVATE METHODS
3057
2929
  /** Compile a shader and get compilation status */
@@ -3062,7 +2934,7 @@ ${source2}`;
3062
2934
  const { gl } = this.device;
3063
2935
  gl.shaderSource(this.handle, source);
3064
2936
  gl.compileShader(this.handle);
3065
- if (import_core14.log.level === 0) {
2937
+ if (import_core13.log.level === 0) {
3066
2938
  this.compilationStatus = "pending";
3067
2939
  return;
3068
2940
  }
@@ -3074,9 +2946,9 @@ ${source2}`;
3074
2946
  }
3075
2947
  return;
3076
2948
  }
3077
- import_core14.log.once(1, "Shader compilation is asynchronous")();
2949
+ import_core13.log.once(1, "Shader compilation is asynchronous")();
3078
2950
  await this._waitForCompilationComplete();
3079
- import_core14.log.info(2, `Shader ${this.id} - async compilation complete: ${this.compilationStatus}`)();
2951
+ import_core13.log.info(2, `Shader ${this.id} - async compilation complete: ${this.compilationStatus}`)();
3080
2952
  this._getCompilationStatus();
3081
2953
  this.debugShader();
3082
2954
  }
@@ -3108,14 +2980,14 @@ ${source2}`;
3108
2980
  };
3109
2981
 
3110
2982
  // dist/adapter/resources/webgl-render-pass.js
3111
- var import_core15 = require("@luma.gl/core");
3112
- var import_constants14 = require("@luma.gl/constants");
2983
+ var import_core14 = require("@luma.gl/core");
2984
+ var import_constants15 = require("@luma.gl/constants");
3113
2985
  var GL_DEPTH_BUFFER_BIT = 256;
3114
2986
  var GL_STENCIL_BUFFER_BIT = 1024;
3115
2987
  var GL_COLOR_BUFFER_BIT = 16384;
3116
2988
  var GL_COLOR = 6144;
3117
2989
  var COLOR_CHANNELS = [1, 2, 4, 8];
3118
- var WEBGLRenderPass = class extends import_core15.RenderPass {
2990
+ var WEBGLRenderPass = class extends import_core14.RenderPass {
3119
2991
  device;
3120
2992
  /** Parameters that should be applied before each draw call */
3121
2993
  glParameters;
@@ -3143,9 +3015,7 @@ var WEBGLRenderPass = class extends import_core15.RenderPass {
3143
3015
  */
3144
3016
  setParameters(parameters = {}) {
3145
3017
  const glParameters = { ...this.glParameters };
3146
- if (this.props.framebuffer) {
3147
- glParameters.framebuffer = this.props.framebuffer;
3148
- }
3018
+ glParameters.framebuffer = this.props.framebuffer || null;
3149
3019
  if (this.props.depthReadOnly) {
3150
3020
  glParameters.depthMask = !this.props.depthReadOnly;
3151
3021
  }
@@ -3231,19 +3101,17 @@ var WEBGLRenderPass = class extends import_core15.RenderPass {
3231
3101
  };
3232
3102
 
3233
3103
  // dist/adapter/resources/webgl-render-pipeline.js
3234
- var import_core17 = require("@luma.gl/core");
3235
- var import_core18 = require("@luma.gl/core");
3236
- var import_constants21 = require("@luma.gl/constants");
3104
+ var import_core15 = require("@luma.gl/core");
3105
+ var import_constants22 = require("@luma.gl/constants");
3237
3106
 
3238
3107
  // dist/adapter/helpers/get-shader-layout.js
3239
- var import_constants18 = require("@luma.gl/constants");
3108
+ var import_constants19 = require("@luma.gl/constants");
3240
3109
 
3241
3110
  // dist/classic/accessor.js
3242
- var import_core16 = require("@luma.gl/core");
3243
- var import_constants16 = require("@luma.gl/constants");
3111
+ var import_constants17 = require("@luma.gl/constants");
3244
3112
 
3245
3113
  // dist/classic/typed-array-utils.js
3246
- var import_constants15 = require("@luma.gl/constants");
3114
+ var import_constants16 = require("@luma.gl/constants");
3247
3115
  var ERR_TYPE_DEDUCTION = "Failed to deduce GL constant from typed array";
3248
3116
  function getGLTypeFromTypedArray(arrayOrType) {
3249
3117
  const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
@@ -3303,12 +3171,6 @@ var DEFAULT_ACCESSOR_VALUES = {
3303
3171
  normalized: false,
3304
3172
  integer: false
3305
3173
  };
3306
- var PROP_CHECKS = {
3307
- deprecatedProps: {
3308
- instanced: "divisor",
3309
- isInstanced: "divisor"
3310
- }
3311
- };
3312
3174
  var Accessor = class {
3313
3175
  offset;
3314
3176
  stride;
@@ -3324,7 +3186,6 @@ var Accessor = class {
3324
3186
  return ArrayType.BYTES_PER_ELEMENT;
3325
3187
  }
3326
3188
  static getBytesPerVertex(accessor) {
3327
- (0, import_core16.assert)(accessor.size);
3328
3189
  const ArrayType = getTypedArrayFromGLType(accessor.type || 5126);
3329
3190
  return ArrayType.BYTES_PER_ELEMENT * accessor.size;
3330
3191
  }
@@ -3353,7 +3214,6 @@ var Accessor = class {
3353
3214
  // PRIVATE
3354
3215
  // eslint-disable-next-line complexity, max-statements
3355
3216
  _assign(props = {}) {
3356
- props = (0, import_core16.checkProps)("Accessor", props, PROP_CHECKS);
3357
3217
  if (props.type !== void 0) {
3358
3218
  this.type = props.type;
3359
3219
  if (props.type === 5124 || props.type === 5125) {
@@ -3420,7 +3280,7 @@ var Accessor = class {
3420
3280
  };
3421
3281
 
3422
3282
  // dist/adapter/helpers/decode-webgl-types.js
3423
- var import_constants17 = require("@luma.gl/constants");
3283
+ var import_constants18 = require("@luma.gl/constants");
3424
3284
  function isSamplerUniform(type) {
3425
3285
  return SAMPLER_TYPES.includes(type);
3426
3286
  }
@@ -3713,7 +3573,7 @@ function parseUniformName(name) {
3713
3573
  }
3714
3574
 
3715
3575
  // dist/adapter/helpers/set-uniform.js
3716
- var import_constants19 = require("@luma.gl/constants");
3576
+ var import_constants20 = require("@luma.gl/constants");
3717
3577
  function setUniform(gl, location, type, value) {
3718
3578
  const gl2 = gl;
3719
3579
  let uniformValue = value;
@@ -3798,8 +3658,26 @@ function setUniform(gl, location, type, value) {
3798
3658
  throw new Error("Illegal uniform");
3799
3659
  }
3800
3660
 
3661
+ // dist/utils/split-uniforms-and-bindings.js
3662
+ var import_types = require("@math.gl/types");
3663
+ function isUniformValue(value) {
3664
+ return (0, import_types.isNumericArray)(value) !== null || typeof value === "number" || typeof value === "boolean";
3665
+ }
3666
+ function splitUniformsAndBindings(uniforms) {
3667
+ const result = { bindings: {}, uniforms: {} };
3668
+ Object.keys(uniforms).forEach((name) => {
3669
+ const uniform = uniforms[name];
3670
+ if (isUniformValue(uniform)) {
3671
+ result.uniforms[name] = uniform;
3672
+ } else {
3673
+ result.bindings[name] = uniform;
3674
+ }
3675
+ });
3676
+ return result;
3677
+ }
3678
+
3801
3679
  // dist/adapter/helpers/webgl-topology-utils.js
3802
- var import_constants20 = require("@luma.gl/constants");
3680
+ var import_constants21 = require("@luma.gl/constants");
3803
3681
  function getGLDrawMode(topology) {
3804
3682
  switch (topology) {
3805
3683
  case "point-list":
@@ -3808,14 +3686,10 @@ function getGLDrawMode(topology) {
3808
3686
  return 1;
3809
3687
  case "line-strip":
3810
3688
  return 3;
3811
- case "line-loop-webgl":
3812
- return 2;
3813
3689
  case "triangle-list":
3814
3690
  return 4;
3815
3691
  case "triangle-strip":
3816
3692
  return 5;
3817
- case "triangle-fan-webgl":
3818
- return 6;
3819
3693
  default:
3820
3694
  throw new Error(topology);
3821
3695
  }
@@ -3828,14 +3702,10 @@ function getGLPrimitive(topology) {
3828
3702
  return 1;
3829
3703
  case "line-strip":
3830
3704
  return 1;
3831
- case "line-loop-webgl":
3832
- return 1;
3833
3705
  case "triangle-list":
3834
3706
  return 4;
3835
3707
  case "triangle-strip":
3836
3708
  return 4;
3837
- case "triangle-fan-webgl":
3838
- return 4;
3839
3709
  default:
3840
3710
  throw new Error(topology);
3841
3711
  }
@@ -3843,7 +3713,7 @@ function getGLPrimitive(topology) {
3843
3713
 
3844
3714
  // dist/adapter/resources/webgl-render-pipeline.js
3845
3715
  var LOG_PROGRAM_PERF_PRIORITY = 4;
3846
- var WEBGLRenderPipeline = class extends import_core17.RenderPipeline {
3716
+ var WEBGLRenderPipeline = class extends import_core15.RenderPipeline {
3847
3717
  /** The WebGL device that created this render pipeline */
3848
3718
  device;
3849
3719
  /** Handle to underlying WebGL program */
@@ -3868,25 +3738,18 @@ var WEBGLRenderPipeline = class extends import_core17.RenderPipeline {
3868
3738
  this.device = device;
3869
3739
  this.handle = this.props.handle || this.device.gl.createProgram();
3870
3740
  this.device.setSpectorMetadata(this.handle, { id: this.props.id });
3871
- this.vs = (0, import_core17.cast)(props.vs);
3872
- this.fs = (0, import_core17.cast)(props.fs);
3741
+ this.vs = props.vs;
3742
+ this.fs = props.fs;
3873
3743
  const { varyings, bufferMode = 35981 } = props;
3874
3744
  if (varyings && varyings.length > 0) {
3875
3745
  this.varyings = varyings;
3876
3746
  this.device.gl.transformFeedbackVaryings(this.handle, varyings, bufferMode);
3877
3747
  }
3878
3748
  this._linkShaders();
3879
- import_core17.log.time(1, `RenderPipeline ${this.id} - shaderLayout introspection`)();
3749
+ import_core15.log.time(1, `RenderPipeline ${this.id} - shaderLayout introspection`)();
3880
3750
  this.introspectedLayout = getShaderLayout(this.device.gl, this.handle);
3881
- import_core17.log.timeEnd(1, `RenderPipeline ${this.id} - shaderLayout introspection`)();
3882
- this.shaderLayout = (0, import_core18.mergeShaderLayout)(this.introspectedLayout, props.shaderLayout);
3883
- switch (this.props.topology) {
3884
- case "triangle-fan-webgl":
3885
- case "line-loop-webgl":
3886
- import_core17.log.warn(`Primitive topology ${this.props.topology} is deprecated and will be removed in v9.1`);
3887
- break;
3888
- default:
3889
- }
3751
+ import_core15.log.timeEnd(1, `RenderPipeline ${this.id} - shaderLayout introspection`)();
3752
+ this.shaderLayout = mergeShaderLayout(this.introspectedLayout, props.shaderLayout);
3890
3753
  }
3891
3754
  destroy() {
3892
3755
  if (this.handle) {
@@ -3904,12 +3767,12 @@ var WEBGLRenderPipeline = class extends import_core17.RenderPipeline {
3904
3767
  if (!binding) {
3905
3768
  const validBindings = this.shaderLayout.bindings.map((binding2) => `"${binding2.name}"`).join(", ");
3906
3769
  if (!(options == null ? void 0 : options.disableWarnings)) {
3907
- import_core17.log.warn(`Unknown binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`)();
3770
+ import_core15.log.warn(`Unknown binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`)();
3908
3771
  }
3909
3772
  continue;
3910
3773
  }
3911
3774
  if (!value) {
3912
- import_core17.log.warn(`Unsetting binding "${name}" in render pipeline "${this.id}"`)();
3775
+ import_core15.log.warn(`Unsetting binding "${name}" in render pipeline "${this.id}"`)();
3913
3776
  }
3914
3777
  switch (binding.type) {
3915
3778
  case "uniform":
@@ -3923,7 +3786,7 @@ var WEBGLRenderPipeline = class extends import_core17.RenderPipeline {
3923
3786
  }
3924
3787
  break;
3925
3788
  case "sampler":
3926
- import_core17.log.warn(`Ignoring sampler ${name}`)();
3789
+ import_core15.log.warn(`Ignoring sampler ${name}`)();
3927
3790
  break;
3928
3791
  default:
3929
3792
  throw new Error(binding.type);
@@ -3956,17 +3819,13 @@ var WEBGLRenderPipeline = class extends import_core17.RenderPipeline {
3956
3819
  const isIndexed = Boolean(vertexArray.indexBuffer);
3957
3820
  const glIndexType = (_a = vertexArray.indexBuffer) == null ? void 0 : _a.glIndexType;
3958
3821
  if (this.linkStatus !== "success") {
3959
- import_core17.log.info(2, `RenderPipeline:${this.id}.draw() aborted - waiting for shader linking`)();
3822
+ import_core15.log.info(2, `RenderPipeline:${this.id}.draw() aborted - waiting for shader linking`)();
3960
3823
  return false;
3961
3824
  }
3962
- if (!this._areTexturesRenderable() || vertexCount === 0) {
3963
- import_core17.log.info(2, `RenderPipeline:${this.id}.draw() aborted - textures not yet loaded`)();
3825
+ if (!this._areTexturesRenderable()) {
3826
+ import_core15.log.info(2, `RenderPipeline:${this.id}.draw() aborted - textures not yet loaded`)();
3964
3827
  return false;
3965
3828
  }
3966
- if (vertexCount === 0) {
3967
- import_core17.log.info(2, `RenderPipeline:${this.id}.draw() aborted - no vertices to draw`)();
3968
- return true;
3969
- }
3970
3829
  this.device.gl.useProgram(this.handle);
3971
3830
  vertexArray.bindBeforeRender(renderPass);
3972
3831
  if (transformFeedback) {
@@ -4001,9 +3860,9 @@ var WEBGLRenderPipeline = class extends import_core17.RenderPipeline {
4001
3860
  }
4002
3861
  // DEPRECATED METHODS
4003
3862
  setUniformsWebGL(uniforms) {
4004
- const { bindings } = (0, import_core17.splitUniformsAndBindings)(uniforms);
3863
+ const { bindings } = splitUniformsAndBindings(uniforms);
4005
3864
  Object.keys(bindings).forEach((name) => {
4006
- import_core17.log.warn(`Unsupported value "${JSON.stringify(bindings[name])}" used in setUniforms() for key ${name}. Use setBindings() instead?`)();
3865
+ import_core15.log.warn(`Unsupported value "${JSON.stringify(bindings[name])}" used in setUniforms() for key ${name}. Use setBindings() instead?`)();
4007
3866
  });
4008
3867
  Object.assign(this.uniforms, uniforms);
4009
3868
  }
@@ -4014,19 +3873,19 @@ var WEBGLRenderPipeline = class extends import_core17.RenderPipeline {
4014
3873
  const { gl } = this.device;
4015
3874
  gl.attachShader(this.handle, this.vs.handle);
4016
3875
  gl.attachShader(this.handle, this.fs.handle);
4017
- import_core17.log.time(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
3876
+ import_core15.log.time(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
4018
3877
  gl.linkProgram(this.handle);
4019
- import_core17.log.timeEnd(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
4020
- if (import_core17.log.level === 0) {
3878
+ import_core15.log.timeEnd(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
3879
+ if (import_core15.log.level === 0) {
4021
3880
  }
4022
3881
  if (!this.device.features.has("compilation-status-async-webgl")) {
4023
3882
  const status2 = this._getLinkStatus();
4024
3883
  this._reportLinkStatus(status2);
4025
3884
  return;
4026
3885
  }
4027
- import_core17.log.once(1, "RenderPipeline linking is asynchronous")();
3886
+ import_core15.log.once(1, "RenderPipeline linking is asynchronous")();
4028
3887
  await this._waitForLinkComplete();
4029
- import_core17.log.info(2, `RenderPipeline ${this.id} - async linking complete: ${this.linkStatus}`)();
3888
+ import_core15.log.info(2, `RenderPipeline ${this.id} - async linking complete: ${this.linkStatus}`)();
4030
3889
  const status = this._getLinkStatus();
4031
3890
  this._reportLinkStatus(status);
4032
3891
  }
@@ -4093,10 +3952,15 @@ var WEBGLRenderPipeline = class extends import_core17.RenderPipeline {
4093
3952
  */
4094
3953
  _areTexturesRenderable() {
4095
3954
  let texturesRenderable = true;
3955
+ for (const bindingInfo of this.shaderLayout.bindings) {
3956
+ if (!this.bindings[bindingInfo.name] && !this.bindings[bindingInfo.name.replace(/Uniforms$/, "")]) {
3957
+ import_core15.log.warn(`Binding ${bindingInfo.name} not found in ${this.id}`)();
3958
+ texturesRenderable = false;
3959
+ }
3960
+ }
4096
3961
  for (const [, texture] of Object.entries(this.bindings)) {
4097
3962
  if (texture instanceof WEBGLTexture) {
4098
3963
  texture.update();
4099
- texturesRenderable = texturesRenderable && texture.loaded;
4100
3964
  }
4101
3965
  }
4102
3966
  return texturesRenderable;
@@ -4149,13 +4013,13 @@ var WEBGLRenderPipeline = class extends import_core17.RenderPipeline {
4149
4013
  } else if (value instanceof WEBGLTexture) {
4150
4014
  texture = value;
4151
4015
  } else if (value instanceof WEBGLFramebuffer && value.colorAttachments[0] instanceof WEBGLTextureView) {
4152
- import_core17.log.warn("Passing framebuffer in texture binding may be deprecated. Use fbo.colorAttachments[0] instead")();
4016
+ import_core15.log.warn("Passing framebuffer in texture binding may be deprecated. Use fbo.colorAttachments[0] instead")();
4153
4017
  texture = value.colorAttachments[0].texture;
4154
4018
  } else {
4155
4019
  throw new Error("No texture");
4156
4020
  }
4157
4021
  gl.activeTexture(33984 + textureUnit);
4158
- gl.bindTexture(texture.target, texture.handle);
4022
+ gl.bindTexture(texture.glTarget, texture.handle);
4159
4023
  textureUnit += 1;
4160
4024
  break;
4161
4025
  case "sampler":
@@ -4180,17 +4044,30 @@ var WEBGLRenderPipeline = class extends import_core17.RenderPipeline {
4180
4044
  }
4181
4045
  }
4182
4046
  };
4047
+ function mergeShaderLayout(baseLayout, overrideLayout) {
4048
+ const mergedLayout = {
4049
+ ...baseLayout,
4050
+ attributes: baseLayout.attributes.map((attribute) => ({ ...attribute }))
4051
+ };
4052
+ for (const attribute of (overrideLayout == null ? void 0 : overrideLayout.attributes) || []) {
4053
+ const baseAttribute = mergedLayout.attributes.find((attr) => attr.name === attribute.name);
4054
+ if (!baseAttribute) {
4055
+ import_core15.log.warn(`shader layout attribute ${attribute.name} not present in shader`);
4056
+ } else {
4057
+ baseAttribute.type = attribute.type || baseAttribute.type;
4058
+ baseAttribute.stepMode = attribute.stepMode || baseAttribute.stepMode;
4059
+ }
4060
+ }
4061
+ return mergedLayout;
4062
+ }
4183
4063
 
4184
4064
  // dist/adapter/resources/webgl-command-encoder.js
4185
- var import_core20 = require("@luma.gl/core");
4065
+ var import_core17 = require("@luma.gl/core");
4186
4066
 
4187
4067
  // dist/adapter/resources/webgl-command-buffer.js
4188
- var import_core19 = require("@luma.gl/core");
4189
- var import_constants22 = require("@luma.gl/constants");
4190
- function cast2(value) {
4191
- return value;
4192
- }
4193
- var WEBGLCommandBuffer = class extends import_core19.CommandBuffer {
4068
+ var import_core16 = require("@luma.gl/core");
4069
+ var import_constants23 = require("@luma.gl/constants");
4070
+ var WEBGLCommandBuffer = class extends import_core16.CommandBuffer {
4194
4071
  device;
4195
4072
  commands = [];
4196
4073
  constructor(device) {
@@ -4217,8 +4094,8 @@ var WEBGLCommandBuffer = class extends import_core19.CommandBuffer {
4217
4094
  }
4218
4095
  };
4219
4096
  function _copyBufferToBuffer(device, options) {
4220
- const source = cast2(options.source);
4221
- const destination = cast2(options.destination);
4097
+ const source = options.source;
4098
+ const destination = options.destination;
4222
4099
  device.gl.bindBuffer(36662, source.handle);
4223
4100
  device.gl.bindBuffer(36663, destination.handle);
4224
4101
  device.gl.copyBufferSubData(36662, 36663, options.sourceOffset ?? 0, options.destinationOffset ?? 0, options.size);
@@ -4271,8 +4148,8 @@ function _copyTextureToBuffer(device, options) {
4271
4148
  const webglBuffer = destination;
4272
4149
  const sourceWidth = width || framebuffer.width;
4273
4150
  const sourceHeight = height || framebuffer.height;
4274
- const sourceParams = getWebGLTextureParameters(framebuffer.texture.props.format);
4275
- const sourceFormat = sourceParams.dataFormat;
4151
+ const sourceParams = getTextureFormatWebGL(framebuffer.colorAttachments[0].texture.props.format);
4152
+ const sourceFormat = sourceParams.format;
4276
4153
  const sourceType = sourceParams.type;
4277
4154
  device.gl.bindBuffer(35051, webglBuffer.handle);
4278
4155
  prevHandle = device.gl.bindFramebuffer(36160, framebuffer.handle);
@@ -4324,7 +4201,7 @@ function _copyTextureToTexture(device, options) {
4324
4201
  width = Number.isFinite(width) ? width : texture.width;
4325
4202
  height = Number.isFinite(height) ? height : texture.height;
4326
4203
  texture.bind(0);
4327
- textureTarget = texture.target;
4204
+ textureTarget = texture.glTarget;
4328
4205
  } else {
4329
4206
  throw new Error("invalid destination");
4330
4207
  }
@@ -4348,7 +4225,7 @@ function _copyTextureToTexture(device, options) {
4348
4225
  }
4349
4226
  }
4350
4227
  function getFramebuffer(source) {
4351
- if (source instanceof import_core19.Texture) {
4228
+ if (source instanceof import_core16.Texture) {
4352
4229
  const { width, height, id } = source;
4353
4230
  const framebuffer = source.device.createFramebuffer({
4354
4231
  id: `framebuffer-for-${id}`,
@@ -4362,7 +4239,7 @@ function getFramebuffer(source) {
4362
4239
  }
4363
4240
 
4364
4241
  // dist/adapter/resources/webgl-command-encoder.js
4365
- var WEBGLCommandEncoder = class extends import_core20.CommandEncoder {
4242
+ var WEBGLCommandEncoder = class extends import_core17.CommandEncoder {
4366
4243
  device;
4367
4244
  commandBuffer;
4368
4245
  constructor(device, props) {
@@ -4401,10 +4278,33 @@ var WEBGLCommandEncoder = class extends import_core20.CommandEncoder {
4401
4278
  };
4402
4279
 
4403
4280
  // dist/adapter/resources/webgl-vertex-array.js
4404
- var import_core21 = require("@luma.gl/core");
4405
- var import_constants23 = require("@luma.gl/constants");
4281
+ var import_core18 = require("@luma.gl/core");
4282
+ var import_constants24 = require("@luma.gl/constants");
4406
4283
  var import_env2 = require("@probe.gl/env");
4407
- var WEBGLVertexArray = class extends import_core21.VertexArray {
4284
+
4285
+ // dist/utils/fill-array.js
4286
+ function fillArray(options) {
4287
+ const { target, source, start = 0, count = 1 } = options;
4288
+ const length = source.length;
4289
+ const total = count * length;
4290
+ let copied = 0;
4291
+ for (let i = start; copied < length; copied++) {
4292
+ target[i++] = source[copied];
4293
+ }
4294
+ while (copied < total) {
4295
+ if (copied < total - copied) {
4296
+ target.copyWithin(start + copied, start, start + copied);
4297
+ copied *= 2;
4298
+ } else {
4299
+ target.copyWithin(start + copied, start, start + total - copied);
4300
+ copied = total;
4301
+ }
4302
+ }
4303
+ return options.target;
4304
+ }
4305
+
4306
+ // dist/adapter/resources/webgl-vertex-array.js
4307
+ var WEBGLVertexArray = class extends import_core18.VertexArray {
4408
4308
  get [Symbol.toStringTag]() {
4409
4309
  return "VertexArray";
4410
4310
  }
@@ -4464,6 +4364,7 @@ var WEBGLVertexArray = class extends import_core21.VertexArray {
4464
4364
  } else {
4465
4365
  this.device.gl.vertexAttribPointer(location, size, type, normalized, stride, offset);
4466
4366
  }
4367
+ this.device.gl.bindBuffer(34962, null);
4467
4368
  this.device.gl.enableVertexAttribArray(location);
4468
4369
  this.device.gl.vertexAttribDivisor(location, divisor || 0);
4469
4370
  this.attributes[location] = buffer;
@@ -4570,8 +4471,8 @@ var WEBGLVertexArray = class extends import_core21.VertexArray {
4570
4471
  this.buffer = this.buffer || this.device.createBuffer({ byteLength });
4571
4472
  updateNeeded = updateNeeded || !compareConstantArrayValues(constantValue, this.bufferValue);
4572
4473
  if (updateNeeded) {
4573
- const typedArray = (0, import_core21.getScratchArray)(value.constructor, length);
4574
- (0, import_core21.fillArray)({ target: typedArray, source: constantValue, start: 0, count: length });
4474
+ const typedArray = (0, import_core18.getScratchArray)(value.constructor, length);
4475
+ fillArray({ target: typedArray, source: constantValue, start: 0, count: length });
4575
4476
  this.buffer.write(typedArray);
4576
4477
  this.bufferValue = value;
4577
4478
  }
@@ -4597,9 +4498,9 @@ function compareConstantArrayValues(v1, v2) {
4597
4498
  }
4598
4499
 
4599
4500
  // dist/adapter/resources/webgl-transform-feedback.js
4600
- var import_core22 = require("@luma.gl/core");
4601
- var import_constants24 = require("@luma.gl/constants");
4602
- var WEBGLTransformFeedback = class extends import_core22.TransformFeedback {
4501
+ var import_core19 = require("@luma.gl/core");
4502
+ var import_constants25 = require("@luma.gl/constants");
4503
+ var WEBGLTransformFeedback = class extends import_core19.TransformFeedback {
4603
4504
  device;
4604
4505
  gl;
4605
4506
  handle;
@@ -4642,7 +4543,7 @@ var WEBGLTransformFeedback = class extends import_core22.TransformFeedback {
4642
4543
  }
4643
4544
  end() {
4644
4545
  this.gl.endTransformFeedback();
4645
- if (!this.bindOnUse) {
4546
+ if (this.bindOnUse) {
4646
4547
  this._unbindBuffers();
4647
4548
  }
4648
4549
  this.gl.bindTransformFeedback(36386, null);
@@ -4662,7 +4563,7 @@ var WEBGLTransformFeedback = class extends import_core22.TransformFeedback {
4662
4563
  const { buffer, byteLength, byteOffset } = this._getBufferRange(bufferOrRange);
4663
4564
  if (location < 0) {
4664
4565
  this.unusedBuffers[locationOrName] = buffer;
4665
- import_core22.log.warn(`${this.id} unusedBuffers varying buffer ${locationOrName}`)();
4566
+ import_core19.log.warn(`${this.id} unusedBuffers varying buffer ${locationOrName}`)();
4666
4567
  return;
4667
4568
  }
4668
4569
  this.buffers[location] = { buffer, byteLength, byteOffset };
@@ -4749,9 +4650,9 @@ function isIndex(value) {
4749
4650
  }
4750
4651
 
4751
4652
  // dist/adapter/resources/webgl-query-set.js
4752
- var import_core23 = require("@luma.gl/core");
4753
- var import_constants25 = require("@luma.gl/constants");
4754
- var WEBGLQuerySet = class extends import_core23.QuerySet {
4653
+ var import_core20 = require("@luma.gl/core");
4654
+ var import_constants26 = require("@luma.gl/constants");
4655
+ var WEBGLQuerySet = class extends import_core20.QuerySet {
4755
4656
  device;
4756
4657
  handle;
4757
4658
  target = null;
@@ -4879,12 +4780,11 @@ var WEBGLQuerySet = class extends import_core23.QuerySet {
4879
4780
  };
4880
4781
 
4881
4782
  // dist/classic/copy-and-blit.js
4882
- var import_core25 = require("@luma.gl/core");
4883
- var import_constants27 = require("@luma.gl/constants");
4783
+ var import_core21 = require("@luma.gl/core");
4784
+ var import_constants28 = require("@luma.gl/constants");
4884
4785
 
4885
4786
  // dist/classic/format-utils.js
4886
- var import_core24 = require("@luma.gl/core");
4887
- var import_constants26 = require("@luma.gl/constants");
4787
+ var import_constants27 = require("@luma.gl/constants");
4888
4788
  function glFormatToComponents(format) {
4889
4789
  switch (format) {
4890
4790
  case 6406:
@@ -4901,7 +4801,6 @@ function glFormatToComponents(format) {
4901
4801
  case 34836:
4902
4802
  return 4;
4903
4803
  default:
4904
- (0, import_core24.assert)(false);
4905
4804
  return 0;
4906
4805
  }
4907
4806
  }
@@ -4916,7 +4815,6 @@ function glTypeToBytes(type) {
4916
4815
  case 5126:
4917
4816
  return 4;
4918
4817
  default:
4919
- (0, import_core24.assert)(false);
4920
4818
  return 0;
4921
4819
  }
4922
4820
  }
@@ -4939,12 +4837,11 @@ function readPixelsToArray(source, options) {
4939
4837
  sourceType
4940
4838
  } = options || {};
4941
4839
  const { framebuffer, deleteFramebuffer } = getFramebuffer2(source);
4942
- (0, import_core25.assert)(framebuffer);
4943
4840
  const { gl, handle } = framebuffer;
4944
4841
  sourceWidth = sourceWidth || framebuffer.width;
4945
4842
  sourceHeight = sourceHeight || framebuffer.height;
4946
4843
  const attachment = sourceAttachment - 36064;
4947
- sourceType = sourceType || ((_b = (_a = framebuffer.colorAttachments[attachment]) == null ? void 0 : _a.texture) == null ? void 0 : _b.type) || 5121;
4844
+ sourceType = sourceType || ((_b = (_a = framebuffer.colorAttachments[attachment]) == null ? void 0 : _a.texture) == null ? void 0 : _b.glType) || 5121;
4948
4845
  target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
4949
4846
  sourceType = sourceType || getGLTypeFromTypedArray(target);
4950
4847
  const prevHandle = gl.bindFramebuffer(36160, handle);
@@ -4959,7 +4856,6 @@ function readPixelsToBuffer(source, options) {
4959
4856
  const { target, sourceX = 0, sourceY = 0, sourceFormat = 6408, targetByteOffset = 0 } = options || {};
4960
4857
  let { sourceWidth, sourceHeight, sourceType } = options || {};
4961
4858
  const { framebuffer, deleteFramebuffer } = getFramebuffer2(source);
4962
- (0, import_core25.assert)(framebuffer);
4963
4859
  sourceWidth = sourceWidth || framebuffer.width;
4964
4860
  sourceHeight = sourceHeight || framebuffer.height;
4965
4861
  const webglFramebuffer = framebuffer;
@@ -4987,7 +4883,7 @@ function readPixelsToBuffer(source, options) {
4987
4883
  return webglBufferTarget;
4988
4884
  }
4989
4885
  function getFramebuffer2(source) {
4990
- if (!(source instanceof import_core25.Framebuffer)) {
4886
+ if (!(source instanceof import_core21.Framebuffer)) {
4991
4887
  return { framebuffer: toFramebuffer(source), deleteFramebuffer: true };
4992
4888
  }
4993
4889
  return { framebuffer: source, deleteFramebuffer: false };
@@ -5014,11 +4910,9 @@ function getPixelArray(pixelArray, type, format, width, height) {
5014
4910
  }
5015
4911
 
5016
4912
  // dist/classic/clear.js
5017
- var import_core26 = require("@luma.gl/core");
5018
4913
  var GL_DEPTH_BUFFER_BIT2 = 256;
5019
4914
  var GL_STENCIL_BUFFER_BIT2 = 1024;
5020
4915
  var GL_COLOR_BUFFER_BIT2 = 16384;
5021
- var ERR_ARGUMENTS = "clear: bad arguments";
5022
4916
  function clear(device, options) {
5023
4917
  const { framebuffer = null, color = null, depth = null, stencil = null } = options || {};
5024
4918
  const parameters = {};
@@ -5044,7 +4938,6 @@ function clear(device, options) {
5044
4938
  parameters.clearStencil = depth;
5045
4939
  }
5046
4940
  }
5047
- (0, import_core26.assert)(clearFlags !== 0, ERR_ARGUMENTS);
5048
4941
  const gl = device.gl;
5049
4942
  withGLParameters(gl, parameters, () => {
5050
4943
  gl.clear(clearFlags);
@@ -5053,7 +4946,7 @@ function clear(device, options) {
5053
4946
 
5054
4947
  // dist/adapter/webgl-device.js
5055
4948
  var LOG_LEVEL2 = 1;
5056
- var _WebGLDevice = class extends import_core27.Device {
4949
+ var _WebGLDevice = class extends import_core22.Device {
5057
4950
  /** type of this device */
5058
4951
  type = "webgl";
5059
4952
  /** The underlying WebGL context */
@@ -5081,7 +4974,7 @@ var _WebGLDevice = class extends import_core27.Device {
5081
4974
  if (gl instanceof _WebGLDevice) {
5082
4975
  return gl;
5083
4976
  }
5084
- if ((gl == null ? void 0 : gl.device) instanceof import_core27.Device) {
4977
+ if ((gl == null ? void 0 : gl.device) instanceof import_core22.Device) {
5085
4978
  return gl.device;
5086
4979
  }
5087
4980
  if (!isWebGL(gl)) {
@@ -5091,7 +4984,7 @@ var _WebGLDevice = class extends import_core27.Device {
5091
4984
  }
5092
4985
  static async create(props = {}) {
5093
4986
  var _a;
5094
- import_core27.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created")();
4987
+ import_core22.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created")();
5095
4988
  const promises = [];
5096
4989
  if (props.debug) {
5097
4990
  promises.push(loadWebGLDeveloperTools());
@@ -5100,24 +4993,24 @@ var _WebGLDevice = class extends import_core27.Device {
5100
4993
  promises.push(loadSpectorJS());
5101
4994
  }
5102
4995
  if (typeof props.canvas === "string") {
5103
- promises.push(import_core27.CanvasContext.pageLoaded);
4996
+ promises.push(import_core22.CanvasContext.pageLoaded);
5104
4997
  }
5105
4998
  const results = await Promise.allSettled(promises);
5106
4999
  for (const result of results) {
5107
5000
  if (result.status === "rejected") {
5108
- import_core27.log.error(`Failed to initialize debug libraries ${result.reason}`)();
5001
+ import_core22.log.error(`Failed to initialize debug libraries ${result.reason}`)();
5109
5002
  }
5110
5003
  }
5111
- import_core27.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
5004
+ import_core22.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
5112
5005
  if ((_a = props.gl) == null ? void 0 : _a.device) {
5113
- import_core27.log.warn("reattaching existing device")();
5006
+ import_core22.log.warn("reattaching existing device")();
5114
5007
  return _WebGLDevice.attach(props.gl);
5115
5008
  }
5116
5009
  const device = new _WebGLDevice(props);
5117
5010
  const message2 = `Created ${device.type}${device.debug ? " debug" : ""} context: ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
5118
- import_core27.log.probe(LOG_LEVEL2, message2)();
5119
- import_core27.log.table(LOG_LEVEL2, device.info)();
5120
- import_core27.log.groupEnd(LOG_LEVEL2)();
5011
+ import_core22.log.probe(LOG_LEVEL2, message2)();
5012
+ import_core22.log.table(LOG_LEVEL2, device.info)();
5013
+ import_core22.log.groupEnd(LOG_LEVEL2)();
5121
5014
  return device;
5122
5015
  }
5123
5016
  //
@@ -5125,7 +5018,7 @@ var _WebGLDevice = class extends import_core27.Device {
5125
5018
  //
5126
5019
  constructor(props) {
5127
5020
  var _a, _b;
5128
- super({ ...props, id: props.id || (0, import_core27.uid)("webgl-device") });
5021
+ super({ ...props, id: props.id || "webgl-device" });
5129
5022
  const device = (_a = props.gl) == null ? void 0 : _a.device;
5130
5023
  if (device) {
5131
5024
  throw new Error(`WebGL context already attached to device ${device.id}`);
@@ -5164,13 +5057,13 @@ var _WebGLDevice = class extends import_core27.Device {
5164
5057
  trackContextState(this.gl, {
5165
5058
  enable: enable2,
5166
5059
  copyState,
5167
- log: (...args) => import_core27.log.log(1, ...args)()
5060
+ log: (...args) => import_core22.log.log(1, ...args)()
5168
5061
  });
5169
5062
  if (props.debug) {
5170
5063
  this.gl = makeDebugContext(this.gl, { ...props, throwOnError: true });
5171
5064
  this.debug = true;
5172
- import_core27.log.level = Math.max(import_core27.log.level, 1);
5173
- import_core27.log.warn("WebGL debug mode activated. Performance reduced.")();
5065
+ import_core22.log.level = Math.max(import_core22.log.level, 1);
5066
+ import_core22.log.warn("WebGL debug mode activated. Performance reduced.")();
5174
5067
  }
5175
5068
  if (props.spector) {
5176
5069
  this.spectorJS = initializeSpectorJS({ ...this.props, canvas: this.handle.canvas });
@@ -5205,6 +5098,7 @@ var _WebGLDevice = class extends import_core27.Device {
5205
5098
  const newProps = this._getBufferProps(props);
5206
5099
  return new WEBGLBuffer(this, newProps);
5207
5100
  }
5101
+ // _createTexture(props: TextureProps): WEBGLTexture {
5208
5102
  _createTexture(props) {
5209
5103
  return new WEBGLTexture(this, props);
5210
5104
  }
@@ -5242,7 +5136,7 @@ var _WebGLDevice = class extends import_core27.Device {
5242
5136
  throw new Error("ComputePass not supported in WebGL");
5243
5137
  }
5244
5138
  renderPass = null;
5245
- createCommandEncoder(props) {
5139
+ createCommandEncoder(props = {}) {
5246
5140
  return new WEBGLCommandEncoder(this, props);
5247
5141
  }
5248
5142
  /**
@@ -5279,7 +5173,7 @@ var _WebGLDevice = class extends import_core27.Device {
5279
5173
  clear(this, options);
5280
5174
  }
5281
5175
  resetWebGL() {
5282
- import_core27.log.warn("WebGLDevice.resetWebGL is deprecated, use only for debugging")();
5176
+ import_core22.log.warn("WebGLDevice.resetWebGL is deprecated, use only for debugging")();
5283
5177
  resetGLParameters(this.gl);
5284
5178
  }
5285
5179
  //
@@ -5357,7 +5251,7 @@ var _WebGLDevice = class extends import_core27.Device {
5357
5251
  this._constants = this._constants || new Array(maxVertexAttributes).fill(null);
5358
5252
  const currentConstant = this._constants[location];
5359
5253
  if (currentConstant && compareConstantArrayValues2(currentConstant, constant)) {
5360
- import_core27.log.info(1, `setConstantAttributeWebGL(${location}) could have been skipped, value unchanged`)();
5254
+ import_core22.log.info(1, `setConstantAttributeWebGL(${location}) could have been skipped, value unchanged`)();
5361
5255
  }
5362
5256
  this._constants[location] = constant;
5363
5257
  switch (constant.constructor) {
@@ -5371,7 +5265,7 @@ var _WebGLDevice = class extends import_core27.Device {
5371
5265
  setConstantUintArray(this, location, constant);
5372
5266
  break;
5373
5267
  default:
5374
- (0, import_core27.assert)(false);
5268
+ throw new Error("constant");
5375
5269
  }
5376
5270
  }
5377
5271
  /** Ensure extensions are only requested once */
@@ -5407,7 +5301,6 @@ function setConstantFloatArray(device, location, array) {
5407
5301
  device.gl.vertexAttrib4fv(location, array);
5408
5302
  break;
5409
5303
  default:
5410
- (0, import_core27.assert)(false);
5411
5304
  }
5412
5305
  }
5413
5306
  function setConstantIntArray(device, location, array) {
@@ -5427,174 +5320,4 @@ function compareConstantArrayValues2(v1, v2) {
5427
5320
  }
5428
5321
  return true;
5429
5322
  }
5430
-
5431
- // dist/adapter/objects/webgl-resource.js
5432
- var import_core28 = require("@luma.gl/core");
5433
- var ERR_RESOURCE_METHOD_UNDEFINED = "Resource subclass must define virtual methods";
5434
- var WebGLResource = class extends import_core28.Resource {
5435
- device;
5436
- gl;
5437
- gl2;
5438
- _handle;
5439
- _bound = false;
5440
- // Only meaningful for resources that allocate GPU memory
5441
- byteLength = 0;
5442
- constructor(device, props, defaultProps) {
5443
- super(device, props, defaultProps);
5444
- this.device = device;
5445
- const gl = this.device.gl;
5446
- const { id } = props || {};
5447
- this.gl = gl;
5448
- this.gl2 = gl;
5449
- this.id = id || (0, import_core28.uid)(this.constructor.name);
5450
- this._handle = props == null ? void 0 : props.handle;
5451
- if (this._handle === void 0) {
5452
- this._handle = this._createHandle();
5453
- }
5454
- this.byteLength = 0;
5455
- }
5456
- toString() {
5457
- return `${this.constructor.name}(${this.id})`;
5458
- }
5459
- get handle() {
5460
- return this._handle;
5461
- }
5462
- delete({ deleteChildren = false } = {}) {
5463
- const children = this._handle && this._deleteHandle(this._handle);
5464
- if (this._handle) {
5465
- this.removeStats();
5466
- }
5467
- this._handle = null;
5468
- if (children && deleteChildren) {
5469
- children.filter(Boolean).forEach((child) => child.destroy());
5470
- }
5471
- return this;
5472
- }
5473
- bind(funcOrHandle = this.handle) {
5474
- if (typeof funcOrHandle !== "function") {
5475
- this._bindHandle(funcOrHandle);
5476
- return this;
5477
- }
5478
- let value;
5479
- if (!this._bound) {
5480
- this._bindHandle(this.handle);
5481
- this._bound = true;
5482
- value = funcOrHandle();
5483
- this._bound = false;
5484
- this._bindHandle(null);
5485
- } else {
5486
- value = funcOrHandle();
5487
- }
5488
- return value;
5489
- }
5490
- unbind() {
5491
- this.bind(null);
5492
- }
5493
- // Install stubs for removed methods
5494
- stubRemovedMethods(className, version, methodNames) {
5495
- return (0, import_core28.stubRemovedMethods)(this, className, version, methodNames);
5496
- }
5497
- // PUBLIC VIRTUAL METHODS
5498
- initialize(props) {
5499
- }
5500
- // PROTECTED METHODS - These must be overridden by subclass
5501
- _createHandle() {
5502
- throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
5503
- }
5504
- _deleteHandle() {
5505
- throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
5506
- }
5507
- _bindHandle(handle) {
5508
- throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
5509
- }
5510
- _getOptsFromHandle() {
5511
- throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
5512
- }
5513
- _getParameter(pname, props) {
5514
- throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
5515
- }
5516
- _setParameter(pname, value) {
5517
- throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
5518
- }
5519
- };
5520
-
5521
- // dist/adapter/objects/webgl-renderbuffer.js
5522
- var import_core29 = require("@luma.gl/core");
5523
- var import_constants28 = require("@luma.gl/constants");
5524
- var _WEBGLRenderbuffer = class extends WebGLResource {
5525
- get [Symbol.toStringTag]() {
5526
- return "Renderbuffer";
5527
- }
5528
- get width() {
5529
- return this.props.width;
5530
- }
5531
- get height() {
5532
- return this.props.height;
5533
- }
5534
- get format() {
5535
- return this.props.format;
5536
- }
5537
- get samples() {
5538
- return this.props.samples;
5539
- }
5540
- get attachment() {
5541
- return;
5542
- }
5543
- /** WebGL format constant */
5544
- glFormat;
5545
- static isTextureFormatSupported(device, format) {
5546
- return isRenderbufferFormatSupported(device.gl, format, device._extensions);
5547
- }
5548
- constructor(device, props) {
5549
- if (typeof props.format === "number") {
5550
- throw new Error("Renderbuffer");
5551
- }
5552
- super(device, props, _WEBGLRenderbuffer.defaultProps);
5553
- this.glFormat = convertTextureFormatToGL(this.props.format);
5554
- this._initialize(this.props);
5555
- }
5556
- resize(size) {
5557
- if (size.width !== this.width || size.height !== this.height) {
5558
- Object.assign(this.props, { ...size, format: this.format, samples: this.samples });
5559
- this._initialize(this.props);
5560
- }
5561
- }
5562
- // PRIVATE METHODS
5563
- /** Creates and initializes a renderbuffer object's data store */
5564
- _initialize(props) {
5565
- const { format, width, height, samples } = props;
5566
- (0, import_core29.assert)(format, "Needs format");
5567
- this.trackDeallocatedMemory();
5568
- this.gl.bindRenderbuffer(36161, this.handle);
5569
- if (samples !== 0) {
5570
- this.gl.renderbufferStorageMultisample(36161, samples, this.glFormat, width, height);
5571
- } else {
5572
- this.gl.renderbufferStorage(36161, this.glFormat, width, height);
5573
- }
5574
- this.gl.bindRenderbuffer(36161, null);
5575
- this.trackAllocatedMemory(width * height * (samples || 1) * getTextureFormatBytesPerPixel(this.format));
5576
- }
5577
- // RESOURCE IMPLEMENTATION
5578
- _createHandle() {
5579
- return this.gl.createRenderbuffer();
5580
- }
5581
- _deleteHandle() {
5582
- this.gl.deleteRenderbuffer(this.handle);
5583
- this.trackDeallocatedMemory();
5584
- }
5585
- _bindHandle(handle) {
5586
- this.gl.bindRenderbuffer(36161, handle);
5587
- }
5588
- };
5589
- var WEBGLRenderbuffer = _WEBGLRenderbuffer;
5590
- __publicField(WEBGLRenderbuffer, "defaultProps", {
5591
- id: void 0,
5592
- handle: void 0,
5593
- userData: void 0,
5594
- format: void 0,
5595
- // 'depth16unorm'
5596
- width: 1,
5597
- height: 1,
5598
- samples: 0
5599
- });
5600
5323
  //# sourceMappingURL=index.cjs.map