@luma.gl/gltf 9.0.0-alpha.47 → 9.0.0-alpha.50

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.
package/dist/dist.dev.js CHANGED
@@ -822,8 +822,6 @@ var __exports__ = (() => {
822
822
  VERSION: VERSION3,
823
823
  version: VERSION3,
824
824
  log,
825
- // A global stats object that various components can add information to
826
- // E.g. see webgl/resource.js
827
825
  stats: lumaStats
828
826
  };
829
827
  }
@@ -863,17 +861,10 @@ var __exports__ = (() => {
863
861
 
864
862
  // ../core/src/adapter/resources/resource.ts
865
863
  var Resource = class {
866
- /** props.id, for debugging. */
867
864
  userData = {};
868
- /** Whether this resource has been destroyed */
869
865
  destroyed = false;
870
- /** For resources that allocate GPU memory */
871
866
  allocatedBytes = 0;
872
- /** Attached resources will be destroyed when this resource is destroyed. Tracks auto-created "sub" resources. */
873
867
  _attachedResources = /* @__PURE__ */ new Set();
874
- /**
875
- * Create a new Resource. Called from Subclass
876
- */
877
868
  constructor(device, props, defaultProps) {
878
869
  if (!device) {
879
870
  throw new Error("no device");
@@ -886,13 +877,9 @@ var __exports__ = (() => {
886
877
  this.userData = this.props.userData || {};
887
878
  this.addStats();
888
879
  }
889
- /**
890
- * destroy can be called on any resource to release it before it is garbage collected.
891
- */
892
880
  destroy() {
893
881
  this.destroyResource();
894
882
  }
895
- /** @deprecated Use destroy() */
896
883
  delete() {
897
884
  this.destroy();
898
885
  return this;
@@ -900,70 +887,48 @@ var __exports__ = (() => {
900
887
  toString() {
901
888
  return `${this[Symbol.toStringTag] || this.constructor.name}(${this.id})`;
902
889
  }
903
- /**
904
- * Combines a map of user props and default props, only including props from defaultProps
905
- * @returns returns a map of overridden default props
906
- */
907
890
  getProps() {
908
891
  return this.props;
909
892
  }
910
- // ATTACHED RESOURCES
911
- /**
912
- * Attaches a resource. Attached resources are auto destroyed when this resource is destroyed
913
- * Called automatically when sub resources are auto created but can be called by application
914
- */
915
893
  attachResource(resource) {
916
894
  this._attachedResources.add(resource);
917
895
  }
918
- /**
919
- * Detach an attached resource. The resource will no longer be auto-destroyed when this resource is destroyed.
920
- */
921
896
  detachResource(resource) {
922
897
  this._attachedResources.delete(resource);
923
898
  }
924
- /**
925
- * Destroys a resource (only if owned), and removes from the owned (auto-destroy) list for this resource.
926
- */
927
899
  destroyAttachedResource(resource) {
928
900
  if (this._attachedResources.delete(resource)) {
929
901
  resource.destroy();
930
902
  }
931
903
  }
932
- /** Destroy all owned resources. Make sure the resources are no longer needed before calling. */
933
904
  destroyAttachedResources() {
934
905
  for (const resource of Object.values(this._attachedResources)) {
935
906
  resource.destroy();
936
907
  }
937
908
  this._attachedResources = /* @__PURE__ */ new Set();
938
909
  }
939
- // PROTECTED METHODS
940
- /** Perform all destroy steps. Can be called by derived resources when overriding destroy() */
941
910
  destroyResource() {
942
911
  this.destroyAttachedResources();
943
912
  this.removeStats();
944
913
  this.destroyed = true;
945
914
  }
946
- /** Called by .destroy() to track object destruction. Subclass must call if overriding destroy() */
947
915
  removeStats() {
948
916
  const stats = this._device.statsManager.getStats("Resource Counts");
949
917
  const name2 = this[Symbol.toStringTag];
950
918
  stats.get(`${name2}s Active`).decrementCount();
951
919
  }
952
- /** Called by subclass to track memory allocations */
953
920
  trackAllocatedMemory(bytes, name2 = this[Symbol.toStringTag]) {
954
921
  const stats = this._device.statsManager.getStats("Resource Counts");
955
922
  stats.get("GPU Memory").addCount(bytes);
956
923
  stats.get(`${name2} Memory`).addCount(bytes);
957
924
  this.allocatedBytes = bytes;
958
925
  }
959
- /** Called by subclass to track memory deallocations */
960
926
  trackDeallocatedMemory(name2 = this[Symbol.toStringTag]) {
961
927
  const stats = this._device.statsManager.getStats("Resource Counts");
962
928
  stats.get("GPU Memory").subtractCount(this.allocatedBytes);
963
929
  stats.get(`${name2} Memory`).subtractCount(this.allocatedBytes);
964
930
  this.allocatedBytes = 0;
965
931
  }
966
- /** Called by resource constructor to track object creation */
967
932
  addStats() {
968
933
  const stats = this._device.statsManager.getStats("Resource Counts");
969
934
  const name2 = this[Symbol.toStringTag];
@@ -972,7 +937,6 @@ var __exports__ = (() => {
972
937
  stats.get(`${name2}s Active`).incrementCount();
973
938
  }
974
939
  };
975
- /** Default properties for resource */
976
940
  __publicField(Resource, "defaultProps", {
977
941
  id: "undefined",
978
942
  handle: void 0,
@@ -995,9 +959,6 @@ var __exports__ = (() => {
995
959
  get [Symbol.toStringTag]() {
996
960
  return "Buffer";
997
961
  }
998
- /** The usage with which this buffer was created */
999
- /** For index buffers, whether indices are 16 or 32 bit */
1000
- /** Length of buffer in bytes */
1001
962
  constructor(device, props) {
1002
963
  const deducedProps = {
1003
964
  ...props
@@ -1019,159 +980,55 @@ var __exports__ = (() => {
1019
980
  readAsync(byteOffset, byteLength) {
1020
981
  throw new Error("not implemented");
1021
982
  }
1022
- // TODO - can sync read be supported in WebGPU?
1023
983
  getData() {
1024
984
  throw new Error("not implemented");
1025
985
  }
1026
- // Convenience API
1027
- /** Read data from the buffer *
1028
- async readAsync(options: {
1029
- byteOffset?: number,
1030
- byteLength?: number,
1031
- map?: boolean,
1032
- unmap?: boolean
1033
- }): Promise<ArrayBuffer> {
1034
- if (options.map ?? true) {
1035
- await this.mapAsync(Buffer.MAP_READ, options.byteOffset, options.byteLength);
1036
- }
1037
- const arrayBuffer = this.getMappedRange(options.byteOffset, options.byteLength);
1038
- if (options.unmap ?? true) {
1039
- this.unmap();
1040
- }
1041
- return arrayBuffer;
1042
- }
1043
- /** Write data to the buffer *
1044
- async writeAsync(options: {
1045
- data: ArrayBuffer,
1046
- byteOffset?: number,
1047
- byteLength?: number,
1048
- map?: boolean,
1049
- unmap?: boolean
1050
- }): Promise<void> {
1051
- if (options.map ?? true) {
1052
- await this.mapAsync(Buffer.MAP_WRITE, options.byteOffset, options.byteLength);
1053
- }
1054
- const arrayBuffer = this.getMappedRange(options.byteOffset, options.byteLength);
1055
- const destArray = new Uint8Array(arrayBuffer);
1056
- const srcArray = new Uint8Array(options.data);
1057
- destArray.set(srcArray);
1058
- if (options.unmap ?? true) {
1059
- this.unmap();
1060
- }
1061
- }
1062
- */
1063
- // Mapped API (WebGPU)
1064
- /** Maps the memory so that it can be read */
1065
- // abstract mapAsync(mode, byteOffset, byteLength): Promise<void>
1066
- /** Get the mapped range of data for reading or writing */
1067
- // abstract getMappedRange(byteOffset, byteLength): ArrayBuffer;
1068
- /** unmap makes the contents of the buffer available to the GPU again */
1069
- // abstract unmap(): void;
1070
986
  };
1071
987
  var Buffer2 = _Buffer;
1072
988
  __publicField(Buffer2, "defaultProps", {
1073
989
  ...Resource.defaultProps,
1074
990
  usage: 0,
1075
- // Buffer.COPY_DST | Buffer.COPY_SRC
1076
991
  byteLength: 0,
1077
992
  byteOffset: 0,
1078
993
  data: null,
1079
994
  indexType: "uint16",
1080
995
  mappedAtCreation: false
1081
996
  });
1082
- // Usage Flags
1083
997
  __publicField(Buffer2, "MAP_READ", 1);
1084
998
  __publicField(Buffer2, "MAP_WRITE", 2);
1085
999
  __publicField(Buffer2, "COPY_SRC", 4);
1086
1000
  __publicField(Buffer2, "COPY_DST", 8);
1087
- /** Index buffer */
1088
1001
  __publicField(Buffer2, "INDEX", 16);
1089
- /** Vertex buffer */
1090
1002
  __publicField(Buffer2, "VERTEX", 32);
1091
- /** Uniform buffer */
1092
1003
  __publicField(Buffer2, "UNIFORM", 64);
1093
- /** Storage buffer */
1094
1004
  __publicField(Buffer2, "STORAGE", 128);
1095
1005
  __publicField(Buffer2, "INDIRECT", 256);
1096
1006
  __publicField(Buffer2, "QUERY_RESOLVE", 512);
1097
1007
 
1098
1008
  // ../core/src/adapter/device.ts
1099
- var DEFAULT_DEVICE_PROPS = {
1100
- id: null,
1101
- type: "best-available",
1102
- canvas: null,
1103
- container: null,
1104
- webgl2: true,
1105
- // Attempt to create a WebGL2 context
1106
- webgl1: true,
1107
- // Attempt to create a WebGL1 context (false to fail if webgl2 not available)
1108
- manageState: true,
1109
- width: 800,
1110
- // width are height are only used by headless gl
1111
- height: 600,
1112
- debug: Boolean(log.get("debug")),
1113
- // Instrument context (at the expense of performance)
1114
- break: [],
1115
- // alpha: undefined,
1116
- // depth: undefined,
1117
- // stencil: undefined,
1118
- // antialias: undefined,
1119
- // premultipliedAlpha: undefined,
1120
- // preserveDrawingBuffer: undefined,
1121
- // failIfMajorPerformanceCaveat: undefined
1122
- gl: null
1123
- };
1124
- var Device = class {
1009
+ var _Device = class {
1125
1010
  get [Symbol.toStringTag]() {
1126
1011
  return "Device";
1127
1012
  }
1128
1013
  constructor(props) {
1129
1014
  this.props = {
1130
- ...DEFAULT_DEVICE_PROPS,
1015
+ ..._Device.defaultProps,
1131
1016
  ...props
1132
1017
  };
1133
1018
  this.id = this.props.id || uid(this[Symbol.toStringTag].toLowerCase());
1134
1019
  }
1135
- /** id of this device, primarily for debugging */
1136
- /** stats */
1137
1020
  statsManager = lumaStats;
1138
- /** A copy of the device props */
1139
- /** Available for the application to store data on the device */
1140
1021
  userData = {};
1141
- /** Used by other luma.gl modules to store data on the device */
1142
1022
  _lumaData = {};
1143
- // Capabilities
1144
- /** Information about the device (vendor, versions etc) */
1145
- /** Optional capability discovery */
1146
- /** WebGPU style device limits */
1147
- /** Check if device supports a specific texture format (creation and `nearest` sampling) */
1148
- /** Check if linear filtering (sampler interpolation) is supported for a specific texture format */
1149
- /** Check if device supports rendering to a specific texture format */
1150
- // Device loss
1151
- /** `true` if device is already lost */
1152
- /** Promise that resolves when device is lost */
1153
- /**
1154
- * Trigger device loss.
1155
- * @returns `true` if context loss could actually be triggered.
1156
- * @note primarily intended for testing how application reacts to device loss
1157
- */
1158
1023
  loseDevice() {
1159
1024
  return false;
1160
1025
  }
1161
- // Canvas context
1162
- /** Default / primary canvas context. Can be null as WebGPU devices can be created without a CanvasContext */
1163
- /** Returns the default / primary canvas context. Throws an error if no canvas context is available (a WebGPU compute device) */
1164
1026
  getCanvasContext() {
1165
1027
  if (!this.canvasContext) {
1166
1028
  throw new Error("Device has no CanvasContext");
1167
1029
  }
1168
1030
  return this.canvasContext;
1169
1031
  }
1170
- /** Creates a new CanvasContext (WebGPU only) */
1171
- /** Call after rendering a frame (necessary e.g. on WebGL OffscreenCanvas) */
1172
- // Resource creation
1173
- /** Create a buffer */
1174
- /** Create a texture */
1175
1032
  createTexture(props) {
1176
1033
  if (props instanceof Promise || typeof props === "string") {
1177
1034
  props = {
@@ -1180,21 +1037,9 @@ var __exports__ = (() => {
1180
1037
  }
1181
1038
  return this._createTexture(props);
1182
1039
  }
1183
- /** Create a temporary texture view of a video source */
1184
- /** Create a sampler */
1185
- /** Create a Framebuffer. Must have at least one attachment. */
1186
- /** Create a shader */
1187
- /** Create a render pipeline (aka program) */
1188
- /** Create a compute pipeline (aka program). WebGPU only. */
1189
1040
  createCommandEncoder(props = {}) {
1190
1041
  throw new Error("not implemented");
1191
1042
  }
1192
- /** Create a vertex array */
1193
- /** Create a RenderPass */
1194
- /** Create a ComputePass */
1195
- /** Get a renderpass that is set up to render to the primary CanvasContext */
1196
- /** Create a transform feedback (immutable set of output buffer bindings). WebGL 2 only. */
1197
- // Implementation
1198
1043
  _getBufferProps(props) {
1199
1044
  if (props instanceof ArrayBuffer || ArrayBuffer.isView(props)) {
1200
1045
  props = {
@@ -1216,6 +1061,21 @@ var __exports__ = (() => {
1216
1061
  return newProps;
1217
1062
  }
1218
1063
  };
1064
+ var Device = _Device;
1065
+ __publicField(Device, "defaultProps", {
1066
+ id: null,
1067
+ type: "best-available",
1068
+ canvas: null,
1069
+ container: null,
1070
+ webgl2: true,
1071
+ webgl1: true,
1072
+ manageState: true,
1073
+ width: 800,
1074
+ height: 600,
1075
+ debug: Boolean(log.get("debug")),
1076
+ break: [],
1077
+ gl: null
1078
+ });
1219
1079
  __publicField(Device, "VERSION", VERSION2);
1220
1080
 
1221
1081
  // ../core/src/adapter/canvas-context.ts
@@ -1224,7 +1084,6 @@ var __exports__ = (() => {
1224
1084
  var DEFAULT_CANVAS_CONTEXT_PROPS = {
1225
1085
  canvas: null,
1226
1086
  width: 800,
1227
- // width are height are only used by headless gl
1228
1087
  height: 600,
1229
1088
  useDevicePixels: true,
1230
1089
  autoResize: true,
@@ -1236,13 +1095,11 @@ var __exports__ = (() => {
1236
1095
  var CanvasContext = class {
1237
1096
  width = 1;
1238
1097
  height = 1;
1239
- /** State used by luma.gl classes: TODO - move to canvasContext*/
1240
1098
  _canvasSizeInfo = {
1241
1099
  clientWidth: 0,
1242
1100
  clientHeight: 0,
1243
1101
  devicePixelRatio: 1
1244
1102
  };
1245
- /** Check if the DOM is loaded */
1246
1103
  static get isPageLoaded() {
1247
1104
  return isPageLoaded();
1248
1105
  }
@@ -1293,11 +1150,6 @@ var __exports__ = (() => {
1293
1150
  this.resizeObserver.observe(this.canvas);
1294
1151
  }
1295
1152
  }
1296
- /** Returns a framebuffer with properly resized current 'swap chain' textures */
1297
- /**
1298
- * Returns the current DPR, if props.useDevicePixels is true
1299
- * Device refers to physical
1300
- */
1301
1153
  getDevicePixelRatio(useDevicePixels) {
1302
1154
  if (typeof OffscreenCanvas !== "undefined" && this.canvas instanceof OffscreenCanvas) {
1303
1155
  return 1;
@@ -1312,12 +1164,6 @@ var __exports__ = (() => {
1312
1164
  }
1313
1165
  return useDevicePixels;
1314
1166
  }
1315
- /**
1316
- * Returns the size of drawing buffer in device pixels.
1317
- * @note This can be different from the 'CSS' size of a canvas, and also from the
1318
- * canvas' internal drawing buffer size (.width, .height).
1319
- * This is the size required to cover the canvas, adjusted for DPR
1320
- */
1321
1167
  getPixelSize() {
1322
1168
  switch (this.type) {
1323
1169
  case "node":
@@ -1336,9 +1182,6 @@ var __exports__ = (() => {
1336
1182
  const [width, height] = this.getPixelSize();
1337
1183
  return width / height;
1338
1184
  }
1339
- /**
1340
- * Returns multiplier need to convert CSS size to Device size
1341
- */
1342
1185
  cssToDeviceRatio() {
1343
1186
  try {
1344
1187
  const [drawingBufferWidth] = this.getDrawingBufferSize();
@@ -1350,18 +1193,11 @@ var __exports__ = (() => {
1350
1193
  return 1;
1351
1194
  }
1352
1195
  }
1353
- /**
1354
- * Maps CSS pixel position to device pixel position
1355
- */
1356
1196
  cssToDevicePixels(cssPixel, yInvert = true) {
1357
1197
  const ratio = this.cssToDeviceRatio();
1358
1198
  const [width, height] = this.getDrawingBufferSize();
1359
1199
  return scalePixels(cssPixel, ratio, width, height, yInvert);
1360
1200
  }
1361
- /**
1362
- * Use devicePixelRatio to set canvas width and height
1363
- * @note this is a raw port of luma.gl v8 code. Might be worth a review
1364
- */
1365
1201
  setDevicePixelRatio(devicePixelRatio, options = {}) {
1366
1202
  if (!this.htmlCanvas) {
1367
1203
  return;
@@ -1393,8 +1229,6 @@ var __exports__ = (() => {
1393
1229
  this._canvasSizeInfo.devicePixelRatio = devicePixelRatio;
1394
1230
  }
1395
1231
  }
1396
- // PRIVATE
1397
- /** @todo Major hack done to port the CSS methods above, base canvas context should not depend on WebGL */
1398
1232
  getDrawingBufferSize() {
1399
1233
  const gl = this.device.gl;
1400
1234
  if (!gl) {
@@ -1402,23 +1236,12 @@ var __exports__ = (() => {
1402
1236
  }
1403
1237
  return [gl.drawingBufferWidth, gl.drawingBufferHeight];
1404
1238
  }
1405
- /** Perform platform specific updates (WebGPU vs WebGL) */
1406
- /**
1407
- * Allows subclass constructor to override the canvas id for auto created canvases.
1408
- * This can really help when debugging DOM in apps that create multiple devices
1409
- */
1410
1239
  _setAutoCreatedCanvasId(id) {
1411
1240
  if (this.htmlCanvas?.id === "lumagl-auto-created-canvas") {
1412
1241
  this.htmlCanvas.id = id;
1413
1242
  }
1414
1243
  }
1415
1244
  };
1416
- /**
1417
- * Get a 'lazy' promise that resolves when the DOM is loaded.
1418
- * @note Since there may be limitations on number of `load` event listeners,
1419
- * it is recommended avoid calling this function until actually needed.
1420
- * I.e. don't call it until you know that you will be looking up a string in the DOM.
1421
- */
1422
1245
  __publicField(CanvasContext, "pageLoaded", getPageLoadPromise());
1423
1246
  function getPageLoadPromise() {
1424
1247
  if (isPageLoaded() || typeof window === "undefined") {
@@ -1449,7 +1272,7 @@ var __exports__ = (() => {
1449
1272
  throw new Error(`Accessing '${canvasId}' before page was loaded`);
1450
1273
  }
1451
1274
  if (!(canvas instanceof HTMLCanvasElement)) {
1452
- throw new Error(`'${canvas}' is not a canvas element`);
1275
+ throw new Error("Object is not a canvas element");
1453
1276
  }
1454
1277
  return canvas;
1455
1278
  }
@@ -1484,7 +1307,6 @@ var __exports__ = (() => {
1484
1307
  return {
1485
1308
  x,
1486
1309
  y,
1487
- // when ratio < 1, current css pixel and next css pixel may point to same device pixel, set width/height to 1 in those cases.
1488
1310
  width: Math.max(xHigh - x + 1, 1),
1489
1311
  height: Math.max(yHigh - y + 1, 1)
1490
1312
  };
@@ -1502,12 +1324,6 @@ var __exports__ = (() => {
1502
1324
  get [Symbol.toStringTag]() {
1503
1325
  return "Texture";
1504
1326
  }
1505
- /** dimension of this texture */
1506
- /** format of this texture */
1507
- /** width in pixels of this texture */
1508
- /** height in pixels of this texture */
1509
- /** depth of this texture */
1510
- /** Default sampler for this texture */
1511
1327
  constructor(device, props, defaultProps = _Texture.defaultProps) {
1512
1328
  super(device, props, defaultProps);
1513
1329
  this.dimension = this.props.dimension;
@@ -1528,11 +1344,8 @@ var __exports__ = (() => {
1528
1344
  depth: 1,
1529
1345
  mipmaps: true,
1530
1346
  sampler: {},
1531
- // type: undefined,
1532
1347
  compressed: false,
1533
- // mipLevels: 1,
1534
1348
  usage: 0,
1535
- // usage: GPUTextureUsage.COPY_DST
1536
1349
  mipLevels: void 0,
1537
1350
  samples: void 0,
1538
1351
  type: void 0
@@ -1585,7 +1398,6 @@ var __exports__ = (() => {
1585
1398
  mipmapFilter: "nearest",
1586
1399
  lodMinClamp: 0,
1587
1400
  lodMaxClamp: 32,
1588
- // Per WebGPU spec
1589
1401
  compare: "less-equal",
1590
1402
  maxAnisotropy: 1
1591
1403
  });
@@ -1595,21 +1407,13 @@ var __exports__ = (() => {
1595
1407
  get [Symbol.toStringTag]() {
1596
1408
  return "Framebuffer";
1597
1409
  }
1598
- /** Width of all attachments in this framebuffer */
1599
- /** Height of all attachments in this framebuffer */
1600
- /** Color attachments */
1601
1410
  colorAttachments = [];
1602
- /** Depth-stencil attachment, if provided */
1603
1411
  depthStencilAttachment = null;
1604
1412
  constructor(device, props = {}) {
1605
1413
  super(device, props, _Framebuffer.defaultProps);
1606
1414
  this.width = this.props.width;
1607
1415
  this.height = this.props.height;
1608
1416
  }
1609
- /**
1610
- * Resizes all attachments
1611
- * @note resize() destroys existing textures (if size has changed).
1612
- */
1613
1417
  resize(size) {
1614
1418
  let updateSize = !size;
1615
1419
  if (size) {
@@ -1623,51 +1427,6 @@ var __exports__ = (() => {
1623
1427
  this.resizeAttachments(this.width, this.height);
1624
1428
  }
1625
1429
  }
1626
- // /** Returns fully populated attachment object. */
1627
- // protected normalizeColorAttachment(
1628
- // attachment: Texture | ColorTextureFormat
1629
- // ): Required<ColorAttachment> {
1630
- // const COLOR_ATTACHMENT_DEFAULTS: Required<ColorAttachment> = {
1631
- // texture: undefined!,
1632
- // format: undefined!,
1633
- // clearValue: [0.0, 0.0, 0.0, 0.0],
1634
- // loadOp: 'clear',
1635
- // storeOp: 'store'
1636
- // };
1637
- // if (attachment instanceof Texture) {
1638
- // return {...COLOR_ATTACHMENT_DEFAULTS, texture: attachment};
1639
- // }
1640
- // if (typeof attachment === 'string') {
1641
- // return {...COLOR_ATTACHMENT_DEFAULTS, format: attachment};
1642
- // }
1643
- // return {...COLOR_ATTACHMENT_DEFAULTS, ...attachment};
1644
- // }
1645
- // /** Wraps texture inside fully populated attachment object. */
1646
- // protected normalizeDepthStencilAttachment(
1647
- // attachment: DepthStencilAttachment | Texture | DepthStencilTextureFormat
1648
- // ): Required<DepthStencilAttachment> {
1649
- // const DEPTH_STENCIL_ATTACHMENT_DEFAULTS: Required<DepthStencilAttachment> = {
1650
- // texture: undefined!,
1651
- // format: undefined!,
1652
- // depthClearValue: 1.0,
1653
- // depthLoadOp: 'clear',
1654
- // depthStoreOp: 'store',
1655
- // depthReadOnly: false,
1656
- // stencilClearValue: 0,
1657
- // stencilLoadOp: 'clear',
1658
- // stencilStoreOp: 'store',
1659
- // stencilReadOnly: false
1660
- // };
1661
- // if (typeof attachment === 'string') {
1662
- // return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, format: attachment};
1663
- // }
1664
- // // @ts-expect-error attachment instanceof Texture doesn't cover Renderbuffer
1665
- // if (attachment.handle || attachment instanceof Texture) {
1666
- // return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, texture: attachment as Texture};
1667
- // }
1668
- // return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, ...attachment};
1669
- // }
1670
- /** Auto creates any textures */
1671
1430
  autoCreateAttachmentTextures() {
1672
1431
  this.colorAttachments = this.props.colorAttachments.map((attachment) => {
1673
1432
  if (typeof attachment === "string") {
@@ -1687,7 +1446,6 @@ var __exports__ = (() => {
1687
1446
  }
1688
1447
  }
1689
1448
  }
1690
- /** Create a color texture */
1691
1449
  createColorTexture(format) {
1692
1450
  return this.device.createTexture({
1693
1451
  id: "color-attachment",
@@ -1697,7 +1455,6 @@ var __exports__ = (() => {
1697
1455
  height: this.height
1698
1456
  });
1699
1457
  }
1700
- /** Create depth stencil texture */
1701
1458
  createDepthStencilTexture(format) {
1702
1459
  return this.device.createTexture({
1703
1460
  id: "depth-stencil-attachment",
@@ -1707,11 +1464,6 @@ var __exports__ = (() => {
1707
1464
  height: this.height
1708
1465
  });
1709
1466
  }
1710
- /**
1711
- * Default implementation of resize
1712
- * Creates new textures with correct size for all attachments.
1713
- * and destroys existing textures if owned
1714
- */
1715
1467
  resizeAttachments(width, height) {
1716
1468
  for (let i = 0; i < this.colorAttachments.length; ++i) {
1717
1469
  if (this.colorAttachments[i]) {
@@ -1736,37 +1488,6 @@ var __exports__ = (() => {
1736
1488
  this.attachResource(resizedTexture);
1737
1489
  }
1738
1490
  }
1739
- /** Create a color attachment for WebGL *
1740
- protected override createColorTexture(colorAttachment: Required<ColorAttachment>): Required<ColorAttachment> {
1741
- return this.device._createTexture({
1742
- id: `${this.id}-color`,
1743
- data: null, // reserves texture memory, but texels are undefined
1744
- format,
1745
- // type: GL.UNSIGNED_BYTE,
1746
- width: this.width,
1747
- height: this.height,
1748
- // Note: Mipmapping can be disabled by texture resource when we resize the texture
1749
- // to a non-power-of-two dimenstion (NPOT texture) under WebGL1. To have consistant
1750
- // behavior we always disable mipmaps.
1751
- mipmaps: false,
1752
- // Set MIN and MAG filtering parameters so mipmaps are not used in sampling.
1753
- // Use LINEAR so subpixel algos like fxaa work.
1754
- // Set WRAP modes that support NPOT textures too.
1755
- sampler: {
1756
- minFilter: 'linear',
1757
- magFilter: 'linear',
1758
- addressModeU: 'clamp-to-edge',
1759
- addressModeV: 'clamp-to-edge'
1760
- }
1761
- // parameters: {
1762
- // [GL.TEXTURE_MIN_FILTER]: GL.LINEAR,
1763
- // [GL.TEXTURE_MAG_FILTER]: GL.LINEAR,
1764
- // [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
1765
- // [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE
1766
- // }
1767
- });
1768
- }
1769
- */
1770
1491
  };
1771
1492
  var Framebuffer = _Framebuffer;
1772
1493
  __publicField(Framebuffer, "defaultProps", {
@@ -1774,9 +1495,7 @@ var __exports__ = (() => {
1774
1495
  width: 1,
1775
1496
  height: 1,
1776
1497
  colorAttachments: [],
1777
- // ['rgba8unorm-unsized'],
1778
1498
  depthStencilAttachment: null
1779
- // 'depth24plus-stencil8'
1780
1499
  });
1781
1500
 
1782
1501
  // ../core/src/adapter/resources/render-pipeline.ts
@@ -1785,31 +1504,20 @@ var __exports__ = (() => {
1785
1504
  return "RenderPipeline";
1786
1505
  }
1787
1506
  hash = "";
1788
- /** The merged layout */
1789
- /** Buffer map describing buffer interleaving etc */
1790
1507
  constructor(device, props) {
1791
1508
  super(device, props, _RenderPipeline.defaultProps);
1792
1509
  this.shaderLayout = this.props.shaderLayout;
1793
1510
  this.bufferLayout = this.props.bufferLayout || [];
1794
1511
  }
1795
- /** Set bindings (stored on pipeline and set before each call) */
1796
- /** Uniforms
1797
- * @deprecated Only supported on WebGL devices.
1798
- * @note textures, samplers and uniform buffers should be set via `setBindings()`, these are not considered uniforms.
1799
- * @note In WebGL uniforms have a performance penalty, they are reset before each call to enable pipeline sharing.
1800
- */
1801
- /** Draw call */
1802
1512
  };
1803
1513
  var RenderPipeline = _RenderPipeline;
1804
1514
  __publicField(RenderPipeline, "defaultProps", {
1805
1515
  ...Resource.defaultProps,
1806
1516
  vs: null,
1807
1517
  vsEntryPoint: "",
1808
- // main
1809
1518
  vsConstants: {},
1810
1519
  fs: null,
1811
1520
  fsEntryPoint: "",
1812
- // main
1813
1521
  fsConstants: {},
1814
1522
  shaderLayout: null,
1815
1523
  bufferLayout: [],
@@ -1829,43 +1537,8 @@ var __exports__ = (() => {
1829
1537
  constructor(device, props) {
1830
1538
  super(device, props, _RenderPass.defaultProps);
1831
1539
  }
1832
- /** Call when rendering is done in this pass. */
1833
- /**
1834
- * A small set of parameters can be changed between every draw call
1835
- * (viewport, scissorRect, blendColor, stencilReference)
1836
- */
1837
- // writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;
1838
- // beginOcclusionQuery(queryIndex: number): void;
1839
- // endOcclusionQuery(): void;
1840
- // executeBundles(bundles: Iterable<GPURenderBundle>): void;
1841
- // In WebGPU the following methods are on the renderpass.
1842
- // luma.gl keeps them on the pipeline for now
1843
- /*
1844
- setPipeline(pipeline: RenderPipeline): void {}
1845
- setIndexBuffer(
1846
- buffer: Buffer,
1847
- indexFormat: 'uint16' | 'uint32',
1848
- offset?: number,
1849
- size?: number
1850
- ): void {}
1851
- abstract setVertexBuffer(slot: number, buffer: Buffer, offset: number): void;
1852
- abstract setBindings(bindings: Record<string, Binding>): void;
1853
- abstract setParameters(parameters: RenderPassParameters);
1854
- draw(options: {
1855
- vertexCount?: number; // Either vertexCount or indexCount must be provided
1856
- indexCount?: number; // Activates indexed drawing (call setIndexBuffer())
1857
- instanceCount?: number; //
1858
- firstVertex?: number;
1859
- firstIndex?: number; // requires device.features.has('indirect-first-instance')?
1860
- firstInstance?: number;
1861
- baseVertex?: number;
1862
- }): void {}
1863
- drawIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): void;
1864
- drawIndexedIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): void;
1865
- */
1866
1540
  };
1867
1541
  var RenderPass = _RenderPass;
1868
- /** Default properties for RenderPass */
1869
1542
  __publicField(RenderPass, "defaultProps", {
1870
1543
  ...Resource.defaultProps,
1871
1544
  framebuffer: null,
@@ -1886,24 +1559,12 @@ var __exports__ = (() => {
1886
1559
  constructor(device, props) {
1887
1560
  super(device, props, _CommandEncoder.defaultProps);
1888
1561
  }
1889
- // TODO - return the CommandBuffer?
1890
- // beginRenderPass(GPURenderPassDescriptor descriptor): GPURenderPassEncoder;
1891
- // beginComputePass(optional GPUComputePassDescriptor descriptor = {}): GPUComputePassEncoder;
1892
- // finish(options?: {id?: string}): GPUCommandBuffer;
1893
1562
  pushDebugGroup(groupLabel) {
1894
1563
  }
1895
1564
  popDebugGroup() {
1896
1565
  }
1897
1566
  insertDebugMarker(markerLabel) {
1898
1567
  }
1899
- // writeTimestamp(querySet: Query, queryIndex: number): void;
1900
- // resolveQuerySet(options: {
1901
- // querySet: GPUQuerySet,
1902
- // firstQuery: number,
1903
- // queryCount: number,
1904
- // destination: Buffer,
1905
- // destinationOffset?: number;
1906
- // }): void;
1907
1568
  };
1908
1569
  var CommandEncoder = _CommandEncoder;
1909
1570
  __publicField(CommandEncoder, "defaultProps", {
@@ -1984,7 +1645,6 @@ var __exports__ = (() => {
1984
1645
  f16: 2,
1985
1646
  i32: 4,
1986
1647
  u32: 4
1987
- // 'bool-webgl': 4,
1988
1648
  };
1989
1649
 
1990
1650
  // ../core/src/adapter/type-utils/decode-data-type.ts
@@ -2091,9 +1751,7 @@ var __exports__ = (() => {
2091
1751
  vertexFormat,
2092
1752
  bufferDataType: vertexFormatInfo.type,
2093
1753
  bufferComponents: vertexFormatInfo.components,
2094
- // normalized is a property of the buffer's vertex format
2095
1754
  normalized: vertexFormatInfo.normalized,
2096
- // integer is a property of the shader declaration
2097
1755
  integer: attributeTypeInfo.integer,
2098
1756
  stepMode: bufferMapping?.stepMode || shaderDeclaration.stepMode,
2099
1757
  byteOffset: bufferMapping?.byteOffset || 0,
@@ -2135,7 +1793,6 @@ var __exports__ = (() => {
2135
1793
  bufferName: name2,
2136
1794
  stepMode: bufferLayout.stepMode,
2137
1795
  vertexFormat: bufferLayout.format,
2138
- // If offset is needed, use `attributes` field.
2139
1796
  byteOffset: 0,
2140
1797
  byteStride: bufferLayout.byteStride || 0
2141
1798
  };
@@ -2190,8 +1847,6 @@ var __exports__ = (() => {
2190
1847
  get [Symbol.toStringTag]() {
2191
1848
  return "VertexArray";
2192
1849
  }
2193
- /** Max number of vertex attributes */
2194
- /** Attribute infos indexed by location - TODO only needed by webgl module? */
2195
1850
  indexBuffer = null;
2196
1851
  constructor(device, props) {
2197
1852
  super(device, props, _VertexArray.defaultProps);
@@ -2199,9 +1854,6 @@ var __exports__ = (() => {
2199
1854
  this.attributes = new Array(this.maxVertexAttributes).fill(null);
2200
1855
  this.attributeInfos = getAttributeInfosByLocation(props.renderPipeline.shaderLayout, props.renderPipeline.bufferLayout, this.maxVertexAttributes);
2201
1856
  }
2202
- /** Set attributes (stored on pipeline and set before each call) */
2203
- /** Set attributes (stored on pipeline and set before each call) */
2204
- /** Set constant attributes (WebGL only) */
2205
1857
  };
2206
1858
  var VertexArray = _VertexArray;
2207
1859
  __publicField(VertexArray, "defaultProps", {
@@ -2232,6 +1884,109 @@ var __exports__ = (() => {
2232
1884
  }
2233
1885
  }
2234
1886
 
1887
+ // ../core/src/adapter/type-utils/decode-shader-types.ts
1888
+ var UNIFORM_FORMATS = {
1889
+ "f32": {
1890
+ type: "f32",
1891
+ components: 1
1892
+ },
1893
+ "i32": {
1894
+ type: "i32",
1895
+ components: 1
1896
+ },
1897
+ "u32": {
1898
+ type: "u32",
1899
+ components: 1
1900
+ },
1901
+ "vec2<f32>": {
1902
+ type: "f32",
1903
+ components: 2
1904
+ },
1905
+ "vec3<f32>": {
1906
+ type: "f32",
1907
+ components: 3
1908
+ },
1909
+ "vec4<f32>": {
1910
+ type: "f32",
1911
+ components: 4
1912
+ },
1913
+ "vec2<i32>": {
1914
+ type: "i32",
1915
+ components: 2
1916
+ },
1917
+ "vec3<i32>": {
1918
+ type: "i32",
1919
+ components: 3
1920
+ },
1921
+ "vec4<i32>": {
1922
+ type: "i32",
1923
+ components: 4
1924
+ },
1925
+ "vec2<u32>": {
1926
+ type: "u32",
1927
+ components: 2
1928
+ },
1929
+ "vec3<u32>": {
1930
+ type: "u32",
1931
+ components: 3
1932
+ },
1933
+ "vec4<u32>": {
1934
+ type: "u32",
1935
+ components: 4
1936
+ },
1937
+ "mat2x2<f32>": {
1938
+ type: "f32",
1939
+ components: 4
1940
+ },
1941
+ "mat2x3<f32>": {
1942
+ type: "f32",
1943
+ components: 6
1944
+ },
1945
+ "mat2x4<f32>": {
1946
+ type: "f32",
1947
+ components: 8
1948
+ },
1949
+ "mat3x2<f32>": {
1950
+ type: "f32",
1951
+ components: 6
1952
+ },
1953
+ "mat3x3<f32>": {
1954
+ type: "f32",
1955
+ components: 9
1956
+ },
1957
+ "mat3x4<f32>": {
1958
+ type: "f32",
1959
+ components: 12
1960
+ },
1961
+ "mat4x2<f32>": {
1962
+ type: "f32",
1963
+ components: 8
1964
+ },
1965
+ "mat4x3<f32>": {
1966
+ type: "f32",
1967
+ components: 12
1968
+ },
1969
+ "mat4x4<f32>": {
1970
+ type: "f32",
1971
+ components: 16
1972
+ }
1973
+ };
1974
+ function decodeShaderUniformType(format) {
1975
+ const decoded = UNIFORM_FORMATS[format];
1976
+ assert2(format);
1977
+ return decoded;
1978
+ }
1979
+ function alignTo(size, count) {
1980
+ switch (count) {
1981
+ case 1:
1982
+ return size;
1983
+ case 2:
1984
+ return size + size % 2;
1985
+ default:
1986
+ return size + (4 - size % 4) % 4;
1987
+ }
1988
+ }
1989
+
2235
1990
  // ../core/src/lib/utils/array-utils-flat.ts
2236
1991
  var arrayBuffer;
2237
1992
  function getScratchArrayBuffer(byteLength) {
@@ -2269,6 +2024,237 @@ var __exports__ = (() => {
2269
2024
  return options.target;
2270
2025
  }
2271
2026
 
2027
+ // ../core/src/lib/uniforms/uniform-buffer-layout.ts
2028
+ var minBufferSize = 1024;
2029
+ var UniformBufferLayout = class {
2030
+ layout = {};
2031
+ constructor(uniformTypes) {
2032
+ let size = 0;
2033
+ for (const [key, uniformType] of Object.entries(uniformTypes)) {
2034
+ const typeAndComponents = decodeShaderUniformType(uniformType);
2035
+ const {
2036
+ type,
2037
+ components: count
2038
+ } = typeAndComponents;
2039
+ size = alignTo(size, count);
2040
+ const offset = size;
2041
+ size += count;
2042
+ this.layout[key] = {
2043
+ type,
2044
+ size: count,
2045
+ offset
2046
+ };
2047
+ }
2048
+ size += (4 - size % 4) % 4;
2049
+ const actualByteLength = size * 4;
2050
+ this.byteLength = Math.max(actualByteLength, minBufferSize);
2051
+ }
2052
+ getData(uniformValues) {
2053
+ const bufferSize = Math.max(this.byteLength, minBufferSize);
2054
+ const arrayBuffer2 = getScratchArrayBuffer(bufferSize);
2055
+ const typedArrays = {
2056
+ i32: new Int32Array(arrayBuffer2),
2057
+ u32: new Uint32Array(arrayBuffer2),
2058
+ f32: new Float32Array(arrayBuffer2),
2059
+ f16: new Uint16Array(arrayBuffer2)
2060
+ };
2061
+ for (const [name2, value] of Object.entries(uniformValues)) {
2062
+ const uniformLayout = this.layout[name2];
2063
+ if (!uniformLayout) {
2064
+ log.warn(`Supplied uniform value ${name2} not present in uniform block layout`)();
2065
+ continue;
2066
+ }
2067
+ const {
2068
+ type,
2069
+ size,
2070
+ offset
2071
+ } = uniformLayout;
2072
+ const typedArray = typedArrays[type];
2073
+ if (size === 1) {
2074
+ if (typeof value !== "number" && typeof value !== "boolean") {
2075
+ log.warn(`Supplied value for single component uniform ${name2} is not a number: ${value}`)();
2076
+ continue;
2077
+ }
2078
+ typedArray[offset] = Number(value);
2079
+ } else {
2080
+ const numericArray = isNumberArray(value);
2081
+ if (!numericArray) {
2082
+ log.warn(`Supplied value for multi component / array uniform ${name2} is not a numeric array: ${value}`)();
2083
+ continue;
2084
+ }
2085
+ typedArray.set(numericArray, offset);
2086
+ }
2087
+ }
2088
+ return new Uint8Array(arrayBuffer2);
2089
+ }
2090
+ has(name2) {
2091
+ return Boolean(this.layout[name2]);
2092
+ }
2093
+ get(name2) {
2094
+ const layout = this.layout[name2];
2095
+ return layout;
2096
+ }
2097
+ };
2098
+
2099
+ // ../core/src/lib/utils/array-equal.ts
2100
+ function arrayEqual(a, b, limit = 16) {
2101
+ if (a !== b) {
2102
+ return false;
2103
+ }
2104
+ const arrayA = isNumberArray(a);
2105
+ if (!arrayA) {
2106
+ return false;
2107
+ }
2108
+ const arrayB = isNumberArray(b);
2109
+ if (arrayB && arrayA.length === arrayB.length) {
2110
+ for (let i = 0; i < arrayA.length; ++i) {
2111
+ if (arrayB[i] !== arrayA[i]) {
2112
+ return false;
2113
+ }
2114
+ }
2115
+ }
2116
+ return true;
2117
+ }
2118
+ function arrayCopy(a) {
2119
+ const numberArray = isNumberArray(a);
2120
+ if (numberArray) {
2121
+ return numberArray.slice();
2122
+ }
2123
+ return a;
2124
+ }
2125
+
2126
+ // ../core/src/lib/uniforms/uniform-block.ts
2127
+ var UniformBlock = class {
2128
+ uniforms = {};
2129
+ modifiedUniforms = {};
2130
+ modified = true;
2131
+ bindingLayout = {};
2132
+ needsRedraw = "initialized";
2133
+ constructor(props) {
2134
+ this.name = props?.name;
2135
+ if (props?.name && props?.shaderLayout) {
2136
+ const binding = props?.shaderLayout.bindings?.find((binding2) => binding2.type === "uniform" && binding2.name === props?.name);
2137
+ if (!binding) {
2138
+ throw new Error(props?.name);
2139
+ }
2140
+ const uniformBlock = binding;
2141
+ for (const uniform of uniformBlock.uniforms || []) {
2142
+ this.bindingLayout[uniform.name] = uniform;
2143
+ }
2144
+ }
2145
+ }
2146
+ setUniforms(uniforms) {
2147
+ for (const [key, value] of Object.entries(uniforms)) {
2148
+ this._setUniform(key, value);
2149
+ if (!this.needsRedraw) {
2150
+ this.setNeedsRedraw(`${this.name}.${key}=${value}`);
2151
+ }
2152
+ }
2153
+ }
2154
+ setNeedsRedraw(reason) {
2155
+ this.needsRedraw = this.needsRedraw || reason;
2156
+ }
2157
+ getAllUniforms() {
2158
+ this.modifiedUniforms = {};
2159
+ this.needsRedraw = false;
2160
+ return this.uniforms || {};
2161
+ }
2162
+ _setUniform(key, value) {
2163
+ if (arrayEqual(this.uniforms[key], value)) {
2164
+ return;
2165
+ }
2166
+ this.uniforms[key] = arrayCopy(value);
2167
+ this.modifiedUniforms[key] = true;
2168
+ this.modified = true;
2169
+ }
2170
+ };
2171
+
2172
+ // ../core/src/lib/uniforms/uniform-store.ts
2173
+ var UniformStore = class {
2174
+ uniformBlocks = /* @__PURE__ */ new Map();
2175
+ uniformBufferLayouts = /* @__PURE__ */ new Map();
2176
+ uniformBuffers = /* @__PURE__ */ new Map();
2177
+ constructor(blocks) {
2178
+ for (const [bufferName, block] of Object.entries(blocks)) {
2179
+ const uniformBufferName = bufferName;
2180
+ const uniformBufferLayout = new UniformBufferLayout(block.uniformTypes || {});
2181
+ this.uniformBufferLayouts.set(uniformBufferName, uniformBufferLayout);
2182
+ const uniformBlock = new UniformBlock({
2183
+ name: bufferName
2184
+ });
2185
+ uniformBlock.setUniforms(block.defaultUniforms || {});
2186
+ this.uniformBlocks.set(uniformBufferName, uniformBlock);
2187
+ }
2188
+ }
2189
+ destroy() {
2190
+ for (const uniformBuffer of Object.values(this.uniformBuffers)) {
2191
+ uniformBuffer.destroy();
2192
+ }
2193
+ }
2194
+ setUniforms(uniforms) {
2195
+ for (const [blockName, uniformValues] of Object.entries(uniforms)) {
2196
+ this.uniformBlocks.get(blockName).setUniforms(uniformValues);
2197
+ }
2198
+ this.updateUniformBuffers();
2199
+ }
2200
+ getUniformBufferByteLength(uniformBufferName) {
2201
+ return this.uniformBufferLayouts.get(uniformBufferName).byteLength;
2202
+ }
2203
+ getUniformBufferData(uniformBufferName) {
2204
+ const uniformValues = this.uniformBlocks.get(uniformBufferName).getAllUniforms();
2205
+ return this.uniformBufferLayouts.get(uniformBufferName).getData(uniformValues);
2206
+ }
2207
+ createUniformBuffer(device, uniformBufferName, uniforms) {
2208
+ if (uniforms) {
2209
+ this.setUniforms(uniforms);
2210
+ }
2211
+ const byteLength = this.getUniformBufferByteLength(uniformBufferName);
2212
+ const uniformBuffer = device.createBuffer({
2213
+ usage: Buffer2.UNIFORM,
2214
+ byteLength
2215
+ });
2216
+ const uniformBufferData = this.getUniformBufferData(uniformBufferName);
2217
+ uniformBuffer.write(uniformBufferData);
2218
+ return uniformBuffer;
2219
+ }
2220
+ getManagedUniformBuffer(device, uniformBufferName) {
2221
+ if (!this.uniformBuffers.get(uniformBufferName)) {
2222
+ const byteLength = this.getUniformBufferByteLength(uniformBufferName);
2223
+ const uniformBuffer = device.createBuffer({
2224
+ usage: Buffer2.UNIFORM,
2225
+ byteLength
2226
+ });
2227
+ this.uniformBuffers.set(uniformBufferName, uniformBuffer);
2228
+ }
2229
+ return this.uniformBuffers.get(uniformBufferName);
2230
+ }
2231
+ updateUniformBuffers() {
2232
+ let reason = false;
2233
+ for (const uniformBufferName of this.uniformBlocks.keys()) {
2234
+ const bufferReason = this.updateUniformBuffer(uniformBufferName);
2235
+ reason ||= bufferReason;
2236
+ }
2237
+ if (reason) {
2238
+ log.log(3, `UniformStore.updateUniformBuffers(): ${reason}`)();
2239
+ }
2240
+ return reason;
2241
+ }
2242
+ updateUniformBuffer(uniformBufferName) {
2243
+ const uniformBlock = this.uniformBlocks.get(uniformBufferName);
2244
+ const uniformBuffer = this.uniformBuffers.get(uniformBufferName);
2245
+ let reason = false;
2246
+ if (uniformBuffer && uniformBlock.needsRedraw) {
2247
+ reason ||= uniformBlock.needsRedraw;
2248
+ const uniformBufferData = this.getUniformBufferData(uniformBufferName);
2249
+ const uniformBuffer2 = this.uniformBuffers.get(uniformBufferName);
2250
+ uniformBuffer2.write(uniformBufferData);
2251
+ const uniformValues = this.uniformBlocks.get(uniformBufferName).getAllUniforms();
2252
+ log.log(4, `Writing to uniform buffer ${String(uniformBufferName)}`, uniformBufferData, uniformValues)();
2253
+ }
2254
+ return reason;
2255
+ }
2256
+ };
2257
+
2272
2258
  // ../core/src/adapter/type-utils/decode-texture-format.ts
2273
2259
  var REGEX = /^(rg?b?a?)([0-9]*)([a-z]*)(-srgb)?(-webgl|-unsized)?$/;
2274
2260
  function decodeTextureFormat(format) {
@@ -2280,8 +2266,7 @@ var __exports__ = (() => {
2280
2266
  const decodedType = decodeVertexType(dataType);
2281
2267
  return {
2282
2268
  format: format2,
2283
- components: 0,
2284
- // dataType - overwritten by decodedType
2269
+ components: format2.length,
2285
2270
  srgb: srgb === "-srgb",
2286
2271
  unsized: suffix === "-unsized",
2287
2272
  webgl: suffix === "-webgl",
@@ -2292,7 +2277,6 @@ var __exports__ = (() => {
2292
2277
  return decodeNonStandardFormat(format);
2293
2278
  }
2294
2279
  var EXCEPTIONS = {
2295
- // Packed 16 bit formats
2296
2280
  "rgba4unorm-webgl": {
2297
2281
  format: "rgba",
2298
2282
  bpp: 2
@@ -2305,7 +2289,6 @@ var __exports__ = (() => {
2305
2289
  format: "rgba",
2306
2290
  bbp: 2
2307
2291
  },
2308
- // Packed 32 bit formats
2309
2292
  "rgb9e5ufloat": {
2310
2293
  format: "rgb",
2311
2294
  bbp: 4
@@ -2322,7 +2305,6 @@ var __exports__ = (() => {
2322
2305
  format: "rgba",
2323
2306
  bbp: 4
2324
2307
  },
2325
- // Depth/stencil
2326
2308
  "stencil8": {
2327
2309
  components: 1,
2328
2310
  bpp: 1,
@@ -2348,13 +2330,11 @@ var __exports__ = (() => {
2348
2330
  bpp: 4,
2349
2331
  a: "depth-stencil"
2350
2332
  },
2351
- // "depth24unorm-stencil8" feature
2352
2333
  "depth24unorm-stencil8": {
2353
2334
  components: 2,
2354
2335
  bpp: 4,
2355
2336
  a: "depth-stencil"
2356
2337
  },
2357
- // "depth32float-stencil8" feature
2358
2338
  "depth32float-stencil8": {
2359
2339
  components: 2,
2360
2340
  bpp: 4,
@@ -2368,7 +2348,7 @@ var __exports__ = (() => {
2368
2348
  }
2369
2349
  return {
2370
2350
  format: data.format || "",
2371
- components: data.components || 1,
2351
+ components: data.components || data.format?.length || 1,
2372
2352
  byteLength: data.bpp || 1,
2373
2353
  srgb: false,
2374
2354
  unsized: false
@@ -2398,22 +2378,28 @@ var __exports__ = (() => {
2398
2378
  throw new Error(type.constructor.name);
2399
2379
  }
2400
2380
  }
2401
- function getVertexFormatFromAttribute(typedArray, size) {
2381
+ function getVertexFormatFromAttribute(typedArray, size, normalized) {
2402
2382
  if (!size || size > 4) {
2403
2383
  throw new Error(`size ${size}`);
2404
2384
  }
2405
2385
  const components = size;
2406
- const dataType = getDataTypeFromTypedArray(typedArray);
2386
+ let dataType = getDataTypeFromTypedArray(typedArray);
2407
2387
  if (dataType === "uint8" || dataType === "sint8") {
2408
2388
  if (components === 1 || components === 3) {
2409
2389
  throw new Error(`size: ${size}`);
2410
2390
  }
2391
+ if (normalized) {
2392
+ dataType = dataType.replace("int", "norm");
2393
+ }
2411
2394
  return `${dataType}x${components}`;
2412
2395
  }
2413
2396
  if (dataType === "uint16" || dataType === "sint16") {
2414
2397
  if (components === 1 || components === 3) {
2415
2398
  throw new Error(`size: ${size}`);
2416
2399
  }
2400
+ if (normalized) {
2401
+ dataType = dataType.replace("int", "norm");
2402
+ }
2417
2403
  return `${dataType}x${components}`;
2418
2404
  }
2419
2405
  if (components === 1) {
@@ -2609,7 +2595,7 @@ var __exports__ = (() => {
2609
2595
  }
2610
2596
 
2611
2597
  // src/pbr/parse-pbr-material.ts
2612
- var GLEnum = /* @__PURE__ */ function(GLEnum4) {
2598
+ var GLEnum = function(GLEnum4) {
2613
2599
  GLEnum4[GLEnum4["FUNC_ADD"] = 32774] = "FUNC_ADD";
2614
2600
  GLEnum4[GLEnum4["ONE"] = 1] = "ONE";
2615
2601
  GLEnum4[GLEnum4["SRC_ALPHA"] = 770] = "SRC_ALPHA";
@@ -2623,17 +2609,13 @@ var __exports__ = (() => {
2623
2609
  function parsePBRMaterial(device, material, attributes, options) {
2624
2610
  const parsedMaterial = {
2625
2611
  defines: {
2626
- // TODO: Use EXT_sRGB if available (Standard in WebGL 2.0)
2627
2612
  MANUAL_SRGB: 1,
2628
2613
  SRGB_FAST_APPROXIMATION: 1
2629
2614
  },
2630
2615
  bindings: {},
2631
2616
  uniforms: {
2632
- // TODO: find better values?
2633
2617
  u_Camera: [0, 0, 0],
2634
- // Model should override
2635
2618
  u_MetallicRoughnessValues: [1, 1]
2636
- // Default is 1 and 1
2637
2619
  },
2638
2620
  parameters: {},
2639
2621
  glParameters: {},
@@ -2974,6 +2956,7 @@ var __exports__ = (() => {
2974
2956
  }
2975
2957
 
2976
2958
  // ../shadertools/src/lib/shader-module/shader-module-instance.ts
2959
+ var index = 1;
2977
2960
  var ShaderModuleInstance = class {
2978
2961
  uniforms = {};
2979
2962
  uniformTypes = {};
@@ -2982,8 +2965,11 @@ var __exports__ = (() => {
2982
2965
  if (module instanceof ShaderModuleInstance) {
2983
2966
  return module;
2984
2967
  }
2985
- assert3(typeof module !== "string", `Shader module use by name is deprecated. Import shader module '${module}' and use it directly.`);
2986
- assert3(module.name, "shader module has no name");
2968
+ assert3(typeof module !== "string", `Shader module use by name is deprecated. Import shader module '${JSON.stringify(module)}' and use it directly.`);
2969
+ if (!module.name) {
2970
+ console.warn("shader module has no name");
2971
+ module.name = `shader-module-${index++}`;
2972
+ }
2987
2973
  const moduleObject = new ShaderModuleInstance(module);
2988
2974
  moduleObject.dependencies = ShaderModuleInstance.instantiateModules(module.dependencies || []);
2989
2975
  return moduleObject;
@@ -3014,7 +3000,6 @@ var __exports__ = (() => {
3014
3000
  this.uniforms = makePropValidators(uniformPropTypes);
3015
3001
  }
3016
3002
  }
3017
- // Extracts the source code chunk for the specified shader type from the named shader module
3018
3003
  getModuleSource(stage) {
3019
3004
  let moduleSource;
3020
3005
  switch (stage) {
@@ -3027,8 +3012,11 @@ var __exports__ = (() => {
3027
3012
  default:
3028
3013
  assert3(false);
3029
3014
  }
3030
- return `#define MODULE_${this.name.toUpperCase().replace(/[^0-9a-z]/gi, "_")}
3031
- ${moduleSource}// END MODULE_${this.name}
3015
+ const moduleName = this.name.toUpperCase().replace(/[^0-9a-z]/gi, "_");
3016
+ return `// ----- MODULE ${this.name} ---------------
3017
+
3018
+ #define MODULE_${moduleName}
3019
+ ${moduleSource}
3032
3020
 
3033
3021
  `;
3034
3022
  }
@@ -3041,7 +3029,6 @@ ${moduleSource}// END MODULE_${this.name}
3041
3029
  getDefines() {
3042
3030
  return this.defines;
3043
3031
  }
3044
- // Warn about deprecated uniforms or functions
3045
3032
  checkDeprecations(shaderSource, log3) {
3046
3033
  this.deprecations.forEach((def) => {
3047
3034
  if (def.regex?.test(shaderSource)) {
@@ -3172,18 +3159,20 @@ ${moduleSource}// END MODULE_${this.name}
3172
3159
  }
3173
3160
  }
3174
3161
  function getVersionDefines(platformInfo) {
3175
- let versionDefines = glsl`\
3176
- #if (__VERSION__ > 120)
3162
+ let versionDefines = "";
3163
+ if (platformInfo.features.has("webgl2")) {
3164
+ versionDefines += glsl`\
3177
3165
  # define FEATURE_GLSL_DERIVATIVES
3178
3166
  # define FEATURE_GLSL_DRAW_BUFFERS
3179
3167
  # define FEATURE_GLSL_FRAG_DEPTH
3180
3168
  # define FEATURE_GLSL_TEXTURE_LOD
3181
- #endif // __VERSION
3182
3169
  `;
3183
- if (!platformInfo.features.has("webgl2") && platformInfo.features.has("glsl-frag-depth")) {
3184
- versionDefines += glsl`\
3170
+ }
3171
+ if (!platformInfo.features.has("webgl2")) {
3172
+ if (platformInfo.features.has("glsl-frag-depth")) {
3173
+ versionDefines += glsl`\
3185
3174
 
3186
- // FRAG_DEPTH => gl_FragDepth is available
3175
+ // FEATURE_GLSL_FRAG_DEPTH => gl_FragDepth is available
3187
3176
  #ifdef GL_EXT_frag_depth
3188
3177
  # extension GL_EXT_frag_depth : enable
3189
3178
  # define FEATURE_GLSL_FRAG_DEPTH
@@ -3191,31 +3180,29 @@ ${moduleSource}// END MODULE_${this.name}
3191
3180
  # define gl_FragDepth gl_FragDepthEXT
3192
3181
  #endif
3193
3182
  `;
3194
- }
3195
- if (!platformInfo.features.has("webgl2") && platformInfo?.features.has("glsl-derivatives")) {
3196
- versionDefines += glsl`\
3183
+ }
3184
+ if (platformInfo?.features.has("glsl-derivatives")) {
3185
+ versionDefines += glsl`\
3197
3186
 
3198
- // DERIVATIVES => dxdF, dxdY and fwidth are available
3187
+ // FEATURE_GLSL_DERIVATIVES => dxdF, dxdY and fwidth are available
3199
3188
  #if defined(GL_OES_standard_derivatives) || defined(FEATURE_GLSL_DERIVATIVES)
3200
3189
  # extension GL_OES_standard_derivatives : enable
3201
3190
  # define FEATURE_GLSL_DERIVATIVES
3202
- # define DERIVATIVES
3203
3191
  #endif
3204
3192
  `;
3205
- }
3206
- if (!platformInfo.features.has("webgl2") && platformInfo?.features.has("glsl-frag-data")) {
3207
- versionDefines += glsl`\
3193
+ }
3194
+ if (platformInfo?.features.has("glsl-frag-data")) {
3195
+ versionDefines += glsl`\
3208
3196
 
3209
- // DRAW_BUFFERS => gl_FragData[] is available
3197
+ // FEATURE_GLSL_DRAW_BUFFERS => gl_FragData[] is available
3210
3198
  #ifdef GL_EXT_draw_buffers
3211
3199
  # extension GL_EXT_draw_buffers : require
3212
3200
  # define FEATURE_GLSL_DRAW_BUFFERS
3213
- # define DRAW_BUFFERS
3214
3201
  #endif
3215
3202
  `;
3216
- }
3217
- if (!platformInfo.features.has("webgl2") && platformInfo?.features.has("glsl-texture-lod")) {
3218
- versionDefines += glsl`\
3203
+ }
3204
+ if (platformInfo?.features.has("glsl-texture-lod")) {
3205
+ versionDefines += glsl`\
3219
3206
  // TEXTURE_LOD => texture2DLod etc are available
3220
3207
  #ifdef GL_EXT_shader_texture_lod
3221
3208
  # extension GL_EXT_shader_texture_lod : enable
@@ -3223,91 +3210,59 @@ ${moduleSource}// END MODULE_${this.name}
3223
3210
  # define TEXTURE_LOD
3224
3211
  #endif
3225
3212
  `;
3213
+ }
3226
3214
  }
3227
3215
  return versionDefines;
3228
3216
  }
3229
3217
 
3230
3218
  // ../shadertools/src/lib/shader-transpiler/transpile-glsl-shader.ts
3231
3219
  function transpileGLSLShader(source, targetGLSLVersion, stage) {
3220
+ const sourceGLSLVersion = Number(source.match(/^#version[ \t]+(\d+)/m)?.[1] || 100);
3221
+ if (sourceGLSLVersion !== 300) {
3222
+ throw new Error("luma.gl v9 only supports GLSL 3.00 shader sources");
3223
+ }
3232
3224
  switch (targetGLSLVersion) {
3233
3225
  case 300:
3234
3226
  switch (stage) {
3235
3227
  case "vertex":
3236
- return convertShader(source, ES300_VERTEX_REPLACEMENTS);
3228
+ source = convertShader(source, ES300_VERTEX_REPLACEMENTS);
3229
+ return source;
3237
3230
  case "fragment":
3238
- return convertFragmentShaderTo300(source);
3231
+ source = convertShader(source, ES300_FRAGMENT_REPLACEMENTS);
3232
+ return source;
3239
3233
  default:
3240
- throw new Error(`unknown shader stage ${stage}`);
3234
+ throw new Error(stage);
3241
3235
  }
3242
3236
  case 100:
3243
3237
  switch (stage) {
3244
3238
  case "vertex":
3245
- return convertShader(source, ES100_VERTEX_REPLACEMENTS);
3239
+ source = convertShader(source, ES100_VERTEX_REPLACEMENTS);
3240
+ return source;
3246
3241
  case "fragment":
3247
- return convertFragmentShaderTo100(source);
3242
+ source = convertShader(source, ES100_FRAGMENT_REPLACEMENTS);
3243
+ source = convertFragmentShaderTo100(source);
3244
+ return source;
3248
3245
  default:
3249
- throw new Error(`unknown shader stage ${stage}`);
3246
+ throw new Error(stage);
3250
3247
  }
3251
3248
  default:
3252
- throw new Error(`unknown GLSL version ${targetGLSLVersion}`);
3253
- }
3254
- }
3255
- var ES300_REPLACEMENTS = [
3256
- // Fix poorly formatted version directive
3257
- [/^(#version[ \t]+(100|300[ \t]+es))?[ \t]*\n/, "#version 300 es\n"],
3258
- // The individual `texture...()` functions were replaced with `texture()` overloads
3259
- [/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g, "textureLod("],
3260
- [/\btexture(2D|2DProj|Cube)(EXT)?\(/g, "texture("]
3261
- ];
3262
- var ES300_VERTEX_REPLACEMENTS = [
3263
- ...ES300_REPLACEMENTS,
3264
- // `attribute` keyword replaced with `in`
3265
- [makeVariableTextRegExp("attribute"), "in $1"],
3266
- // `varying` keyword replaced with `out`
3267
- [makeVariableTextRegExp("varying"), "out $1"]
3268
- ];
3269
- var ES300_FRAGMENT_REPLACEMENTS = [
3270
- ...ES300_REPLACEMENTS,
3271
- // `varying` keyword replaced with `in`
3272
- [makeVariableTextRegExp("varying"), "in $1"]
3273
- ];
3274
- var ES100_REPLACEMENTS = [
3275
- [/^#version[ \t]+300[ \t]+es/, "#version 100"],
3276
- // In GLSL 1.00 ES these functions are provided by an extension
3277
- [/\btexture(2D|2DProj|Cube)Lod\(/g, "texture$1LodEXT("],
3278
- // Overloads in GLSL 3.00 map to individual functions. Note that we cannot
3279
- // differentiate 2D,2DProj,Cube without type analysis so we choose the most common variant.
3280
- [/\btexture\(/g, "texture2D("],
3281
- [/\btextureLod\(/g, "texture2DLodEXT("]
3282
- ];
3249
+ throw new Error(String(targetGLSLVersion));
3250
+ }
3251
+ }
3252
+ var ES300_REPLACEMENTS = [[/^(#version[ \t]+(100|300[ \t]+es))?[ \t]*\n/, "#version 300 es\n"], [/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g, "textureLod("], [/\btexture(2D|2DProj|Cube)(EXT)?\(/g, "texture("]];
3253
+ var ES300_VERTEX_REPLACEMENTS = [...ES300_REPLACEMENTS, [makeVariableTextRegExp("attribute"), "in $1"], [makeVariableTextRegExp("varying"), "out $1"]];
3254
+ var ES300_FRAGMENT_REPLACEMENTS = [...ES300_REPLACEMENTS, [makeVariableTextRegExp("varying"), "in $1"]];
3255
+ var ES100_REPLACEMENTS = [[/^#version[ \t]+300[ \t]+es/, "#version 100"], [/\btexture(2D|2DProj|Cube)Lod\(/g, "texture$1LodEXT("], [/\btexture\(/g, "texture2D("], [/\btextureLod\(/g, "texture2DLodEXT("]];
3283
3256
  var ES100_VERTEX_REPLACEMENTS = [...ES100_REPLACEMENTS, [makeVariableTextRegExp("in"), "attribute $1"], [makeVariableTextRegExp("out"), "varying $1"]];
3284
- var ES100_FRAGMENT_REPLACEMENTS = [
3285
- ...ES100_REPLACEMENTS,
3286
- // Replace `in` with `varying`
3287
- [makeVariableTextRegExp("in"), "varying $1"]
3288
- ];
3257
+ var ES100_FRAGMENT_REPLACEMENTS = [...ES100_REPLACEMENTS, [makeVariableTextRegExp("in"), "varying $1"]];
3289
3258
  var ES100_FRAGMENT_OUTPUT_NAME = "gl_FragColor";
3290
3259
  var ES300_FRAGMENT_OUTPUT_REGEX = /\bout[ \t]+vec4[ \t]+(\w+)[ \t]*;\n?/;
3291
- var REGEX_START_OF_MAIN2 = /void\s+main\s*\([^)]*\)\s*\{\n?/;
3292
3260
  function convertShader(source, replacements) {
3293
3261
  for (const [pattern, replacement] of replacements) {
3294
3262
  source = source.replace(pattern, replacement);
3295
3263
  }
3296
3264
  return source;
3297
3265
  }
3298
- function convertFragmentShaderTo300(source) {
3299
- source = convertShader(source, ES300_FRAGMENT_REPLACEMENTS);
3300
- const outputMatch = ES300_FRAGMENT_OUTPUT_REGEX.exec(source);
3301
- if (outputMatch) {
3302
- const outputName = outputMatch[1];
3303
- source = source.replace(new RegExp(`\\b${ES100_FRAGMENT_OUTPUT_NAME}\\b`, "g"), outputName);
3304
- } else {
3305
- const outputName = "fragmentColor";
3306
- source = source.replace(REGEX_START_OF_MAIN2, (match) => `out vec4 ${outputName};
3307
- ${match}`).replace(new RegExp(`\\b${ES100_FRAGMENT_OUTPUT_NAME}\\b`, "g"), outputName);
3308
- }
3309
- return source;
3310
- }
3311
3266
  function convertFragmentShaderTo100(source) {
3312
3267
  source = convertShader(source, ES100_FRAGMENT_REPLACEMENTS);
3313
3268
  const outputMatch = ES300_FRAGMENT_OUTPUT_REGEX.exec(source);
@@ -3381,32 +3336,58 @@ ${match}`).replace(new RegExp(`\\b${ES100_FRAGMENT_OUTPUT_NAME}\\b`, "g"), outpu
3381
3336
  return result;
3382
3337
  }
3383
3338
 
3339
+ // ../shadertools/src/lib/glsl-utils/get-shader-info.ts
3340
+ function getShaderInfo(source, defaultName) {
3341
+ return {
3342
+ name: getShaderName(source, defaultName),
3343
+ language: "glsl",
3344
+ version: getShaderVersion(source)
3345
+ };
3346
+ }
3347
+ function getShaderName(shader, defaultName = "unnamed") {
3348
+ const SHADER_NAME_REGEXP = /#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/;
3349
+ const match = SHADER_NAME_REGEXP.exec(shader);
3350
+ return match ? match[1] : defaultName;
3351
+ }
3352
+ function getShaderVersion(source) {
3353
+ let version = 100;
3354
+ const words = source.match(/[^\s]+/g);
3355
+ if (words && words.length >= 2 && words[0] === "#version") {
3356
+ const parsedVersion = parseInt(words[1], 10);
3357
+ if (Number.isFinite(parsedVersion)) {
3358
+ version = parsedVersion;
3359
+ }
3360
+ }
3361
+ if (version !== 100 && version !== 300) {
3362
+ throw new Error(`Invalid GLSL version ${version}`);
3363
+ }
3364
+ return version;
3365
+ }
3366
+
3384
3367
  // ../shadertools/src/lib/shader-assembly/assemble-shaders.ts
3385
3368
  var INJECT_SHADER_DECLARATIONS = `
3386
3369
 
3387
3370
  ${DECLARATION_INJECT_MARKER}
3388
-
3389
3371
  `;
3390
3372
  var FRAGMENT_SHADER_PROLOGUE = glsl`\
3391
3373
  precision highp float;
3392
-
3393
3374
  `;
3394
- function assembleShaders(platformInfo, options) {
3375
+ function assembleShaders(options) {
3395
3376
  const {
3396
3377
  vs: vs3,
3397
3378
  fs: fs3
3398
3379
  } = options;
3399
3380
  const modules = resolveModules(options.modules || []);
3400
- switch (platformInfo.shaderLanguage) {
3381
+ switch (options.platformInfo.shaderLanguage) {
3401
3382
  case "glsl":
3402
3383
  return {
3403
- vs: assembleGLSLShader(platformInfo, {
3384
+ vs: assembleGLSLShader(options.platformInfo, {
3404
3385
  ...options,
3405
3386
  source: vs3,
3406
3387
  stage: "vertex",
3407
3388
  modules
3408
3389
  }),
3409
- fs: assembleGLSLShader(platformInfo, {
3390
+ fs: assembleGLSLShader(options.platformInfo, {
3410
3391
  ...options,
3411
3392
  source: fs3,
3412
3393
  stage: "fragment",
@@ -3416,13 +3397,13 @@ precision highp float;
3416
3397
  };
3417
3398
  case "wgsl":
3418
3399
  return {
3419
- vs: assembleWGSLShader(platformInfo, {
3400
+ vs: assembleWGSLShader(options.platformInfo, {
3420
3401
  ...options,
3421
3402
  source: vs3,
3422
3403
  stage: "vertex",
3423
3404
  modules
3424
3405
  }),
3425
- fs: assembleWGSLShader(platformInfo, {
3406
+ fs: assembleWGSLShader(options.platformInfo, {
3426
3407
  ...options,
3427
3408
  source: fs3,
3428
3409
  stage: "fragment",
@@ -3434,7 +3415,6 @@ precision highp float;
3434
3415
  }
3435
3416
  function assembleWGSLShader(platformInfo, options) {
3436
3417
  const {
3437
- // id,
3438
3418
  source,
3439
3419
  stage,
3440
3420
  modules,
@@ -3505,33 +3485,24 @@ precision highp float;
3505
3485
  return assembledSource;
3506
3486
  }
3507
3487
  function assembleGLSLShader(platformInfo, options) {
3508
- const isWGSL = options.source.includes("->");
3509
3488
  const {
3510
3489
  id,
3511
3490
  source,
3512
3491
  stage,
3513
- language = isWGSL ? "wgsl" : "glsl",
3492
+ language = "glsl",
3514
3493
  modules,
3515
3494
  defines = {},
3516
3495
  hookFunctions = [],
3517
3496
  inject = {},
3518
- transpileToGLSL100 = false,
3519
- prologue = !isWGSL,
3497
+ prologue = true,
3520
3498
  log: log3
3521
3499
  } = options;
3522
3500
  assert3(typeof source === "string", "shader source must be a string");
3501
+ const sourceVersion = language === "glsl" ? getShaderInfo(source).version : -1;
3502
+ const targetVersion = platformInfo.shaderLanguageVersion;
3503
+ const sourceVersionDirective = sourceVersion === 100 ? "#version 100" : "#version 300 es";
3523
3504
  const sourceLines = source.split("\n");
3524
- let glslVersion = 100;
3525
- let versionLine = "";
3526
- let coreSource = source;
3527
- if (sourceLines[0].indexOf("#version ") === 0) {
3528
- glslVersion = 300;
3529
- versionLine = sourceLines[0];
3530
- coreSource = sourceLines.slice(1).join("\n");
3531
- } else {
3532
- versionLine = `#version ${glslVersion}`;
3533
- }
3534
- const targetVersion = transpileToGLSL100 ? 100 : glslVersion;
3505
+ const coreSource = sourceLines.slice(1).join("\n");
3535
3506
  const allDefines = {};
3536
3507
  modules.forEach((module) => {
3537
3508
  Object.assign(allDefines, module.getDefines());
@@ -3542,7 +3513,9 @@ precision highp float;
3542
3513
  case "wgsl":
3543
3514
  break;
3544
3515
  case "glsl":
3545
- assembledSource = prologue ? `${versionLine}
3516
+ assembledSource = prologue ? `${sourceVersionDirective}
3517
+
3518
+ // ----- PROLOGUE -------------------------
3546
3519
  ${getShaderNameDefine({
3547
3520
  id,
3548
3521
  source,
@@ -3551,9 +3524,13 @@ ${getShaderNameDefine({
3551
3524
  ${`#define SHADER_TYPE_${stage.toUpperCase()}`}
3552
3525
  ${getPlatformShaderDefines(platformInfo)}
3553
3526
  ${getVersionDefines(platformInfo)}
3554
- ${getApplicationDefines(allDefines)}
3555
3527
  ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
3556
- ` : `${versionLine}
3528
+
3529
+ // ----- APPLICATION DEFINES -------------------------
3530
+
3531
+ ${getApplicationDefines(allDefines)}
3532
+
3533
+ ` : `${sourceVersionDirective}
3557
3534
  `;
3558
3535
  break;
3559
3536
  }
@@ -3603,12 +3580,15 @@ ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
3603
3580
  }
3604
3581
  }
3605
3582
  }
3583
+ assembledSource += "// ----- MAIN SHADER SOURCE -------------------------";
3606
3584
  assembledSource += INJECT_SHADER_DECLARATIONS;
3607
3585
  assembledSource = injectShader(assembledSource, stage, declInjections);
3608
3586
  assembledSource += getShaderHooks(hookFunctionMap[stage], hookInjections);
3609
3587
  assembledSource += coreSource;
3610
3588
  assembledSource = injectShader(assembledSource, stage, mainInjections);
3611
- assembledSource = transpileGLSLShader(assembledSource, targetVersion, stage);
3589
+ if (language === "glsl" && sourceVersion !== targetVersion) {
3590
+ assembledSource = transpileGLSLShader(assembledSource, targetVersion, stage);
3591
+ }
3612
3592
  return assembledSource.trim();
3613
3593
  }
3614
3594
  function assembleGetUniforms(modules) {
@@ -3634,34 +3614,26 @@ ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
3634
3614
  ` : "";
3635
3615
  }
3636
3616
  function getApplicationDefines(defines = {}) {
3637
- let count = 0;
3638
3617
  let sourceText = "";
3639
3618
  for (const define in defines) {
3640
- if (count === 0) {
3641
- sourceText += "\n// APPLICATION DEFINES\n";
3642
- }
3643
- count++;
3644
3619
  const value = defines[define];
3645
3620
  if (value || Number.isFinite(value)) {
3646
3621
  sourceText += `#define ${define.toUpperCase()} ${defines[define]}
3647
3622
  `;
3648
3623
  }
3649
3624
  }
3650
- if (count === 0) {
3651
- sourceText += "\n";
3652
- }
3653
3625
  return sourceText;
3654
3626
  }
3655
3627
 
3656
3628
  // ../shadertools/src/lib/shader-assembly/select-shaders.ts
3657
- function selectShaders(platformInfo, props) {
3629
+ function selectShaders(props) {
3658
3630
  if (!props.vs) {
3659
3631
  throw new Error("no vertex shader");
3660
3632
  }
3661
- const vs3 = getShaderSource(platformInfo, props.vs);
3633
+ const vs3 = getShaderSource(props.platformInfo, props.vs);
3662
3634
  let fs3;
3663
3635
  if (props.fs) {
3664
- fs3 = getShaderSource(platformInfo, props.fs);
3636
+ fs3 = getShaderSource(props.platformInfo, props.fs);
3665
3637
  }
3666
3638
  return {
3667
3639
  ...props,
@@ -3689,39 +3661,21 @@ ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
3689
3661
 
3690
3662
  // ../shadertools/src/lib/shader-assembler.ts
3691
3663
  var ShaderAssembler = class {
3692
- /** Default ShaderAssembler instance */
3693
- /** Hook functions */
3694
3664
  _hookFunctions = [];
3695
- /** Shader modules */
3696
3665
  _defaultModules = [];
3697
- /**
3698
- * A default shader assembler instance - the natural place to register default modules and hooks
3699
- * @returns
3700
- */
3701
3666
  static getDefaultShaderAssembler() {
3702
3667
  ShaderAssembler.defaultShaderAssembler = ShaderAssembler.defaultShaderAssembler || new ShaderAssembler();
3703
3668
  return ShaderAssembler.defaultShaderAssembler;
3704
3669
  }
3705
- /**
3706
- * Add a default module that does not have to be provided with every call to assembleShaders()
3707
- */
3708
3670
  addDefaultModule(module) {
3709
3671
  if (!this._defaultModules.find((m) => m.name === (typeof module === "string" ? module : module.name))) {
3710
3672
  this._defaultModules.push(module);
3711
3673
  }
3712
3674
  }
3713
- /**
3714
- * Remove a default module
3715
- */
3716
3675
  removeDefaultModule(module) {
3717
3676
  const moduleName = typeof module === "string" ? module : module.name;
3718
3677
  this._defaultModules = this._defaultModules.filter((m) => m.name !== moduleName);
3719
3678
  }
3720
- /**
3721
- * Register a shader hook
3722
- * @param hook
3723
- * @param opts
3724
- */
3725
3679
  addShaderHook(hook, opts) {
3726
3680
  if (opts) {
3727
3681
  hook = Object.assign(opts, {
@@ -3730,26 +3684,21 @@ ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
3730
3684
  }
3731
3685
  this._hookFunctions.push(hook);
3732
3686
  }
3733
- /**
3734
- * Assemble a pair of shaders into a single shader program
3735
- * @param platformInfo
3736
- * @param props
3737
- * @returns
3738
- */
3739
- assembleShaders(platformInfo, props) {
3687
+ assembleShaders(props) {
3740
3688
  const modules = this._getModuleList(props.modules);
3741
3689
  const hookFunctions = this._hookFunctions;
3742
- const options = selectShaders(platformInfo, props);
3743
- const assembled = assembleShaders(platformInfo, {
3690
+ const options = selectShaders(props);
3691
+ const assembled = assembleShaders({
3692
+ platformInfo: props.platformInfo,
3744
3693
  ...options,
3745
3694
  modules,
3746
3695
  hookFunctions
3747
3696
  });
3748
- return assembled;
3697
+ return {
3698
+ ...assembled,
3699
+ modules
3700
+ };
3749
3701
  }
3750
- /**
3751
- * Dedupe and combine with default modules
3752
- */
3753
3702
  _getModuleList(appModules = []) {
3754
3703
  const modules = new Array(this._defaultModules.length + appModules.length);
3755
3704
  const seen = {};
@@ -3769,7 +3718,7 @@ ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
3769
3718
  }
3770
3719
  }
3771
3720
  modules.length = count;
3772
- return modules;
3721
+ return ShaderModuleInstance.instantiateModules(modules);
3773
3722
  }
3774
3723
  };
3775
3724
 
@@ -6386,15 +6335,15 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
6386
6335
  } else {
6387
6336
  lightSourceUniforms["lighting_uAmbientLight.color"] = [0, 0, 0];
6388
6337
  }
6389
- pointLights.forEach((pointLight, index) => {
6390
- lightSourceUniforms[`lighting_uPointLight[${index}].color`] = convertColor(pointLight);
6391
- lightSourceUniforms[`lighting_uPointLight[${index}].position`] = pointLight.position;
6392
- lightSourceUniforms[`lighting_uPointLight[${index}].attenuation`] = pointLight.attenuation || [1, 0, 0];
6338
+ pointLights.forEach((pointLight, index2) => {
6339
+ lightSourceUniforms[`lighting_uPointLight[${index2}].color`] = convertColor(pointLight);
6340
+ lightSourceUniforms[`lighting_uPointLight[${index2}].position`] = pointLight.position;
6341
+ lightSourceUniforms[`lighting_uPointLight[${index2}].attenuation`] = pointLight.attenuation || [1, 0, 0];
6393
6342
  });
6394
6343
  lightSourceUniforms.lighting_uPointLightCount = pointLights.length;
6395
- directionalLights.forEach((directionalLight, index) => {
6396
- lightSourceUniforms[`lighting_uDirectionalLight[${index}].color`] = convertColor(directionalLight);
6397
- lightSourceUniforms[`lighting_uDirectionalLight[${index}].direction`] = directionalLight.direction;
6344
+ directionalLights.forEach((directionalLight, index2) => {
6345
+ lightSourceUniforms[`lighting_uDirectionalLight[${index2}].color`] = convertColor(directionalLight);
6346
+ lightSourceUniforms[`lighting_uDirectionalLight[${index2}].direction`] = directionalLight.direction;
6398
6347
  });
6399
6348
  lightSourceUniforms.lighting_uDirectionalLightCount = directionalLights.length;
6400
6349
  return lightSourceUniforms;
@@ -6909,10 +6858,53 @@ vec4 pbr_filterColor(vec4 colorUnused)
6909
6858
  dependencies: [lights]
6910
6859
  };
6911
6860
 
6861
+ // ../engine/src/shader-inputs.ts
6862
+ var ShaderInputs = class {
6863
+ constructor(modules) {
6864
+ const allModules = resolveModules(Object.values(modules));
6865
+ log.log(1, "Creating ShaderInputs with modules", allModules.map((m) => m.name))();
6866
+ this.modules = modules;
6867
+ this.moduleUniforms = {};
6868
+ this.moduleBindings = {};
6869
+ for (const [name2, module] of Object.entries(modules)) {
6870
+ const moduleName = name2;
6871
+ this.moduleUniforms[moduleName] = module.defaultUniforms || {};
6872
+ this.moduleBindings[moduleName] = {};
6873
+ }
6874
+ }
6875
+ destroy() {
6876
+ }
6877
+ setProps(props) {
6878
+ for (const name2 of Object.keys(props)) {
6879
+ const moduleName = name2;
6880
+ const moduleProps = props[moduleName];
6881
+ const module = this.modules[moduleName];
6882
+ const oldUniforms = this.moduleUniforms[moduleName];
6883
+ const uniforms = module.getUniforms?.(moduleProps, this.moduleUniforms[moduleName]) || moduleProps;
6884
+ this.moduleUniforms[moduleName] = {
6885
+ ...oldUniforms,
6886
+ ...uniforms
6887
+ };
6888
+ }
6889
+ }
6890
+ getModules() {
6891
+ return Object.values(this.modules);
6892
+ }
6893
+ getUniformValues() {
6894
+ return this.moduleUniforms;
6895
+ }
6896
+ getBindings() {
6897
+ const bindings = {};
6898
+ for (const moduleBindings of Object.values(this.moduleBindings)) {
6899
+ Object.assign(bindings, moduleBindings);
6900
+ }
6901
+ return bindings;
6902
+ }
6903
+ };
6904
+
6912
6905
  // ../engine/src/geometry/gpu-geometry.ts
6913
6906
  var GPUGeometry = class {
6914
6907
  userData = {};
6915
- /** Determines how vertices are read from the 'vertex' attributes */
6916
6908
  bufferLayout = [];
6917
6909
  constructor(props) {
6918
6910
  this.id = props.id || uid("geometry");
@@ -6995,11 +6987,12 @@ vec4 pbr_filterColor(vec4 colorUnused)
6995
6987
  });
6996
6988
  const {
6997
6989
  value,
6998
- size
6990
+ size,
6991
+ normalized
6999
6992
  } = attribute;
7000
6993
  bufferLayout.push({
7001
6994
  name: name2,
7002
- format: getVertexFormatFromAttribute(value, size)
6995
+ format: getVertexFormatFromAttribute(value, size, normalized)
7003
6996
  });
7004
6997
  }
7005
6998
  const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices);
@@ -7059,7 +7052,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
7059
7052
  delete this._useCounts[hash];
7060
7053
  }
7061
7054
  }
7062
- // PRIVATE
7063
7055
  _createRenderPipeline(props) {
7064
7056
  if (!props.fs) {
7065
7057
  throw new Error("fs");
@@ -7077,7 +7069,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
7077
7069
  });
7078
7070
  return pipeline;
7079
7071
  }
7080
- /** Calculate a hash based on all the inputs for a render pipeline */
7081
7072
  _hashRenderPipeline(props) {
7082
7073
  const vsHash = this._getHash(props.vs);
7083
7074
  const fsHash = props.fs ? this._getHash(props.fs) : 0;
@@ -7108,31 +7099,12 @@ vec4 pbr_filterColor(vec4 colorUnused)
7108
7099
  // ../engine/src/model/model.ts
7109
7100
  var _Model = class {
7110
7101
  userData = {};
7111
- // Fixed properties (change can trigger pipeline rebuild)
7112
- /** The render pipeline GPU parameters, depth testing etc */
7113
- /** The primitive topology */
7114
- /** Buffer layout */
7115
- // Dynamic properties
7116
- /** Vertex count */
7117
- /** instance count */
7118
7102
  instanceCount = 0;
7119
- /** Index buffer */
7120
7103
  indexBuffer = null;
7121
- /** Buffer-valued attributes */
7122
7104
  bufferAttributes = {};
7123
- /** Constant-valued attributes */
7124
7105
  constantAttributes = {};
7125
- /** Bindings (textures, samplers, uniform buffers) */
7126
7106
  bindings = {};
7127
- /** Sets uniforms @deprecated Use uniform buffers and setBindings() for portability*/
7128
7107
  uniforms = {};
7129
- /** The underlying GPU "program". @note May be recreated if parameters change */
7130
- /**
7131
- * VertexArray
7132
- * @note not implemented: if bufferLayout is updated, vertex array has to be rebuilt!
7133
- * @todo - allow application to define multiple vertex arrays?
7134
- * */
7135
- /** TransformFeedback, WebGL 2 only. */
7136
7108
  transformFeedback = null;
7137
7109
  _pipelineNeedsUpdate = "newly created";
7138
7110
  _attributeInfos = {};
@@ -7146,17 +7118,19 @@ vec4 pbr_filterColor(vec4 colorUnused)
7146
7118
  this.id = props.id || uid("model");
7147
7119
  this.device = device;
7148
7120
  Object.assign(this.userData, props.userData);
7149
- const platformInfo = {
7150
- type: device.info.type,
7151
- shaderLanguage: device.info.shadingLanguages[0],
7152
- gpu: device.info.gpu,
7153
- features: device.features
7154
- };
7121
+ const moduleMap = Object.fromEntries(this.props.modules?.map((module) => [module.name, module]) || []);
7122
+ this.setShaderInputs(props.shaderInputs || new ShaderInputs(moduleMap));
7123
+ const platformInfo = getPlatformInfo(device);
7124
+ const modules = (this.props.modules?.length > 0 ? this.props.modules : this.shaderInputs?.getModules()) || [];
7155
7125
  const {
7156
7126
  vs: vs3,
7157
7127
  fs: fs3,
7158
7128
  getUniforms: getUniforms2
7159
- } = this.props.shaderAssembler.assembleShaders(platformInfo, this.props);
7129
+ } = this.props.shaderAssembler.assembleShaders({
7130
+ platformInfo,
7131
+ ...this.props,
7132
+ modules
7133
+ });
7160
7134
  this.vs = vs3;
7161
7135
  this.fs = fs3;
7162
7136
  this._getModuleUniforms = getUniforms2;
@@ -7201,19 +7175,23 @@ vec4 pbr_filterColor(vec4 colorUnused)
7201
7175
  this.setUniforms(props.uniforms);
7202
7176
  }
7203
7177
  if (props.moduleSettings) {
7178
+ console.warn("Model.props.moduleSettings is deprecated. Use Model.shaderInputs.setProps()");
7204
7179
  this.updateModuleSettings(props.moduleSettings);
7205
7180
  }
7206
7181
  if (props.transformFeedback) {
7207
7182
  this.transformFeedback = props.transformFeedback;
7208
7183
  }
7209
- this.setUniforms(this._getModuleUniforms());
7210
7184
  Object.seal(this);
7211
7185
  }
7212
7186
  destroy() {
7213
7187
  this.pipelineFactory.release(this.pipeline);
7188
+ this._uniformStore.destroy();
7189
+ }
7190
+ predraw() {
7191
+ this.updateShaderInputs();
7214
7192
  }
7215
- // Draw call
7216
7193
  draw(renderPass) {
7194
+ this.predraw();
7217
7195
  this.pipeline = this._updatePipeline();
7218
7196
  this.pipeline.setBindings(this.bindings);
7219
7197
  this.pipeline.setUniforms(this.uniforms);
@@ -7225,12 +7203,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
7225
7203
  transformFeedback: this.transformFeedback
7226
7204
  });
7227
7205
  }
7228
- // Update fixed fields (can trigger pipeline rebuild)
7229
- /**
7230
- * Updates the optional geometry
7231
- * Geometry, set topology and bufferLayout
7232
- * @note Can trigger a pipeline rebuild / pipeline cache fetch on WebGPU
7233
- */
7234
7206
  setGeometry(geometry) {
7235
7207
  const gpuGeometry = geometry && makeGPUGeometry(this.device, geometry);
7236
7208
  this.setTopology(gpuGeometry.topology || "triangle-list");
@@ -7240,30 +7212,17 @@ vec4 pbr_filterColor(vec4 colorUnused)
7240
7212
  }
7241
7213
  return gpuGeometry;
7242
7214
  }
7243
- /**
7244
- * Updates the optional geometry attributes
7245
- * Geometry, sets several attributes, indexBuffer, and also vertex count
7246
- * @note Can trigger a pipeline rebuild / pipeline cache fetch on WebGPU
7247
- */
7248
7215
  _setGeometryAttributes(gpuGeometry) {
7249
7216
  this.vertexCount = gpuGeometry.vertexCount;
7250
7217
  this.setAttributes(gpuGeometry.attributes);
7251
7218
  this.setIndexBuffer(gpuGeometry.indices);
7252
7219
  }
7253
- /**
7254
- * Updates the primitive topology ('triangle-list', 'triangle-strip' etc).
7255
- * @note Triggers a pipeline rebuild / pipeline cache fetch on WebGPU
7256
- */
7257
7220
  setTopology(topology) {
7258
7221
  if (topology !== this.topology) {
7259
7222
  this.topology = topology;
7260
7223
  this._setPipelineNeedsUpdate("topology");
7261
7224
  }
7262
7225
  }
7263
- /**
7264
- * Updates the buffer layout.
7265
- * @note Triggers a pipeline rebuild / pipeline cache fetch on WebGPU
7266
- */
7267
7226
  setBufferLayout(bufferLayout) {
7268
7227
  this.bufferLayout = this._gpuGeometry ? mergeBufferLayouts(bufferLayout, this._gpuGeometry.bufferLayout) : bufferLayout;
7269
7228
  this._setPipelineNeedsUpdate("bufferLayout");
@@ -7275,36 +7234,31 @@ vec4 pbr_filterColor(vec4 colorUnused)
7275
7234
  this._setGeometryAttributes(this._gpuGeometry);
7276
7235
  }
7277
7236
  }
7278
- /**
7279
- * Set GPU parameters.
7280
- * @note Can trigger a pipeline rebuild / pipeline cache fetch.
7281
- * @param parameters
7282
- */
7283
7237
  setParameters(parameters) {
7284
7238
  if (!deepEqual(parameters, this.parameters, 2)) {
7285
7239
  this.parameters = parameters;
7286
7240
  this._setPipelineNeedsUpdate("parameters");
7287
7241
  }
7288
7242
  }
7289
- // Update dynamic fields
7290
- /**
7291
- * Updates the vertex count (used in draw calls)
7292
- * @note Any attributes with stepMode=vertex need to be at least this big
7293
- */
7294
7243
  setVertexCount(vertexCount) {
7295
7244
  this.vertexCount = vertexCount;
7296
7245
  }
7297
- /**
7298
- * Updates the instance count (used in draw calls)
7299
- * @note Any attributes with stepMode=instance need to be at least this big
7300
- */
7301
7246
  setInstanceCount(instanceCount) {
7302
7247
  this.instanceCount = instanceCount;
7303
7248
  }
7304
- /**
7305
- * Updates shader module settings (which results in bindings & uniforms being set)
7306
- */
7307
- setShaderModuleProps(props) {
7249
+ setShaderInputs(shaderInputs) {
7250
+ this.shaderInputs = shaderInputs;
7251
+ this._uniformStore = new UniformStore(this.shaderInputs.modules);
7252
+ for (const moduleName of Object.keys(this.shaderInputs.modules)) {
7253
+ const uniformBuffer = this._uniformStore.getManagedUniformBuffer(this.device, moduleName);
7254
+ this.bindings[`${moduleName}Uniforms`] = uniformBuffer;
7255
+ }
7256
+ }
7257
+ updateShaderInputs() {
7258
+ this._uniformStore.setUniforms(this.shaderInputs.getUniformValues());
7259
+ }
7260
+ updateModuleSettings(props) {
7261
+ console.warn("Model.updateModuleSettings is deprecated. Use Model.shaderInputs.setProps()");
7308
7262
  const {
7309
7263
  bindings,
7310
7264
  uniforms
@@ -7312,45 +7266,19 @@ vec4 pbr_filterColor(vec4 colorUnused)
7312
7266
  Object.assign(this.bindings, bindings);
7313
7267
  Object.assign(this.uniforms, uniforms);
7314
7268
  }
7315
- /**
7316
- * Updates optional transform feedback. WebGL 2 only.
7317
- */
7318
- setTransformFeedback(transformFeedback) {
7319
- this.transformFeedback = transformFeedback;
7320
- }
7321
- /**
7322
- * @deprecated Updates shader module settings (which results in uniforms being set)
7323
- */
7324
- updateModuleSettings(props) {
7325
- this.setShaderModuleProps(props);
7326
- }
7327
- /**
7328
- * Sets bindings (textures, samplers, uniform buffers)
7329
- */
7330
7269
  setBindings(bindings) {
7331
7270
  Object.assign(this.bindings, bindings);
7332
7271
  }
7333
- /**
7334
- * Sets individual uniforms
7335
- * @deprecated WebGL only, use uniform buffers for portability
7336
- * @param uniforms
7337
- * @returns self for chaining
7338
- */
7339
7272
  setUniforms(uniforms) {
7340
7273
  this.pipeline.setUniforms(uniforms);
7341
7274
  Object.assign(this.uniforms, uniforms);
7342
7275
  }
7343
- /**
7344
- * Sets the index buffer
7345
- * @todo - how to unset it if we change geometry?
7346
- */
7347
7276
  setIndexBuffer(indexBuffer) {
7348
7277
  this.vertexArray.setIndexBuffer(indexBuffer);
7349
7278
  }
7350
- /**
7351
- * Sets attributes (buffers)
7352
- * @note Overrides any attributes previously set with the same name
7353
- */
7279
+ setTransformFeedback(transformFeedback) {
7280
+ this.transformFeedback = transformFeedback;
7281
+ }
7354
7282
  setAttributes(buffers) {
7355
7283
  if (buffers.indices) {
7356
7284
  log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`);
@@ -7375,14 +7303,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
7375
7303
  }
7376
7304
  }
7377
7305
  }
7378
- /**
7379
- * Sets constant attributes
7380
- * @note Overrides any attributes previously set with the same name
7381
- * Constant attributes are only supported in WebGL, not in WebGPU
7382
- * Any attribute that is disabled in the current vertex array object
7383
- * is read from the context's global constant value for that attribute location.
7384
- * @param constantAttributes
7385
- */
7386
7306
  setConstantAttributes(attributes) {
7387
7307
  for (const [attributeName, value] of Object.entries(attributes)) {
7388
7308
  const attributeInfo = this._attributeInfos[attributeName];
@@ -7433,12 +7353,13 @@ vec4 pbr_filterColor(vec4 colorUnused)
7433
7353
  userData: {},
7434
7354
  defines: {},
7435
7355
  modules: [],
7436
- moduleSettings: {},
7356
+ moduleSettings: void 0,
7437
7357
  geometry: null,
7438
7358
  indexBuffer: null,
7439
7359
  attributes: {},
7440
7360
  constantAttributes: {},
7441
7361
  varyings: [],
7362
+ shaderInputs: void 0,
7442
7363
  pipelineFactory: void 0,
7443
7364
  transformFeedback: void 0,
7444
7365
  shaderAssembler: ShaderAssembler.getDefaultShaderAssembler()
@@ -7446,19 +7367,27 @@ vec4 pbr_filterColor(vec4 colorUnused)
7446
7367
  function mergeBufferLayouts(layouts1, layouts2) {
7447
7368
  const layouts = [...layouts1];
7448
7369
  for (const attribute of layouts2) {
7449
- const index = layouts.findIndex((attribute2) => attribute2.name === attribute.name);
7450
- if (index < 0) {
7370
+ const index2 = layouts.findIndex((attribute2) => attribute2.name === attribute.name);
7371
+ if (index2 < 0) {
7451
7372
  layouts.push(attribute);
7452
7373
  } else {
7453
- layouts[index] = attribute;
7374
+ layouts[index2] = attribute;
7454
7375
  }
7455
7376
  }
7456
7377
  return layouts;
7457
7378
  }
7379
+ function getPlatformInfo(device) {
7380
+ return {
7381
+ type: device.info.type,
7382
+ shaderLanguage: device.info.shadingLanguage,
7383
+ shaderLanguageVersion: device.info.shadingLanguageVersion,
7384
+ gpu: device.info.gpu,
7385
+ features: device.features
7386
+ };
7387
+ }
7458
7388
 
7459
7389
  // ../engine/src/geometry/geometry.ts
7460
7390
  var Geometry = class {
7461
- /** Determines how vertices are read from the 'vertex' attributes */
7462
7391
  userData = {};
7463
7392
  constructor(props) {
7464
7393
  const {
@@ -7499,31 +7428,15 @@ vec4 pbr_filterColor(vec4 colorUnused)
7499
7428
  getVertexCount() {
7500
7429
  return this.vertexCount;
7501
7430
  }
7502
- /**
7503
- * Return an object with all attributes plus indices added as a field.
7504
- * TODO Geometry types are a mess
7505
- */
7506
7431
  getAttributes() {
7507
7432
  return this.indices ? {
7508
7433
  indices: this.indices,
7509
7434
  ...this.attributes
7510
7435
  } : this.attributes;
7511
7436
  }
7512
- // PRIVATE
7513
7437
  _print(attributeName) {
7514
7438
  return `Geometry ${this.id} attribute ${attributeName}`;
7515
7439
  }
7516
- /**
7517
- * GeometryAttribute
7518
- * value: typed array
7519
- * type: indices, vertices, uvs
7520
- * size: elements per vertex
7521
- * target: WebGL buffer type (string or constant)
7522
- *
7523
- * @param attributes
7524
- * @param indices
7525
- * @returns
7526
- */
7527
7440
  _setAttributes(attributes, indices) {
7528
7441
  return this;
7529
7442
  }
@@ -7568,7 +7481,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
7568
7481
  }
7569
7482
  destroy() {
7570
7483
  }
7571
- /** @deprecated use .destroy() */
7572
7484
  delete() {
7573
7485
  this.destroy();
7574
7486
  }
@@ -7665,26 +7577,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
7665
7577
  worldInverseTransposeMatrix: worldInverseTranspose
7666
7578
  };
7667
7579
  }
7668
- // TODO - copied code, not yet vetted
7669
- /*
7670
- transform() {
7671
- if (!this.parent) {
7672
- this.endPosition.set(this.position);
7673
- this.endRotation.set(this.rotation);
7674
- this.endScale.set(this.scale);
7675
- } else {
7676
- const parent = this.parent;
7677
- this.endPosition.set(this.position.add(parent.endPosition));
7678
- this.endRotation.set(this.rotation.add(parent.endRotation));
7679
- this.endScale.set(this.scale.add(parent.endScale));
7680
- }
7681
- const ch = this.children;
7682
- for (let i = 0; i < ch.length; ++i) {
7683
- ch[i].transform();
7684
- }
7685
- return this;
7686
- }
7687
- */
7688
7580
  _setScenegraphNodeProps(props) {
7689
7581
  if ("display" in props) {
7690
7582
  this.display = props.display;
@@ -7750,7 +7642,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
7750
7642
  this.removeAll();
7751
7643
  super.destroy();
7752
7644
  }
7753
- // Unpacks arrays and nested arrays of children
7754
7645
  add(...children) {
7755
7646
  for (const child of children) {
7756
7647
  if (Array.isArray(child)) {
@@ -7794,10 +7685,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
7794
7685
  // ../engine/src/scenegraph/model-node.ts
7795
7686
  var ModelNode = class extends ScenegraphNode {
7796
7687
  bounds = null;
7797
- // TODO - is this used? override callbacks to make sure we call them with this
7798
- // onBeforeRender = null;
7799
- // onAfterRender = null;
7800
- // AfterRender = null;
7801
7688
  constructor(props) {
7802
7689
  super(props);
7803
7690
  this.model = props.model;
@@ -7816,7 +7703,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
7816
7703
  this.managedResources.forEach((resource) => resource.destroy());
7817
7704
  this.managedResources = [];
7818
7705
  }
7819
- // Expose model methods
7820
7706
  draw(renderPass) {
7821
7707
  return this.model.draw(renderPass);
7822
7708
  }
@@ -7944,17 +7830,17 @@ vec4 pbr_filterColor(vec4 colorUnused)
7944
7830
  }
7945
7831
  return original.getParameter.apply(this, arguments);
7946
7832
  };
7947
- gl.enableVertexAttribArray = function enableVertexAttribArray(index) {
7833
+ gl.enableVertexAttribArray = function enableVertexAttribArray(index2) {
7948
7834
  const vao = self.currentVertexArrayObject;
7949
- vao.maxAttrib = Math.max(vao.maxAttrib, index);
7950
- const attrib = vao.attribs[index];
7835
+ vao.maxAttrib = Math.max(vao.maxAttrib, index2);
7836
+ const attrib = vao.attribs[index2];
7951
7837
  attrib.enabled = true;
7952
7838
  return original.enableVertexAttribArray.apply(this, arguments);
7953
7839
  };
7954
- gl.disableVertexAttribArray = function disableVertexAttribArray(index) {
7840
+ gl.disableVertexAttribArray = function disableVertexAttribArray(index2) {
7955
7841
  const vao = self.currentVertexArrayObject;
7956
- vao.maxAttrib = Math.max(vao.maxAttrib, index);
7957
- const attrib = vao.attribs[index];
7842
+ vao.maxAttrib = Math.max(vao.maxAttrib, index2);
7843
+ const attrib = vao.attribs[index2];
7958
7844
  attrib.enabled = false;
7959
7845
  return original.disableVertexAttribArray.apply(this, arguments);
7960
7846
  };
@@ -7970,9 +7856,9 @@ vec4 pbr_filterColor(vec4 colorUnused)
7970
7856
  }
7971
7857
  return original.bindBuffer.apply(this, arguments);
7972
7858
  };
7973
- gl.getVertexAttrib = function getVertexAttrib(index, pname) {
7859
+ gl.getVertexAttrib = function getVertexAttrib(index2, pname) {
7974
7860
  const vao = self.currentVertexArrayObject;
7975
- const attrib = vao.attribs[index];
7861
+ const attrib = vao.attribs[index2];
7976
7862
  switch (pname) {
7977
7863
  case gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
7978
7864
  return attrib.buffer;
@@ -8126,7 +8012,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
8126
8012
  }
8127
8013
 
8128
8014
  // ../constants/src/constants-enum.ts
8129
- var GLEnum2 = /* @__PURE__ */ function(GLEnum4) {
8015
+ var GLEnum2 = function(GLEnum4) {
8130
8016
  GLEnum4[GLEnum4["DEPTH_BUFFER_BIT"] = 256] = "DEPTH_BUFFER_BIT";
8131
8017
  GLEnum4[GLEnum4["STENCIL_BUFFER_BIT"] = 1024] = "STENCIL_BUFFER_BIT";
8132
8018
  GLEnum4[GLEnum4["COLOR_BUFFER_BIT"] = 16384] = "COLOR_BUFFER_BIT";
@@ -8833,16 +8719,13 @@ vec4 pbr_filterColor(vec4 colorUnused)
8833
8719
  var getWebGL2ValueOrZero = (gl) => !isWebGL2(gl) ? 0 : void 0;
8834
8720
  var WEBGL_PARAMETERS = {
8835
8721
  [GLEnum2.READ_BUFFER]: (gl) => !isWebGL2(gl) ? GLEnum2.COLOR_ATTACHMENT0 : void 0,
8836
- // WebGL2 context parameters
8837
8722
  [GL_FRAGMENT_SHADER_DERIVATIVE_HINT]: (gl) => !isWebGL2(gl) ? GL_DONT_CARE : void 0,
8838
8723
  [GLEnum2.RASTERIZER_DISCARD]: getWebGL2ValueOrZero,
8839
8724
  [GLEnum2.SAMPLES]: getWebGL2ValueOrZero,
8840
- // WebGL2 extension context parameters
8841
8725
  [GL_GPU_DISJOINT_EXT]: (gl, getParameter) => {
8842
8726
  const ext = isWebGL2(gl) ? gl.getExtension(EXT_disjoint_timer_query_webgl2) : gl.getExtension(EXT_disjoint_timer_query);
8843
8727
  return ext && ext.GPU_DISJOINT_EXT ? getParameter(ext.GPU_DISJOINT_EXT) : 0;
8844
8728
  },
8845
- // Extension fixed values
8846
8729
  [GL_UNMASKED_VENDOR_WEBGL]: (gl, getParameter) => {
8847
8730
  const ext = gl.getExtension(WEBGL_debug_renderer_info);
8848
8731
  return getParameter(ext && ext.UNMASKED_VENDOR_WEBGL || GLEnum2.VENDOR);
@@ -8851,12 +8734,10 @@ vec4 pbr_filterColor(vec4 colorUnused)
8851
8734
  const ext = gl.getExtension(WEBGL_debug_renderer_info);
8852
8735
  return getParameter(ext && ext.UNMASKED_RENDERER_WEBGL || GLEnum2.RENDERER);
8853
8736
  },
8854
- // Extension LIMITS
8855
8737
  [GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT]: (gl, getParameter) => {
8856
8738
  const ext = gl.luma?.extensions?.[EXT_texture_filter_anisotropic] || gl.getExtension("EXT_texture_filter_anisotropic");
8857
8739
  return ext ? getParameter(ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 1;
8858
8740
  },
8859
- // WebGL2 Limits
8860
8741
  [GLEnum2.MAX_3D_TEXTURE_SIZE]: getWebGL2ValueOrZero,
8861
8742
  [GLEnum2.MAX_ARRAY_TEXTURE_LAYERS]: getWebGL2ValueOrZero,
8862
8743
  [GLEnum2.MAX_CLIENT_WAIT_TIMEOUT_WEBGL]: getWebGL2ValueOrZero,
@@ -8877,18 +8758,9 @@ vec4 pbr_filterColor(vec4 colorUnused)
8877
8758
  }
8878
8759
  return void 0;
8879
8760
  },
8880
- [GLEnum2.MAX_ELEMENT_INDEX]: (
8881
- // Guess: per webglstats.com 99.6% of webgl2 supports 2147483647
8882
- (gl) => gl.getExtension(OES_element_index) ? 2147483647 : 65535
8883
- ),
8884
- [GLEnum2.MAX_ELEMENTS_INDICES]: (
8885
- // Guess: "Reasonably safe" per webglstats.com - could be higher/lower (on some mobile devices)
8886
- (gl) => gl.getExtension(OES_element_index) ? 16777216 : 65535
8887
- ),
8888
- [GLEnum2.MAX_ELEMENTS_VERTICES]: (
8889
- // Guess: "Reasonably safe" per webglstats.com - could be higher/lower (on some mobile devices)
8890
- (gl) => 16777216
8891
- ),
8761
+ [GLEnum2.MAX_ELEMENT_INDEX]: (gl) => gl.getExtension(OES_element_index) ? 2147483647 : 65535,
8762
+ [GLEnum2.MAX_ELEMENTS_INDICES]: (gl) => gl.getExtension(OES_element_index) ? 16777216 : 65535,
8763
+ [GLEnum2.MAX_ELEMENTS_VERTICES]: (gl) => 16777216,
8892
8764
  [GLEnum2.MAX_FRAGMENT_INPUT_COMPONENTS]: getWebGL2ValueOrZero,
8893
8765
  [GLEnum2.MAX_FRAGMENT_UNIFORM_BLOCKS]: getWebGL2ValueOrZero,
8894
8766
  [GLEnum2.MAX_FRAGMENT_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
@@ -8942,12 +8814,10 @@ vec4 pbr_filterColor(vec4 colorUnused)
8942
8814
  };
8943
8815
  }
8944
8816
  var WEBGL2_CONTEXT_POLYFILLS = {
8945
- // POLYFILL TABLE
8946
8817
  [OES_vertex_array_object]: {
8947
8818
  meta: {
8948
8819
  suffix: "OES"
8949
8820
  },
8950
- // NEW METHODS
8951
8821
  createVertexArray: () => {
8952
8822
  assert2(false, ERR_VAO_NOT_SUPPORTED);
8953
8823
  },
@@ -8960,9 +8830,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
8960
8830
  [ANGLE_instanced_arrays]: {
8961
8831
  meta: {
8962
8832
  suffix: "ANGLE"
8963
- // constants: {
8964
- // VERTEX_ATTRIB_ARRAY_DIVISOR: 'VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE'
8965
- // }
8966
8833
  },
8967
8834
  vertexAttribDivisor(location, divisor) {
8968
8835
  assert2(divisor === 0, "WebGL instanced rendering not supported");
@@ -8984,7 +8851,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
8984
8851
  meta: {
8985
8852
  suffix: "EXT"
8986
8853
  },
8987
- // WebGL1: Polyfills the WebGL2 Query API
8988
8854
  createQuery: () => {
8989
8855
  assert2(false);
8990
8856
  },
@@ -8999,7 +8865,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
8999
8865
  getQuery(handle, pname) {
9000
8866
  return this.getQueryObject(handle, pname);
9001
8867
  },
9002
- // The WebGL1 extension uses getQueryObject rather then getQueryParameter
9003
8868
  getQueryParameter(handle, pname) {
9004
8869
  return this.getQueryObject(handle, pname);
9005
8870
  },
@@ -9008,14 +8873,12 @@ vec4 pbr_filterColor(vec4 colorUnused)
9008
8873
  }
9009
8874
  };
9010
8875
  var WEBGL2_CONTEXT_OVERRIDES = {
9011
- // Ensure readBuffer is a no-op
9012
8876
  readBuffer: (gl, originalFunc, attachment) => {
9013
8877
  if (isWebGL2(gl)) {
9014
8878
  originalFunc(attachment);
9015
8879
  } else {
9016
8880
  }
9017
8881
  },
9018
- // Override for getVertexAttrib that returns sane values for non-WebGL1 constants
9019
8882
  getVertexAttrib: (gl, originalFunc, location, pname) => {
9020
8883
  const {
9021
8884
  webgl2,
@@ -9033,7 +8896,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
9033
8896
  }
9034
8897
  return result !== void 0 ? result : originalFunc(location, pname);
9035
8898
  },
9036
- // Handle transform feedback and uniform block queries in WebGL1
9037
8899
  getProgramParameter: (gl, originalFunc, program, pname) => {
9038
8900
  if (!isWebGL2(gl)) {
9039
8901
  switch (pname) {
@@ -9170,7 +9032,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
9170
9032
  [GLEnum2.BLEND_SRC_ALPHA]: GLEnum2.ONE,
9171
9033
  [GLEnum2.BLEND_DST_ALPHA]: GLEnum2.ZERO,
9172
9034
  [GLEnum2.COLOR_CLEAR_VALUE]: new Float32Array([0, 0, 0, 0]),
9173
- // TBD
9174
9035
  [GLEnum2.COLOR_WRITEMASK]: [true, true, true, true],
9175
9036
  [GLEnum2.CULL_FACE]: false,
9176
9037
  [GLEnum2.CULL_FACE_MODE]: GLEnum2.BACK,
@@ -9178,11 +9039,9 @@ vec4 pbr_filterColor(vec4 colorUnused)
9178
9039
  [GLEnum2.DEPTH_CLEAR_VALUE]: 1,
9179
9040
  [GLEnum2.DEPTH_FUNC]: GLEnum2.LESS,
9180
9041
  [GLEnum2.DEPTH_RANGE]: new Float32Array([0, 1]),
9181
- // TBD
9182
9042
  [GLEnum2.DEPTH_WRITEMASK]: true,
9183
9043
  [GLEnum2.DITHER]: true,
9184
9044
  [GLEnum2.CURRENT_PROGRAM]: null,
9185
- // FRAMEBUFFER_BINDING and DRAW_FRAMEBUFFER_BINDING(WebGL2) refer same state.
9186
9045
  [GLEnum2.FRAMEBUFFER_BINDING]: null,
9187
9046
  [GLEnum2.RENDERBUFFER_BINDING]: null,
9188
9047
  [GLEnum2.VERTEX_ARRAY_BINDING]: null,
@@ -9198,7 +9057,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
9198
9057
  [GLEnum2.SAMPLE_COVERAGE_VALUE]: 1,
9199
9058
  [GLEnum2.SAMPLE_COVERAGE_INVERT]: false,
9200
9059
  [GLEnum2.SCISSOR_TEST]: false,
9201
- // Note: Dynamic value. If scissor test enabled we expect users to set correct scissor box
9202
9060
  [GLEnum2.SCISSOR_BOX]: new Int32Array([0, 0, 1024, 1024]),
9203
9061
  [GLEnum2.STENCIL_TEST]: false,
9204
9062
  [GLEnum2.STENCIL_CLEAR_VALUE]: 0,
@@ -9216,16 +9074,12 @@ vec4 pbr_filterColor(vec4 colorUnused)
9216
9074
  [GLEnum2.STENCIL_BACK_FAIL]: GLEnum2.KEEP,
9217
9075
  [GLEnum2.STENCIL_BACK_PASS_DEPTH_FAIL]: GLEnum2.KEEP,
9218
9076
  [GLEnum2.STENCIL_BACK_PASS_DEPTH_PASS]: GLEnum2.KEEP,
9219
- // Dynamic value: We use [0, 0, 1024, 1024] as default, but usually this is updated in each frame.
9220
9077
  [GLEnum2.VIEWPORT]: [0, 0, 1024, 1024],
9221
- // WEBGL1 PIXEL PACK/UNPACK MODES
9222
9078
  [GLEnum2.PACK_ALIGNMENT]: 4,
9223
9079
  [GLEnum2.UNPACK_ALIGNMENT]: 4,
9224
9080
  [GLEnum2.UNPACK_FLIP_Y_WEBGL]: false,
9225
9081
  [GLEnum2.UNPACK_PREMULTIPLY_ALPHA_WEBGL]: false,
9226
9082
  [GLEnum2.UNPACK_COLORSPACE_CONVERSION_WEBGL]: GLEnum2.BROWSER_DEFAULT_WEBGL,
9227
- // WEBGL2 / EXTENSIONS
9228
- // gl1: 'OES_standard_derivatives'
9229
9083
  [GLEnum2.TRANSFORM_FEEDBACK_BINDING]: null,
9230
9084
  [GLEnum2.COPY_READ_BUFFER_BINDING]: null,
9231
9085
  [GLEnum2.COPY_WRITE_BUFFER_BINDING]: null,
@@ -9293,10 +9147,8 @@ vec4 pbr_filterColor(vec4 colorUnused)
9293
9147
  [GLEnum2.RENDERBUFFER_BINDING]: (gl, value) => gl.bindRenderbuffer(GLEnum2.RENDERBUFFER, value),
9294
9148
  [GLEnum2.TRANSFORM_FEEDBACK_BINDING]: (gl, value) => gl.bindTransformFeedback?.(GLEnum2.TRANSFORM_FEEDBACK, value),
9295
9149
  [GLEnum2.VERTEX_ARRAY_BINDING]: (gl, value) => gl.bindVertexArray(value),
9296
- // NOTE: FRAMEBUFFER_BINDING and DRAW_FRAMEBUFFER_BINDING(WebGL2) refer same state.
9297
9150
  [GLEnum2.FRAMEBUFFER_BINDING]: bindFramebuffer,
9298
9151
  [GLEnum2.READ_FRAMEBUFFER_BINDING]: bindFramebuffer,
9299
- // Buffers
9300
9152
  [GLEnum2.ARRAY_BUFFER_BINDING]: bindBuffer,
9301
9153
  [GLEnum2.COPY_READ_BUFFER_BINDING]: bindBuffer,
9302
9154
  [GLEnum2.COPY_WRITE_BUFFER_BINDING]: bindBuffer,
@@ -9332,14 +9184,11 @@ vec4 pbr_filterColor(vec4 colorUnused)
9332
9184
  [GLEnum2.STENCIL_BACK_PASS_DEPTH_FAIL]: "stencilOpBack",
9333
9185
  [GLEnum2.STENCIL_BACK_PASS_DEPTH_PASS]: "stencilOpBack",
9334
9186
  [GLEnum2.VIEWPORT]: (gl, value) => gl.viewport(...value),
9335
- // WEBGL1 PIXEL PACK/UNPACK MODES
9336
9187
  [GLEnum2.PACK_ALIGNMENT]: pixelStorei,
9337
9188
  [GLEnum2.UNPACK_ALIGNMENT]: pixelStorei,
9338
9189
  [GLEnum2.UNPACK_FLIP_Y_WEBGL]: pixelStorei,
9339
9190
  [GLEnum2.UNPACK_PREMULTIPLY_ALPHA_WEBGL]: pixelStorei,
9340
9191
  [GLEnum2.UNPACK_COLORSPACE_CONVERSION_WEBGL]: pixelStorei,
9341
- // WEBGL2 PIXEL PACK/UNPACK MODES
9342
- // RASTERIZER_DISCARD ...
9343
9192
  [GLEnum2.PACK_ROW_LENGTH]: pixelStorei,
9344
9193
  [GLEnum2.PACK_SKIP_PIXELS]: pixelStorei,
9345
9194
  [GLEnum2.PACK_SKIP_ROWS]: pixelStorei,
@@ -9348,7 +9197,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
9348
9197
  [GLEnum2.UNPACK_SKIP_PIXELS]: pixelStorei,
9349
9198
  [GLEnum2.UNPACK_SKIP_ROWS]: pixelStorei,
9350
9199
  [GLEnum2.UNPACK_SKIP_IMAGES]: pixelStorei,
9351
- // Function-style setters
9352
9200
  framebuffer: (gl, framebuffer) => {
9353
9201
  const handle = framebuffer && "handle" in framebuffer ? framebuffer.handle : framebuffer;
9354
9202
  return gl.bindFramebuffer(GLEnum2.FRAMEBUFFER, handle);
@@ -9420,7 +9268,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
9420
9268
  stencilOpBack: (gl, values, cache2) => gl.stencilOpSeparate(GLEnum2.BACK, getValue(GLEnum2.STENCIL_BACK_FAIL, values, cache2), getValue(GLEnum2.STENCIL_BACK_PASS_DEPTH_FAIL, values, cache2), getValue(GLEnum2.STENCIL_BACK_PASS_DEPTH_PASS, values, cache2))
9421
9269
  };
9422
9270
  var GL_HOOKED_SETTERS = {
9423
- // GENERIC SETTERS
9424
9271
  enable: (update, capability) => update({
9425
9272
  [capability]: true
9426
9273
  }),
@@ -9433,7 +9280,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
9433
9280
  hint: (update, pname, hint2) => update({
9434
9281
  [pname]: hint2
9435
9282
  }),
9436
- // SPECIFIC SETTERS
9437
9283
  useProgram: (update, value) => update({
9438
9284
  [GLEnum2.CURRENT_PROGRAM]: value
9439
9285
  }),
@@ -9594,47 +9440,9 @@ vec4 pbr_filterColor(vec4 colorUnused)
9594
9440
  [GLEnum2.SAMPLE_COVERAGE]: isEnabled,
9595
9441
  [GLEnum2.SCISSOR_TEST]: isEnabled,
9596
9442
  [GLEnum2.STENCIL_TEST]: isEnabled,
9597
- // WebGL 2
9598
9443
  [GLEnum2.RASTERIZER_DISCARD]: isEnabled
9599
9444
  };
9600
- var NON_CACHE_PARAMETERS = /* @__PURE__ */ new Set([
9601
- // setter not intercepted
9602
- GLEnum2.ACTIVE_TEXTURE,
9603
- GLEnum2.TRANSFORM_FEEDBACK_ACTIVE,
9604
- GLEnum2.TRANSFORM_FEEDBACK_PAUSED,
9605
- // setters bindBufferRange/bindBufferBase cannot be pruned based on cache
9606
- GLEnum2.TRANSFORM_FEEDBACK_BUFFER_BINDING,
9607
- GLEnum2.UNIFORM_BUFFER_BINDING,
9608
- // states depending on VERTEX_ARRAY_BINDING
9609
- GLEnum2.ELEMENT_ARRAY_BUFFER_BINDING,
9610
- // states depending on READ_FRAMEBUFFER_BINDING
9611
- GLEnum2.IMPLEMENTATION_COLOR_READ_FORMAT,
9612
- GLEnum2.IMPLEMENTATION_COLOR_READ_TYPE,
9613
- // states depending on FRAMEBUFFER_BINDING
9614
- GLEnum2.READ_BUFFER,
9615
- GLEnum2.DRAW_BUFFER0,
9616
- GLEnum2.DRAW_BUFFER1,
9617
- GLEnum2.DRAW_BUFFER2,
9618
- GLEnum2.DRAW_BUFFER3,
9619
- GLEnum2.DRAW_BUFFER4,
9620
- GLEnum2.DRAW_BUFFER5,
9621
- GLEnum2.DRAW_BUFFER6,
9622
- GLEnum2.DRAW_BUFFER7,
9623
- GLEnum2.DRAW_BUFFER8,
9624
- GLEnum2.DRAW_BUFFER9,
9625
- GLEnum2.DRAW_BUFFER10,
9626
- GLEnum2.DRAW_BUFFER11,
9627
- GLEnum2.DRAW_BUFFER12,
9628
- GLEnum2.DRAW_BUFFER13,
9629
- GLEnum2.DRAW_BUFFER14,
9630
- GLEnum2.DRAW_BUFFER15,
9631
- // states depending on ACTIVE_TEXTURE
9632
- GLEnum2.SAMPLER_BINDING,
9633
- GLEnum2.TEXTURE_BINDING_2D,
9634
- GLEnum2.TEXTURE_BINDING_2D_ARRAY,
9635
- GLEnum2.TEXTURE_BINDING_3D,
9636
- GLEnum2.TEXTURE_BINDING_CUBE_MAP
9637
- ]);
9445
+ var NON_CACHE_PARAMETERS = /* @__PURE__ */ new Set([GLEnum2.ACTIVE_TEXTURE, GLEnum2.TRANSFORM_FEEDBACK_ACTIVE, GLEnum2.TRANSFORM_FEEDBACK_PAUSED, GLEnum2.TRANSFORM_FEEDBACK_BUFFER_BINDING, GLEnum2.UNIFORM_BUFFER_BINDING, GLEnum2.ELEMENT_ARRAY_BUFFER_BINDING, GLEnum2.IMPLEMENTATION_COLOR_READ_FORMAT, GLEnum2.IMPLEMENTATION_COLOR_READ_TYPE, GLEnum2.READ_BUFFER, GLEnum2.DRAW_BUFFER0, GLEnum2.DRAW_BUFFER1, GLEnum2.DRAW_BUFFER2, GLEnum2.DRAW_BUFFER3, GLEnum2.DRAW_BUFFER4, GLEnum2.DRAW_BUFFER5, GLEnum2.DRAW_BUFFER6, GLEnum2.DRAW_BUFFER7, GLEnum2.DRAW_BUFFER8, GLEnum2.DRAW_BUFFER9, GLEnum2.DRAW_BUFFER10, GLEnum2.DRAW_BUFFER11, GLEnum2.DRAW_BUFFER12, GLEnum2.DRAW_BUFFER13, GLEnum2.DRAW_BUFFER14, GLEnum2.DRAW_BUFFER15, GLEnum2.SAMPLER_BINDING, GLEnum2.TEXTURE_BINDING_2D, GLEnum2.TEXTURE_BINDING_2D_ARRAY, GLEnum2.TEXTURE_BINDING_3D, GLEnum2.TEXTURE_BINDING_CUBE_MAP]);
9638
9446
 
9639
9447
  // ../webgl/src/context/parameters/unified-parameter-api.ts
9640
9448
  function setGLParameters(device, parameters) {
@@ -9711,10 +9519,8 @@ vec4 pbr_filterColor(vec4 colorUnused)
9711
9519
  enable = true;
9712
9520
  constructor(gl, {
9713
9521
  copyState = false,
9714
- // Copy cache from params (slow) or initialize from WebGL defaults (fast)
9715
9522
  log: log3 = () => {
9716
9523
  }
9717
- // Logging function, called when gl parameter change calls are actually issued
9718
9524
  } = {}) {
9719
9525
  this.gl = gl;
9720
9526
  this.cache = copyState ? getGLParameters(gl) : Object.assign({}, GL_PARAMETER_DEFAULTS);
@@ -9731,12 +9537,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
9731
9537
  setGLParameters(this.gl, oldValues);
9732
9538
  this.stateStack.pop();
9733
9539
  }
9734
- /**
9735
- // interceptor for context set functions - update our cache and our stack
9736
- // values (Object) - the key values for this setter
9737
- * @param values
9738
- * @returns
9739
- */
9740
9540
  _updateCache(values) {
9741
9541
  let valueChanged = false;
9742
9542
  let oldValue;
@@ -9810,13 +9610,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
9810
9610
  if (!(pname in glState.cache)) {
9811
9611
  glState.cache[pname] = originalGetterFunc(pname);
9812
9612
  }
9813
- return glState.enable ? (
9814
- // Call the getter the params so that it can e.g. serve from a cache
9815
- glState.cache[pname]
9816
- ) : (
9817
- // Optionally call the original function to do a "hard" query from the WebGLRenderingContext
9818
- originalGetterFunc(pname)
9819
- );
9613
+ return glState.enable ? glState.cache[pname] : originalGetterFunc(pname);
9820
9614
  };
9821
9615
  Object.defineProperty(gl[functionName], "name", {
9822
9616
  value: `${functionName}-from-cache`,
@@ -9858,14 +9652,9 @@ vec4 pbr_filterColor(vec4 colorUnused)
9858
9652
  // ../webgl/src/context/context/create-browser-context.ts
9859
9653
  var DEFAULT_CONTEXT_PROPS = {
9860
9654
  webgl2: true,
9861
- // Attempt to create a WebGL2 context
9862
9655
  webgl1: true,
9863
- // Attempt to create a WebGL1 context (false to fail if webgl2 not available)
9864
9656
  powerPreference: "high-performance",
9865
- // After all, most apps are using WebGL for performance reasons
9866
- // eslint-disable-next-line no-console
9867
9657
  onContextLost: () => console.error("WebGL context lost"),
9868
- // eslint-disable-next-line no-console
9869
9658
  onContextRestored: () => console.info("WebGL context restored")
9870
9659
  };
9871
9660
  function createBrowserContext(canvas, props) {
@@ -9923,17 +9712,20 @@ vec4 pbr_filterColor(vec4 colorUnused)
9923
9712
  const rendererUnmasked = gl.getParameter(ext ? ext.UNMASKED_RENDERER_WEBGL : GLEnum2.RENDERER);
9924
9713
  const vendor = vendorUnmasked || vendorMasked;
9925
9714
  const renderer = rendererUnmasked || rendererMasked;
9715
+ const version = gl.getParameter(GLEnum2.VERSION);
9926
9716
  const gpu = identifyGPUVendor(vendor, renderer);
9717
+ const gpuBackend = identifyGPUBackend(vendor, renderer);
9718
+ const shadingLanguage = "glsl";
9719
+ const shadingLanguageVersion = isWebGL2(gl) ? 300 : 100;
9927
9720
  return {
9928
9721
  type: isWebGL2(gl) ? "webgl2" : "webgl",
9929
9722
  gpu,
9930
- vendor: vendorUnmasked || vendorMasked,
9931
- renderer: rendererUnmasked || rendererMasked,
9932
- version: gl.getParameter(GLEnum2.VERSION),
9933
- shadingLanguages: ["glsl"],
9934
- shadingLanguageVersions: {
9935
- "glsl": gl.getParameter(GLEnum2.SHADING_LANGUAGE_VERSION)
9936
- }
9723
+ gpuBackend,
9724
+ vendor,
9725
+ renderer,
9726
+ version,
9727
+ shadingLanguage,
9728
+ shadingLanguageVersion
9937
9729
  };
9938
9730
  }
9939
9731
  function identifyGPUVendor(vendor, renderer) {
@@ -9954,6 +9746,15 @@ vec4 pbr_filterColor(vec4 colorUnused)
9954
9746
  }
9955
9747
  return "unknown";
9956
9748
  }
9749
+ function identifyGPUBackend(vendor, renderer) {
9750
+ if (/ANGLE/i.exec(vendor) || /ANGLE/i.exec(renderer)) {
9751
+ return "angle";
9752
+ }
9753
+ if (/Metal/i.exec(vendor) || /Metal/i.exec(renderer)) {
9754
+ return "metal";
9755
+ }
9756
+ return "unknown";
9757
+ }
9957
9758
 
9958
9759
  // ../webgl/src/adapter/device-helpers/is-old-ie.ts
9959
9760
  function isOldIE(opts = {}) {
@@ -10028,13 +9829,9 @@ vec4 pbr_filterColor(vec4 colorUnused)
10028
9829
  "texture-filter-linear-float16-webgl": (gl) => checkExtension(gl, "OES_texture_half_float_linear"),
10029
9830
  "texture-filter-anisotropic-webgl": (gl) => checkExtension(gl, "EXT_texture_filter_anisotropic"),
10030
9831
  "texture-renderable-float32-webgl": (gl) => checkExtension(gl, "EXT_color_buffer_float"),
10031
- // [false, 'EXT_color_buffer_float'],
10032
9832
  "texture-renderable-float16-webgl": (gl) => checkExtension(gl, "EXT_color_buffer_half_float"),
10033
9833
  "texture-compression-bc": (gl) => checkExtensions(gl, [X_S3TC, X_S3TC_SRGB, X_RGTC, X_BPTC]),
10034
9834
  "texture-compression-bc5-webgl": (gl) => checkExtensions(gl, [X_RGTC]),
10035
- // 'texture-compression-bc7-webgl': gl => checkExtensions(gl, [X_BPTC]),
10036
- // 'texture-compression-bc3-srgb-webgl': gl => checkExtensions(gl, [X_S3TC_SRGB]),
10037
- // 'texture-compression-bc3-webgl': gl => checkExtensions(gl, [X_S3TC]),
10038
9835
  "texture-compression-etc2": (gl) => checkExtensions(gl, [X_ETC2]),
10039
9836
  "texture-compression-astc": (gl) => checkExtensions(gl, [X_ASTC]),
10040
9837
  "texture-compression-etc1-webgl": (gl) => checkExtensions(gl, [X_ETC1]),
@@ -10049,9 +9846,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10049
9846
  return textureFeatures.filter((feature) => checkTextureFeature(gl, feature));
10050
9847
  }
10051
9848
  var TEXTURE_FORMATS = {
10052
- // Unsized formats that leave the precision up to the driver.
10053
- // TODO - Fix bpp constants
10054
- // 'r8unorm-unsized': {gl: GL.LUMINANCE, b: 4, c: 2, bpp: 4},
10055
9849
  "rgb8unorm-unsized": {
10056
9850
  gl: GLEnum2.RGB,
10057
9851
  gl1: GLEnum2.RGB,
@@ -10070,9 +9864,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10070
9864
  dataFormat: GLEnum2.RGBA,
10071
9865
  types: [GLEnum2.UNSIGNED_BYTE, GLEnum2.UNSIGNED_SHORT_4_4_4_4, GLEnum2.UNSIGNED_SHORT_5_5_5_1]
10072
9866
  },
10073
- // 'rgb8unorm-srgb-unsized': {gl: GL.SRGB_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
10074
- // 'rgba8unorm-srgb-unsized': {gl: GL.SRGB_ALPHA_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
10075
- // 8-bit formats
10076
9867
  "r8unorm": {
10077
9868
  gl: GLEnum2.R8,
10078
9869
  b: 1,
@@ -10096,7 +9887,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10096
9887
  c: 1,
10097
9888
  renderbuffer: true
10098
9889
  },
10099
- // 16-bit formats
10100
9890
  "rg8unorm": {
10101
9891
  gl: GLEnum2.RG8,
10102
9892
  b: 2,
@@ -10155,7 +9945,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10155
9945
  f: "texture-formats-norm16-webgl",
10156
9946
  x: EXT_TEXTURE_NORM16
10157
9947
  },
10158
- // Packed 16-bit formats
10159
9948
  "rgba4unorm-webgl": {
10160
9949
  gl: GLEnum2.RGBA4,
10161
9950
  b: 2,
@@ -10177,7 +9966,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10177
9966
  wgpu: false,
10178
9967
  renderbuffer: true
10179
9968
  },
10180
- // 24-bit formats
10181
9969
  "rgb8unorm-webgl": {
10182
9970
  gl: GLEnum2.RGB8,
10183
9971
  b: 3,
@@ -10190,7 +9978,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10190
9978
  c: 3,
10191
9979
  wgpu: false
10192
9980
  },
10193
- // 32-bit formats
10194
9981
  "rgba8unorm": {
10195
9982
  gl: GLEnum2.RGBA8,
10196
9983
  gl1: GLEnum2.RGBA,
@@ -10223,7 +10010,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10223
10010
  c: 4,
10224
10011
  bpp: 4
10225
10012
  },
10226
- // reverse colors, webgpu only
10227
10013
  "bgra8unorm": {
10228
10014
  b: 4,
10229
10015
  c: 4
@@ -10244,7 +10030,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10244
10030
  c: 2,
10245
10031
  bpp: 4
10246
10032
  },
10247
- // When using a WebGL 2 context and the EXT_color_buffer_float WebGL2 extension
10248
10033
  "rg16float": {
10249
10034
  gl: GLEnum2.RG16F,
10250
10035
  bpp: 4,
@@ -10290,7 +10075,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10290
10075
  render: "texture-renderable-float32-webgl",
10291
10076
  filter: "texture-filter-linear-float32-webgl"
10292
10077
  },
10293
- // Packed 32-bit formats
10294
10078
  "rgb9e5ufloat": {
10295
10079
  gl: GLEnum2.RGB9_E5,
10296
10080
  b: 4,
@@ -10314,7 +10098,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10314
10098
  p: 1,
10315
10099
  renderbuffer: true
10316
10100
  },
10317
- // webgl2 only
10318
10101
  "rgb10a2unorm-webgl": {
10319
10102
  b: 4,
10320
10103
  c: 4,
@@ -10324,7 +10107,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10324
10107
  bpp: 4,
10325
10108
  renderbuffer: true
10326
10109
  },
10327
- // 48-bit formats
10328
10110
  "rgb16unorm-webgl": {
10329
10111
  gl: GLEnum2.RGB16_EXT,
10330
10112
  b: 2,
@@ -10339,7 +10121,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10339
10121
  f: "texture-formats-norm16-webgl",
10340
10122
  x: EXT_TEXTURE_NORM16
10341
10123
  },
10342
- // 64-bit formats
10343
10124
  "rg32uint": {
10344
10125
  gl: GLEnum2.RG32UI,
10345
10126
  b: 8,
@@ -10395,7 +10176,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10395
10176
  f: "texture-formats-norm16-webgl",
10396
10177
  x: EXT_TEXTURE_NORM16
10397
10178
  },
10398
- // 96-bit formats (deprecated!)
10399
10179
  "rgb32float-webgl": {
10400
10180
  gl: GLEnum2.RGB32F,
10401
10181
  gl1: GLEnum2.RGB,
@@ -10403,11 +10183,9 @@ vec4 pbr_filterColor(vec4 colorUnused)
10403
10183
  filter: "texture-filter-linear-float32-webgl",
10404
10184
  gl2ext: EXT_FLOAT_RENDER_WEBGL2,
10405
10185
  gl1ext: EXT_FLOAT_WEBGL1,
10406
- // WebGL1 render buffers are supported with GL.RGB32F
10407
10186
  dataFormat: GLEnum2.RGB,
10408
10187
  types: [GLEnum2.FLOAT]
10409
10188
  },
10410
- // 128-bit formats
10411
10189
  "rgba32uint": {
10412
10190
  gl: GLEnum2.RGBA32UI,
10413
10191
  b: 16,
@@ -10428,7 +10206,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10428
10206
  filter: "texture-filter-linear-float32-webgl",
10429
10207
  renderbuffer: true
10430
10208
  },
10431
- // Depth and stencil formats
10432
10209
  "stencil8": {
10433
10210
  gl: GLEnum2.STENCIL_INDEX8,
10434
10211
  gl1: GLEnum2.STENCIL_INDEX8,
@@ -10437,7 +10214,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10437
10214
  attachment: GLEnum2.STENCIL_ATTACHMENT,
10438
10215
  renderbuffer: true
10439
10216
  },
10440
- // 8 stencil bits
10441
10217
  "depth16unorm": {
10442
10218
  gl: GLEnum2.DEPTH_COMPONENT16,
10443
10219
  gl1: GLEnum2.DEPTH_COMPONENT16,
@@ -10446,7 +10222,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10446
10222
  attachment: GLEnum2.DEPTH_ATTACHMENT,
10447
10223
  renderbuffer: true
10448
10224
  },
10449
- // 16 depth bits
10450
10225
  "depth24plus": {
10451
10226
  gl: GLEnum2.DEPTH_COMPONENT24,
10452
10227
  b: 3,
@@ -10460,7 +10235,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10460
10235
  attachment: GLEnum2.DEPTH_ATTACHMENT,
10461
10236
  renderbuffer: true
10462
10237
  },
10463
- // The depth component of the "depth24plus" and "depth24plus-stencil8" formats may be implemented as either a 24-bit depth value or a "depth32float" value.
10464
10238
  "depth24plus-stencil8": {
10465
10239
  gl: GLEnum2.DEPTH_STENCIL,
10466
10240
  gl1: GLEnum2.DEPTH_STENCIL,
@@ -10471,7 +10245,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10471
10245
  renderbuffer: true,
10472
10246
  depthTexture: true
10473
10247
  },
10474
- // "depth24unorm-stencil8" feature
10475
10248
  "depth24unorm-stencil8": {
10476
10249
  gl: GLEnum2.DEPTH24_STENCIL8,
10477
10250
  b: 4,
@@ -10480,7 +10253,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10480
10253
  attachment: GLEnum2.DEPTH_STENCIL_ATTACHMENT,
10481
10254
  renderbuffer: true
10482
10255
  },
10483
- // "depth32float-stencil8" feature
10484
10256
  "depth32float-stencil8": {
10485
10257
  gl: GLEnum2.DEPTH32F_STENCIL8,
10486
10258
  b: 5,
@@ -10489,7 +10261,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10489
10261
  attachment: GLEnum2.DEPTH_STENCIL_ATTACHMENT,
10490
10262
  renderbuffer: true
10491
10263
  },
10492
- // BC compressed formats: check device.features.has("texture-compression-bc");
10493
10264
  "bc1-rgb-unorm-webgl": {
10494
10265
  gl: GLEnum2.COMPRESSED_RGB_S3TC_DXT1_EXT,
10495
10266
  x: X_S3TC,
@@ -10570,8 +10341,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10570
10341
  x: X_BPTC,
10571
10342
  f: texture_compression_bc
10572
10343
  },
10573
- // WEBGL_compressed_texture_etc: device.features.has("texture-compression-etc2")
10574
- // Note: Supposedly guaranteed availability compressed formats in WebGL2, but through CPU decompression
10575
10344
  "etc2-rgb8unorm": {
10576
10345
  gl: GLEnum2.COMPRESSED_RGB8_ETC2,
10577
10346
  f: texture_compression_etc2
@@ -10612,7 +10381,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10612
10381
  gl: GLEnum2.COMPRESSED_SIGNED_RG11_EAC,
10613
10382
  f: texture_compression_etc2
10614
10383
  },
10615
- // X_ASTC compressed formats: device.features.has("texture-compression-astc")
10616
10384
  "astc-4x4-unorm": {
10617
10385
  gl: GLEnum2.COMPRESSED_RGBA_ASTC_4x4_KHR,
10618
10386
  f: texture_compression_astc
@@ -10725,7 +10493,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
10725
10493
  gl: GLEnum2.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
10726
10494
  f: texture_compression_astc
10727
10495
  },
10728
- // WEBGL_compressed_texture_pvrtc
10729
10496
  "pvrtc-rgb4unorm-webgl": {
10730
10497
  gl: GLEnum2.COMPRESSED_RGB_PVRTC_4BPPV1_IMG,
10731
10498
  f: texture_compression_pvrtc_webgl
@@ -10742,12 +10509,10 @@ vec4 pbr_filterColor(vec4 colorUnused)
10742
10509
  gl: GLEnum2.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG,
10743
10510
  f: texture_compression_pvrtc_webgl
10744
10511
  },
10745
- // WEBGL_compressed_texture_etc1
10746
10512
  "etc1-rbg-unorm-webgl": {
10747
10513
  gl: GLEnum2.COMPRESSED_RGB_ETC1_WEBGL,
10748
10514
  f: texture_compression_etc1_webgl
10749
10515
  },
10750
- // WEBGL_compressed_texture_atc
10751
10516
  "atc-rgb-unorm-webgl": {
10752
10517
  gl: GLEnum2.COMPRESSED_RGB_ATC_WEBGL,
10753
10518
  f: texture_compression_atc_webgl
@@ -10860,9 +10625,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
10860
10625
  return {
10861
10626
  format: webglFormat,
10862
10627
  dataFormat: getWebGLPixelDataFormat(decoded.format, decoded.integer, decoded.normalized, webglFormat),
10863
- // depth formats don't have a type
10864
10628
  type: decoded.dataType ? getGLFromVertexType(decoded.dataType) : GLEnum2.UNSIGNED_BYTE,
10865
- // @ts-expect-error
10866
10629
  compressed: decoded.compressed
10867
10630
  };
10868
10631
  }
@@ -10993,28 +10756,22 @@ void main(void) {}`;
10993
10756
  "webgl2": [false, true],
10994
10757
  "timer-query-webgl": ["EXT_disjoint_timer_query", "EXT_disjoint_timer_query_webgl2"],
10995
10758
  "transform-feedback-webgl2": [false, true],
10996
- // WEBGL1 SUPPORT
10997
10759
  "vertex-array-object-webgl1": ["OES_vertex_array_object", true],
10998
10760
  "instanced-rendering-webgl1": ["ANGLE_instanced_arrays", true],
10999
10761
  "multiple-render-targets-webgl1": ["WEBGL_draw_buffers", true],
11000
10762
  "index-uint32-webgl1": ["OES_element_index_uint", true],
11001
10763
  "blend-minmax-webgl1": ["EXT_blend_minmax", true],
11002
10764
  "texture-blend-float-webgl1": ["EXT_float_blend", "EXT_float_blend"],
11003
- // TEXTURES, RENDERBUFFERS
11004
10765
  "texture-formats-srgb-webgl1": ["EXT_sRGB", true],
11005
- // TEXTURES
11006
10766
  "texture-formats-depth-webgl1": ["WEBGL_depth_texture", true],
11007
10767
  "texture-formats-float32-webgl1": ["OES_texture_float", true],
11008
10768
  "texture-formats-float16-webgl1": ["OES_texture_half_float", true],
11009
10769
  "texture-filter-linear-float32-webgl": ["OES_texture_float_linear", "OES_texture_float_linear"],
11010
10770
  "texture-filter-linear-float16-webgl": ["OES_texture_half_float_linear", "OES_texture_half_float_linear"],
11011
10771
  "texture-filter-anisotropic-webgl": ["EXT_texture_filter_anisotropic", "EXT_texture_filter_anisotropic"],
11012
- // FRAMEBUFFERS, TEXTURES AND RENDERBUFFERS
11013
10772
  "texture-renderable-rgba32float-webgl": ["WEBGL_color_buffer_float", "EXT_color_buffer_float"],
11014
- // Note override check
11015
10773
  "texture-renderable-float32-webgl": [false, "EXT_color_buffer_float"],
11016
10774
  "texture-renderable-float16-webgl": ["EXT_color_buffer_half_float", "EXT_color_buffer_half_float"],
11017
- // GLSL extensions
11018
10775
  "glsl-frag-data": ["WEBGL_draw_buffers", true],
11019
10776
  "glsl-frag-depth": ["EXT_frag_depth", true],
11020
10777
  "glsl-derivatives": ["OES_standard_derivatives", true],
@@ -11026,46 +10783,31 @@ void main(void) {}`;
11026
10783
  const gl2 = getWebGL2Context(gl);
11027
10784
  return {
11028
10785
  maxTextureDimension1D: 0,
11029
- // WebGL does not support 1D textures
11030
10786
  maxTextureDimension2D: gl.getParameter(GLEnum2.MAX_TEXTURE_SIZE),
11031
10787
  maxTextureDimension3D: gl2 ? gl2.getParameter(GLEnum2.MAX_3D_TEXTURE_SIZE) : 0,
11032
10788
  maxTextureArrayLayers: gl2 ? gl2.getParameter(GLEnum2.MAX_ARRAY_TEXTURE_LAYERS) : 0,
11033
10789
  maxBindGroups: 1,
11034
- // TBD
11035
10790
  maxDynamicUniformBuffersPerPipelineLayout: 0,
11036
- // TBD
11037
10791
  maxDynamicStorageBuffersPerPipelineLayout: 0,
11038
- // TBD
11039
10792
  maxSampledTexturesPerShaderStage: gl.getParameter(GLEnum2.MAX_VERTEX_TEXTURE_IMAGE_UNITS),
11040
- // TBD
11041
10793
  maxSamplersPerShaderStage: gl.getParameter(GLEnum2.MAX_COMBINED_TEXTURE_IMAGE_UNITS),
11042
10794
  maxStorageBuffersPerShaderStage: 0,
11043
- // TBD
11044
10795
  maxStorageTexturesPerShaderStage: 0,
11045
- // TBD
11046
10796
  maxUniformBuffersPerShaderStage: gl2 ? gl2.getParameter(GLEnum2.MAX_UNIFORM_BUFFER_BINDINGS) : 0,
11047
10797
  maxUniformBufferBindingSize: gl2 ? gl2.getParameter(GLEnum2.MAX_UNIFORM_BLOCK_SIZE) : 0,
11048
10798
  maxStorageBufferBindingSize: 0,
11049
10799
  minUniformBufferOffsetAlignment: gl2 ? gl2.getParameter(GLEnum2.UNIFORM_BUFFER_OFFSET_ALIGNMENT) : 0,
11050
10800
  minStorageBufferOffsetAlignment: 0,
11051
- // TBD
11052
10801
  maxVertexBuffers: 0,
11053
10802
  maxVertexAttributes: gl.getParameter(GLEnum2.MAX_VERTEX_ATTRIBS),
11054
10803
  maxVertexBufferArrayStride: 2048,
11055
- // TBD, this is just the default value from WebGPU
11056
10804
  maxInterStageShaderComponents: gl2 ? gl2.getParameter(GLEnum2.MAX_VARYING_COMPONENTS) : 0,
11057
10805
  maxComputeWorkgroupStorageSize: 0,
11058
- // WebGL does not support compute shaders
11059
10806
  maxComputeInvocationsPerWorkgroup: 0,
11060
- // WebGL does not support compute shaders
11061
10807
  maxComputeWorkgroupSizeX: 0,
11062
- // WebGL does not support compute shaders
11063
10808
  maxComputeWorkgroupSizeY: 0,
11064
- // WebGL does not support compute shaders
11065
10809
  maxComputeWorkgroupSizeZ: 0,
11066
- // WebGL does not support compute shaders
11067
10810
  maxComputeWorkgroupsPerDimension: 0
11068
- // WebGL does not support compute shaders
11069
10811
  };
11070
10812
  }
11071
10813
  function getWebGLLimits(gl) {
@@ -11081,86 +10823,45 @@ void main(void) {}`;
11081
10823
  [GLEnum2.ALIASED_POINT_SIZE_RANGE]: get(GLEnum2.ALIASED_POINT_SIZE_RANGE),
11082
10824
  [GLEnum2.MAX_TEXTURE_SIZE]: get(GLEnum2.MAX_TEXTURE_SIZE),
11083
10825
  [GLEnum2.MAX_CUBE_MAP_TEXTURE_SIZE]: get(GLEnum2.MAX_CUBE_MAP_TEXTURE_SIZE),
11084
- // GLint
11085
10826
  [GLEnum2.MAX_TEXTURE_IMAGE_UNITS]: get(GLEnum2.MAX_TEXTURE_IMAGE_UNITS),
11086
- // GLint
11087
10827
  [GLEnum2.MAX_COMBINED_TEXTURE_IMAGE_UNITS]: get(GLEnum2.MAX_COMBINED_TEXTURE_IMAGE_UNITS),
11088
- // GLint
11089
10828
  [GLEnum2.MAX_VERTEX_TEXTURE_IMAGE_UNITS]: get(GLEnum2.MAX_VERTEX_TEXTURE_IMAGE_UNITS),
11090
- // GLint
11091
10829
  [GLEnum2.MAX_RENDERBUFFER_SIZE]: get(GLEnum2.MAX_RENDERBUFFER_SIZE),
11092
- // GLint
11093
10830
  [GLEnum2.MAX_VARYING_VECTORS]: get(GLEnum2.MAX_VARYING_VECTORS),
11094
- // GLint
11095
10831
  [GLEnum2.MAX_VERTEX_ATTRIBS]: get(GLEnum2.MAX_VERTEX_ATTRIBS),
11096
- // GLint
11097
10832
  [GLEnum2.MAX_VERTEX_UNIFORM_VECTORS]: get(GLEnum2.MAX_VERTEX_UNIFORM_VECTORS),
11098
- // GLint
11099
10833
  [GLEnum2.MAX_FRAGMENT_UNIFORM_VECTORS]: get(GLEnum2.MAX_FRAGMENT_UNIFORM_VECTORS),
11100
- // GLint
11101
10834
  [GLEnum2.MAX_VIEWPORT_DIMS]: get(GLEnum2.MAX_VIEWPORT_DIMS),
11102
- // Extensions
11103
10835
  [GLEnum2.MAX_TEXTURE_MAX_ANISOTROPY_EXT]: get(GLEnum2.MAX_TEXTURE_MAX_ANISOTROPY_EXT),
11104
- // getMaxAnistropy(),
11105
- // WebGL2 Limits
11106
10836
  [GLEnum2.MAX_3D_TEXTURE_SIZE]: get2(GLEnum2.MAX_3D_TEXTURE_SIZE),
11107
- // GLint
11108
10837
  [GLEnum2.MAX_ARRAY_TEXTURE_LAYERS]: get2(GLEnum2.MAX_ARRAY_TEXTURE_LAYERS),
11109
- // GLint
11110
10838
  [GLEnum2.MAX_CLIENT_WAIT_TIMEOUT_WEBGL]: get2(GLEnum2.MAX_CLIENT_WAIT_TIMEOUT_WEBGL),
11111
- // GLint64
11112
10839
  [GLEnum2.MAX_COLOR_ATTACHMENTS]: get2(GLEnum2.MAX_COLOR_ATTACHMENTS),
11113
- // GLint
11114
10840
  [GLEnum2.MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS]: get2(GLEnum2.MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS),
11115
- // GLint64
11116
10841
  [GLEnum2.MAX_COMBINED_UNIFORM_BLOCKS]: get2(GLEnum2.MAX_COMBINED_UNIFORM_BLOCKS),
11117
- // GLint
11118
10842
  [GLEnum2.MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS]: get2(GLEnum2.MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS),
11119
- // GLint64
11120
10843
  [GLEnum2.MAX_DRAW_BUFFERS]: get2(GLEnum2.MAX_DRAW_BUFFERS),
11121
- // GLint
11122
10844
  [GLEnum2.MAX_ELEMENT_INDEX]: get2(GLEnum2.MAX_ELEMENT_INDEX),
11123
- // GLint64
11124
10845
  [GLEnum2.MAX_ELEMENTS_INDICES]: get2(GLEnum2.MAX_ELEMENTS_INDICES),
11125
- // GLint
11126
10846
  [GLEnum2.MAX_ELEMENTS_VERTICES]: get2(GLEnum2.MAX_ELEMENTS_VERTICES),
11127
- // GLint
11128
10847
  [GLEnum2.MAX_FRAGMENT_INPUT_COMPONENTS]: get2(GLEnum2.MAX_FRAGMENT_INPUT_COMPONENTS),
11129
- // GLint
11130
10848
  [GLEnum2.MAX_FRAGMENT_UNIFORM_BLOCKS]: get2(GLEnum2.MAX_FRAGMENT_UNIFORM_BLOCKS),
11131
- // GLint
11132
10849
  [GLEnum2.MAX_FRAGMENT_UNIFORM_COMPONENTS]: get2(GLEnum2.MAX_FRAGMENT_UNIFORM_COMPONENTS),
11133
- // GLint
11134
10850
  [GLEnum2.MAX_SAMPLES]: get2(GLEnum2.MAX_SAMPLES),
11135
- // GLint
11136
10851
  [GLEnum2.MAX_SERVER_WAIT_TIMEOUT]: get2(GLEnum2.MAX_SERVER_WAIT_TIMEOUT),
11137
- // GLint64
11138
10852
  [GLEnum2.MAX_TEXTURE_LOD_BIAS]: get2(GLEnum2.MAX_TEXTURE_LOD_BIAS),
11139
- // GLfloat
11140
10853
  [GLEnum2.MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS]: get2(GLEnum2.MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS),
11141
- // GLint
11142
10854
  [GLEnum2.MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS]: get2(GLEnum2.MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS),
11143
- // GLint
11144
10855
  [GLEnum2.MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS]: get2(GLEnum2.MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS),
11145
- // GLint
11146
10856
  [GLEnum2.MAX_UNIFORM_BLOCK_SIZE]: get2(GLEnum2.MAX_UNIFORM_BLOCK_SIZE),
11147
- // GLint64
11148
10857
  [GLEnum2.MAX_UNIFORM_BUFFER_BINDINGS]: get2(GLEnum2.MAX_UNIFORM_BUFFER_BINDINGS),
11149
- // GLint
11150
10858
  [GLEnum2.MAX_VARYING_COMPONENTS]: get2(GLEnum2.MAX_VARYING_COMPONENTS),
11151
- // GLint
11152
10859
  [GLEnum2.MAX_VERTEX_OUTPUT_COMPONENTS]: get2(GLEnum2.MAX_VERTEX_OUTPUT_COMPONENTS),
11153
- // GLint
11154
10860
  [GLEnum2.MAX_VERTEX_UNIFORM_BLOCKS]: get2(GLEnum2.MAX_VERTEX_UNIFORM_BLOCKS),
11155
- // GLint
11156
10861
  [GLEnum2.MAX_VERTEX_UNIFORM_COMPONENTS]: get2(GLEnum2.MAX_VERTEX_UNIFORM_COMPONENTS),
11157
- // GLint
11158
10862
  [GLEnum2.MIN_PROGRAM_TEXEL_OFFSET]: get2(GLEnum2.MIN_PROGRAM_TEXEL_OFFSET),
11159
- // GLint
11160
10863
  [GLEnum2.MAX_PROGRAM_TEXEL_OFFSET]: get2(GLEnum2.MAX_PROGRAM_TEXEL_OFFSET),
11161
- // GLint
11162
10864
  [GLEnum2.UNIFORM_BUFFER_OFFSET_ALIGNMENT]: get2(GLEnum2.UNIFORM_BUFFER_OFFSET_ALIGNMENT)
11163
- // GLint
11164
10865
  };
11165
10866
  }
11166
10867
 
@@ -11268,6 +10969,17 @@ void main(void) {}`;
11268
10969
  gl.stencilOpSeparate(GLEnum2.FRONT, sfail, dpfail, dppass);
11269
10970
  gl.stencilOpSeparate(GLEnum2.BACK, sfail, dpfail, dppass);
11270
10971
  }
10972
+ if (parameters.blendColorOperation || parameters.blendAlphaOperation) {
10973
+ gl.enable(GLEnum2.BLEND);
10974
+ const colorEquation = convertBlendOperationToEquation("blendColorOperation", parameters.blendColorOperation || "add");
10975
+ const alphaEquation = convertBlendOperationToEquation("blendAlphaOperation", parameters.blendAlphaOperation || "add");
10976
+ gl.blendEquationSeparate(colorEquation, alphaEquation);
10977
+ const colorSrcFactor = convertBlendFactorToFunction("blendColorSrcFactor", parameters.blendColorSrcFactor || "one");
10978
+ const colorDstFactor = convertBlendFactorToFunction("blendColorDstFactor", parameters.blendColorDstFactor || "zero");
10979
+ const alphaSrcFactor = convertBlendFactorToFunction("blendAlphaSrcFactor", parameters.blendAlphaSrcFactor || "one");
10980
+ const alphaDstFactor = convertBlendFactorToFunction("blendAlphaDstFactor", parameters.blendAlphaDstFactor || "zero");
10981
+ gl.blendFuncSeparate(colorSrcFactor, colorDstFactor, alphaSrcFactor, alphaDstFactor);
10982
+ }
11271
10983
  }
11272
10984
  function convertCompareFunction(parameter, value) {
11273
10985
  return map(parameter, value, {
@@ -11293,6 +11005,29 @@ void main(void) {}`;
11293
11005
  "decrement-wrap": GLEnum2.DECR_WRAP
11294
11006
  });
11295
11007
  }
11008
+ function convertBlendOperationToEquation(parameter, value) {
11009
+ return map(parameter, value, {
11010
+ "add": GLEnum2.FUNC_ADD,
11011
+ "subtract": GLEnum2.FUNC_SUBTRACT,
11012
+ "reverse-subtract": GLEnum2.FUNC_REVERSE_SUBTRACT,
11013
+ "min": GLEnum2.MIN,
11014
+ "max": GLEnum2.MAX
11015
+ });
11016
+ }
11017
+ function convertBlendFactorToFunction(parameter, value) {
11018
+ return map(parameter, value, {
11019
+ "one": GLEnum2.ONE,
11020
+ "zero": GLEnum2.ZERO,
11021
+ "src-color": GLEnum2.SRC_COLOR,
11022
+ "one-minus-src-color": GLEnum2.ONE_MINUS_SRC_COLOR,
11023
+ "dst-color": GLEnum2.DST_COLOR,
11024
+ "one-minus-dst-color": GLEnum2.ONE_MINUS_DST_COLOR,
11025
+ "src-alpha": GLEnum2.SRC_ALPHA,
11026
+ "one-minus-src-alpha": GLEnum2.ONE_MINUS_SRC_ALPHA,
11027
+ "dst-alpha": GLEnum2.DST_ALPHA,
11028
+ "one-minus-dst-alpha": GLEnum2.ONE_MINUS_DST_ALPHA
11029
+ });
11030
+ }
11296
11031
  function message(parameter, value) {
11297
11032
  return `Illegal parameter ${value} for ${parameter}`;
11298
11033
  }
@@ -11385,13 +11120,7 @@ void main(void) {}`;
11385
11120
  // ../webgl/src/adapter/resources/webgl-buffer.ts
11386
11121
  var DEBUG_DATA_LENGTH = 10;
11387
11122
  var WEBGLBuffer = class extends Buffer2 {
11388
- /** Target in OpenGL defines the type of buffer */
11389
- /** Usage is a hint on how frequently the buffer will be updates */
11390
- /** Index type is needed when issuing draw calls, so we pre-compute it */
11391
11123
  glIndexType = GLEnum2.UNSIGNED_SHORT;
11392
- /** Number of bytes allocated on the GPU for this buffer */
11393
- /** Number of bytes used */
11394
- /** A partial CPU-side copy of the data in this buffer, for debugging purposes */
11395
11124
  debugData = null;
11396
11125
  constructor(device, props = {}) {
11397
11126
  super(device, props);
@@ -11414,8 +11143,6 @@ void main(void) {}`;
11414
11143
  this._initWithByteLength(props.byteLength || 0);
11415
11144
  }
11416
11145
  }
11417
- // PRIVATE METHODS
11418
- /** Allocate a new buffer and initialize to contents of typed array */
11419
11146
  _initWithData(data, byteOffset = 0, byteLength = data.byteLength + byteOffset) {
11420
11147
  assert2(ArrayBuffer.isView(data));
11421
11148
  const glTarget = this._getWriteTarget();
@@ -11429,7 +11156,6 @@ void main(void) {}`;
11429
11156
  this.trackAllocatedMemory(byteLength);
11430
11157
  return this;
11431
11158
  }
11432
- // Allocate a GPU buffer of specified size.
11433
11159
  _initWithByteLength(byteLength) {
11434
11160
  assert2(byteLength >= 0);
11435
11161
  let data = byteLength;
@@ -11467,7 +11193,6 @@ void main(void) {}`;
11467
11193
  }
11468
11194
  this.gl.bindBuffer(glTarget, null);
11469
11195
  }
11470
- /** Read data from the buffer */
11471
11196
  async readAsync(byteOffset = 0, byteLength) {
11472
11197
  this.device.assertWebGL2();
11473
11198
  byteLength = byteLength ?? this.byteLength;
@@ -11478,7 +11203,6 @@ void main(void) {}`;
11478
11203
  this.gl.bindBuffer(GLEnum2.COPY_READ_BUFFER, null);
11479
11204
  return data;
11480
11205
  }
11481
- // PROTECTED METHODS (INTENDED FOR USE BY OTHER FRAMEWORK CODE ONLY)
11482
11206
  _invalidateDebugData() {
11483
11207
  this.debugData = null;
11484
11208
  }
@@ -11534,7 +11258,6 @@ void main(void) {}`;
11534
11258
  toString() {
11535
11259
  return `Sampler(${this.id},${JSON.stringify(this.props)})`;
11536
11260
  }
11537
- /** Set sampler parameters on the sampler */
11538
11261
  _setSamplerParameters(parameters) {
11539
11262
  for (const [pname, value] of Object.entries(parameters)) {
11540
11263
  const param = Number(pname);
@@ -11553,7 +11276,6 @@ void main(void) {}`;
11553
11276
 
11554
11277
  // ../webgl/src/adapter/resources/webgl-texture.ts
11555
11278
  var DEFAULT_WEBGL_TEXTURE_PROPS = {
11556
- // deprecated
11557
11279
  parameters: {},
11558
11280
  pixelStore: {},
11559
11281
  pixels: null,
@@ -11563,28 +11285,12 @@ void main(void) {}`;
11563
11285
  target: void 0
11564
11286
  };
11565
11287
  var _WEBGLTexture = class extends Texture {
11566
- /** Sampler object (currently unused) */
11567
11288
  sampler = void 0;
11568
- // data;
11569
11289
  glFormat = void 0;
11570
11290
  type = void 0;
11571
11291
  dataFormat = void 0;
11572
11292
  mipmaps = void 0;
11573
- /**
11574
- * @note `target` cannot be modified by bind:
11575
- * textures are special because when you first bind them to a target,
11576
- * they get special information. When you first bind a texture as a
11577
- * GL_TEXTURE_2D, you are saying that this texture is a 2D texture.
11578
- * And it will always be a 2D texture; this state cannot be changed ever.
11579
- * A texture that was first bound as a GL_TEXTURE_2D, must always be bound as a GL_TEXTURE_2D;
11580
- * attempting to bind it as GL_TEXTURE_3D will give rise to a run-time error
11581
- * */
11582
11293
  textureUnit = void 0;
11583
- /**
11584
- * Program.draw() checks the loaded flag of all textures to avoid
11585
- * Textures that are still loading from promises
11586
- * Set to true as soon as texture has been initialized with valid data
11587
- */
11588
11294
  loaded = false;
11589
11295
  constructor(device, props) {
11590
11296
  super(device, {
@@ -11622,7 +11328,6 @@ void main(void) {}`;
11622
11328
  toString() {
11623
11329
  return `Texture(${this.id},${this.width}x${this.height})`;
11624
11330
  }
11625
- // eslint-disable-next-line max-statements
11626
11331
  initialize(props = {}) {
11627
11332
  if (this.props.dimension === "cube") {
11628
11333
  return this.initializeCube(props);
@@ -11702,7 +11407,6 @@ void main(void) {}`;
11702
11407
  format: glFormat,
11703
11408
  type,
11704
11409
  dataFormat,
11705
- // @ts-expect-error
11706
11410
  parameters: pixelStore,
11707
11411
  compressed
11708
11412
  });
@@ -11715,7 +11419,6 @@ void main(void) {}`;
11715
11419
  this._video = {
11716
11420
  video: data,
11717
11421
  parameters,
11718
- // @ts-expect-error
11719
11422
  lastTime: data.readyState >= HTMLVideoElement.HAVE_CURRENT_DATA ? data.currentTime : -1
11720
11423
  };
11721
11424
  }
@@ -11749,10 +11452,6 @@ void main(void) {}`;
11749
11452
  this._setSamplerParameters(parameters);
11750
11453
  return this;
11751
11454
  }
11752
- /**
11753
- * If size has changed, reinitializes with current format
11754
- * @note note clears image and mipmaps
11755
- */
11756
11455
  resize(options) {
11757
11456
  const {
11758
11457
  height,
@@ -11771,7 +11470,6 @@ void main(void) {}`;
11771
11470
  }
11772
11471
  return this;
11773
11472
  }
11774
- /** Update external texture (video frame) */
11775
11473
  update() {
11776
11474
  if (this._video) {
11777
11475
  const {
@@ -11792,7 +11490,6 @@ void main(void) {}`;
11792
11490
  this._video.lastTime = video.currentTime;
11793
11491
  }
11794
11492
  }
11795
- // Call to regenerate mipmaps after modifying texture(s)
11796
11493
  generateMipmap(params = {}) {
11797
11494
  if (this.device.isWebGL1 && isNPOT(this.width, this.height)) {
11798
11495
  log.warn(`texture: ${this} is Non-Power-Of-Two, disabling mipmaping`)();
@@ -11806,27 +11503,6 @@ void main(void) {}`;
11806
11503
  this.gl.bindTexture(this.target, null);
11807
11504
  return this;
11808
11505
  }
11809
- /*
11810
- * Allocates storage
11811
- * @param {*} pixels -
11812
- * null - create empty texture of specified format
11813
- * Typed array - init from image data in typed array
11814
- * Buffer|WebGLBuffer - (WEBGL2) init from image data in WebGLBuffer
11815
- * HTMLImageElement|Image - Inits with content of image. Auto width/height
11816
- * HTMLCanvasElement - Inits with contents of canvas. Auto width/height
11817
- * HTMLVideoElement - Creates video texture. Auto width/height
11818
- *
11819
- * @param width -
11820
- * @param height -
11821
- * @param mipMapLevel -
11822
- * @param {GLenum} format - format of image data.
11823
- * @param {GLenum} type
11824
- * - format of array (autodetect from type) or
11825
- * - (WEBGL2) format of buffer
11826
- * @param {Number} offset - (WEBGL2) offset from start of buffer
11827
- * @parameters - temporary settings to be applied, can be used to supply pixel store settings.
11828
- */
11829
- // eslint-disable-next-line max-statements, complexity
11830
11506
  setImageData(options) {
11831
11507
  if (this.props.dimension === "3d" || this.props.dimension === "2d-array") {
11832
11508
  return this.setImageData3D(options);
@@ -11885,20 +11561,7 @@ void main(void) {}`;
11885
11561
  gl.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
11886
11562
  break;
11887
11563
  case "typed-array":
11888
- gl.texImage2D(
11889
- target,
11890
- level,
11891
- glFormat,
11892
- width,
11893
- height,
11894
- 0,
11895
- // border (must be 0)
11896
- dataFormat,
11897
- type,
11898
- data,
11899
- // @ts-expect-error
11900
- offset
11901
- );
11564
+ gl.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data, offset);
11902
11565
  break;
11903
11566
  case "buffer":
11904
11567
  gl2 = this.device.assertWebGL2();
@@ -11931,11 +11594,6 @@ void main(void) {}`;
11931
11594
  this.loaded = true;
11932
11595
  return this;
11933
11596
  }
11934
- /**
11935
- * Redefines an area of an existing texture
11936
- * Note: does not allocate storage
11937
- * Redefines an area of an existing texture
11938
- */
11939
11597
  setSubImageData({
11940
11598
  target = this.target,
11941
11599
  pixels = null,
@@ -12002,14 +11660,6 @@ void main(void) {}`;
12002
11660
  });
12003
11661
  this.gl.bindTexture(this.target, null);
12004
11662
  }
12005
- /**
12006
- * Defines a two-dimensional texture image or cube-map texture image with
12007
- * pixels from the current framebuffer (rather than from client memory).
12008
- * (gl.copyTexImage2D wrapper)
12009
- *
12010
- * Note that binding a texture into a Framebuffer's color buffer and
12011
- * rendering can be faster.
12012
- */
12013
11663
  copyFramebuffer(opts = {}) {
12014
11664
  log.error("Texture.copyFramebuffer({...}) is no logner supported, use copyToTexture(source, target, opts})")();
12015
11665
  return null;
@@ -12039,7 +11689,6 @@ void main(void) {}`;
12039
11689
  gl.bindTexture(this.target, null);
12040
11690
  return textureUnit;
12041
11691
  }
12042
- // PRIVATE METHODS
12043
11692
  _getDataType({
12044
11693
  data,
12045
11694
  compressed = false
@@ -12079,7 +11728,6 @@ void main(void) {}`;
12079
11728
  dataType: "browser-object"
12080
11729
  };
12081
11730
  }
12082
- // HELPER METHODS
12083
11731
  _deduceParameters(opts) {
12084
11732
  const {
12085
11733
  format,
@@ -12110,7 +11758,6 @@ void main(void) {}`;
12110
11758
  data
12111
11759
  };
12112
11760
  }
12113
- // eslint-disable-next-line complexity
12114
11761
  _deduceImageSize(data, width, height) {
12115
11762
  let size;
12116
11763
  if (typeof ImageData !== "undefined" && data instanceof ImageData) {
@@ -12154,8 +11801,6 @@ void main(void) {}`;
12154
11801
  assert2(height === void 0 || size.height === height, "Deduced texture height does not match supplied height");
12155
11802
  return size;
12156
11803
  }
12157
- // CUBE MAP METHODS
12158
- /* eslint-disable max-statements, max-len */
12159
11804
  async setCubeMapImageData(options) {
12160
11805
  const {
12161
11806
  gl
@@ -12174,11 +11819,11 @@ void main(void) {}`;
12174
11819
  return Promise.all(Array.isArray(facePixels) ? facePixels : [facePixels]);
12175
11820
  }));
12176
11821
  this.bind();
12177
- _WEBGLTexture.FACES.forEach((face, index) => {
12178
- if (resolvedFaces[index].length > 1 && this.props.mipmaps !== false) {
11822
+ _WEBGLTexture.FACES.forEach((face, index2) => {
11823
+ if (resolvedFaces[index2].length > 1 && this.props.mipmaps !== false) {
12179
11824
  log.warn(`${this.id} has mipmap and multiple LODs.`)();
12180
11825
  }
12181
- resolvedFaces[index].forEach((image, lodLevel) => {
11826
+ resolvedFaces[index2].forEach((image, lodLevel) => {
12182
11827
  if (width && height) {
12183
11828
  gl.texImage2D(face, lodLevel, format, width, height, 0, format, type, image);
12184
11829
  } else {
@@ -12188,7 +11833,6 @@ void main(void) {}`;
12188
11833
  });
12189
11834
  this.unbind();
12190
11835
  }
12191
- /** @todo update this method to accept LODs */
12192
11836
  setImageDataForFace(options) {
12193
11837
  const {
12194
11838
  face,
@@ -12198,7 +11842,6 @@ void main(void) {}`;
12198
11842
  data,
12199
11843
  format = GLEnum2.RGBA,
12200
11844
  type = GLEnum2.UNSIGNED_BYTE
12201
- // generateMipmap = false // TODO
12202
11845
  } = options;
12203
11846
  const {
12204
11847
  gl
@@ -12218,14 +11861,12 @@ void main(void) {}`;
12218
11861
  }
12219
11862
  return this;
12220
11863
  }
12221
- /** Image 3D copies from Typed Array or WebGLBuffer */
12222
11864
  setImageData3D(options) {
12223
11865
  const {
12224
11866
  level = 0,
12225
11867
  dataFormat,
12226
11868
  format,
12227
11869
  type,
12228
- // = GL.UNSIGNED_BYTE,
12229
11870
  width,
12230
11871
  height,
12231
11872
  depth = 1,
@@ -12238,19 +11879,7 @@ void main(void) {}`;
12238
11879
  const webglTextureFormat = getWebGLTextureParameters(format, this.device.isWebGL2);
12239
11880
  withGLParameters(this.gl, parameters, () => {
12240
11881
  if (ArrayBuffer.isView(data)) {
12241
- this.gl.texImage3D(
12242
- this.target,
12243
- level,
12244
- webglTextureFormat.format,
12245
- width,
12246
- height,
12247
- depth,
12248
- 0,
12249
- webglTextureFormat.dataFormat,
12250
- webglTextureFormat.type,
12251
- // dataType: getWebGL,
12252
- data
12253
- );
11882
+ this.gl.texImage3D(this.target, level, webglTextureFormat.format, width, height, depth, 0, webglTextureFormat.dataFormat, webglTextureFormat.type, data);
12254
11883
  }
12255
11884
  if (data instanceof WEBGLBuffer) {
12256
11885
  this.gl.bindBuffer(GLEnum2.PIXEL_UNPACK_BUFFER, data.handle);
@@ -12266,11 +11895,6 @@ void main(void) {}`;
12266
11895
  this.loaded = true;
12267
11896
  return this;
12268
11897
  }
12269
- // RESOURCE METHODS
12270
- /**
12271
- * Sets sampler parameters on texture
12272
- * @note: Applies NPOT workaround if appropriate
12273
- */
12274
11898
  _setSamplerParameters(parameters) {
12275
11899
  if (this.device.isWebGL1 && isNPOT(this.width, this.height)) {
12276
11900
  parameters = updateSamplerParametersForNPOT(parameters);
@@ -12296,7 +11920,6 @@ void main(void) {}`;
12296
11920
  this.gl.bindTexture(this.target, null);
12297
11921
  return;
12298
11922
  }
12299
- /** @deprecated For LegacyTexture subclass */
12300
11923
  _getWebGL1NPOTParameterOverride(pname, value) {
12301
11924
  const npot = this.device.isWebGL1 && isNPOT(this.width, this.height);
12302
11925
  if (npot) {
@@ -12317,7 +11940,6 @@ void main(void) {}`;
12317
11940
  }
12318
11941
  };
12319
11942
  var WEBGLTexture = _WEBGLTexture;
12320
- // TODO - remove?
12321
11943
  __publicField(WEBGLTexture, "FACES", [GLEnum2.TEXTURE_CUBE_MAP_POSITIVE_X, GLEnum2.TEXTURE_CUBE_MAP_NEGATIVE_X, GLEnum2.TEXTURE_CUBE_MAP_POSITIVE_Y, GLEnum2.TEXTURE_CUBE_MAP_NEGATIVE_Y, GLEnum2.TEXTURE_CUBE_MAP_POSITIVE_Z, GLEnum2.TEXTURE_CUBE_MAP_NEGATIVE_Z]);
12322
11944
  function getWebGLTextureTarget(props) {
12323
11945
  switch (props.dimension) {
@@ -12364,7 +11986,6 @@ void main(void) {}`;
12364
11986
  var ERR_RESOURCE_METHOD_UNDEFINED = "Resource subclass must define virtual methods";
12365
11987
  var WebGLResource = class extends Resource {
12366
11988
  _bound = false;
12367
- // Only meaningful for resources that allocate GPU memory
12368
11989
  byteLength = 0;
12369
11990
  constructor(device, props, defaultProps) {
12370
11991
  super(device, props, defaultProps);
@@ -12422,12 +12043,6 @@ void main(void) {}`;
12422
12043
  unbind() {
12423
12044
  this.bind(null);
12424
12045
  }
12425
- /**
12426
- * Query a Resource parameter
12427
- *
12428
- * @param name
12429
- * @return param
12430
- */
12431
12046
  getParameter(pname, props = {}) {
12432
12047
  pname = getKeyValue(this.gl, pname);
12433
12048
  assert2(pname);
@@ -12445,9 +12060,6 @@ void main(void) {}`;
12445
12060
  }
12446
12061
  return this._getParameter(pname, props);
12447
12062
  }
12448
- // Many resources support a getParameter call -
12449
- // getParameters will get all parameters - slow but useful for debugging
12450
- // eslint-disable-next-line complexity
12451
12063
  getParameters(options = {}) {
12452
12064
  const {
12453
12065
  parameters,
@@ -12470,15 +12082,6 @@ void main(void) {}`;
12470
12082
  }
12471
12083
  return values;
12472
12084
  }
12473
- /**
12474
- * Update a Resource setting
12475
- *
12476
- * @todo - cache parameter to avoid issuing WebGL calls?
12477
- *
12478
- * @param pname - parameter (GL constant, value or key)
12479
- * @param value {GLint|GLfloat|GLenum}
12480
- * @return returns self to enable chaining
12481
- */
12482
12085
  setParameter(pname, value) {
12483
12086
  pname = getKeyValue(this.gl, pname);
12484
12087
  assert2(pname);
@@ -12497,24 +12100,17 @@ void main(void) {}`;
12497
12100
  this._setParameter(pname, value);
12498
12101
  return this;
12499
12102
  }
12500
- /*
12501
- * Batch update resource parameters
12502
- * Assumes the subclass supports a setParameter call
12503
- */
12504
12103
  setParameters(parameters) {
12505
12104
  for (const pname in parameters) {
12506
12105
  this.setParameter(pname, parameters[pname]);
12507
12106
  }
12508
12107
  return this;
12509
12108
  }
12510
- // Install stubs for removed methods
12511
12109
  stubRemovedMethods(className, version, methodNames) {
12512
12110
  return stubRemovedMethods(this, className, version, methodNames);
12513
12111
  }
12514
- // PUBLIC VIRTUAL METHODS
12515
12112
  initialize(props) {
12516
12113
  }
12517
- // PROTECTED METHODS - These must be overridden by subclass
12518
12114
  _createHandle() {
12519
12115
  throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
12520
12116
  }
@@ -12533,33 +12129,6 @@ void main(void) {}`;
12533
12129
  _setParameter(pname, value) {
12534
12130
  throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
12535
12131
  }
12536
- // PRIVATE METHODS
12537
- /*
12538
- _addStats() {
12539
- const name = this.constructor.name;
12540
- const stats = lumaStats.get('Resource Counts');
12541
- stats.get('Resources Created').incrementCount();
12542
- stats.get(`${name}s Created`).incrementCount();
12543
- stats.get(`${name}s Active`).incrementCount();
12544
- }
12545
- _removeStats() {
12546
- const name = this.constructor.name;
12547
- const stats = lumaStats.get('Resource Counts');
12548
- stats.get(`${name}s Active`).decrementCount();
12549
- }
12550
- trackAllocatedMemory(bytes, name = this.constructor.name) {
12551
- const stats = lumaStats.get('Memory Usage');
12552
- stats.get('GPU Memory').addCount(bytes);
12553
- stats.get(`${name} Memory`).addCount(bytes);
12554
- this.byteLength = bytes;
12555
- }
12556
- trackDeallocatedMemory(name = this.constructor.name) {
12557
- const stats = lumaStats.get('Memory Usage');
12558
- stats.get('GPU Memory').subtractCount(this.byteLength);
12559
- stats.get(`${name} Memory`).subtractCount(this.byteLength);
12560
- this.byteLength = 0;
12561
- }
12562
- */
12563
12132
  };
12564
12133
 
12565
12134
  // ../webgl/src/adapter/objects/webgl-renderbuffer.ts
@@ -12582,7 +12151,6 @@ void main(void) {}`;
12582
12151
  get attachment() {
12583
12152
  return;
12584
12153
  }
12585
- /** WebGL format constant */
12586
12154
  static isTextureFormatSupported(device, format) {
12587
12155
  return isRenderbufferFormatSupported(device.gl, format);
12588
12156
  }
@@ -12604,8 +12172,6 @@ void main(void) {}`;
12604
12172
  this._initialize(this.props);
12605
12173
  }
12606
12174
  }
12607
- // PRIVATE METHODS
12608
- /** Creates and initializes a renderbuffer object's data store */
12609
12175
  _initialize(props) {
12610
12176
  const {
12611
12177
  format,
@@ -12624,7 +12190,6 @@ void main(void) {}`;
12624
12190
  this.gl.bindRenderbuffer(GLEnum2.RENDERBUFFER, null);
12625
12191
  this.trackAllocatedMemory(width * height * (samples || 1) * getTextureFormatBytesPerPixel(this.glFormat, this.device.isWebGL2));
12626
12192
  }
12627
- // RESOURCE IMPLEMENTATION
12628
12193
  _createHandle() {
12629
12194
  return this.gl.createRenderbuffer();
12630
12195
  }
@@ -12642,7 +12207,6 @@ void main(void) {}`;
12642
12207
  handle: void 0,
12643
12208
  userData: void 0,
12644
12209
  format: void 0,
12645
- // 'depth16unorm'
12646
12210
  width: 1,
12647
12211
  height: 1,
12648
12212
  samples: 0
@@ -12682,15 +12246,12 @@ void main(void) {}`;
12682
12246
  this._checkStatus();
12683
12247
  }
12684
12248
  }
12685
- /** destroys any auto created resources etc. */
12686
12249
  destroy() {
12687
12250
  super.destroy();
12688
12251
  if (!this.destroyed && this.handle !== null) {
12689
12252
  this.gl.deleteFramebuffer(this.handle);
12690
12253
  }
12691
12254
  }
12692
- // PRIVATE
12693
- /** Check the status */
12694
12255
  _checkStatus() {
12695
12256
  const {
12696
12257
  gl
@@ -12702,21 +12263,14 @@ void main(void) {}`;
12702
12263
  throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);
12703
12264
  }
12704
12265
  }
12705
- /** In WebGL we must use renderbuffers for depth/stencil attachments (unless we have extensions) */
12706
12266
  createDepthStencilTexture(format) {
12707
12267
  return new WEBGLRenderbuffer(this.device, {
12708
12268
  id: `${this.id}-depth-stencil`,
12709
- // TODO misleading if not depth and stencil?
12710
12269
  format,
12711
- // dataFormat: GL.DEPTH_STENCIL,
12712
- // type: GL.UNSIGNED_INT_24_8,
12713
12270
  width: this.width,
12714
12271
  height: this.height
12715
12272
  });
12716
12273
  }
12717
- /**
12718
- * Attachment resize is expected to be a noop if size is same
12719
- */
12720
12274
  resizeAttachments(width, height) {
12721
12275
  if (this.handle === null) {
12722
12276
  this.width = this.gl.drawingBufferWidth;
@@ -12743,7 +12297,6 @@ void main(void) {}`;
12743
12297
  }
12744
12298
  return this;
12745
12299
  }
12746
- /** Attach one attachment */
12747
12300
  _attachOne(attachmentPoint, attachment) {
12748
12301
  if (attachment instanceof WEBGLRenderbuffer) {
12749
12302
  this._attachWEBGLRenderbuffer(attachmentPoint, attachment);
@@ -12761,12 +12314,6 @@ void main(void) {}`;
12761
12314
  _attachWEBGLRenderbuffer(attachment, renderbuffer) {
12762
12315
  this.gl.framebufferRenderbuffer(GLEnum2.FRAMEBUFFER, attachment, GLEnum2.RENDERBUFFER, renderbuffer.handle);
12763
12316
  }
12764
- /**
12765
- * @param attachment
12766
- * @param texture
12767
- * @param layer = 0 - index into WEBGLTextureArray and Texture3D or face for `TextureCubeMap`
12768
- * @param level = 0 - mipmapLevel (must be 0 in WebGL1)
12769
- */
12770
12317
  _attachTexture(attachment, texture, layer, level) {
12771
12318
  const {
12772
12319
  gl,
@@ -12831,7 +12378,6 @@ void main(void) {}`;
12831
12378
  });
12832
12379
  return this._framebuffer;
12833
12380
  }
12834
- /** Resizes and updates render targets if necessary */
12835
12381
  update() {
12836
12382
  const size = this.getPixelSize();
12837
12383
  const sizeChanged = size[0] !== this.presentationSize[0] || size[1] !== this.presentationSize[1];
@@ -12839,18 +12385,6 @@ void main(void) {}`;
12839
12385
  this.presentationSize = size;
12840
12386
  }
12841
12387
  }
12842
- /**
12843
- * Resize the canvas' drawing buffer.
12844
- *
12845
- * Can match the canvas CSS size, and optionally also consider devicePixelRatio
12846
- * Can be called every frame
12847
- *
12848
- * Regardless of size, the drawing buffer will always be scaled to the viewport, but
12849
- * for best visual results, usually set to either:
12850
- * canvas CSS width x canvas CSS height
12851
- * canvas CSS width * devicePixelRatio x canvas CSS height * devicePixelRatio
12852
- * See http://webgl2fundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html
12853
- */
12854
12388
  resize(options) {
12855
12389
  if (this.canvas) {
12856
12390
  const devicePixelRatio = this.getDevicePixelRatio(options?.useDevicePixels);
@@ -13022,19 +12556,19 @@ void main(void) {}`;
13022
12556
  }
13023
12557
 
13024
12558
  // ../webgl/src/adapter/helpers/get-shader-info.ts
13025
- function getShaderInfo(source, defaultName) {
12559
+ function getShaderInfo2(source, defaultName) {
13026
12560
  return {
13027
- name: getShaderName(source, defaultName),
12561
+ name: getShaderName2(source, defaultName),
13028
12562
  language: "glsl",
13029
- version: getShaderVersion(source)
12563
+ version: getShaderVersion2(source)
13030
12564
  };
13031
12565
  }
13032
- function getShaderName(shader, defaultName = "unnamed") {
12566
+ function getShaderName2(shader, defaultName = "unnamed") {
13033
12567
  const SHADER_NAME_REGEXP = /#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/;
13034
12568
  const match = SHADER_NAME_REGEXP.exec(shader);
13035
12569
  return match ? match[1] : defaultName;
13036
12570
  }
13037
- function getShaderVersion(source) {
12571
+ function getShaderVersion2(source) {
13038
12572
  let version = 100;
13039
12573
  const words = source.match(/[^\s]+/g);
13040
12574
  if (words && words.length >= 2 && words[0] === "#version") {
@@ -13047,7 +12581,6 @@ void main(void) {}`;
13047
12581
  }
13048
12582
 
13049
12583
  // ../webgl/src/adapter/helpers/parse-shader-compiler-log.ts
13050
- var MESSAGE_TYPES = ["warning", "error", "info"];
13051
12584
  function parseShaderCompilerLog(errLog) {
13052
12585
  const lines = errLog.split(/\r?\n/);
13053
12586
  const messages = [];
@@ -13056,6 +12589,16 @@ void main(void) {}`;
13056
12589
  continue;
13057
12590
  }
13058
12591
  const segments = line.split(":");
12592
+ if (segments.length === 2) {
12593
+ const [messageType2, message2] = segments;
12594
+ messages.push({
12595
+ message: message2.trim(),
12596
+ type: getMessageType(messageType2),
12597
+ lineNum: 0,
12598
+ linePos: 0
12599
+ });
12600
+ continue;
12601
+ }
13059
12602
  const [messageType, linePosition, lineNumber, ...rest] = segments;
13060
12603
  let lineNum = parseInt(lineNumber, 10);
13061
12604
  if (isNaN(lineNum)) {
@@ -13065,18 +12608,20 @@ void main(void) {}`;
13065
12608
  if (isNaN(linePos)) {
13066
12609
  linePos = 0;
13067
12610
  }
13068
- const lowerCaseType = messageType.toLowerCase();
13069
- const type = MESSAGE_TYPES.includes(lowerCaseType) ? lowerCaseType : "info";
13070
12611
  messages.push({
13071
12612
  message: rest.join(":").trim(),
13072
- type,
12613
+ type: getMessageType(messageType),
13073
12614
  lineNum,
13074
12615
  linePos
13075
- // TODO
13076
12616
  });
13077
12617
  }
13078
12618
  return messages;
13079
12619
  }
12620
+ function getMessageType(messageType) {
12621
+ const MESSAGE_TYPES = ["warning", "error", "info"];
12622
+ const lowerCaseType = messageType.toLowerCase();
12623
+ return MESSAGE_TYPES.includes(lowerCaseType) ? lowerCaseType : "info";
12624
+ }
13080
12625
 
13081
12626
  // ../webgl/src/adapter/resources/webgl-shader.ts
13082
12627
  var WEBGLShader = class extends Shader {
@@ -13109,7 +12654,6 @@ void main(void) {}`;
13109
12654
  const log3 = this.device.gl.getShaderInfoLog(this.handle);
13110
12655
  return log3 ? parseShaderCompilerLog(log3) : [];
13111
12656
  }
13112
- // PRIVATE METHODS
13113
12657
  _compile(source) {
13114
12658
  const addGLSLVersion = (source2) => source2.startsWith("#version ") ? source2 : `#version 100
13115
12659
  ${source2}`;
@@ -13127,7 +12671,7 @@ ${source2}`;
13127
12671
  const formattedLog = formatCompilerLog(messages, source, {
13128
12672
  showSourceCode: true
13129
12673
  });
13130
- const shaderName = getShaderInfo(source).name;
12674
+ const shaderName = getShaderInfo2(source).name;
13131
12675
  const shaderDescription = `${this.stage} shader ${shaderName}`;
13132
12676
  log.error(`GLSL compilation errors in ${shaderDescription}
13133
12677
  ${formattedLog}`)();
@@ -13136,7 +12680,7 @@ ${formattedLog}`)();
13136
12680
  }
13137
12681
  };
13138
12682
  function getShaderIdFromProps(props) {
13139
- return getShaderInfo(props.source).name || props.id || uid(`unnamed ${props.stage}-shader`);
12683
+ return getShaderInfo2(props.source).name || props.id || uid(`unnamed ${props.stage}-shader`);
13140
12684
  }
13141
12685
 
13142
12686
  // ../webgl/src/adapter/resources/webgl-render-pass.ts
@@ -13145,7 +12689,6 @@ ${formattedLog}`)();
13145
12689
  var GL_COLOR_BUFFER_BIT = 16384;
13146
12690
  var GL_COLOR = 6144;
13147
12691
  var WEBGLRenderPass = class extends RenderPass {
13148
- /** Parameters that should be applied before each draw call */
13149
12692
  constructor(device, props) {
13150
12693
  super(device, props);
13151
12694
  this.device = device;
@@ -13167,13 +12710,6 @@ ${formattedLog}`)();
13167
12710
  }
13168
12711
  insertDebugMarker(markerLabel) {
13169
12712
  }
13170
- // writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;
13171
- // beginOcclusionQuery(queryIndex: number): void;
13172
- // endOcclusionQuery(): void;
13173
- // executeBundles(bundles: Iterable<GPURenderBundle>): void;
13174
- /**
13175
- * Maps RenderPass parameters to GL parameters
13176
- */
13177
12713
  setParameters(parameters = {}) {
13178
12714
  const glParameters = {};
13179
12715
  if (this.props.framebuffer) {
@@ -13206,10 +12742,6 @@ ${formattedLog}`)();
13206
12742
  this.glParameters = glParameters;
13207
12743
  setGLParameters(this.device, glParameters);
13208
12744
  }
13209
- // Internal
13210
- /**
13211
- * Optionally clears depth, color and stencil buffers based on parameters
13212
- */
13213
12745
  clear() {
13214
12746
  const glParameters = {
13215
12747
  ...this.glParameters
@@ -13233,9 +12765,6 @@ ${formattedLog}`)();
13233
12765
  });
13234
12766
  }
13235
12767
  }
13236
- /**
13237
- * WebGL2 - clear a specific color buffer
13238
- */
13239
12768
  clearColorBuffer(drawBuffer = 0, value = [0, 0, 0, 0]) {
13240
12769
  withGLParameters(this.device.gl2, {
13241
12770
  framebuffer: this.props.framebuffer
@@ -13254,24 +12783,6 @@ ${formattedLog}`)();
13254
12783
  }
13255
12784
  });
13256
12785
  }
13257
- // clearDepthStencil() {
13258
- // const GL_DEPTH = 0x1801;
13259
- // const GL_STENCIL = 0x1802;
13260
- // const GL_DEPTH_STENCIL = 0x84f9;
13261
- // case GL_DEPTH:
13262
- // this.device.gl2.clearBufferfv(GL_DEPTH, 0, [value]);
13263
- // break;
13264
- // case GL_STENCIL:
13265
- // this.device.gl2.clearBufferiv(GL_STENCIL, 0, [value]);
13266
- // break;
13267
- // case GL_DEPTH_STENCIL:
13268
- // const [depth, stencil] = value;
13269
- // this.device.gl2.clearBufferfi(GL_DEPTH_STENCIL, 0, depth, stencil);
13270
- // break;
13271
- // default:
13272
- // assert(false, ERR_ARGUMENTS);
13273
- // }
13274
- // });
13275
12786
  };
13276
12787
 
13277
12788
  // ../webgl/src/classic/typed-array-utils.ts
@@ -13328,10 +12839,6 @@ ${formattedLog}`)();
13328
12839
  const ArrayType = getTypedArrayFromGLType(accessor.type || GLEnum2.FLOAT);
13329
12840
  return ArrayType.BYTES_PER_ELEMENT * accessor.size;
13330
12841
  }
13331
- // Combines (merges) a list of accessors. On top of default values
13332
- // Usually [programAccessor, bufferAccessor, appAccessor]
13333
- // All props will be set in the returned object.
13334
- // TODO check for conflicts between values in the supplied accessors
13335
12842
  static resolve(...accessors) {
13336
12843
  return new Accessor(...[DEFAULT_ACCESSOR_VALUES, ...accessors]);
13337
12844
  }
@@ -13342,16 +12849,12 @@ ${formattedLog}`)();
13342
12849
  toString() {
13343
12850
  return JSON.stringify(this);
13344
12851
  }
13345
- // ACCESSORS
13346
- // TODO - remove>
13347
12852
  get BYTES_PER_ELEMENT() {
13348
12853
  return Accessor.getBytesPerElement(this);
13349
12854
  }
13350
12855
  get BYTES_PER_VERTEX() {
13351
12856
  return Accessor.getBytesPerVertex(this);
13352
12857
  }
13353
- // PRIVATE
13354
- // eslint-disable-next-line complexity, max-statements
13355
12858
  _assign(props = {}) {
13356
12859
  props = checkProps("Accessor", props, PROP_CHECKS);
13357
12860
  if (props.type !== void 0) {
@@ -13441,25 +12944,15 @@ ${formattedLog}`)();
13441
12944
  [GLEnum2.BOOL_VEC2]: [GLEnum2.FLOAT, 2, "bvec2", "vec2<f32>", "float32x2"],
13442
12945
  [GLEnum2.BOOL_VEC3]: [GLEnum2.FLOAT, 3, "bvec3", "vec3<f32>", "float32x3"],
13443
12946
  [GLEnum2.BOOL_VEC4]: [GLEnum2.FLOAT, 4, "bvec4", "vec4<f32>", "float32x4"],
13444
- // TODO - are sizes/components below correct?
13445
12947
  [GLEnum2.FLOAT_MAT2]: [GLEnum2.FLOAT, 8, "mat2", "mat2x2<f32>"],
13446
- // 4
13447
12948
  [GLEnum2.FLOAT_MAT2x3]: [GLEnum2.FLOAT, 8, "mat2x3", "mat2x3<f32>"],
13448
- // 6
13449
12949
  [GLEnum2.FLOAT_MAT2x4]: [GLEnum2.FLOAT, 8, "mat2x4", "mat2x4<f32>"],
13450
- // 8
13451
12950
  [GLEnum2.FLOAT_MAT3x2]: [GLEnum2.FLOAT, 12, "mat3x2", "mat3x2<f32>"],
13452
- // 6
13453
12951
  [GLEnum2.FLOAT_MAT3]: [GLEnum2.FLOAT, 12, "mat3", "mat3x3<f32>"],
13454
- // 9
13455
12952
  [GLEnum2.FLOAT_MAT3x4]: [GLEnum2.FLOAT, 12, "mat3x4", "mat3x4<f32>"],
13456
- // 12
13457
12953
  [GLEnum2.FLOAT_MAT4x2]: [GLEnum2.FLOAT, 16, "mat4x2", "mat4x2<f32>"],
13458
- // 8
13459
12954
  [GLEnum2.FLOAT_MAT4x3]: [GLEnum2.FLOAT, 16, "mat4x3", "mat4x3<f32>"],
13460
- // 12
13461
12955
  [GLEnum2.FLOAT_MAT4]: [GLEnum2.FLOAT, 16, "mat4", "mat4x4<f32>"]
13462
- // 16
13463
12956
  };
13464
12957
  function decodeGLUniformType(glUniformType) {
13465
12958
  const typeAndSize = COMPOSITE_GL_TYPES[glUniformType];
@@ -13543,15 +13036,14 @@ ${formattedLog}`)();
13543
13036
  function readAttributeDeclarations(gl, program) {
13544
13037
  const attributes = [];
13545
13038
  const count = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
13546
- for (let index = 0; index < count; index++) {
13547
- const activeInfo = gl.getActiveAttrib(program, index);
13039
+ for (let index2 = 0; index2 < count; index2++) {
13040
+ const activeInfo = gl.getActiveAttrib(program, index2);
13548
13041
  if (!activeInfo) {
13549
13042
  throw new Error("activeInfo");
13550
13043
  }
13551
13044
  const {
13552
13045
  name: name2,
13553
13046
  type: compositeType
13554
- /* , size*/
13555
13047
  } = activeInfo;
13556
13048
  const location = gl.getAttribLocation(program, name2);
13557
13049
  if (location >= 0) {
@@ -13564,7 +13056,6 @@ ${formattedLog}`)();
13564
13056
  location,
13565
13057
  stepMode,
13566
13058
  type: attributeType
13567
- // size - for arrays, size is the number of elements in the array
13568
13059
  });
13569
13060
  }
13570
13061
  }
@@ -13625,7 +13116,6 @@ ${formattedLog}`)();
13625
13116
  } = parseUniformName(rawName);
13626
13117
  let webglLocation = gl.getUniformLocation(program, name2);
13627
13118
  const uniformInfo = {
13628
- // WebGL locations are uniquely typed but just numbers
13629
13119
  location: webglLocation,
13630
13120
  name: name2,
13631
13121
  size,
@@ -13683,8 +13173,6 @@ ${formattedLog}`)();
13683
13173
  arrayLength: uniformArrayLength[i],
13684
13174
  byteOffset: uniformOffset[i],
13685
13175
  byteStride: uniformStride[i]
13686
- // matrixStride: uniformStride[i],
13687
- // rowMajor: uniformRowMajor[i]
13688
13176
  });
13689
13177
  }
13690
13178
  uniformBlocks.push(blockInfo);
@@ -13870,20 +13358,11 @@ ${formattedLog}`)();
13870
13358
  // ../webgl/src/adapter/resources/webgl-render-pipeline.ts
13871
13359
  var LOG_PROGRAM_PERF_PRIORITY = 4;
13872
13360
  var WEBGLRenderPipeline = class extends RenderPipeline {
13873
- /** The WebGL device that created this render pipeline */
13874
- /** Handle to underlying WebGL program */
13875
- /** vertex shader */
13876
- /** fragment shader */
13877
- /** The layout extracted from shader by WebGL introspection APIs */
13878
- /** Uniforms set on this model */
13879
13361
  uniforms = {};
13880
- /** Bindings set on this model */
13881
13362
  bindings = {};
13882
- /** WebGL varyings */
13883
13363
  varyings = null;
13884
13364
  _uniformCount = 0;
13885
13365
  _uniformSetters = {};
13886
- // TODO are these used?
13887
13366
  constructor(device, props) {
13888
13367
  super(device, props);
13889
13368
  this.device = device;
@@ -13912,41 +13391,6 @@ ${formattedLog}`)();
13912
13391
  this.destroyed = true;
13913
13392
  }
13914
13393
  }
13915
- // setIndexBuffer(indexBuffer: Buffer): void {
13916
- // const webglBuffer = cast<WEBGLBuffer>(indexBuffer);
13917
- // this.vertexArrayObject.setElementBuffer(webglBuffer);
13918
- // this._indexBuffer = indexBuffer;
13919
- // }
13920
- // /** @todo needed for portable model */
13921
- // setAttributes(attributes: Record<string, Buffer>): void {
13922
- // for (const [name, buffer] of Object.entries(attributes)) {
13923
- // const webglBuffer = cast<WEBGLBuffer>(buffer);
13924
- // const attribute = getAttributeLayout(this.layout, name);
13925
- // if (!attribute) {
13926
- // log.warn(
13927
- // `Ignoring buffer supplied for unknown attribute "${name}" in pipeline "${this.id}" (buffer "${buffer.id}")`
13928
- // )();
13929
- // continue;
13930
- // }
13931
- // const decoded = decodeVertexFormat(attribute.format);
13932
- // const {type: typeString, components: size, byteLength: stride, normalized, integer} = decoded;
13933
- // const divisor = attribute.stepMode === 'instance' ? 1 : 0;
13934
- // const type = getWebGLDataType(typeString);
13935
- // this.vertexArrayObject.setBuffer(attribute.location, webglBuffer, {
13936
- // size,
13937
- // type,
13938
- // stride,
13939
- // offset: 0,
13940
- // normalized,
13941
- // integer,
13942
- // divisor
13943
- // });
13944
- // }
13945
- // }
13946
- /**
13947
- * Bindings include: textures, samplers and uniform buffers
13948
- * @todo needed for portable model
13949
- */
13950
13394
  setBindings(bindings) {
13951
13395
  for (const [name2, value] of Object.entries(bindings)) {
13952
13396
  const binding = this.shaderLayout.bindings.find((binding2) => binding2.name === name2) || this.shaderLayout.bindings.find((binding2) => binding2.name === `${name2}Uniforms`);
@@ -13983,25 +13427,17 @@ ${formattedLog}`)();
13983
13427
  bindings
13984
13428
  } = splitUniformsAndBindings(uniforms);
13985
13429
  Object.keys(bindings).forEach((name2) => {
13986
- log.warn(`Unsupported value "${bindings[name2]}" used in setUniforms() for key ${name2}. Use setBindings() instead?`)();
13430
+ log.warn(`Unsupported value "${JSON.stringify(bindings[name2])}" used in setUniforms() for key ${name2}. Use setBindings() instead?`)();
13987
13431
  });
13988
13432
  Object.assign(this.uniforms, uniforms);
13989
13433
  }
13990
- /** @todo needed for portable model
13991
- * @note The WebGL API is offers many ways to draw things
13992
- * This function unifies those ways into a single call using common parameters with sane defaults
13993
- */
13994
13434
  draw(options) {
13995
13435
  const {
13996
13436
  renderPass,
13997
13437
  vertexArray,
13998
13438
  vertexCount,
13999
- // indexCount,
14000
13439
  instanceCount,
14001
13440
  firstVertex = 0,
14002
- // firstIndex,
14003
- // firstInstance,
14004
- // baseVertex,
14005
13441
  transformFeedback
14006
13442
  } = options;
14007
13443
  const glDrawMode = getGLDrawMode(this.props.topology);
@@ -14021,14 +13457,7 @@ ${formattedLog}`)();
14021
13457
  const webglRenderPass = renderPass;
14022
13458
  withDeviceAndGLParameters(this.device, this.props.parameters, webglRenderPass.glParameters, () => {
14023
13459
  if (isIndexed && isInstanced) {
14024
- this.device.gl2?.drawElementsInstanced(
14025
- glDrawMode,
14026
- vertexCount || 0,
14027
- // indexCount?
14028
- glIndexType,
14029
- firstVertex,
14030
- instanceCount || 0
14031
- );
13460
+ this.device.gl2?.drawElementsInstanced(glDrawMode, vertexCount || 0, glIndexType, firstVertex, instanceCount || 0);
14032
13461
  } else if (isIndexed) {
14033
13462
  this.device.gl.drawElements(glDrawMode, vertexCount || 0, glIndexType, firstVertex);
14034
13463
  } else if (isInstanced) {
@@ -14043,8 +13472,6 @@ ${formattedLog}`)();
14043
13472
  vertexArray.unbindAfterRender(renderPass);
14044
13473
  return true;
14045
13474
  }
14046
- // setAttributes(attributes: Record<string, Buffer>): void {}
14047
- // setBindings(bindings: Record<string, Binding>): void {}
14048
13475
  _compileAndLink() {
14049
13476
  const {
14050
13477
  gl
@@ -14066,12 +13493,6 @@ ${formattedLog}`)();
14066
13493
  throw new Error(`Error validating: ${gl.getProgramInfoLog(this.handle)}`);
14067
13494
  }
14068
13495
  }
14069
- // PRIVATE METHODS
14070
- /**
14071
- * Checks if all texture-values uniforms are renderable (i.e. loaded)
14072
- * Update a texture if needed (e.g. from video)
14073
- * Note: This is currently done before every draw call
14074
- */
14075
13496
  _areTexturesRenderable() {
14076
13497
  let texturesRenderable = true;
14077
13498
  for (const [, texture] of Object.entries(this.bindings)) {
@@ -14082,28 +13503,6 @@ ${formattedLog}`)();
14082
13503
  }
14083
13504
  return texturesRenderable;
14084
13505
  }
14085
- /**
14086
- * Constant attributes need to be reset before every draw call
14087
- * Any attribute that is disabled in the current vertex array object
14088
- * is read from the context's global constant value for that attribute location.
14089
- * @note Constant attributes are only supported in WebGL, not in WebGPU
14090
- *
14091
- _applyConstantAttributes(vertexArray: WEBGLVertexArray): void {
14092
- const attributeInfos = getAttributeInfosFromLayouts(this.shaderLayout, this.bufferLayout);
14093
- for (const [name, value] of Object.entries(this.)) {
14094
- const attributeInfo = attributeInfos[name];
14095
- if (!attributeInfo) {
14096
- log.warn(
14097
- `Ignoring constant value supplied for unknown attribute "${name}" in pipeline "${this.id}"`
14098
- )();
14099
- continue; // eslint-disable-line no-continue
14100
- }
14101
- vertexArray.setConstant(attributeInfo.location, value);
14102
- vertexArray.enable(attributeInfo.location, false);
14103
- }
14104
- }
14105
- */
14106
- /** Apply any bindings (before each draw call) */
14107
13506
  _applyBindings() {
14108
13507
  this.device.gl.useProgram(this.handle);
14109
13508
  const {
@@ -14132,16 +13531,7 @@ ${formattedLog}`)();
14132
13531
  if (value instanceof WEBGLBuffer) {
14133
13532
  gl2.bindBufferBase(GLEnum2.UNIFORM_BUFFER, uniformBufferIndex, value.handle);
14134
13533
  } else {
14135
- gl2.bindBufferRange(
14136
- GLEnum2.UNIFORM_BUFFER,
14137
- uniformBufferIndex,
14138
- // @ts-expect-error
14139
- value.buffer.handle,
14140
- // @ts-expect-error
14141
- value.offset || 0,
14142
- // @ts-expect-error
14143
- value.size || value.buffer.byteLength - value.offset
14144
- );
13534
+ gl2.bindBufferRange(GLEnum2.UNIFORM_BUFFER, uniformBufferIndex, value.buffer.handle, value.offset || 0, value.size || value.buffer.byteLength - value.offset);
14145
13535
  }
14146
13536
  uniformBufferIndex += 1;
14147
13537
  break;
@@ -14170,10 +13560,6 @@ ${formattedLog}`)();
14170
13560
  }
14171
13561
  }
14172
13562
  }
14173
- /**
14174
- * Due to program sharing, uniforms need to be reset before every draw call
14175
- * (though caching will avoid redundant WebGL calls)
14176
- */
14177
13563
  _applyUniforms() {
14178
13564
  for (const uniformLayout of this.shaderLayout.uniforms || []) {
14179
13565
  const {
@@ -14238,33 +13624,16 @@ ${formattedLog}`)();
14238
13624
  }
14239
13625
  function _copyTextureToBuffer(device, options) {
14240
13626
  const {
14241
- /** Texture to copy to/from. */
14242
13627
  source,
14243
- /** Mip-map level of the texture to copy to/from. (Default 0) */
14244
13628
  mipLevel = 0,
14245
- /** Defines which aspects of the texture to copy to/from. */
14246
13629
  aspect = "all",
14247
- /** Width to copy */
14248
13630
  width = options.source.width,
14249
- /** Height to copy */
14250
13631
  height = options.source.height,
14251
13632
  depthOrArrayLayers = 0,
14252
- /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
14253
13633
  origin = [0, 0],
14254
- /** Destination buffer */
14255
13634
  destination,
14256
- /** Offset, in bytes, from the beginning of the buffer to the start of the image data (default 0) */
14257
13635
  byteOffset = 0,
14258
- /**
14259
- * The stride, in bytes, between the beginning of each block row and the subsequent block row.
14260
- * Required if there are multiple block rows (i.e. the copy height or depth is more than one block).
14261
- */
14262
13636
  bytesPerRow,
14263
- /**
14264
- * Number of block rows per single image of the texture.
14265
- * rowsPerImage &times; bytesPerRow is the stride, in bytes, between the beginning of each image of data and the subsequent image.
14266
- * Required if there are multiple images (i.e. the copy depth is more than one).
14267
- */
14268
13637
  rowsPerImage
14269
13638
  } = options;
14270
13639
  if (aspect !== "all") {
@@ -14298,27 +13667,13 @@ ${formattedLog}`)();
14298
13667
  }
14299
13668
  function _copyTextureToTexture(device, options) {
14300
13669
  const {
14301
- /** Texture to copy to/from. */
14302
13670
  source,
14303
- /** Mip-map level of the texture to copy to/from. (Default 0) */
14304
- // mipLevel = 0,
14305
- /** Defines which aspects of the texture to copy to/from. */
14306
- // aspect = 'all',
14307
- /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
14308
13671
  origin = [0, 0],
14309
- /** Texture to copy to/from. */
14310
13672
  destination
14311
- /** Mip-map level of the texture to copy to/from. (Default 0) */
14312
- // destinationMipLevel = options.mipLevel,
14313
- /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
14314
- // destinationOrigin = [0, 0],
14315
- /** Defines which aspects of the texture to copy to/from. */
14316
- // destinationAspect = options.aspect,
14317
13673
  } = options;
14318
13674
  let {
14319
13675
  width = options.destination.width,
14320
13676
  height = options.destination.width
14321
- // depthOrArrayLayers = 0
14322
13677
  } = options;
14323
13678
  const destinationMipmaplevel = 0;
14324
13679
  const destinationInternalFormat = GLEnum2.RGBA;
@@ -14341,17 +13696,7 @@ ${formattedLog}`)();
14341
13696
  throw new Error("whoops");
14342
13697
  }
14343
13698
  if (!isSubCopy) {
14344
- device.gl.copyTexImage2D(
14345
- textureTarget,
14346
- destinationMipmaplevel,
14347
- destinationInternalFormat,
14348
- sourceX,
14349
- sourceY,
14350
- width,
14351
- height,
14352
- 0
14353
- /* border must be 0 */
14354
- );
13699
+ device.gl.copyTexImage2D(textureTarget, destinationMipmaplevel, destinationInternalFormat, sourceX, sourceY, width, height, 0);
14355
13700
  } else {
14356
13701
  }
14357
13702
  if (texture) {
@@ -14398,9 +13743,6 @@ ${formattedLog}`)();
14398
13743
  finish() {
14399
13744
  this.commandBuffer.submitCommands();
14400
13745
  }
14401
- // beginRenderPass(GPURenderPassDescriptor descriptor): GPURenderPassEncoder;
14402
- // beginComputePass(optional GPUComputePassDescriptor descriptor = {}): GPUComputePassEncoder;
14403
- // finish(options?: {id?: string}): GPUCommandBuffer;
14404
13746
  copyBufferToBuffer(options) {
14405
13747
  this.commandBuffer.commands.push({
14406
13748
  name: "copy-buffer-to-buffer",
@@ -14431,14 +13773,6 @@ ${formattedLog}`)();
14431
13773
  }
14432
13774
  insertDebugMarker(markerLabel) {
14433
13775
  }
14434
- // writeTimestamp(querySet: Query, queryIndex: number): void {}
14435
- // resolveQuerySet(options: {
14436
- // querySet: GPUQuerySet,
14437
- // firstQuery: number,
14438
- // queryCount: number,
14439
- // destination: Buffer,
14440
- // destinationOffset?: number;
14441
- // }): void;
14442
13776
  };
14443
13777
 
14444
13778
  // ../webgl/src/adapter/resources/webgl-vertex-array.ts
@@ -14446,14 +13780,11 @@ ${formattedLog}`)();
14446
13780
  get [Symbol.toStringTag]() {
14447
13781
  return "VertexArray";
14448
13782
  }
14449
- /** Attribute 0 buffer constant */
14450
13783
  buffer = null;
14451
13784
  bufferValue = null;
14452
- /** * Attribute 0 can not be disable on most desktop OpenGL based browsers */
14453
13785
  static isConstantAttributeZeroSupported(device) {
14454
13786
  return device.info.type === "webgl2" || getBrowser() === "Chrome";
14455
13787
  }
14456
- // Create a VertexArray
14457
13788
  constructor(device, props) {
14458
13789
  super(device, props);
14459
13790
  this.device = device;
@@ -14469,22 +13800,15 @@ ${formattedLog}`)();
14469
13800
  this.handle = void 0;
14470
13801
  }
14471
13802
  }
14472
- /**
14473
- // Set (bind) an elements buffer, for indexed rendering.
14474
- // Must be a Buffer bound to GL.ELEMENT_ARRAY_BUFFER. Constants not supported
14475
- *
14476
- * @param elementBuffer
14477
- */
14478
13803
  setIndexBuffer(indexBuffer) {
14479
13804
  const buffer = indexBuffer;
14480
- if (buffer?.glTarget !== GLEnum2.ELEMENT_ARRAY_BUFFER) {
13805
+ if (buffer && buffer.glTarget !== GLEnum2.ELEMENT_ARRAY_BUFFER) {
14481
13806
  throw new Error("Use .setBuffer()");
14482
13807
  }
14483
13808
  this.device.gl2.bindVertexArray(this.handle);
14484
13809
  this.device.gl2.bindBuffer(GLEnum2.ELEMENT_ARRAY_BUFFER, buffer ? buffer.handle : null);
14485
13810
  this.indexBuffer = buffer;
14486
13811
  }
14487
- /** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */
14488
13812
  setBuffer(location, attributeBuffer) {
14489
13813
  const buffer = attributeBuffer;
14490
13814
  if (buffer.glTarget === GLEnum2.ELEMENT_ARRAY_BUFFER) {
@@ -14511,7 +13835,6 @@ ${formattedLog}`)();
14511
13835
  this.device.gl2.vertexAttribDivisor(location, divisor || 0);
14512
13836
  this.attributes[location] = buffer;
14513
13837
  }
14514
- /** Set a location in vertex attributes array to a constant value, disables the location */
14515
13838
  setConstant(location, value) {
14516
13839
  this._enable(location, false);
14517
13840
  this.attributes[location] = value;
@@ -14529,13 +13852,6 @@ ${formattedLog}`)();
14529
13852
  unbindAfterRender() {
14530
13853
  this.device.gl2.bindVertexArray(null);
14531
13854
  }
14532
- // Internal methods
14533
- /**
14534
- * Constant attributes need to be reset before every draw call
14535
- * Any attribute that is disabled in the current vertex array object
14536
- * is read from the context's global constant value for that attribute location.
14537
- * @note Constant attributes are only supported in WebGL, not in WebGPU
14538
- */
14539
13855
  _applyConstantAttributes() {
14540
13856
  for (let location = 0; location < this.maxVertexAttributes; ++location) {
14541
13857
  const constant = this.attributes[location];
@@ -14544,23 +13860,6 @@ ${formattedLog}`)();
14544
13860
  }
14545
13861
  }
14546
13862
  }
14547
- /**
14548
- * Set a location in vertex attributes array to a buffer, enables the location, sets divisor
14549
- * @note requires vertex array to be bound
14550
- */
14551
- // protected _setAttributeLayout(location: number): void {
14552
- // const {size, type, stride, offset, normalized, integer, divisor} = this._getAccessor(location);
14553
- // // WebGL2 supports *integer* data formats, i.e. GPU will see integer values
14554
- // if (integer) {
14555
- // this.device.assertWebGL2();
14556
- // this.device.gl2.vertexAttribIPointer(location, size, type, stride, offset);
14557
- // } else {
14558
- // // Attaches ARRAY_BUFFER with specified buffer format to location
14559
- // this.device.gl.vertexAttribPointer(location, size, type, normalized, stride, offset);
14560
- // }
14561
- // this.device.gl2.vertexAttribDivisor(location, divisor || 0);
14562
- // }
14563
- /** Get an accessor from the */
14564
13863
  _getAccessor(location) {
14565
13864
  const attributeInfo = this.attributeInfos[location];
14566
13865
  if (!attributeInfo) {
@@ -14573,21 +13872,10 @@ ${formattedLog}`)();
14573
13872
  stride: attributeInfo.byteStride,
14574
13873
  offset: attributeInfo.byteOffset,
14575
13874
  normalized: attributeInfo.normalized,
14576
- // it is the shader attribute declaration, not the vertex memory format,
14577
- // that determines if the data in the buffer will be treated as integers.
14578
- //
14579
- // Also note that WebGL supports assigning non-normalized integer data to floating point attributes,
14580
- // but as far as we can tell, WebGPU does not.
14581
13875
  integer: attributeInfo.integer,
14582
13876
  divisor: attributeInfo.stepMode === "instance" ? 1 : 0
14583
13877
  };
14584
13878
  }
14585
- /**
14586
- * Enabling an attribute location makes it reference the currently bound buffer
14587
- * Disabling an attribute location makes it reference the global constant value
14588
- * TODO - handle single values for size 1 attributes?
14589
- * TODO - convert classic arrays based on known type?
14590
- */
14591
13879
  _enable(location, enable2 = true) {
14592
13880
  const canDisableAttributeZero = WEBGLVertexArray.isConstantAttributeZeroSupported(this.device);
14593
13881
  const canDisableAttribute = canDisableAttributeZero || location !== 0;
@@ -14602,12 +13890,6 @@ ${formattedLog}`)();
14602
13890
  this.device.gl2.bindVertexArray(null);
14603
13891
  }
14604
13892
  }
14605
- /**
14606
- * Provide a means to create a buffer that is equivalent to a constant.
14607
- * NOTE: Desktop OpenGL cannot disable attribute 0.
14608
- * https://stackoverflow.com/questions/20305231/webgl-warning-attribute-0-is-disabled-
14609
- * this-has-significant-performance-penalty
14610
- */
14611
13893
  getConstantBuffer(elementCount, value) {
14612
13894
  const constantValue = normalizeConstantArrayValue(value);
14613
13895
  const byteLength = constantValue.byteLength * elementCount;
@@ -14654,18 +13936,8 @@ ${formattedLog}`)();
14654
13936
 
14655
13937
  // ../webgl/src/adapter/resources/webgl-transform-feedback.ts
14656
13938
  var WEBGLTransformFeedback = class extends TransformFeedback {
14657
- /**
14658
- * NOTE: The Model already has this information while drawing, but
14659
- * TransformFeedback currently needs it internally, to look up
14660
- * varying information outside of a draw() call.
14661
- */
14662
13939
  buffers = {};
14663
13940
  unusedBuffers = {};
14664
- /**
14665
- * Allows us to avoid a Chrome bug where a buffer that is already bound to a
14666
- * different target cannot be bound to 'TRANSFORM_FEEDBACK_BUFFER' target.
14667
- * This a major workaround, see: https://github.com/KhronosGroup/WebGL/issues/2346
14668
- */
14669
13941
  bindOnUse = true;
14670
13942
  _bound = false;
14671
13943
  constructor(device, props) {
@@ -14698,7 +13970,6 @@ ${formattedLog}`)();
14698
13970
  }
14699
13971
  this.gl2.bindTransformFeedback(GLEnum2.TRANSFORM_FEEDBACK, null);
14700
13972
  }
14701
- // SUBCLASS
14702
13973
  setBuffers(buffers) {
14703
13974
  this.buffers = {};
14704
13975
  this.unusedBuffers = {};
@@ -14756,8 +14027,6 @@ ${formattedLog}`)();
14756
14027
  unbind() {
14757
14028
  this.bind(null);
14758
14029
  }
14759
- // PRIVATE METHODS
14760
- /** Extract offsets for bindBufferRange */
14761
14030
  _getBufferRange(bufferOrRange) {
14762
14031
  if (bufferOrRange instanceof WEBGLBuffer) {
14763
14032
  return {
@@ -14788,10 +14057,6 @@ ${formattedLog}`)();
14788
14057
  }
14789
14058
  return -1;
14790
14059
  }
14791
- /**
14792
- * Need to avoid chrome bug where buffer that is already bound to a different target
14793
- * cannot be bound to 'TRANSFORM_FEEDBACK_BUFFER' target.
14794
- */
14795
14060
  _bindBuffers() {
14796
14061
  for (const bufferIndex in this.buffers) {
14797
14062
  const {
@@ -14807,12 +14072,12 @@ ${formattedLog}`)();
14807
14072
  this.gl2.bindBufferBase(GLEnum2.TRANSFORM_FEEDBACK_BUFFER, Number(bufferIndex), null);
14808
14073
  }
14809
14074
  }
14810
- _bindBuffer(index, buffer, byteOffset = 0, byteLength) {
14075
+ _bindBuffer(index2, buffer, byteOffset = 0, byteLength) {
14811
14076
  const handle = buffer && buffer.handle;
14812
14077
  if (!handle || byteLength === void 0) {
14813
- this.gl2.bindBufferBase(GLEnum2.TRANSFORM_FEEDBACK_BUFFER, index, handle);
14078
+ this.gl2.bindBufferBase(GLEnum2.TRANSFORM_FEEDBACK_BUFFER, index2, handle);
14814
14079
  } else {
14815
- this.gl2.bindBufferRange(GLEnum2.TRANSFORM_FEEDBACK_BUFFER, index, handle, byteOffset, byteLength);
14080
+ this.gl2.bindBufferRange(GLEnum2.TRANSFORM_FEEDBACK_BUFFER, index2, handle, byteOffset, byteLength);
14816
14081
  }
14817
14082
  }
14818
14083
  };
@@ -14837,15 +14102,6 @@ ${formattedLog}`)();
14837
14102
  this._limits = this._limits || getDeviceLimits(this.gl);
14838
14103
  return this._limits;
14839
14104
  }
14840
- //
14841
- // Static methods, expected to be present by `luma.createDevice()`
14842
- //
14843
- /**
14844
- * Get a device instance from a GL context
14845
- * Creates and instruments the device if not already created
14846
- * @param gl
14847
- * @returns
14848
- */
14849
14105
  static attach(gl) {
14850
14106
  if (gl instanceof _WebGLDevice) {
14851
14107
  return gl;
@@ -14880,9 +14136,6 @@ ${formattedLog}`)();
14880
14136
  }
14881
14137
  return new _WebGLDevice(props);
14882
14138
  }
14883
- //
14884
- // Public API
14885
- //
14886
14139
  constructor(props) {
14887
14140
  super({
14888
14141
  ...props,
@@ -14952,10 +14205,6 @@ ${formattedLog}`)();
14952
14205
  log.probe(LOG_LEVEL2, message2)();
14953
14206
  log.groupEnd(LOG_LEVEL2)();
14954
14207
  }
14955
- /**
14956
- * Destroys the context
14957
- * @note Has no effect for browser contexts, there is no browser API for destroying contexts
14958
- */
14959
14208
  destroy() {
14960
14209
  const ext = this.gl.getExtension("STACKGL_destroy_context");
14961
14210
  if (ext) {
@@ -14977,15 +14226,12 @@ ${formattedLog}`)();
14977
14226
  isTextureFormatRenderable(format) {
14978
14227
  return isTextureFormatRenderable(this.gl, format);
14979
14228
  }
14980
- // WEBGL SPECIFIC METHODS
14981
- /** Returns a WebGL2RenderingContext or throws an error */
14982
14229
  assertWebGL2() {
14983
14230
  if (!this.gl2) {
14984
14231
  throw new Error("Requires WebGL2");
14985
14232
  }
14986
14233
  return this.gl2;
14987
14234
  }
14988
- // IMPLEMENTATION OF ABSTRACT DEVICE
14989
14235
  createCanvasContext(props) {
14990
14236
  throw new Error("WebGL only supports a single canvas");
14991
14237
  }
@@ -15036,43 +14282,23 @@ ${formattedLog}`)();
15036
14282
  createCommandEncoder(props) {
15037
14283
  return new WEBGLCommandEncoder(this, props);
15038
14284
  }
15039
- /**
15040
- * Offscreen Canvas Support: Commit the frame
15041
- * https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/commit
15042
- * Chrome's offscreen canvas does not require gl.commit
15043
- */
15044
14285
  submit() {
15045
14286
  this.renderPass?.end();
15046
14287
  this.renderPass = null;
15047
14288
  }
15048
- //
15049
- // WebGL-only API (not part of `Device` API)
15050
- //
15051
- /** WebGL1 typed context. Can always be used. */
15052
- /** WebGL2 typed context. Need to check isWebGL2 or isWebGL1 before using. */
15053
14289
  gl2 = null;
15054
14290
  debug = false;
15055
- /** `true` if this is a WebGL1 context. @note `false` if WebGL2 */
15056
- /** `true` if this is a WebGL2 context. @note `false` if WebGL1 */
15057
- /** State used by luma.gl classes: TODO - move to canvasContext*/
15058
14291
  _canvasSizeInfo = {
15059
14292
  clientWidth: 0,
15060
14293
  clientHeight: 0,
15061
14294
  devicePixelRatio: 1
15062
14295
  };
15063
- /** State used by luma.gl classes - TODO - not used? */
15064
14296
  _extensions = {};
15065
14297
  _polyfilled = false;
15066
- /** Instance of Spector.js (if initialized) */
15067
- /** Return WebGL specific limits */
15068
14298
  get webglLimits() {
15069
14299
  this._webglLimits = this._webglLimits || getWebGLLimits(this.gl);
15070
14300
  return this._webglLimits;
15071
14301
  }
15072
- /**
15073
- * Triggers device (or WebGL context) loss.
15074
- * @note primarily intended for testing how application reacts to device loss
15075
- */
15076
14302
  loseDevice() {
15077
14303
  let deviceLossTriggered = false;
15078
14304
  const ext = this.gl.getExtension("WEBGL_lose_context");
@@ -15086,26 +14312,15 @@ ${formattedLog}`)();
15086
14312
  });
15087
14313
  return deviceLossTriggered;
15088
14314
  }
15089
- /** Save current WebGL context state onto an internal stack */
15090
14315
  pushState() {
15091
14316
  pushContextState(this.gl);
15092
14317
  }
15093
- /** Restores previously saved context state */
15094
14318
  popState() {
15095
14319
  popContextState(this.gl);
15096
14320
  }
15097
- /**
15098
- * Storing data on a special field on WebGLObjects makes that data visible in SPECTOR chrome debug extension
15099
- * luma.gl ids and props can be inspected
15100
- */
15101
14321
  setSpectorMetadata(handle, props) {
15102
14322
  handle.__SPECTOR_Metadata = props;
15103
14323
  }
15104
- /**
15105
- * Returns the GL.<KEY> constant that corresponds to a numeric value of a GL constant
15106
- * Be aware that there are some duplicates especially for constants that are 0,
15107
- * so this isn't guaranteed to return the right key in all cases.
15108
- */
15109
14324
  getGLKey(value, gl) {
15110
14325
  gl = gl || this.gl2 || this.gl;
15111
14326
  const number = Number(value);
@@ -15116,13 +14331,6 @@ ${formattedLog}`)();
15116
14331
  }
15117
14332
  return String(value);
15118
14333
  }
15119
- /** Store constants */
15120
- /**
15121
- * Set a constant value for a location. Disabled attributes at that location will read from this value
15122
- * @note WebGL constants are stored globally on the WebGL context, not the VertexArray
15123
- * so they need to be updated before every render
15124
- * @todo - remember/cache values to avoid setting them unnecessarily?
15125
- */
15126
14334
  setConstantAttribute(location, constant) {
15127
14335
  this._constants = this._constants || new Array(this.limits.maxVertexAttributes).fill(null);
15128
14336
  const currentConstant = this._constants[location];
@@ -15146,9 +14354,6 @@ ${formattedLog}`)();
15146
14354
  }
15147
14355
  };
15148
14356
  var WebGLDevice = _WebGLDevice;
15149
- //
15150
- // Public `Device` API
15151
- //
15152
14357
  __publicField(WebGLDevice, "type", "webgl");
15153
14358
  function isWebGL3(gl) {
15154
14359
  if (typeof WebGLRenderingContext !== "undefined" && gl instanceof WebGLRenderingContext) {
@@ -15247,8 +14452,8 @@ ${formattedLog}`)();
15247
14452
  };
15248
14453
  var GLTFAnimator = class {
15249
14454
  constructor(gltf) {
15250
- this.animations = gltf.animations.map((animation, index) => {
15251
- const name2 = animation.name || `Animation-${index}`;
14455
+ this.animations = gltf.animations.map((animation, index2) => {
14456
+ const name2 = animation.name || `Animation-${index2}`;
15252
14457
  const samplers = animation.samplers.map(({
15253
14458
  input,
15254
14459
  interpolation = "LINEAR",
@@ -15272,7 +14477,6 @@ ${formattedLog}`)();
15272
14477
  });
15273
14478
  });
15274
14479
  }
15275
- /** @deprecated Use .setTime(). Will be removed (deck.gl is using this) */
15276
14480
  animate(time) {
15277
14481
  this.setTime(time);
15278
14482
  }
@@ -15541,7 +14745,6 @@ ${source}` : source;
15541
14745
  useTangents: false
15542
14746
  };
15543
14747
  var GLTFInstantiator = class {
15544
- // TODO - replace with Device
15545
14748
  constructor(device, options = {}) {
15546
14749
  this.device = WebGLDevice.attach(device);
15547
14750
  this.options = {
@@ -15663,22 +14866,19 @@ ${source}` : source;
15663
14866
  if (!bufferView.lumaBuffers[usage]) {
15664
14867
  bufferView.lumaBuffers[usage] = this.device.createBuffer({
15665
14868
  id: `from-${bufferView.id}`,
15666
- // Draco decoded files have attribute.value
15667
14869
  data: bufferView.data || attribute.value
15668
14870
  });
15669
14871
  }
15670
14872
  return bufferView.lumaBuffers[usage];
15671
14873
  }
15672
- // TODO - create sampler in WebGL2
15673
14874
  createSampler(gltfSampler) {
15674
14875
  return gltfSampler;
15675
14876
  }
15676
- // Helper methods (move to GLTFLoader.resolve...?)
15677
14877
  needsPOT() {
15678
14878
  return false;
15679
14879
  }
15680
14880
  };
15681
- var GLEnum3 = /* @__PURE__ */ function(GLEnum4) {
14881
+ var GLEnum3 = function(GLEnum4) {
15682
14882
  GLEnum4[GLEnum4["POINTS"] = 0] = "POINTS";
15683
14883
  GLEnum4[GLEnum4["LINES"] = 1] = "LINES";
15684
14884
  GLEnum4[GLEnum4["LINE_LOOP"] = 2] = "LINE_LOOP";