@luma.gl/webgl 9.0.0-alpha.44 → 9.0.0-alpha.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/adapter/device-helpers/device-features.js +1 -0
  2. package/dist/adapter/device-helpers/device-features.js.map +1 -1
  3. package/dist/adapter/helpers/webgl-topology-utils.d.ts +6 -1
  4. package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
  5. package/dist/adapter/helpers/webgl-topology-utils.js +40 -0
  6. package/dist/adapter/helpers/webgl-topology-utils.js.map +1 -1
  7. package/dist/adapter/resources/webgl-buffer.d.ts +1 -1
  8. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  9. package/dist/adapter/resources/webgl-buffer.js +2 -0
  10. package/dist/adapter/resources/webgl-buffer.js.map +1 -1
  11. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  12. package/dist/adapter/resources/webgl-command-buffer.js +6 -4
  13. package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
  14. package/dist/adapter/resources/webgl-render-pipeline.d.ts +2 -0
  15. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  16. package/dist/adapter/resources/webgl-render-pipeline.js +4 -44
  17. package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
  18. package/dist/adapter/resources/webgl-transform-feedback.d.ts +53 -0
  19. package/dist/adapter/resources/webgl-transform-feedback.d.ts.map +1 -0
  20. package/dist/adapter/resources/webgl-transform-feedback.js +161 -0
  21. package/dist/adapter/resources/webgl-transform-feedback.js.map +1 -0
  22. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
  23. package/dist/adapter/resources/webgl-vertex-array.js +5 -3
  24. package/dist/adapter/resources/webgl-vertex-array.js.map +1 -1
  25. package/dist/adapter/webgl-device.d.ts +4 -2
  26. package/dist/adapter/webgl-device.d.ts.map +1 -1
  27. package/dist/adapter/webgl-device.js +7 -3
  28. package/dist/adapter/webgl-device.js.map +1 -1
  29. package/dist/classic/copy-and-blit.d.ts +3 -3
  30. package/dist/classic/copy-and-blit.d.ts.map +1 -1
  31. package/dist/classic/copy-and-blit.js +12 -20
  32. package/dist/classic/copy-and-blit.js.map +1 -1
  33. package/dist/dist.dev.js +2140 -2302
  34. package/dist/index.cjs +645 -806
  35. package/dist/index.d.ts +1 -2
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +1 -1
  38. package/dist/index.js.map +1 -1
  39. package/dist.min.js +23 -22
  40. package/package.json +5 -5
  41. package/src/adapter/device-helpers/device-features.ts +1 -0
  42. package/src/adapter/helpers/webgl-topology-utils.ts +40 -0
  43. package/src/adapter/resources/webgl-buffer.ts +12 -8
  44. package/src/adapter/resources/webgl-command-buffer.ts +7 -13
  45. package/src/adapter/resources/webgl-render-pipeline.ts +11 -47
  46. package/src/adapter/resources/webgl-transform-feedback.ts +205 -0
  47. package/src/adapter/resources/webgl-vertex-array.ts +11 -8
  48. package/src/adapter/webgl-device.ts +10 -5
  49. package/src/classic/copy-and-blit.ts +16 -19
  50. package/src/index.ts +5 -4
  51. package/LICENSE +0 -34
  52. package/dist/classic/buffer-with-accessor.d.ts +0 -82
  53. package/dist/classic/buffer-with-accessor.d.ts.map +0 -1
  54. package/dist/classic/buffer-with-accessor.js +0 -314
  55. package/dist/classic/buffer-with-accessor.js.map +0 -1
  56. package/src/classic/buffer-with-accessor.ts +0 -466
package/dist/index.cjs CHANGED
@@ -57,7 +57,6 @@ var __async = (__this, __arguments, generator) => {
57
57
  var src_exports = {};
58
58
  __export(src_exports, {
59
59
  Accessor: () => Accessor,
60
- BufferWithAccessor: () => BufferWithAccessor,
61
60
  WEBGLBuffer: () => WEBGLBuffer,
62
61
  WEBGLCommandEncoder: () => WEBGLCommandEncoder,
63
62
  WEBGLFramebuffer: () => WEBGLFramebuffer,
@@ -68,6 +67,7 @@ __export(src_exports, {
68
67
  WEBGLSampler: () => WEBGLSampler,
69
68
  WEBGLShader: () => WEBGLShader,
70
69
  WEBGLTexture: () => WEBGLTexture,
70
+ WEBGLTransformFeedback: () => WEBGLTransformFeedback,
71
71
  WEBGLVertexArray: () => WEBGLVertexArray,
72
72
  WebGLCanvasContext: () => WebGLCanvasContext,
73
73
  WebGLDevice: () => WebGLDevice,
@@ -1357,7 +1357,7 @@ var GLState = class {
1357
1357
  constructor(gl, {
1358
1358
  copyState = false,
1359
1359
  // Copy cache from params (slow) or initialize from WebGL defaults (fast)
1360
- log: log9 = () => {
1360
+ log: log10 = () => {
1361
1361
  }
1362
1362
  // Logging function, called when gl parameter change calls are actually issued
1363
1363
  } = {}) {
@@ -1366,7 +1366,7 @@ var GLState = class {
1366
1366
  this.enable = true;
1367
1367
  this.gl = gl;
1368
1368
  this.cache = copyState ? getGLParameters(gl) : Object.assign({}, GL_PARAMETER_DEFAULTS);
1369
- this.log = log9;
1369
+ this.log = log10;
1370
1370
  this._updateCache = this._updateCache.bind(this);
1371
1371
  Object.seal(this);
1372
1372
  }
@@ -2111,6 +2111,7 @@ var WEBGL_FEATURES = {
2111
2111
  "webgl": [true, true],
2112
2112
  "webgl2": [false, true],
2113
2113
  "timer-query-webgl": ["EXT_disjoint_timer_query", "EXT_disjoint_timer_query_webgl2"],
2114
+ "transform-feedback-webgl2": [false, true],
2114
2115
  // WEBGL1 SUPPORT
2115
2116
  "vertex-array-object-webgl1": ["OES_vertex_array_object", true],
2116
2117
  "instanced-rendering-webgl1": ["ANGLE_instanced_arrays", true],
@@ -2613,6 +2614,7 @@ var WEBGLBuffer = class extends import_core7.Buffer {
2613
2614
  readAsync(byteOffset = 0, byteLength) {
2614
2615
  return __async(this, null, function* () {
2615
2616
  this.device.assertWebGL2();
2617
+ byteLength = byteLength != null ? byteLength : this.byteLength;
2616
2618
  const data = new Uint8Array(byteLength);
2617
2619
  const dstOffset = 0;
2618
2620
  this.gl.bindBuffer(import_constants10.GL.COPY_READ_BUFFER, this.handle);
@@ -4088,490 +4090,9 @@ function onValidateGLFunc(props, functionName, functionArgs) {
4088
4090
  }
4089
4091
  }
4090
4092
 
4091
- // src/classic/buffer-with-accessor.ts
4092
- var import_core19 = require("@luma.gl/core");
4093
- var import_constants18 = require("@luma.gl/constants");
4094
-
4095
- // src/classic/accessor.ts
4093
+ // src/adapter/resources/webgl-shader.ts
4096
4094
  var import_core18 = require("@luma.gl/core");
4097
- var import_constants17 = require("@luma.gl/constants");
4098
-
4099
- // src/classic/typed-array-utils.ts
4100
4095
  var import_constants16 = require("@luma.gl/constants");
4101
- var ERR_TYPE_DEDUCTION = "Failed to deduce GL constant from typed array";
4102
- function getGLTypeFromTypedArray(arrayOrType) {
4103
- const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
4104
- switch (type) {
4105
- case Float32Array:
4106
- return import_constants16.GL.FLOAT;
4107
- case Uint16Array:
4108
- return import_constants16.GL.UNSIGNED_SHORT;
4109
- case Uint32Array:
4110
- return import_constants16.GL.UNSIGNED_INT;
4111
- case Uint8Array:
4112
- return import_constants16.GL.UNSIGNED_BYTE;
4113
- case Uint8ClampedArray:
4114
- return import_constants16.GL.UNSIGNED_BYTE;
4115
- case Int8Array:
4116
- return import_constants16.GL.BYTE;
4117
- case Int16Array:
4118
- return import_constants16.GL.SHORT;
4119
- case Int32Array:
4120
- return import_constants16.GL.INT;
4121
- default:
4122
- throw new Error(ERR_TYPE_DEDUCTION);
4123
- }
4124
- }
4125
- function getTypedArrayFromGLType(glType, options) {
4126
- const { clamped = true } = options || {};
4127
- switch (glType) {
4128
- case import_constants16.GL.FLOAT:
4129
- return Float32Array;
4130
- case import_constants16.GL.UNSIGNED_SHORT:
4131
- case import_constants16.GL.UNSIGNED_SHORT_5_6_5:
4132
- case import_constants16.GL.UNSIGNED_SHORT_4_4_4_4:
4133
- case import_constants16.GL.UNSIGNED_SHORT_5_5_5_1:
4134
- return Uint16Array;
4135
- case import_constants16.GL.UNSIGNED_INT:
4136
- return Uint32Array;
4137
- case import_constants16.GL.UNSIGNED_BYTE:
4138
- return clamped ? Uint8ClampedArray : Uint8Array;
4139
- case import_constants16.GL.BYTE:
4140
- return Int8Array;
4141
- case import_constants16.GL.SHORT:
4142
- return Int16Array;
4143
- case import_constants16.GL.INT:
4144
- return Int32Array;
4145
- default:
4146
- throw new Error("Failed to deduce typed array type from GL constant");
4147
- }
4148
- }
4149
-
4150
- // src/classic/accessor.ts
4151
- var DEFAULT_ACCESSOR_VALUES = {
4152
- offset: 0,
4153
- stride: 0,
4154
- type: import_constants17.GL.FLOAT,
4155
- size: 1,
4156
- divisor: 0,
4157
- normalized: false,
4158
- integer: false
4159
- };
4160
- var PROP_CHECKS = {
4161
- deprecatedProps: {
4162
- instanced: "divisor",
4163
- isInstanced: "divisor"
4164
- }
4165
- };
4166
- var Accessor = class {
4167
- static getBytesPerElement(accessor) {
4168
- const ArrayType = getTypedArrayFromGLType(accessor.type || import_constants17.GL.FLOAT);
4169
- return ArrayType.BYTES_PER_ELEMENT;
4170
- }
4171
- static getBytesPerVertex(accessor) {
4172
- (0, import_core18.assert)(accessor.size);
4173
- const ArrayType = getTypedArrayFromGLType(accessor.type || import_constants17.GL.FLOAT);
4174
- return ArrayType.BYTES_PER_ELEMENT * accessor.size;
4175
- }
4176
- // Combines (merges) a list of accessors. On top of default values
4177
- // Usually [programAccessor, bufferAccessor, appAccessor]
4178
- // All props will be set in the returned object.
4179
- // TODO check for conflicts between values in the supplied accessors
4180
- static resolve(...accessors) {
4181
- return new Accessor(...[DEFAULT_ACCESSOR_VALUES, ...accessors]);
4182
- }
4183
- constructor(...accessors) {
4184
- accessors.forEach((accessor) => this._assign(accessor));
4185
- Object.freeze(this);
4186
- }
4187
- toString() {
4188
- return JSON.stringify(this);
4189
- }
4190
- // ACCESSORS
4191
- // TODO - remove>
4192
- get BYTES_PER_ELEMENT() {
4193
- return Accessor.getBytesPerElement(this);
4194
- }
4195
- get BYTES_PER_VERTEX() {
4196
- return Accessor.getBytesPerVertex(this);
4197
- }
4198
- // PRIVATE
4199
- // eslint-disable-next-line complexity, max-statements
4200
- _assign(props = {}) {
4201
- props = (0, import_core18.checkProps)("Accessor", props, PROP_CHECKS);
4202
- if (props.type !== void 0) {
4203
- this.type = props.type;
4204
- if (props.type === import_constants17.GL.INT || props.type === import_constants17.GL.UNSIGNED_INT) {
4205
- this.integer = true;
4206
- }
4207
- }
4208
- if (props.size !== void 0) {
4209
- this.size = props.size;
4210
- }
4211
- if (props.offset !== void 0) {
4212
- this.offset = props.offset;
4213
- }
4214
- if (props.stride !== void 0) {
4215
- this.stride = props.stride;
4216
- }
4217
- if (props.normalize !== void 0) {
4218
- this.normalized = props.normalize;
4219
- }
4220
- if (props.normalized !== void 0) {
4221
- this.normalized = props.normalized;
4222
- }
4223
- if (props.integer !== void 0) {
4224
- this.integer = props.integer;
4225
- }
4226
- if (props.divisor !== void 0) {
4227
- this.divisor = props.divisor;
4228
- }
4229
- if (props.buffer !== void 0) {
4230
- this.buffer = props.buffer;
4231
- }
4232
- if (props.index !== void 0) {
4233
- if (typeof props.index === "boolean") {
4234
- this.index = props.index ? 1 : 0;
4235
- } else {
4236
- this.index = props.index;
4237
- }
4238
- }
4239
- if (props.instanced !== void 0) {
4240
- this.divisor = props.instanced ? 1 : 0;
4241
- }
4242
- if (props.isInstanced !== void 0) {
4243
- this.divisor = props.isInstanced ? 1 : 0;
4244
- }
4245
- if (this.offset === void 0)
4246
- delete this.offset;
4247
- if (this.stride === void 0)
4248
- delete this.stride;
4249
- if (this.type === void 0)
4250
- delete this.type;
4251
- if (this.size === void 0)
4252
- delete this.size;
4253
- if (this.divisor === void 0)
4254
- delete this.divisor;
4255
- if (this.normalized === void 0)
4256
- delete this.normalized;
4257
- if (this.integer === void 0)
4258
- delete this.integer;
4259
- if (this.buffer === void 0)
4260
- delete this.buffer;
4261
- if (this.index === void 0)
4262
- delete this.index;
4263
- return this;
4264
- }
4265
- };
4266
-
4267
- // src/classic/buffer-with-accessor.ts
4268
- var DEBUG_DATA_LENGTH2 = 10;
4269
- var DEPRECATED_PROPS = {
4270
- offset: "accessor.offset",
4271
- stride: "accessor.stride",
4272
- type: "accessor.type",
4273
- size: "accessor.size",
4274
- divisor: "accessor.divisor",
4275
- normalized: "accessor.normalized",
4276
- integer: "accessor.integer",
4277
- instanced: "accessor.divisor",
4278
- isInstanced: "accessor.divisor"
4279
- };
4280
- var PROP_CHECKS_INITIALIZE = {
4281
- removedProps: {},
4282
- replacedProps: {
4283
- bytes: "byteLength"
4284
- },
4285
- // new Buffer() with individual accessor props is still used in apps, emit warnings
4286
- deprecatedProps: DEPRECATED_PROPS
4287
- };
4288
- var PROP_CHECKS_SET_PROPS = {
4289
- // Buffer.setProps() with individual accessor props is rare => emit errors
4290
- removedProps: DEPRECATED_PROPS
4291
- };
4292
- function getWEBGLBufferProps(props) {
4293
- if (ArrayBuffer.isView(props)) {
4294
- return { data: props };
4295
- } else if (typeof props === "number") {
4296
- return { byteLength: props };
4297
- }
4298
- props = (0, import_core19.checkProps)("Buffer", props, PROP_CHECKS_INITIALIZE);
4299
- const bufferProps = __spreadValues({}, props);
4300
- return bufferProps;
4301
- }
4302
- var BufferWithAccessor = class extends WEBGLBuffer {
4303
- constructor(device, props = {}) {
4304
- super(WebGLDevice.attach(device), getWEBGLBufferProps(props));
4305
- this.setAccessor(Object.assign({}, props, props.accessor));
4306
- if (this.props.data) {
4307
- const type = getGLTypeFromTypedArray(this.props.data);
4308
- (0, import_core19.assert)(type);
4309
- this.setAccessor(new Accessor(this.accessor, { type }));
4310
- }
4311
- Object.seal(this);
4312
- }
4313
- // override write(data: TypedArray, byteOffset: number = 0): void {
4314
- // this.subData({data, offset: byteOffset});
4315
- // }
4316
- // returns number of elements in the buffer (assuming that the full buffer is used)
4317
- getElementCount(accessor = this.accessor) {
4318
- return Math.round(this.byteLength / Accessor.getBytesPerElement(accessor));
4319
- }
4320
- // returns number of vertices in the buffer (assuming that the full buffer is used)
4321
- getVertexCount(accessor = this.accessor) {
4322
- return Math.round(this.byteLength / Accessor.getBytesPerVertex(accessor));
4323
- }
4324
- // Creates and initializes the buffer object's data store.
4325
- // Signature: `new Buffer(gl, {data: new Float32Array(...)})`
4326
- // Signature: `new Buffer(gl, new Float32Array(...))`
4327
- // Signature: `new Buffer(gl, 100)`
4328
- initialize(props = {}) {
4329
- if (ArrayBuffer.isView(props)) {
4330
- props = { data: props };
4331
- }
4332
- if (Number.isFinite(props)) {
4333
- props = { byteLength: props };
4334
- }
4335
- props = (0, import_core19.checkProps)("Buffer", props, PROP_CHECKS_INITIALIZE);
4336
- this.glUsage = props.glUsage || import_constants18.GL.STATIC_DRAW;
4337
- this.debugData = null;
4338
- this.setAccessor(Object.assign({}, props, props.accessor));
4339
- if (props.data) {
4340
- this._setData(props.data, props.byteOffset, props.byteLength);
4341
- } else {
4342
- this._setByteLength(props.byteLength || 0);
4343
- }
4344
- return this;
4345
- }
4346
- setProps(props) {
4347
- props = (0, import_core19.checkProps)("Buffer", props, PROP_CHECKS_SET_PROPS);
4348
- if ("accessor" in props) {
4349
- this.setAccessor(props.accessor);
4350
- }
4351
- return this;
4352
- }
4353
- // Optionally stores an accessor with the buffer, makes it easier to use it as an attribute later
4354
- // {type, size = 1, offset = 0, stride = 0, normalized = false, integer = false, divisor = 0}
4355
- setAccessor(accessor) {
4356
- accessor = Object.assign({}, accessor);
4357
- delete accessor.buffer;
4358
- this.accessor = new Accessor(accessor);
4359
- return this;
4360
- }
4361
- // Allocate a bigger GPU buffer (if the current buffer is not big enough).
4362
- // If a reallocation is triggered it clears the buffer
4363
- // Returns:
4364
- // `true`: buffer was reallocated, data was cleared
4365
- // `false`: buffer was big enough, data is intact
4366
- reallocate(byteLength) {
4367
- if (byteLength > this.byteLength) {
4368
- this._setByteLength(byteLength);
4369
- return true;
4370
- }
4371
- this.bytesUsed = byteLength;
4372
- return false;
4373
- }
4374
- // Update with new data. Reinitializes the buffer
4375
- setData(props) {
4376
- return this.initialize(props);
4377
- }
4378
- // Updates a subset of a buffer object's data store.
4379
- // Data (Typed Array or ArrayBuffer), length is inferred unless provided
4380
- // Offset into buffer
4381
- // WebGL2 only: Offset into srcData
4382
- // WebGL2 only: Number of bytes to be copied
4383
- subData(options) {
4384
- if (ArrayBuffer.isView(options)) {
4385
- options = { data: options };
4386
- }
4387
- const { data, offset = 0, srcOffset = 0 } = options;
4388
- const byteLength = options.byteLength || options.length;
4389
- (0, import_core19.assert)(data);
4390
- const glTarget = this.gl.webgl2 ? import_constants18.GL.COPY_WRITE_BUFFER : this.glTarget;
4391
- this.gl.bindBuffer(glTarget, this.handle);
4392
- if (srcOffset !== 0 || byteLength !== void 0) {
4393
- assertWebGL2Context(this.gl);
4394
- this.gl.bufferSubData(this.glTarget, offset, data, srcOffset, byteLength);
4395
- } else {
4396
- this.gl.bufferSubData(glTarget, offset, data);
4397
- }
4398
- this.gl.bindBuffer(glTarget, null);
4399
- this.debugData = null;
4400
- this._inferType(data);
4401
- return this;
4402
- }
4403
- /**
4404
- * Copies part of the data of another buffer into this buffer
4405
- * @note WEBGL2 ONLY
4406
- */
4407
- copyData(options) {
4408
- const { sourceBuffer, readOffset = 0, writeOffset = 0, size } = options;
4409
- const { gl, gl2 } = this;
4410
- assertWebGL2Context(gl);
4411
- gl.bindBuffer(import_constants18.GL.COPY_READ_BUFFER, sourceBuffer.handle);
4412
- gl.bindBuffer(import_constants18.GL.COPY_WRITE_BUFFER, this.handle);
4413
- gl2 == null ? void 0 : gl2.copyBufferSubData(import_constants18.GL.COPY_READ_BUFFER, import_constants18.GL.COPY_WRITE_BUFFER, readOffset, writeOffset, size);
4414
- gl.bindBuffer(import_constants18.GL.COPY_READ_BUFFER, null);
4415
- gl.bindBuffer(import_constants18.GL.COPY_WRITE_BUFFER, null);
4416
- this.debugData = null;
4417
- return this;
4418
- }
4419
- /**
4420
- * Reads data from buffer into an ArrayBufferView or SharedArrayBuffer.
4421
- * @note WEBGL2 ONLY
4422
- */
4423
- getData(options) {
4424
- var _a;
4425
- let { dstData = null, length = 0 } = options || {};
4426
- const { srcByteOffset = 0, dstOffset = 0 } = options || {};
4427
- assertWebGL2Context(this.gl);
4428
- const ArrayType = getTypedArrayFromGLType(this.accessor.type || import_constants18.GL.FLOAT, { clamped: false });
4429
- const sourceAvailableElementCount = this._getAvailableElementCount(srcByteOffset);
4430
- const dstElementOffset = dstOffset;
4431
- let dstAvailableElementCount;
4432
- let dstElementCount;
4433
- if (dstData) {
4434
- dstElementCount = dstData.length;
4435
- dstAvailableElementCount = dstElementCount - dstElementOffset;
4436
- } else {
4437
- dstAvailableElementCount = Math.min(
4438
- sourceAvailableElementCount,
4439
- length || sourceAvailableElementCount
4440
- );
4441
- dstElementCount = dstElementOffset + dstAvailableElementCount;
4442
- }
4443
- const copyElementCount = Math.min(sourceAvailableElementCount, dstAvailableElementCount);
4444
- length = length || copyElementCount;
4445
- (0, import_core19.assert)(length <= copyElementCount);
4446
- dstData = dstData || new ArrayType(dstElementCount);
4447
- this.gl.bindBuffer(import_constants18.GL.COPY_READ_BUFFER, this.handle);
4448
- (_a = this.gl2) == null ? void 0 : _a.getBufferSubData(import_constants18.GL.COPY_READ_BUFFER, srcByteOffset, dstData, dstOffset, length);
4449
- this.gl.bindBuffer(import_constants18.GL.COPY_READ_BUFFER, null);
4450
- return dstData;
4451
- }
4452
- /**
4453
- * Binds a buffer to a given binding point (target).
4454
- * GL.TRANSFORM_FEEDBACK_BUFFER and GL.UNIFORM_BUFFER take an index, and optionally a range.
4455
- * - GL.TRANSFORM_FEEDBACK_BUFFER and GL.UNIFORM_BUFFER need an index to affect state
4456
- * - GL.UNIFORM_BUFFER: `offset` must be aligned to GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT.
4457
- * - GL.UNIFORM_BUFFER: `size` must be a minimum of GL.UNIFORM_BLOCK_SIZE_DATA.
4458
- */
4459
- bind(options) {
4460
- var _a, _b;
4461
- const {
4462
- glTarget = this.glTarget,
4463
- // target for the bind operation
4464
- index = this.accessor && this.accessor.index,
4465
- // index = index of target (indexed bind point)
4466
- offset = 0,
4467
- size
4468
- } = options || {};
4469
- if (glTarget === import_constants18.GL.UNIFORM_BUFFER || glTarget === import_constants18.GL.TRANSFORM_FEEDBACK_BUFFER) {
4470
- if (size !== void 0) {
4471
- (_a = this.gl2) == null ? void 0 : _a.bindBufferRange(glTarget, index, this.handle, offset, size);
4472
- } else {
4473
- (0, import_core19.assert)(offset === 0);
4474
- (_b = this.gl2) == null ? void 0 : _b.bindBufferBase(glTarget, index, this.handle);
4475
- }
4476
- } else {
4477
- this.gl.bindBuffer(glTarget, this.handle);
4478
- }
4479
- return this;
4480
- }
4481
- unbind(options) {
4482
- var _a;
4483
- const { glTarget = this.glTarget, index = this.accessor && this.accessor.index } = options || {};
4484
- const isIndexedBuffer = glTarget === import_constants18.GL.UNIFORM_BUFFER || glTarget === import_constants18.GL.TRANSFORM_FEEDBACK_BUFFER;
4485
- if (isIndexedBuffer) {
4486
- (_a = this.gl2) == null ? void 0 : _a.bindBufferBase(glTarget, index, null);
4487
- } else {
4488
- this.gl.bindBuffer(glTarget, null);
4489
- }
4490
- return this;
4491
- }
4492
- // PROTECTED METHODS (INTENDED FOR USE BY OTHER FRAMEWORK CODE ONLY)
4493
- // Returns a short initial data array
4494
- getDebugData() {
4495
- if (!this.debugData) {
4496
- this.debugData = this.getData({ length: Math.min(DEBUG_DATA_LENGTH2, this.byteLength) });
4497
- return { data: this.debugData, changed: true };
4498
- }
4499
- return { data: this.debugData, changed: false };
4500
- }
4501
- invalidateDebugData() {
4502
- this.debugData = null;
4503
- }
4504
- // PRIVATE METHODS
4505
- // Allocate a new buffer and initialize to contents of typed array
4506
- _setData(data, offset = 0, byteLength = data.byteLength + offset) {
4507
- (0, import_core19.assert)(ArrayBuffer.isView(data));
4508
- this.trackDeallocatedMemory();
4509
- const target = this._getTarget();
4510
- this.gl.bindBuffer(target, this.handle);
4511
- this.gl.bufferData(target, byteLength, this.glUsage);
4512
- this.gl.bufferSubData(target, offset, data);
4513
- this.gl.bindBuffer(target, null);
4514
- this.debugData = data.slice(0, DEBUG_DATA_LENGTH2);
4515
- this.bytesUsed = byteLength;
4516
- this.byteLength = byteLength;
4517
- this.trackAllocatedMemory(byteLength);
4518
- const type = getGLTypeFromTypedArray(data);
4519
- (0, import_core19.assert)(type);
4520
- this.setAccessor(new Accessor(this.accessor, { type }));
4521
- return this;
4522
- }
4523
- // Allocate a GPU buffer of specified size.
4524
- _setByteLength(byteLength) {
4525
- (0, import_core19.assert)(byteLength >= 0);
4526
- this.trackDeallocatedMemory();
4527
- let data = byteLength;
4528
- if (byteLength === 0) {
4529
- data = new Float32Array(0);
4530
- }
4531
- const glTarget = this._getTarget();
4532
- this.gl.bindBuffer(glTarget, this.handle);
4533
- this.gl.bufferData(glTarget, data, this.glUsage);
4534
- this.gl.bindBuffer(glTarget, null);
4535
- this.debugData = null;
4536
- this.bytesUsed = byteLength;
4537
- this.byteLength = byteLength;
4538
- this.trackAllocatedMemory(byteLength);
4539
- return this;
4540
- }
4541
- // Binding a buffer for the first time locks the type
4542
- // In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type
4543
- _getTarget() {
4544
- return this.gl.webgl2 ? import_constants18.GL.COPY_WRITE_BUFFER : this.glTarget;
4545
- }
4546
- _getAvailableElementCount(srcByteOffset) {
4547
- const ArrayType = getTypedArrayFromGLType(this.accessor.type || import_constants18.GL.FLOAT, { clamped: false });
4548
- const sourceElementOffset = srcByteOffset / ArrayType.BYTES_PER_ELEMENT;
4549
- return this.getElementCount() - sourceElementOffset;
4550
- }
4551
- // Automatically infers type from typed array passed to setData
4552
- // Note: No longer that useful, since type is now autodeduced from the compiled shaders
4553
- _inferType(data) {
4554
- if (!this.accessor.type) {
4555
- this.setAccessor(new Accessor(this.accessor, { type: getGLTypeFromTypedArray(data) }));
4556
- }
4557
- }
4558
- // RESOURCE METHODS
4559
- getParameter(pname) {
4560
- this.gl.bindBuffer(this.glTarget, this.handle);
4561
- const value = this.gl.getBufferParameter(this.glTarget, pname);
4562
- this.gl.bindBuffer(this.glTarget, null);
4563
- return value;
4564
- }
4565
- // DEPRECATIONS - v7.0
4566
- /** @deprecated Use Buffer.accessor.type */
4567
- get type() {
4568
- return this.accessor.type;
4569
- }
4570
- };
4571
-
4572
- // src/adapter/resources/webgl-shader.ts
4573
- var import_core20 = require("@luma.gl/core");
4574
- var import_constants19 = require("@luma.gl/constants");
4575
4096
 
4576
4097
  // src/adapter/helpers/get-shader-info.ts
4577
4098
  function getShaderInfo(source, defaultName) {
@@ -4631,16 +4152,16 @@ function parseShaderCompilerLog(errLog) {
4631
4152
  }
4632
4153
 
4633
4154
  // src/adapter/resources/webgl-shader.ts
4634
- var WEBGLShader = class extends import_core20.Shader {
4155
+ var WEBGLShader = class extends import_core18.Shader {
4635
4156
  constructor(device, props) {
4636
4157
  super(device, __spreadValues({ id: getShaderIdFromProps(props) }, props));
4637
4158
  this.device = device;
4638
4159
  switch (this.props.stage) {
4639
4160
  case "vertex":
4640
- this.handle = this.props.handle || this.device.gl.createShader(import_constants19.GL.VERTEX_SHADER);
4161
+ this.handle = this.props.handle || this.device.gl.createShader(import_constants16.GL.VERTEX_SHADER);
4641
4162
  break;
4642
4163
  case "fragment":
4643
- this.handle = this.props.handle || this.device.gl.createShader(import_constants19.GL.FRAGMENT_SHADER);
4164
+ this.handle = this.props.handle || this.device.gl.createShader(import_constants16.GL.FRAGMENT_SHADER);
4644
4165
  break;
4645
4166
  default:
4646
4167
  throw new Error(this.props.stage);
@@ -4656,8 +4177,8 @@ var WEBGLShader = class extends import_core20.Shader {
4656
4177
  }
4657
4178
  compilationInfo() {
4658
4179
  return __async(this, null, function* () {
4659
- const log9 = this.device.gl.getShaderInfoLog(this.handle);
4660
- return log9 ? parseShaderCompilerLog(log9) : [];
4180
+ const log10 = this.device.gl.getShaderInfoLog(this.handle);
4181
+ return log10 ? parseShaderCompilerLog(log10) : [];
4661
4182
  });
4662
4183
  }
4663
4184
  // PRIVATE METHODS
@@ -4668,32 +4189,32 @@ ${source2}`;
4668
4189
  const { gl } = this.device;
4669
4190
  gl.shaderSource(this.handle, source);
4670
4191
  gl.compileShader(this.handle);
4671
- const compileStatus = gl.getShaderParameter(this.handle, import_constants19.GL.COMPILE_STATUS);
4192
+ const compileStatus = gl.getShaderParameter(this.handle, import_constants16.GL.COMPILE_STATUS);
4672
4193
  if (!compileStatus) {
4673
4194
  const shaderLog = gl.getShaderInfoLog(this.handle);
4674
4195
  const parsedLog = shaderLog ? parseShaderCompilerLog(shaderLog) : [];
4675
4196
  const messages = parsedLog.filter((message2) => message2.type === "error");
4676
- const formattedLog = (0, import_core20.formatCompilerLog)(messages, source, { showSourceCode: true });
4197
+ const formattedLog = (0, import_core18.formatCompilerLog)(messages, source, { showSourceCode: true });
4677
4198
  const shaderName = getShaderInfo(source).name;
4678
4199
  const shaderDescription = `${this.stage} shader ${shaderName}`;
4679
- import_core20.log.error(`GLSL compilation errors in ${shaderDescription}
4200
+ import_core18.log.error(`GLSL compilation errors in ${shaderDescription}
4680
4201
  ${formattedLog}`)();
4681
4202
  throw new Error(`GLSL compilation errors in ${shaderName}`);
4682
4203
  }
4683
4204
  }
4684
4205
  };
4685
4206
  function getShaderIdFromProps(props) {
4686
- return getShaderInfo(props.source).name || props.id || (0, import_core20.uid)(`unnamed ${props.stage}-shader`);
4207
+ return getShaderInfo(props.source).name || props.id || (0, import_core18.uid)(`unnamed ${props.stage}-shader`);
4687
4208
  }
4688
4209
 
4689
4210
  // src/adapter/resources/webgl-render-pass.ts
4690
- var import_core21 = require("@luma.gl/core");
4691
- var import_constants20 = require("@luma.gl/constants");
4211
+ var import_core19 = require("@luma.gl/core");
4212
+ var import_constants17 = require("@luma.gl/constants");
4692
4213
  var GL_DEPTH_BUFFER_BIT = 256;
4693
4214
  var GL_STENCIL_BUFFER_BIT = 1024;
4694
4215
  var GL_COLOR_BUFFER_BIT = 16384;
4695
4216
  var GL_COLOR = 6144;
4696
- var WEBGLRenderPass = class extends import_core21.RenderPass {
4217
+ var WEBGLRenderPass = class extends import_core19.RenderPass {
4697
4218
  constructor(device, props) {
4698
4219
  super(device, props);
4699
4220
  this.device = device;
@@ -4729,7 +4250,7 @@ var WEBGLRenderPass = class extends import_core21.RenderPass {
4729
4250
  glParameters.depthMask = !this.props.depthReadOnly;
4730
4251
  }
4731
4252
  glParameters.stencilMask = this.props.stencilReadOnly ? 0 : 1;
4732
- glParameters[import_constants20.GL.RASTERIZER_DISCARD] = this.props.discard;
4253
+ glParameters[import_constants17.GL.RASTERIZER_DISCARD] = this.props.discard;
4733
4254
  if (parameters.viewport) {
4734
4255
  if (parameters.viewport.length >= 6) {
4735
4256
  glParameters.viewport = parameters.viewport.slice(0, 4);
@@ -4738,149 +4259,321 @@ var WEBGLRenderPass = class extends import_core21.RenderPass {
4738
4259
  glParameters.viewport = parameters.viewport;
4739
4260
  }
4740
4261
  }
4741
- glParameters.scissorTest = Boolean(parameters.scissorRect);
4742
- if (parameters.scissorRect) {
4743
- glParameters.scissor = parameters.scissorRect;
4262
+ glParameters.scissorTest = Boolean(parameters.scissorRect);
4263
+ if (parameters.scissorRect) {
4264
+ glParameters.scissor = parameters.scissorRect;
4265
+ }
4266
+ if (parameters.blendConstant) {
4267
+ glParameters.blendColor = parameters.blendConstant;
4268
+ }
4269
+ if (parameters.stencilReference) {
4270
+ console.warn("RenderPassParameters.stencilReference not yet implemented in WebGL");
4271
+ parameters[import_constants17.GL.STENCIL_REF] = parameters.stencilReference;
4272
+ }
4273
+ this.glParameters = glParameters;
4274
+ setGLParameters(this.device, glParameters);
4275
+ }
4276
+ // Internal
4277
+ /**
4278
+ * Optionally clears depth, color and stencil buffers based on parameters
4279
+ */
4280
+ clear() {
4281
+ const glParameters = __spreadValues({}, this.glParameters);
4282
+ let clearMask = 0;
4283
+ if (this.props.clearColor !== false) {
4284
+ clearMask |= GL_COLOR_BUFFER_BIT;
4285
+ glParameters.clearColor = this.props.clearColor;
4286
+ }
4287
+ if (this.props.clearDepth !== false) {
4288
+ clearMask |= GL_DEPTH_BUFFER_BIT;
4289
+ glParameters.clearDepth = this.props.clearDepth;
4290
+ }
4291
+ if (this.props.clearStencil !== false) {
4292
+ clearMask |= GL_STENCIL_BUFFER_BIT;
4293
+ glParameters.clearStencil = this.props.clearStencil;
4294
+ }
4295
+ if (clearMask !== 0) {
4296
+ withGLParameters(this.device, glParameters, () => {
4297
+ this.device.gl.clear(clearMask);
4298
+ });
4299
+ }
4300
+ }
4301
+ /**
4302
+ * WebGL2 - clear a specific color buffer
4303
+ */
4304
+ clearColorBuffer(drawBuffer = 0, value = [0, 0, 0, 0]) {
4305
+ withGLParameters(this.device.gl2, { framebuffer: this.props.framebuffer }, () => {
4306
+ switch (value.constructor) {
4307
+ case Int32Array:
4308
+ this.device.gl2.clearBufferiv(GL_COLOR, drawBuffer, value);
4309
+ break;
4310
+ case Uint32Array:
4311
+ this.device.gl2.clearBufferuiv(GL_COLOR, drawBuffer, value);
4312
+ break;
4313
+ case Float32Array:
4314
+ default:
4315
+ this.device.gl2.clearBufferfv(GL_COLOR, drawBuffer, value);
4316
+ break;
4317
+ }
4318
+ });
4319
+ }
4320
+ // clearDepthStencil() {
4321
+ // const GL_DEPTH = 0x1801;
4322
+ // const GL_STENCIL = 0x1802;
4323
+ // const GL_DEPTH_STENCIL = 0x84f9;
4324
+ // case GL_DEPTH:
4325
+ // this.device.gl2.clearBufferfv(GL_DEPTH, 0, [value]);
4326
+ // break;
4327
+ // case GL_STENCIL:
4328
+ // this.device.gl2.clearBufferiv(GL_STENCIL, 0, [value]);
4329
+ // break;
4330
+ // case GL_DEPTH_STENCIL:
4331
+ // const [depth, stencil] = value;
4332
+ // this.device.gl2.clearBufferfi(GL_DEPTH_STENCIL, 0, depth, stencil);
4333
+ // break;
4334
+ // default:
4335
+ // assert(false, ERR_ARGUMENTS);
4336
+ // }
4337
+ // });
4338
+ };
4339
+
4340
+ // src/adapter/resources/webgl-render-pipeline.ts
4341
+ var import_core21 = require("@luma.gl/core");
4342
+ var import_core22 = require("@luma.gl/core");
4343
+ var import_constants24 = require("@luma.gl/constants");
4344
+
4345
+ // src/adapter/helpers/get-shader-layout.ts
4346
+ var import_constants21 = require("@luma.gl/constants");
4347
+
4348
+ // src/classic/accessor.ts
4349
+ var import_core20 = require("@luma.gl/core");
4350
+ var import_constants19 = require("@luma.gl/constants");
4351
+
4352
+ // src/classic/typed-array-utils.ts
4353
+ var import_constants18 = require("@luma.gl/constants");
4354
+ var ERR_TYPE_DEDUCTION = "Failed to deduce GL constant from typed array";
4355
+ function getGLTypeFromTypedArray(arrayOrType) {
4356
+ const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
4357
+ switch (type) {
4358
+ case Float32Array:
4359
+ return import_constants18.GL.FLOAT;
4360
+ case Uint16Array:
4361
+ return import_constants18.GL.UNSIGNED_SHORT;
4362
+ case Uint32Array:
4363
+ return import_constants18.GL.UNSIGNED_INT;
4364
+ case Uint8Array:
4365
+ return import_constants18.GL.UNSIGNED_BYTE;
4366
+ case Uint8ClampedArray:
4367
+ return import_constants18.GL.UNSIGNED_BYTE;
4368
+ case Int8Array:
4369
+ return import_constants18.GL.BYTE;
4370
+ case Int16Array:
4371
+ return import_constants18.GL.SHORT;
4372
+ case Int32Array:
4373
+ return import_constants18.GL.INT;
4374
+ default:
4375
+ throw new Error(ERR_TYPE_DEDUCTION);
4376
+ }
4377
+ }
4378
+ function getTypedArrayFromGLType(glType, options) {
4379
+ const { clamped = true } = options || {};
4380
+ switch (glType) {
4381
+ case import_constants18.GL.FLOAT:
4382
+ return Float32Array;
4383
+ case import_constants18.GL.UNSIGNED_SHORT:
4384
+ case import_constants18.GL.UNSIGNED_SHORT_5_6_5:
4385
+ case import_constants18.GL.UNSIGNED_SHORT_4_4_4_4:
4386
+ case import_constants18.GL.UNSIGNED_SHORT_5_5_5_1:
4387
+ return Uint16Array;
4388
+ case import_constants18.GL.UNSIGNED_INT:
4389
+ return Uint32Array;
4390
+ case import_constants18.GL.UNSIGNED_BYTE:
4391
+ return clamped ? Uint8ClampedArray : Uint8Array;
4392
+ case import_constants18.GL.BYTE:
4393
+ return Int8Array;
4394
+ case import_constants18.GL.SHORT:
4395
+ return Int16Array;
4396
+ case import_constants18.GL.INT:
4397
+ return Int32Array;
4398
+ default:
4399
+ throw new Error("Failed to deduce typed array type from GL constant");
4400
+ }
4401
+ }
4402
+
4403
+ // src/classic/accessor.ts
4404
+ var DEFAULT_ACCESSOR_VALUES = {
4405
+ offset: 0,
4406
+ stride: 0,
4407
+ type: import_constants19.GL.FLOAT,
4408
+ size: 1,
4409
+ divisor: 0,
4410
+ normalized: false,
4411
+ integer: false
4412
+ };
4413
+ var PROP_CHECKS = {
4414
+ deprecatedProps: {
4415
+ instanced: "divisor",
4416
+ isInstanced: "divisor"
4417
+ }
4418
+ };
4419
+ var Accessor = class {
4420
+ static getBytesPerElement(accessor) {
4421
+ const ArrayType = getTypedArrayFromGLType(accessor.type || import_constants19.GL.FLOAT);
4422
+ return ArrayType.BYTES_PER_ELEMENT;
4423
+ }
4424
+ static getBytesPerVertex(accessor) {
4425
+ (0, import_core20.assert)(accessor.size);
4426
+ const ArrayType = getTypedArrayFromGLType(accessor.type || import_constants19.GL.FLOAT);
4427
+ return ArrayType.BYTES_PER_ELEMENT * accessor.size;
4428
+ }
4429
+ // Combines (merges) a list of accessors. On top of default values
4430
+ // Usually [programAccessor, bufferAccessor, appAccessor]
4431
+ // All props will be set in the returned object.
4432
+ // TODO check for conflicts between values in the supplied accessors
4433
+ static resolve(...accessors) {
4434
+ return new Accessor(...[DEFAULT_ACCESSOR_VALUES, ...accessors]);
4435
+ }
4436
+ constructor(...accessors) {
4437
+ accessors.forEach((accessor) => this._assign(accessor));
4438
+ Object.freeze(this);
4439
+ }
4440
+ toString() {
4441
+ return JSON.stringify(this);
4442
+ }
4443
+ // ACCESSORS
4444
+ // TODO - remove>
4445
+ get BYTES_PER_ELEMENT() {
4446
+ return Accessor.getBytesPerElement(this);
4447
+ }
4448
+ get BYTES_PER_VERTEX() {
4449
+ return Accessor.getBytesPerVertex(this);
4450
+ }
4451
+ // PRIVATE
4452
+ // eslint-disable-next-line complexity, max-statements
4453
+ _assign(props = {}) {
4454
+ props = (0, import_core20.checkProps)("Accessor", props, PROP_CHECKS);
4455
+ if (props.type !== void 0) {
4456
+ this.type = props.type;
4457
+ if (props.type === import_constants19.GL.INT || props.type === import_constants19.GL.UNSIGNED_INT) {
4458
+ this.integer = true;
4459
+ }
4460
+ }
4461
+ if (props.size !== void 0) {
4462
+ this.size = props.size;
4463
+ }
4464
+ if (props.offset !== void 0) {
4465
+ this.offset = props.offset;
4466
+ }
4467
+ if (props.stride !== void 0) {
4468
+ this.stride = props.stride;
4469
+ }
4470
+ if (props.normalize !== void 0) {
4471
+ this.normalized = props.normalize;
4472
+ }
4473
+ if (props.normalized !== void 0) {
4474
+ this.normalized = props.normalized;
4744
4475
  }
4745
- if (parameters.blendConstant) {
4746
- glParameters.blendColor = parameters.blendConstant;
4476
+ if (props.integer !== void 0) {
4477
+ this.integer = props.integer;
4747
4478
  }
4748
- if (parameters.stencilReference) {
4749
- console.warn("RenderPassParameters.stencilReference not yet implemented in WebGL");
4750
- parameters[import_constants20.GL.STENCIL_REF] = parameters.stencilReference;
4479
+ if (props.divisor !== void 0) {
4480
+ this.divisor = props.divisor;
4751
4481
  }
4752
- this.glParameters = glParameters;
4753
- setGLParameters(this.device, glParameters);
4754
- }
4755
- // Internal
4756
- /**
4757
- * Optionally clears depth, color and stencil buffers based on parameters
4758
- */
4759
- clear() {
4760
- const glParameters = __spreadValues({}, this.glParameters);
4761
- let clearMask = 0;
4762
- if (this.props.clearColor !== false) {
4763
- clearMask |= GL_COLOR_BUFFER_BIT;
4764
- glParameters.clearColor = this.props.clearColor;
4482
+ if (props.buffer !== void 0) {
4483
+ this.buffer = props.buffer;
4765
4484
  }
4766
- if (this.props.clearDepth !== false) {
4767
- clearMask |= GL_DEPTH_BUFFER_BIT;
4768
- glParameters.clearDepth = this.props.clearDepth;
4485
+ if (props.index !== void 0) {
4486
+ if (typeof props.index === "boolean") {
4487
+ this.index = props.index ? 1 : 0;
4488
+ } else {
4489
+ this.index = props.index;
4490
+ }
4769
4491
  }
4770
- if (this.props.clearStencil !== false) {
4771
- clearMask |= GL_STENCIL_BUFFER_BIT;
4772
- glParameters.clearStencil = this.props.clearStencil;
4492
+ if (props.instanced !== void 0) {
4493
+ this.divisor = props.instanced ? 1 : 0;
4773
4494
  }
4774
- if (clearMask !== 0) {
4775
- withGLParameters(this.device, glParameters, () => {
4776
- this.device.gl.clear(clearMask);
4777
- });
4495
+ if (props.isInstanced !== void 0) {
4496
+ this.divisor = props.isInstanced ? 1 : 0;
4778
4497
  }
4498
+ if (this.offset === void 0)
4499
+ delete this.offset;
4500
+ if (this.stride === void 0)
4501
+ delete this.stride;
4502
+ if (this.type === void 0)
4503
+ delete this.type;
4504
+ if (this.size === void 0)
4505
+ delete this.size;
4506
+ if (this.divisor === void 0)
4507
+ delete this.divisor;
4508
+ if (this.normalized === void 0)
4509
+ delete this.normalized;
4510
+ if (this.integer === void 0)
4511
+ delete this.integer;
4512
+ if (this.buffer === void 0)
4513
+ delete this.buffer;
4514
+ if (this.index === void 0)
4515
+ delete this.index;
4516
+ return this;
4779
4517
  }
4780
- /**
4781
- * WebGL2 - clear a specific color buffer
4782
- */
4783
- clearColorBuffer(drawBuffer = 0, value = [0, 0, 0, 0]) {
4784
- withGLParameters(this.device.gl2, { framebuffer: this.props.framebuffer }, () => {
4785
- switch (value.constructor) {
4786
- case Int32Array:
4787
- this.device.gl2.clearBufferiv(GL_COLOR, drawBuffer, value);
4788
- break;
4789
- case Uint32Array:
4790
- this.device.gl2.clearBufferuiv(GL_COLOR, drawBuffer, value);
4791
- break;
4792
- case Float32Array:
4793
- default:
4794
- this.device.gl2.clearBufferfv(GL_COLOR, drawBuffer, value);
4795
- break;
4796
- }
4797
- });
4798
- }
4799
- // clearDepthStencil() {
4800
- // const GL_DEPTH = 0x1801;
4801
- // const GL_STENCIL = 0x1802;
4802
- // const GL_DEPTH_STENCIL = 0x84f9;
4803
- // case GL_DEPTH:
4804
- // this.device.gl2.clearBufferfv(GL_DEPTH, 0, [value]);
4805
- // break;
4806
- // case GL_STENCIL:
4807
- // this.device.gl2.clearBufferiv(GL_STENCIL, 0, [value]);
4808
- // break;
4809
- // case GL_DEPTH_STENCIL:
4810
- // const [depth, stencil] = value;
4811
- // this.device.gl2.clearBufferfi(GL_DEPTH_STENCIL, 0, depth, stencil);
4812
- // break;
4813
- // default:
4814
- // assert(false, ERR_ARGUMENTS);
4815
- // }
4816
- // });
4817
4518
  };
4818
4519
 
4819
- // src/adapter/resources/webgl-render-pipeline.ts
4820
- var import_core22 = require("@luma.gl/core");
4821
- var import_core23 = require("@luma.gl/core");
4822
- var import_constants24 = require("@luma.gl/constants");
4823
-
4824
- // src/adapter/helpers/get-shader-layout.ts
4825
- var import_constants22 = require("@luma.gl/constants");
4826
-
4827
4520
  // src/adapter/helpers/decode-webgl-types.ts
4828
- var import_constants21 = require("@luma.gl/constants");
4521
+ var import_constants20 = require("@luma.gl/constants");
4829
4522
  function isSamplerUniform(type) {
4830
4523
  return SAMPLER_TYPES.includes(type);
4831
4524
  }
4832
4525
  var SAMPLER_TYPES = [
4833
- import_constants21.GL.SAMPLER_2D,
4834
- import_constants21.GL.SAMPLER_CUBE,
4835
- import_constants21.GL.SAMPLER_3D,
4836
- import_constants21.GL.SAMPLER_2D_SHADOW,
4837
- import_constants21.GL.SAMPLER_2D_ARRAY,
4838
- import_constants21.GL.SAMPLER_2D_ARRAY_SHADOW,
4839
- import_constants21.GL.SAMPLER_CUBE_SHADOW,
4840
- import_constants21.GL.INT_SAMPLER_2D,
4841
- import_constants21.GL.INT_SAMPLER_3D,
4842
- import_constants21.GL.INT_SAMPLER_CUBE,
4843
- import_constants21.GL.INT_SAMPLER_2D_ARRAY,
4844
- import_constants21.GL.UNSIGNED_INT_SAMPLER_2D,
4845
- import_constants21.GL.UNSIGNED_INT_SAMPLER_3D,
4846
- import_constants21.GL.UNSIGNED_INT_SAMPLER_CUBE,
4847
- import_constants21.GL.UNSIGNED_INT_SAMPLER_2D_ARRAY
4526
+ import_constants20.GL.SAMPLER_2D,
4527
+ import_constants20.GL.SAMPLER_CUBE,
4528
+ import_constants20.GL.SAMPLER_3D,
4529
+ import_constants20.GL.SAMPLER_2D_SHADOW,
4530
+ import_constants20.GL.SAMPLER_2D_ARRAY,
4531
+ import_constants20.GL.SAMPLER_2D_ARRAY_SHADOW,
4532
+ import_constants20.GL.SAMPLER_CUBE_SHADOW,
4533
+ import_constants20.GL.INT_SAMPLER_2D,
4534
+ import_constants20.GL.INT_SAMPLER_3D,
4535
+ import_constants20.GL.INT_SAMPLER_CUBE,
4536
+ import_constants20.GL.INT_SAMPLER_2D_ARRAY,
4537
+ import_constants20.GL.UNSIGNED_INT_SAMPLER_2D,
4538
+ import_constants20.GL.UNSIGNED_INT_SAMPLER_3D,
4539
+ import_constants20.GL.UNSIGNED_INT_SAMPLER_CUBE,
4540
+ import_constants20.GL.UNSIGNED_INT_SAMPLER_2D_ARRAY
4848
4541
  ];
4849
4542
  var COMPOSITE_GL_TYPES = {
4850
- [import_constants21.GL.FLOAT]: [import_constants21.GL.FLOAT, 1, "float", "f32", "float32"],
4851
- [import_constants21.GL.FLOAT_VEC2]: [import_constants21.GL.FLOAT, 2, "vec2", "vec2<f32>", "float32x2"],
4852
- [import_constants21.GL.FLOAT_VEC3]: [import_constants21.GL.FLOAT, 3, "vec3", "vec3<f32>", "float32x3"],
4853
- [import_constants21.GL.FLOAT_VEC4]: [import_constants21.GL.FLOAT, 4, "vec4", "vec4<f32>", "float32x4"],
4854
- [import_constants21.GL.INT]: [import_constants21.GL.INT, 1, "int", "i32", "sint32"],
4855
- [import_constants21.GL.INT_VEC2]: [import_constants21.GL.INT, 2, "ivec2", "vec2<i32>", "sint32x2"],
4856
- [import_constants21.GL.INT_VEC3]: [import_constants21.GL.INT, 3, "ivec3", "vec3<i32>", "sint32x3"],
4857
- [import_constants21.GL.INT_VEC4]: [import_constants21.GL.INT, 4, "ivec4", "vec4<i32>", "sint32x4"],
4858
- [import_constants21.GL.UNSIGNED_INT]: [import_constants21.GL.UNSIGNED_INT, 1, "uint", "u32", "uint32"],
4859
- [import_constants21.GL.UNSIGNED_INT_VEC2]: [import_constants21.GL.UNSIGNED_INT, 2, "uvec2", "vec2<u32>", "uint32x2"],
4860
- [import_constants21.GL.UNSIGNED_INT_VEC3]: [import_constants21.GL.UNSIGNED_INT, 3, "uvec3", "vec3<u32>", "uint32x3"],
4861
- [import_constants21.GL.UNSIGNED_INT_VEC4]: [import_constants21.GL.UNSIGNED_INT, 4, "uvec4", "vec4<u32>", "uint32x4"],
4862
- [import_constants21.GL.BOOL]: [import_constants21.GL.FLOAT, 1, "bool", "f32", "float32"],
4863
- [import_constants21.GL.BOOL_VEC2]: [import_constants21.GL.FLOAT, 2, "bvec2", "vec2<f32>", "float32x2"],
4864
- [import_constants21.GL.BOOL_VEC3]: [import_constants21.GL.FLOAT, 3, "bvec3", "vec3<f32>", "float32x3"],
4865
- [import_constants21.GL.BOOL_VEC4]: [import_constants21.GL.FLOAT, 4, "bvec4", "vec4<f32>", "float32x4"],
4543
+ [import_constants20.GL.FLOAT]: [import_constants20.GL.FLOAT, 1, "float", "f32", "float32"],
4544
+ [import_constants20.GL.FLOAT_VEC2]: [import_constants20.GL.FLOAT, 2, "vec2", "vec2<f32>", "float32x2"],
4545
+ [import_constants20.GL.FLOAT_VEC3]: [import_constants20.GL.FLOAT, 3, "vec3", "vec3<f32>", "float32x3"],
4546
+ [import_constants20.GL.FLOAT_VEC4]: [import_constants20.GL.FLOAT, 4, "vec4", "vec4<f32>", "float32x4"],
4547
+ [import_constants20.GL.INT]: [import_constants20.GL.INT, 1, "int", "i32", "sint32"],
4548
+ [import_constants20.GL.INT_VEC2]: [import_constants20.GL.INT, 2, "ivec2", "vec2<i32>", "sint32x2"],
4549
+ [import_constants20.GL.INT_VEC3]: [import_constants20.GL.INT, 3, "ivec3", "vec3<i32>", "sint32x3"],
4550
+ [import_constants20.GL.INT_VEC4]: [import_constants20.GL.INT, 4, "ivec4", "vec4<i32>", "sint32x4"],
4551
+ [import_constants20.GL.UNSIGNED_INT]: [import_constants20.GL.UNSIGNED_INT, 1, "uint", "u32", "uint32"],
4552
+ [import_constants20.GL.UNSIGNED_INT_VEC2]: [import_constants20.GL.UNSIGNED_INT, 2, "uvec2", "vec2<u32>", "uint32x2"],
4553
+ [import_constants20.GL.UNSIGNED_INT_VEC3]: [import_constants20.GL.UNSIGNED_INT, 3, "uvec3", "vec3<u32>", "uint32x3"],
4554
+ [import_constants20.GL.UNSIGNED_INT_VEC4]: [import_constants20.GL.UNSIGNED_INT, 4, "uvec4", "vec4<u32>", "uint32x4"],
4555
+ [import_constants20.GL.BOOL]: [import_constants20.GL.FLOAT, 1, "bool", "f32", "float32"],
4556
+ [import_constants20.GL.BOOL_VEC2]: [import_constants20.GL.FLOAT, 2, "bvec2", "vec2<f32>", "float32x2"],
4557
+ [import_constants20.GL.BOOL_VEC3]: [import_constants20.GL.FLOAT, 3, "bvec3", "vec3<f32>", "float32x3"],
4558
+ [import_constants20.GL.BOOL_VEC4]: [import_constants20.GL.FLOAT, 4, "bvec4", "vec4<f32>", "float32x4"],
4866
4559
  // TODO - are sizes/components below correct?
4867
- [import_constants21.GL.FLOAT_MAT2]: [import_constants21.GL.FLOAT, 8, "mat2", "mat2x2<f32>"],
4560
+ [import_constants20.GL.FLOAT_MAT2]: [import_constants20.GL.FLOAT, 8, "mat2", "mat2x2<f32>"],
4868
4561
  // 4
4869
- [import_constants21.GL.FLOAT_MAT2x3]: [import_constants21.GL.FLOAT, 8, "mat2x3", "mat2x3<f32>"],
4562
+ [import_constants20.GL.FLOAT_MAT2x3]: [import_constants20.GL.FLOAT, 8, "mat2x3", "mat2x3<f32>"],
4870
4563
  // 6
4871
- [import_constants21.GL.FLOAT_MAT2x4]: [import_constants21.GL.FLOAT, 8, "mat2x4", "mat2x4<f32>"],
4564
+ [import_constants20.GL.FLOAT_MAT2x4]: [import_constants20.GL.FLOAT, 8, "mat2x4", "mat2x4<f32>"],
4872
4565
  // 8
4873
- [import_constants21.GL.FLOAT_MAT3x2]: [import_constants21.GL.FLOAT, 12, "mat3x2", "mat3x2<f32>"],
4566
+ [import_constants20.GL.FLOAT_MAT3x2]: [import_constants20.GL.FLOAT, 12, "mat3x2", "mat3x2<f32>"],
4874
4567
  // 6
4875
- [import_constants21.GL.FLOAT_MAT3]: [import_constants21.GL.FLOAT, 12, "mat3", "mat3x3<f32>"],
4568
+ [import_constants20.GL.FLOAT_MAT3]: [import_constants20.GL.FLOAT, 12, "mat3", "mat3x3<f32>"],
4876
4569
  // 9
4877
- [import_constants21.GL.FLOAT_MAT3x4]: [import_constants21.GL.FLOAT, 12, "mat3x4", "mat3x4<f32>"],
4570
+ [import_constants20.GL.FLOAT_MAT3x4]: [import_constants20.GL.FLOAT, 12, "mat3x4", "mat3x4<f32>"],
4878
4571
  // 12
4879
- [import_constants21.GL.FLOAT_MAT4x2]: [import_constants21.GL.FLOAT, 16, "mat4x2", "mat4x2<f32>"],
4572
+ [import_constants20.GL.FLOAT_MAT4x2]: [import_constants20.GL.FLOAT, 16, "mat4x2", "mat4x2<f32>"],
4880
4573
  // 8
4881
- [import_constants21.GL.FLOAT_MAT4x3]: [import_constants21.GL.FLOAT, 16, "mat4x3", "mat4x3<f32>"],
4574
+ [import_constants20.GL.FLOAT_MAT4x3]: [import_constants20.GL.FLOAT, 16, "mat4x3", "mat4x3<f32>"],
4882
4575
  // 12
4883
- [import_constants21.GL.FLOAT_MAT4]: [import_constants21.GL.FLOAT, 16, "mat4", "mat4x4<f32>"]
4576
+ [import_constants20.GL.FLOAT_MAT4]: [import_constants20.GL.FLOAT, 16, "mat4", "mat4x4<f32>"]
4884
4577
  // 16
4885
4578
  };
4886
4579
  function decodeGLUniformType(glUniformType) {
@@ -4986,7 +4679,7 @@ function readVaryings(gl, program) {
4986
4679
  }
4987
4680
  const gl2 = gl;
4988
4681
  const varyings = [];
4989
- const count = gl.getProgramParameter(program, import_constants22.GL.TRANSFORM_FEEDBACK_VARYINGS);
4682
+ const count = gl.getProgramParameter(program, import_constants21.GL.TRANSFORM_FEEDBACK_VARYINGS);
4990
4683
  for (let location = 0; location < count; location++) {
4991
4684
  const activeInfo = gl2.getTransformFeedbackVarying(program, location);
4992
4685
  if (!activeInfo) {
@@ -5003,7 +4696,7 @@ function readVaryings(gl, program) {
5003
4696
  }
5004
4697
  function readUniformBindings(gl, program) {
5005
4698
  const uniforms = [];
5006
- const uniformCount = gl.getProgramParameter(program, import_constants22.GL.ACTIVE_UNIFORMS);
4699
+ const uniformCount = gl.getProgramParameter(program, import_constants21.GL.ACTIVE_UNIFORMS);
5007
4700
  for (let i = 0; i < uniformCount; i++) {
5008
4701
  const activeInfo = gl.getActiveUniform(program, i);
5009
4702
  if (!activeInfo) {
@@ -5042,22 +4735,22 @@ function readUniformBlocks(gl, program) {
5042
4735
  const gl2 = gl;
5043
4736
  const getBlockParameter = (blockIndex, pname) => gl2.getActiveUniformBlockParameter(program, blockIndex, pname);
5044
4737
  const uniformBlocks = [];
5045
- const blockCount = gl2.getProgramParameter(program, import_constants22.GL.ACTIVE_UNIFORM_BLOCKS);
4738
+ const blockCount = gl2.getProgramParameter(program, import_constants21.GL.ACTIVE_UNIFORM_BLOCKS);
5046
4739
  for (let blockIndex = 0; blockIndex < blockCount; blockIndex++) {
5047
4740
  const blockInfo = {
5048
4741
  name: gl2.getActiveUniformBlockName(program, blockIndex) || "",
5049
- location: getBlockParameter(blockIndex, import_constants22.GL.UNIFORM_BLOCK_BINDING),
5050
- byteLength: getBlockParameter(blockIndex, import_constants22.GL.UNIFORM_BLOCK_DATA_SIZE),
5051
- vertex: getBlockParameter(blockIndex, import_constants22.GL.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER),
5052
- fragment: getBlockParameter(blockIndex, import_constants22.GL.UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER),
5053
- uniformCount: getBlockParameter(blockIndex, import_constants22.GL.UNIFORM_BLOCK_ACTIVE_UNIFORMS),
4742
+ location: getBlockParameter(blockIndex, import_constants21.GL.UNIFORM_BLOCK_BINDING),
4743
+ byteLength: getBlockParameter(blockIndex, import_constants21.GL.UNIFORM_BLOCK_DATA_SIZE),
4744
+ vertex: getBlockParameter(blockIndex, import_constants21.GL.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER),
4745
+ fragment: getBlockParameter(blockIndex, import_constants21.GL.UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER),
4746
+ uniformCount: getBlockParameter(blockIndex, import_constants21.GL.UNIFORM_BLOCK_ACTIVE_UNIFORMS),
5054
4747
  uniforms: []
5055
4748
  };
5056
- const uniformIndices = getBlockParameter(blockIndex, import_constants22.GL.UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) || [];
5057
- const uniformType = gl2.getActiveUniforms(program, uniformIndices, import_constants22.GL.UNIFORM_TYPE);
5058
- const uniformArrayLength = gl2.getActiveUniforms(program, uniformIndices, import_constants22.GL.UNIFORM_SIZE);
5059
- const uniformOffset = gl2.getActiveUniforms(program, uniformIndices, import_constants22.GL.UNIFORM_OFFSET);
5060
- const uniformStride = gl2.getActiveUniforms(program, uniformIndices, import_constants22.GL.UNIFORM_ARRAY_STRIDE);
4749
+ const uniformIndices = getBlockParameter(blockIndex, import_constants21.GL.UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) || [];
4750
+ const uniformType = gl2.getActiveUniforms(program, uniformIndices, import_constants21.GL.UNIFORM_TYPE);
4751
+ const uniformArrayLength = gl2.getActiveUniforms(program, uniformIndices, import_constants21.GL.UNIFORM_SIZE);
4752
+ const uniformOffset = gl2.getActiveUniforms(program, uniformIndices, import_constants21.GL.UNIFORM_OFFSET);
4753
+ const uniformStride = gl2.getActiveUniforms(program, uniformIndices, import_constants21.GL.UNIFORM_ARRAY_STRIDE);
5061
4754
  for (let i = 0; i < blockInfo.uniformCount; ++i) {
5062
4755
  const activeInfo = gl2.getActiveUniform(program, uniformIndices[i]);
5063
4756
  if (!activeInfo) {
@@ -5080,21 +4773,21 @@ function readUniformBlocks(gl, program) {
5080
4773
  return uniformBlocks;
5081
4774
  }
5082
4775
  var SAMPLER_UNIFORMS_GL_TO_GPU = {
5083
- [import_constants22.GL.SAMPLER_2D]: ["2d", "float"],
5084
- [import_constants22.GL.SAMPLER_CUBE]: ["cube", "float"],
5085
- [import_constants22.GL.SAMPLER_3D]: ["3d", "float"],
5086
- [import_constants22.GL.SAMPLER_2D_SHADOW]: ["3d", "depth"],
5087
- [import_constants22.GL.SAMPLER_2D_ARRAY]: ["2d-array", "float"],
5088
- [import_constants22.GL.SAMPLER_2D_ARRAY_SHADOW]: ["2d-array", "depth"],
5089
- [import_constants22.GL.SAMPLER_CUBE_SHADOW]: ["cube", "float"],
5090
- [import_constants22.GL.INT_SAMPLER_2D]: ["2d", "sint"],
5091
- [import_constants22.GL.INT_SAMPLER_3D]: ["3d", "sint"],
5092
- [import_constants22.GL.INT_SAMPLER_CUBE]: ["cube", "sint"],
5093
- [import_constants22.GL.INT_SAMPLER_2D_ARRAY]: ["2d-array", "uint"],
5094
- [import_constants22.GL.UNSIGNED_INT_SAMPLER_2D]: ["2d", "uint"],
5095
- [import_constants22.GL.UNSIGNED_INT_SAMPLER_3D]: ["3d", "uint"],
5096
- [import_constants22.GL.UNSIGNED_INT_SAMPLER_CUBE]: ["cube", "uint"],
5097
- [import_constants22.GL.UNSIGNED_INT_SAMPLER_2D_ARRAY]: ["2d-array", "uint"]
4776
+ [import_constants21.GL.SAMPLER_2D]: ["2d", "float"],
4777
+ [import_constants21.GL.SAMPLER_CUBE]: ["cube", "float"],
4778
+ [import_constants21.GL.SAMPLER_3D]: ["3d", "float"],
4779
+ [import_constants21.GL.SAMPLER_2D_SHADOW]: ["3d", "depth"],
4780
+ [import_constants21.GL.SAMPLER_2D_ARRAY]: ["2d-array", "float"],
4781
+ [import_constants21.GL.SAMPLER_2D_ARRAY_SHADOW]: ["2d-array", "depth"],
4782
+ [import_constants21.GL.SAMPLER_CUBE_SHADOW]: ["cube", "float"],
4783
+ [import_constants21.GL.INT_SAMPLER_2D]: ["2d", "sint"],
4784
+ [import_constants21.GL.INT_SAMPLER_3D]: ["3d", "sint"],
4785
+ [import_constants21.GL.INT_SAMPLER_CUBE]: ["cube", "sint"],
4786
+ [import_constants21.GL.INT_SAMPLER_2D_ARRAY]: ["2d-array", "uint"],
4787
+ [import_constants21.GL.UNSIGNED_INT_SAMPLER_2D]: ["2d", "uint"],
4788
+ [import_constants21.GL.UNSIGNED_INT_SAMPLER_3D]: ["3d", "uint"],
4789
+ [import_constants21.GL.UNSIGNED_INT_SAMPLER_CUBE]: ["cube", "uint"],
4790
+ [import_constants21.GL.UNSIGNED_INT_SAMPLER_2D_ARRAY]: ["2d-array", "uint"]
5098
4791
  };
5099
4792
  function getSamplerInfo(type) {
5100
4793
  const sampler = SAMPLER_UNIFORMS_GL_TO_GPU[type];
@@ -5125,7 +4818,7 @@ function parseUniformName(name) {
5125
4818
  }
5126
4819
 
5127
4820
  // src/adapter/helpers/set-uniform.ts
5128
- var import_constants23 = require("@luma.gl/constants");
4821
+ var import_constants22 = require("@luma.gl/constants");
5129
4822
  function setUniform(gl, location, type, value) {
5130
4823
  const gl2 = gl;
5131
4824
  let uniformValue = value;
@@ -5137,82 +4830,125 @@ function setUniform(gl, location, type, value) {
5137
4830
  }
5138
4831
  const arrayValue = typeof uniformValue === "number" ? [uniformValue] : uniformValue;
5139
4832
  switch (type) {
5140
- case import_constants23.GL.SAMPLER_2D:
5141
- case import_constants23.GL.SAMPLER_CUBE:
5142
- case import_constants23.GL.SAMPLER_3D:
5143
- case import_constants23.GL.SAMPLER_2D_SHADOW:
5144
- case import_constants23.GL.SAMPLER_2D_ARRAY:
5145
- case import_constants23.GL.SAMPLER_2D_ARRAY_SHADOW:
5146
- case import_constants23.GL.SAMPLER_CUBE_SHADOW:
5147
- case import_constants23.GL.INT_SAMPLER_2D:
5148
- case import_constants23.GL.INT_SAMPLER_3D:
5149
- case import_constants23.GL.INT_SAMPLER_CUBE:
5150
- case import_constants23.GL.INT_SAMPLER_2D_ARRAY:
5151
- case import_constants23.GL.UNSIGNED_INT_SAMPLER_2D:
5152
- case import_constants23.GL.UNSIGNED_INT_SAMPLER_3D:
5153
- case import_constants23.GL.UNSIGNED_INT_SAMPLER_CUBE:
5154
- case import_constants23.GL.UNSIGNED_INT_SAMPLER_2D_ARRAY:
4833
+ case import_constants22.GL.SAMPLER_2D:
4834
+ case import_constants22.GL.SAMPLER_CUBE:
4835
+ case import_constants22.GL.SAMPLER_3D:
4836
+ case import_constants22.GL.SAMPLER_2D_SHADOW:
4837
+ case import_constants22.GL.SAMPLER_2D_ARRAY:
4838
+ case import_constants22.GL.SAMPLER_2D_ARRAY_SHADOW:
4839
+ case import_constants22.GL.SAMPLER_CUBE_SHADOW:
4840
+ case import_constants22.GL.INT_SAMPLER_2D:
4841
+ case import_constants22.GL.INT_SAMPLER_3D:
4842
+ case import_constants22.GL.INT_SAMPLER_CUBE:
4843
+ case import_constants22.GL.INT_SAMPLER_2D_ARRAY:
4844
+ case import_constants22.GL.UNSIGNED_INT_SAMPLER_2D:
4845
+ case import_constants22.GL.UNSIGNED_INT_SAMPLER_3D:
4846
+ case import_constants22.GL.UNSIGNED_INT_SAMPLER_CUBE:
4847
+ case import_constants22.GL.UNSIGNED_INT_SAMPLER_2D_ARRAY:
5155
4848
  if (typeof value !== "number") {
5156
4849
  throw new Error("samplers must be set to integers");
5157
4850
  }
5158
4851
  return gl.uniform1i(location, value);
5159
- case import_constants23.GL.FLOAT:
4852
+ case import_constants22.GL.FLOAT:
5160
4853
  return gl.uniform1fv(location, arrayValue);
5161
- case import_constants23.GL.FLOAT_VEC2:
4854
+ case import_constants22.GL.FLOAT_VEC2:
5162
4855
  return gl.uniform2fv(location, arrayValue);
5163
- case import_constants23.GL.FLOAT_VEC3:
4856
+ case import_constants22.GL.FLOAT_VEC3:
5164
4857
  return gl.uniform3fv(location, arrayValue);
5165
- case import_constants23.GL.FLOAT_VEC4:
4858
+ case import_constants22.GL.FLOAT_VEC4:
5166
4859
  return gl.uniform4fv(location, arrayValue);
5167
- case import_constants23.GL.INT:
4860
+ case import_constants22.GL.INT:
5168
4861
  return gl.uniform1iv(location, arrayValue);
5169
- case import_constants23.GL.INT_VEC2:
4862
+ case import_constants22.GL.INT_VEC2:
5170
4863
  return gl.uniform2iv(location, arrayValue);
5171
- case import_constants23.GL.INT_VEC3:
4864
+ case import_constants22.GL.INT_VEC3:
5172
4865
  return gl.uniform3iv(location, arrayValue);
5173
- case import_constants23.GL.INT_VEC4:
4866
+ case import_constants22.GL.INT_VEC4:
5174
4867
  return gl.uniform4iv(location, arrayValue);
5175
- case import_constants23.GL.BOOL:
4868
+ case import_constants22.GL.BOOL:
5176
4869
  return gl.uniform1iv(location, arrayValue);
5177
- case import_constants23.GL.BOOL_VEC2:
4870
+ case import_constants22.GL.BOOL_VEC2:
5178
4871
  return gl.uniform2iv(location, arrayValue);
5179
- case import_constants23.GL.BOOL_VEC3:
4872
+ case import_constants22.GL.BOOL_VEC3:
5180
4873
  return gl.uniform3iv(location, arrayValue);
5181
- case import_constants23.GL.BOOL_VEC4:
4874
+ case import_constants22.GL.BOOL_VEC4:
5182
4875
  return gl.uniform4iv(location, arrayValue);
5183
- case import_constants23.GL.UNSIGNED_INT:
4876
+ case import_constants22.GL.UNSIGNED_INT:
5184
4877
  return gl2.uniform1uiv(location, arrayValue, 1);
5185
- case import_constants23.GL.UNSIGNED_INT_VEC2:
4878
+ case import_constants22.GL.UNSIGNED_INT_VEC2:
5186
4879
  return gl2.uniform2uiv(location, arrayValue, 2);
5187
- case import_constants23.GL.UNSIGNED_INT_VEC3:
4880
+ case import_constants22.GL.UNSIGNED_INT_VEC3:
5188
4881
  return gl2.uniform3uiv(location, arrayValue, 3);
5189
- case import_constants23.GL.UNSIGNED_INT_VEC4:
4882
+ case import_constants22.GL.UNSIGNED_INT_VEC4:
5190
4883
  return gl2.uniform4uiv(location, arrayValue, 4);
5191
- case import_constants23.GL.FLOAT_MAT2:
4884
+ case import_constants22.GL.FLOAT_MAT2:
5192
4885
  return gl.uniformMatrix2fv(location, false, arrayValue);
5193
- case import_constants23.GL.FLOAT_MAT3:
4886
+ case import_constants22.GL.FLOAT_MAT3:
5194
4887
  return gl.uniformMatrix3fv(location, false, arrayValue);
5195
- case import_constants23.GL.FLOAT_MAT4:
4888
+ case import_constants22.GL.FLOAT_MAT4:
5196
4889
  return gl.uniformMatrix4fv(location, false, arrayValue);
5197
- case import_constants23.GL.FLOAT_MAT2x3:
4890
+ case import_constants22.GL.FLOAT_MAT2x3:
5198
4891
  return gl2.uniformMatrix2x3fv(location, false, arrayValue);
5199
- case import_constants23.GL.FLOAT_MAT2x4:
4892
+ case import_constants22.GL.FLOAT_MAT2x4:
5200
4893
  return gl2.uniformMatrix2x4fv(location, false, arrayValue);
5201
- case import_constants23.GL.FLOAT_MAT3x2:
4894
+ case import_constants22.GL.FLOAT_MAT3x2:
5202
4895
  return gl2.uniformMatrix3x2fv(location, false, arrayValue);
5203
- case import_constants23.GL.FLOAT_MAT3x4:
4896
+ case import_constants22.GL.FLOAT_MAT3x4:
5204
4897
  return gl2.uniformMatrix3x4fv(location, false, arrayValue);
5205
- case import_constants23.GL.FLOAT_MAT4x2:
4898
+ case import_constants22.GL.FLOAT_MAT4x2:
5206
4899
  return gl2.uniformMatrix4x2fv(location, false, arrayValue);
5207
- case import_constants23.GL.FLOAT_MAT4x3:
4900
+ case import_constants22.GL.FLOAT_MAT4x3:
5208
4901
  return gl2.uniformMatrix4x3fv(location, false, arrayValue);
5209
4902
  }
5210
4903
  throw new Error("Illegal uniform");
5211
4904
  }
5212
4905
 
4906
+ // src/adapter/helpers/webgl-topology-utils.ts
4907
+ var import_constants23 = require("@luma.gl/constants");
4908
+ function getGLDrawMode(topology) {
4909
+ switch (topology) {
4910
+ case "point-list":
4911
+ return import_constants23.GL.POINTS;
4912
+ case "line-list":
4913
+ return import_constants23.GL.LINES;
4914
+ case "line-strip":
4915
+ return import_constants23.GL.LINE_STRIP;
4916
+ case "line-loop-webgl":
4917
+ return import_constants23.GL.LINE_LOOP;
4918
+ case "triangle-list":
4919
+ return import_constants23.GL.TRIANGLES;
4920
+ case "triangle-strip":
4921
+ return import_constants23.GL.TRIANGLE_STRIP;
4922
+ case "triangle-fan-webgl":
4923
+ return import_constants23.GL.TRIANGLE_FAN;
4924
+ default:
4925
+ throw new Error(topology);
4926
+ }
4927
+ }
4928
+ function getGLPrimitive(topology) {
4929
+ switch (topology) {
4930
+ case "point-list":
4931
+ return import_constants23.GL.POINTS;
4932
+ case "line-list":
4933
+ return import_constants23.GL.LINES;
4934
+ case "line-strip":
4935
+ return import_constants23.GL.LINES;
4936
+ case "line-loop-webgl":
4937
+ return import_constants23.GL.LINES;
4938
+ case "triangle-list":
4939
+ return import_constants23.GL.TRIANGLES;
4940
+ case "triangle-strip":
4941
+ return import_constants23.GL.TRIANGLES;
4942
+ case "triangle-fan-webgl":
4943
+ return import_constants23.GL.TRIANGLES;
4944
+ default:
4945
+ throw new Error(topology);
4946
+ }
4947
+ }
4948
+
5213
4949
  // src/adapter/resources/webgl-render-pipeline.ts
5214
4950
  var LOG_PROGRAM_PERF_PRIORITY = 4;
5215
- var WEBGLRenderPipeline = class extends import_core22.RenderPipeline {
4951
+ var WEBGLRenderPipeline = class extends import_core21.RenderPipeline {
5216
4952
  // TODO are these used?
5217
4953
  constructor(device, props) {
5218
4954
  var _a;
@@ -5228,8 +4964,8 @@ var WEBGLRenderPipeline = class extends import_core22.RenderPipeline {
5228
4964
  this.device = device;
5229
4965
  this.handle = this.props.handle || this.device.gl.createProgram();
5230
4966
  this.device.setSpectorMetadata(this.handle, { id: this.props.id });
5231
- this.vs = (0, import_core22.cast)(props.vs);
5232
- this.fs = (0, import_core22.cast)(props.fs);
4967
+ this.vs = (0, import_core21.cast)(props.vs);
4968
+ this.fs = (0, import_core21.cast)(props.fs);
5233
4969
  const { varyings, bufferMode = import_constants24.GL.SEPARATE_ATTRIBS } = props;
5234
4970
  if (varyings && varyings.length > 0) {
5235
4971
  this.device.assertWebGL2();
@@ -5238,7 +4974,7 @@ var WEBGLRenderPipeline = class extends import_core22.RenderPipeline {
5238
4974
  }
5239
4975
  this._compileAndLink();
5240
4976
  this.introspectedLayout = getShaderLayout(this.device.gl, this.handle);
5241
- this.shaderLayout = (0, import_core23.mergeShaderLayout)(this.introspectedLayout, props.shaderLayout);
4977
+ this.shaderLayout = (0, import_core22.mergeShaderLayout)(this.introspectedLayout, props.shaderLayout);
5242
4978
  }
5243
4979
  destroy() {
5244
4980
  if (this.handle) {
@@ -5286,13 +5022,13 @@ var WEBGLRenderPipeline = class extends import_core22.RenderPipeline {
5286
5022
  const binding = this.shaderLayout.bindings.find((binding2) => binding2.name === name) || this.shaderLayout.bindings.find((binding2) => binding2.name === `${name}Uniforms`);
5287
5023
  if (!binding) {
5288
5024
  const validBindings = this.shaderLayout.bindings.map((binding2) => `"${binding2.name}"`).join(", ");
5289
- import_core22.log.warn(
5025
+ import_core21.log.warn(
5290
5026
  `Unknown binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`
5291
5027
  )();
5292
5028
  continue;
5293
5029
  }
5294
5030
  if (!value) {
5295
- import_core22.log.warn(`Unsetting binding "${name}" in render pipeline "${this.id}"`)();
5031
+ import_core21.log.warn(`Unsetting binding "${name}" in render pipeline "${this.id}"`)();
5296
5032
  }
5297
5033
  switch (binding.type) {
5298
5034
  case "uniform":
@@ -5306,7 +5042,7 @@ var WEBGLRenderPipeline = class extends import_core22.RenderPipeline {
5306
5042
  }
5307
5043
  break;
5308
5044
  case "sampler":
5309
- import_core22.log.warn(`Ignoring sampler ${name}`)();
5045
+ import_core21.log.warn(`Ignoring sampler ${name}`)();
5310
5046
  break;
5311
5047
  default:
5312
5048
  throw new Error(binding.type);
@@ -5315,9 +5051,9 @@ var WEBGLRenderPipeline = class extends import_core22.RenderPipeline {
5315
5051
  }
5316
5052
  }
5317
5053
  setUniforms(uniforms) {
5318
- const { bindings } = (0, import_core22.splitUniformsAndBindings)(uniforms);
5054
+ const { bindings } = (0, import_core21.splitUniformsAndBindings)(uniforms);
5319
5055
  Object.keys(bindings).forEach((name) => {
5320
- import_core22.log.warn(
5056
+ import_core21.log.warn(
5321
5057
  `Unsupported value "${bindings[name]}" used in setUniforms() for key ${name}. Use setBindings() instead?`
5322
5058
  )();
5323
5059
  });
@@ -5335,10 +5071,11 @@ var WEBGLRenderPipeline = class extends import_core22.RenderPipeline {
5335
5071
  vertexCount,
5336
5072
  // indexCount,
5337
5073
  instanceCount,
5338
- firstVertex = 0
5074
+ firstVertex = 0,
5339
5075
  // firstIndex,
5340
5076
  // firstInstance,
5341
- // baseVertex
5077
+ // baseVertex,
5078
+ transformFeedback
5342
5079
  } = options;
5343
5080
  const glDrawMode = getGLDrawMode(this.props.topology);
5344
5081
  const isIndexed = Boolean(vertexArray.indexBuffer);
@@ -5349,10 +5086,8 @@ var WEBGLRenderPipeline = class extends import_core22.RenderPipeline {
5349
5086
  }
5350
5087
  this.device.gl.useProgram(this.handle);
5351
5088
  vertexArray.bindBeforeRender(renderPass);
5352
- const primitiveMode = getGLPrimitive(this.props.topology);
5353
- const transformFeedback = null;
5354
5089
  if (transformFeedback) {
5355
- transformFeedback.begin(primitiveMode);
5090
+ transformFeedback.begin(this.props.topology);
5356
5091
  }
5357
5092
  this._applyBindings();
5358
5093
  this._applyUniforms();
@@ -5398,10 +5133,10 @@ var WEBGLRenderPipeline = class extends import_core22.RenderPipeline {
5398
5133
  const { gl } = this.device;
5399
5134
  gl.attachShader(this.handle, this.vs.handle);
5400
5135
  gl.attachShader(this.handle, this.fs.handle);
5401
- import_core22.log.time(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
5136
+ import_core21.log.time(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
5402
5137
  gl.linkProgram(this.handle);
5403
- import_core22.log.timeEnd(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
5404
- if (!gl.debug && import_core22.log.level === 0) {
5138
+ import_core21.log.timeEnd(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
5139
+ if (!gl.debug && import_core21.log.level === 0) {
5405
5140
  }
5406
5141
  const linked = gl.getProgramParameter(this.handle, gl.LINK_STATUS);
5407
5142
  if (!linked) {
@@ -5496,7 +5231,7 @@ var WEBGLRenderPipeline = class extends import_core22.RenderPipeline {
5496
5231
  if (value instanceof WEBGLTexture) {
5497
5232
  texture = value;
5498
5233
  } else if (value instanceof WEBGLFramebuffer && value.colorAttachments[0] instanceof WEBGLTexture) {
5499
- import_core22.log.warn(
5234
+ import_core21.log.warn(
5500
5235
  "Passing framebuffer in texture binding may be deprecated. Use fbo.colorAttachments[0] instead"
5501
5236
  )();
5502
5237
  texture = value.colorAttachments[0];
@@ -5530,59 +5265,19 @@ var WEBGLRenderPipeline = class extends import_core22.RenderPipeline {
5530
5265
  }
5531
5266
  }
5532
5267
  };
5533
- function getGLDrawMode(topology) {
5534
- switch (topology) {
5535
- case "point-list":
5536
- return import_constants24.GL.POINTS;
5537
- case "line-list":
5538
- return import_constants24.GL.LINES;
5539
- case "line-strip":
5540
- return import_constants24.GL.LINE_STRIP;
5541
- case "line-loop-webgl":
5542
- return import_constants24.GL.LINE_LOOP;
5543
- case "triangle-list":
5544
- return import_constants24.GL.TRIANGLES;
5545
- case "triangle-strip":
5546
- return import_constants24.GL.TRIANGLE_STRIP;
5547
- case "triangle-fan-webgl":
5548
- return import_constants24.GL.TRIANGLE_FAN;
5549
- default:
5550
- throw new Error(topology);
5551
- }
5552
- }
5553
- function getGLPrimitive(topology) {
5554
- switch (topology) {
5555
- case "point-list":
5556
- return import_constants24.GL.POINTS;
5557
- case "line-list":
5558
- return import_constants24.GL.LINES;
5559
- case "line-strip":
5560
- return import_constants24.GL.LINES;
5561
- case "line-loop-webgl":
5562
- return import_constants24.GL.LINES;
5563
- case "triangle-list":
5564
- return import_constants24.GL.TRIANGLES;
5565
- case "triangle-strip":
5566
- return import_constants24.GL.TRIANGLES;
5567
- case "triangle-fan-webgl":
5568
- return import_constants24.GL.TRIANGLES;
5569
- default:
5570
- throw new Error(topology);
5571
- }
5572
- }
5573
5268
 
5574
5269
  // src/adapter/resources/webgl-command-encoder.ts
5575
- var import_core25 = require("@luma.gl/core");
5270
+ var import_core24 = require("@luma.gl/core");
5576
5271
 
5577
5272
  // src/adapter/resources/webgl-command-buffer.ts
5578
- var import_core24 = require("@luma.gl/core");
5273
+ var import_core23 = require("@luma.gl/core");
5579
5274
  var import_constants25 = require("@luma.gl/constants");
5580
5275
  function cast3(value) {
5581
5276
  return value;
5582
5277
  }
5583
- var WEBGLCommandBuffer = class extends import_core24.CommandBuffer {
5278
+ var WEBGLCommandBuffer = class extends import_core23.CommandBuffer {
5584
5279
  constructor(device) {
5585
- super({});
5280
+ super(device, {});
5586
5281
  this.commands = [];
5587
5282
  this.device = device;
5588
5283
  }
@@ -5663,7 +5358,7 @@ function _copyTextureToBuffer(device, options) {
5663
5358
  if (aspect !== "all") {
5664
5359
  throw new Error("not supported");
5665
5360
  }
5666
- if (mipLevel !== 0 || depthOrArrayLayers !== void 0 || bytesPerRow || rowsPerImage) {
5361
+ if (mipLevel !== 0 || depthOrArrayLayers !== 0 || bytesPerRow || rowsPerImage) {
5667
5362
  throw new Error("not implemented");
5668
5363
  }
5669
5364
  const gl2 = device.assertWebGL2();
@@ -5672,8 +5367,9 @@ function _copyTextureToBuffer(device, options) {
5672
5367
  const webglBuffer = destination;
5673
5368
  const sourceWidth = width || framebuffer.width;
5674
5369
  const sourceHeight = height || framebuffer.height;
5675
- const sourceFormat = import_constants25.GL.RGBA;
5676
- const sourceType = import_constants25.GL.UNSIGNED_BYTE;
5370
+ const sourceParams = getWebGLTextureParameters(framebuffer.texture.format, true);
5371
+ const sourceFormat = sourceParams.dataFormat;
5372
+ const sourceType = sourceParams.type;
5677
5373
  gl2.bindBuffer(import_constants25.GL.PIXEL_PACK_BUFFER, webglBuffer.handle);
5678
5374
  gl2.bindFramebuffer(import_constants25.GL.FRAMEBUFFER, framebuffer.handle);
5679
5375
  gl2.readPixels(
@@ -5757,7 +5453,7 @@ function _copyTextureToTexture(device, options) {
5757
5453
  return texture;
5758
5454
  }
5759
5455
  function getFramebuffer(source) {
5760
- if (source instanceof import_core24.Texture) {
5456
+ if (source instanceof import_core23.Texture) {
5761
5457
  const { width, height, id } = source;
5762
5458
  const framebuffer = source.device.createFramebuffer({
5763
5459
  id: `framebuffer-for-${id}`,
@@ -5771,7 +5467,7 @@ function getFramebuffer(source) {
5771
5467
  }
5772
5468
 
5773
5469
  // src/adapter/resources/webgl-command-encoder.ts
5774
- var WEBGLCommandEncoder = class extends import_core25.CommandEncoder {
5470
+ var WEBGLCommandEncoder = class extends import_core24.CommandEncoder {
5775
5471
  constructor(device, props) {
5776
5472
  super(device, props);
5777
5473
  this.device = device;
@@ -5814,10 +5510,10 @@ var WEBGLCommandEncoder = class extends import_core25.CommandEncoder {
5814
5510
  };
5815
5511
 
5816
5512
  // src/adapter/resources/webgl-vertex-array.ts
5817
- var import_core26 = require("@luma.gl/core");
5513
+ var import_core25 = require("@luma.gl/core");
5818
5514
  var import_constants26 = require("@luma.gl/constants");
5819
5515
  var import_env2 = require("@probe.gl/env");
5820
- var WEBGLVertexArray = class extends import_core26.VertexArray {
5516
+ var WEBGLVertexArray = class extends import_core25.VertexArray {
5821
5517
  // Create a VertexArray
5822
5518
  constructor(device, props) {
5823
5519
  super(device, props);
@@ -5854,7 +5550,7 @@ var WEBGLVertexArray = class extends import_core26.VertexArray {
5854
5550
  */
5855
5551
  setIndexBuffer(indexBuffer) {
5856
5552
  const buffer = indexBuffer;
5857
- if (buffer && buffer.glTarget !== import_constants26.GL.ELEMENT_ARRAY_BUFFER) {
5553
+ if ((buffer == null ? void 0 : buffer.glTarget) !== import_constants26.GL.ELEMENT_ARRAY_BUFFER) {
5858
5554
  throw new Error("Use .setBuffer()");
5859
5555
  }
5860
5556
  this.device.gl2.bindVertexArray(this.handle);
@@ -5980,14 +5676,18 @@ var WEBGLVertexArray = class extends import_core26.VertexArray {
5980
5676
  const constantValue = normalizeConstantArrayValue(value);
5981
5677
  const byteLength = constantValue.byteLength * elementCount;
5982
5678
  const length = constantValue.length * elementCount;
5679
+ if (this.buffer && byteLength !== this.buffer.byteLength) {
5680
+ throw new Error(
5681
+ `Buffer size is immutable, byte length ${byteLength} !== ${this.buffer.byteLength}.`
5682
+ );
5683
+ }
5983
5684
  let updateNeeded = !this.buffer;
5984
5685
  this.buffer = this.buffer || this.device.createBuffer({ byteLength });
5985
- updateNeeded = updateNeeded || this.buffer.reallocate(byteLength);
5986
5686
  updateNeeded = updateNeeded || !compareConstantArrayValues(constantValue, this.bufferValue);
5987
5687
  if (updateNeeded) {
5988
- const typedArray = (0, import_core26.getScratchArray)(value.constructor, length);
5989
- (0, import_core26.fillArray)({ target: typedArray, source: constantValue, start: 0, count: length });
5990
- this.buffer.subData(typedArray);
5688
+ const typedArray = (0, import_core25.getScratchArray)(value.constructor, length);
5689
+ (0, import_core25.fillArray)({ target: typedArray, source: constantValue, start: 0, count: length });
5690
+ this.buffer.write(typedArray);
5991
5691
  this.bufferValue = value;
5992
5692
  }
5993
5693
  return this.buffer;
@@ -6011,6 +5711,146 @@ function compareConstantArrayValues(v1, v2) {
6011
5711
  return true;
6012
5712
  }
6013
5713
 
5714
+ // src/adapter/resources/webgl-transform-feedback.ts
5715
+ var import_core26 = require("@luma.gl/core");
5716
+ var import_constants27 = require("@luma.gl/constants");
5717
+ var WEBGLTransformFeedback = class extends import_core26.TransformFeedback {
5718
+ constructor(device, props) {
5719
+ super(device, props);
5720
+ this.buffers = {};
5721
+ this.unusedBuffers = {};
5722
+ /**
5723
+ * Allows us to avoid a Chrome bug where a buffer that is already bound to a
5724
+ * different target cannot be bound to 'TRANSFORM_FEEDBACK_BUFFER' target.
5725
+ * This a major workaround, see: https://github.com/KhronosGroup/WebGL/issues/2346
5726
+ */
5727
+ this.bindOnUse = true;
5728
+ this._bound = false;
5729
+ device.assertWebGL2();
5730
+ this.device = device;
5731
+ this.gl2 = device.gl2;
5732
+ this.handle = this.props.handle || this.gl2.createTransformFeedback();
5733
+ this.layout = this.props.layout;
5734
+ if (props.buffers) {
5735
+ this.setBuffers(props.buffers);
5736
+ }
5737
+ Object.seal(this);
5738
+ }
5739
+ destroy() {
5740
+ this.gl2.deleteTransformFeedback(this.handle);
5741
+ super.destroy();
5742
+ }
5743
+ begin(topology = "point-list") {
5744
+ this.gl2.bindTransformFeedback(import_constants27.GL.TRANSFORM_FEEDBACK, this.handle);
5745
+ if (this.bindOnUse) {
5746
+ this._bindBuffers();
5747
+ }
5748
+ this.gl2.beginTransformFeedback(getGLPrimitive(topology));
5749
+ }
5750
+ end() {
5751
+ this.gl2.endTransformFeedback();
5752
+ if (!this.bindOnUse) {
5753
+ this._unbindBuffers();
5754
+ }
5755
+ this.gl2.bindTransformFeedback(import_constants27.GL.TRANSFORM_FEEDBACK, null);
5756
+ }
5757
+ // SUBCLASS
5758
+ setBuffers(buffers) {
5759
+ this.buffers = {};
5760
+ this.unusedBuffers = {};
5761
+ this.bind(() => {
5762
+ for (const bufferName in buffers) {
5763
+ this.setBuffer(bufferName, buffers[bufferName]);
5764
+ }
5765
+ });
5766
+ return this;
5767
+ }
5768
+ setBuffer(locationOrName, bufferOrRange) {
5769
+ const location = this._getVaryingIndex(locationOrName);
5770
+ const { buffer, byteLength, byteOffset } = this._getBufferRange(bufferOrRange);
5771
+ if (location < 0) {
5772
+ this.unusedBuffers[locationOrName] = buffer;
5773
+ import_core26.log.warn(`${this.id} unusedBuffers varying buffer ${locationOrName}`)();
5774
+ return this;
5775
+ }
5776
+ this.buffers[location] = { buffer, byteLength, byteOffset };
5777
+ if (!this.bindOnUse) {
5778
+ this._bindBuffer(location, buffer, byteOffset, byteLength);
5779
+ }
5780
+ return this;
5781
+ }
5782
+ bind(funcOrHandle = this.handle) {
5783
+ if (typeof funcOrHandle !== "function") {
5784
+ this.gl2.bindTransformFeedback(import_constants27.GL.TRANSFORM_FEEDBACK, funcOrHandle);
5785
+ return this;
5786
+ }
5787
+ let value;
5788
+ if (!this._bound) {
5789
+ this.gl2.bindTransformFeedback(import_constants27.GL.TRANSFORM_FEEDBACK, this.handle);
5790
+ this._bound = true;
5791
+ value = funcOrHandle();
5792
+ this._bound = false;
5793
+ this.gl2.bindTransformFeedback(import_constants27.GL.TRANSFORM_FEEDBACK, null);
5794
+ } else {
5795
+ value = funcOrHandle();
5796
+ }
5797
+ return value;
5798
+ }
5799
+ unbind() {
5800
+ this.bind(null);
5801
+ }
5802
+ // PRIVATE METHODS
5803
+ /** Extract offsets for bindBufferRange */
5804
+ _getBufferRange(bufferOrRange) {
5805
+ if (bufferOrRange instanceof WEBGLBuffer) {
5806
+ return { buffer: bufferOrRange, byteOffset: 0, byteLength: bufferOrRange.byteLength };
5807
+ }
5808
+ const { buffer, byteOffset = 0, byteLength = bufferOrRange.buffer.byteLength } = bufferOrRange;
5809
+ return { buffer, byteOffset, byteLength };
5810
+ }
5811
+ _getVaryingIndex(locationOrName) {
5812
+ if (isIndex(locationOrName)) {
5813
+ return Number(locationOrName);
5814
+ }
5815
+ for (const varying of this.layout.varyings) {
5816
+ if (locationOrName === varying.name) {
5817
+ return varying.location;
5818
+ }
5819
+ }
5820
+ return -1;
5821
+ }
5822
+ /**
5823
+ * Need to avoid chrome bug where buffer that is already bound to a different target
5824
+ * cannot be bound to 'TRANSFORM_FEEDBACK_BUFFER' target.
5825
+ */
5826
+ _bindBuffers() {
5827
+ for (const bufferIndex in this.buffers) {
5828
+ const { buffer, byteLength, byteOffset } = this._getBufferRange(this.buffers[bufferIndex]);
5829
+ this._bindBuffer(Number(bufferIndex), buffer, byteOffset, byteLength);
5830
+ }
5831
+ }
5832
+ _unbindBuffers() {
5833
+ for (const bufferIndex in this.buffers) {
5834
+ this.gl2.bindBufferBase(import_constants27.GL.TRANSFORM_FEEDBACK_BUFFER, Number(bufferIndex), null);
5835
+ }
5836
+ }
5837
+ _bindBuffer(index, buffer, byteOffset = 0, byteLength) {
5838
+ const handle = buffer && buffer.handle;
5839
+ if (!handle || byteLength === void 0) {
5840
+ this.gl2.bindBufferBase(import_constants27.GL.TRANSFORM_FEEDBACK_BUFFER, index, handle);
5841
+ } else {
5842
+ this.gl2.bindBufferRange(import_constants27.GL.TRANSFORM_FEEDBACK_BUFFER, index, handle, byteOffset, byteLength);
5843
+ }
5844
+ return this;
5845
+ }
5846
+ };
5847
+ function isIndex(value) {
5848
+ if (typeof value === "number") {
5849
+ return Number.isInteger(value);
5850
+ }
5851
+ return /^\d+$/.test(value);
5852
+ }
5853
+
6014
5854
  // src/adapter/webgl-device.ts
6015
5855
  var LOG_LEVEL2 = 1;
6016
5856
  var _WebGLDevice = class extends import_core27.Device {
@@ -6171,7 +6011,7 @@ var _WebGLDevice = class extends import_core27.Device {
6171
6011
  }
6172
6012
  createBuffer(props) {
6173
6013
  const newProps = this._getBufferProps(props);
6174
- return new BufferWithAccessor(this, newProps);
6014
+ return new WEBGLBuffer(this, newProps);
6175
6015
  }
6176
6016
  _createTexture(props) {
6177
6017
  return new WEBGLTexture(this, props);
@@ -6201,7 +6041,10 @@ var _WebGLDevice = class extends import_core27.Device {
6201
6041
  throw new Error("ComputePipeline not supported in WebGL");
6202
6042
  }
6203
6043
  beginComputePass(props) {
6204
- throw new Error("compute shaders not supported in WebGL");
6044
+ throw new Error("ComputePass not supported in WebGL");
6045
+ }
6046
+ createTransformFeedback(props) {
6047
+ return new WEBGLTransformFeedback(this, props);
6205
6048
  }
6206
6049
  getDefaultRenderPass() {
6207
6050
  this.renderPass = this.renderPass || this.beginRenderPass({
@@ -6403,25 +6246,25 @@ function clear(gl, options) {
6403
6246
 
6404
6247
  // src/classic/copy-and-blit.ts
6405
6248
  var import_core30 = require("@luma.gl/core");
6406
- var import_constants28 = require("@luma.gl/constants");
6249
+ var import_constants29 = require("@luma.gl/constants");
6407
6250
 
6408
6251
  // src/classic/format-utils.ts
6409
6252
  var import_core29 = require("@luma.gl/core");
6410
- var import_constants27 = require("@luma.gl/constants");
6253
+ var import_constants28 = require("@luma.gl/constants");
6411
6254
  function glFormatToComponents(format) {
6412
6255
  switch (format) {
6413
- case import_constants27.GL.ALPHA:
6414
- case import_constants27.GL.R32F:
6415
- case import_constants27.GL.RED:
6256
+ case import_constants28.GL.ALPHA:
6257
+ case import_constants28.GL.R32F:
6258
+ case import_constants28.GL.RED:
6416
6259
  return 1;
6417
- case import_constants27.GL.RG32F:
6418
- case import_constants27.GL.RG:
6260
+ case import_constants28.GL.RG32F:
6261
+ case import_constants28.GL.RG:
6419
6262
  return 2;
6420
- case import_constants27.GL.RGB:
6421
- case import_constants27.GL.RGB32F:
6263
+ case import_constants28.GL.RGB:
6264
+ case import_constants28.GL.RGB32F:
6422
6265
  return 3;
6423
- case import_constants27.GL.RGBA:
6424
- case import_constants27.GL.RGBA32F:
6266
+ case import_constants28.GL.RGBA:
6267
+ case import_constants28.GL.RGBA32F:
6425
6268
  return 4;
6426
6269
  default:
6427
6270
  (0, import_core29.assert)(false);
@@ -6430,13 +6273,13 @@ function glFormatToComponents(format) {
6430
6273
  }
6431
6274
  function glTypeToBytes(type) {
6432
6275
  switch (type) {
6433
- case import_constants27.GL.UNSIGNED_BYTE:
6276
+ case import_constants28.GL.UNSIGNED_BYTE:
6434
6277
  return 1;
6435
- case import_constants27.GL.UNSIGNED_SHORT_5_6_5:
6436
- case import_constants27.GL.UNSIGNED_SHORT_4_4_4_4:
6437
- case import_constants27.GL.UNSIGNED_SHORT_5_5_5_1:
6278
+ case import_constants28.GL.UNSIGNED_SHORT_5_6_5:
6279
+ case import_constants28.GL.UNSIGNED_SHORT_4_4_4_4:
6280
+ case import_constants28.GL.UNSIGNED_SHORT_5_5_5_1:
6438
6281
  return 2;
6439
- case import_constants27.GL.FLOAT:
6282
+ case import_constants28.GL.FLOAT:
6440
6283
  return 4;
6441
6284
  default:
6442
6285
  (0, import_core29.assert)(false);
@@ -6450,8 +6293,8 @@ function readPixelsToArray(source, options) {
6450
6293
  const {
6451
6294
  sourceX = 0,
6452
6295
  sourceY = 0,
6453
- sourceFormat = import_constants28.GL.RGBA,
6454
- sourceAttachment = import_constants28.GL.COLOR_ATTACHMENT0
6296
+ sourceFormat = import_constants29.GL.RGBA,
6297
+ sourceAttachment = import_constants29.GL.COLOR_ATTACHMENT0
6455
6298
  // TODO - support gl.readBuffer
6456
6299
  } = options || {};
6457
6300
  let {
@@ -6466,47 +6309,43 @@ function readPixelsToArray(source, options) {
6466
6309
  const { gl, handle } = framebuffer;
6467
6310
  sourceWidth = sourceWidth || framebuffer.width;
6468
6311
  sourceHeight = sourceHeight || framebuffer.height;
6469
- const attachment = sourceAttachment - import_constants28.GL.COLOR_ATTACHMENT0;
6470
- sourceType = sourceType || ((_a = framebuffer.colorAttachments[attachment]) == null ? void 0 : _a.type) || import_constants28.GL.UNSIGNED_BYTE;
6312
+ const attachment = sourceAttachment - import_constants29.GL.COLOR_ATTACHMENT0;
6313
+ sourceType = sourceType || ((_a = framebuffer.colorAttachments[attachment]) == null ? void 0 : _a.type) || import_constants29.GL.UNSIGNED_BYTE;
6471
6314
  target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
6472
6315
  sourceType = sourceType || getGLTypeFromTypedArray(target);
6473
- const prevHandle = gl.bindFramebuffer(import_constants28.GL.FRAMEBUFFER, handle);
6316
+ const prevHandle = gl.bindFramebuffer(import_constants29.GL.FRAMEBUFFER, handle);
6474
6317
  gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
6475
- gl.bindFramebuffer(import_constants28.GL.FRAMEBUFFER, prevHandle || null);
6318
+ gl.bindFramebuffer(import_constants29.GL.FRAMEBUFFER, prevHandle || null);
6476
6319
  if (deleteFramebuffer) {
6477
6320
  framebuffer.destroy();
6478
6321
  }
6479
6322
  return target;
6480
6323
  }
6481
6324
  function readPixelsToBuffer(source, options) {
6482
- const { sourceX = 0, sourceY = 0, sourceFormat = import_constants28.GL.RGBA, targetByteOffset = 0 } = options || {};
6325
+ const { sourceX = 0, sourceY = 0, sourceFormat = import_constants29.GL.RGBA, targetByteOffset = 0 } = options || {};
6483
6326
  let { target, sourceWidth, sourceHeight, sourceType } = options || {};
6484
6327
  const { framebuffer, deleteFramebuffer } = getFramebuffer2(source);
6485
6328
  (0, import_core30.assert)(framebuffer);
6486
6329
  sourceWidth = sourceWidth || framebuffer.width;
6487
6330
  sourceHeight = sourceHeight || framebuffer.height;
6488
6331
  const webglFramebuffer = framebuffer;
6489
- const gl2 = webglFramebuffer.device.assertWebGL2();
6490
- sourceType = sourceType || (target ? target.type : import_constants28.GL.UNSIGNED_BYTE);
6332
+ sourceType = sourceType || import_constants29.GL.UNSIGNED_BYTE;
6491
6333
  if (!target) {
6492
6334
  const components = glFormatToComponents(sourceFormat);
6493
6335
  const byteCount = glTypeToBytes(sourceType);
6494
6336
  const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;
6495
- target = new BufferWithAccessor(gl2, { byteLength, accessor: { type: sourceType, size: components } });
6337
+ target = webglFramebuffer.device.createBuffer({ byteLength });
6496
6338
  }
6497
- target.bind({ glTarget: import_constants28.GL.PIXEL_PACK_BUFFER });
6498
- withGLParameters(gl2, { framebuffer }, () => {
6499
- gl2.readPixels(
6500
- sourceX,
6501
- sourceY,
6502
- sourceWidth,
6503
- sourceHeight,
6504
- sourceFormat,
6505
- sourceType,
6506
- targetByteOffset
6507
- );
6339
+ const commandEncoder = source.device.createCommandEncoder();
6340
+ commandEncoder.copyTextureToBuffer({
6341
+ source,
6342
+ width: sourceWidth,
6343
+ height: sourceHeight,
6344
+ origin: [sourceX, sourceY],
6345
+ destination: target,
6346
+ byteOffset: targetByteOffset
6508
6347
  });
6509
- target.unbind({ glTarget: import_constants28.GL.PIXEL_PACK_BUFFER });
6348
+ commandEncoder.destroy();
6510
6349
  if (deleteFramebuffer) {
6511
6350
  framebuffer.destroy();
6512
6351
  }
@@ -6518,7 +6357,7 @@ function copyToTexture(source, target, options) {
6518
6357
  sourceY = 0,
6519
6358
  // attachment = GL.COLOR_ATTACHMENT0, // TODO - support gl.readBuffer
6520
6359
  targetMipmaplevel = 0,
6521
- targetInternalFormat = import_constants28.GL.RGBA
6360
+ targetInternalFormat = import_constants29.GL.RGBA
6522
6361
  } = options || {};
6523
6362
  let {
6524
6363
  targetX,
@@ -6537,7 +6376,7 @@ function copyToTexture(source, target, options) {
6537
6376
  targetX = targetX || 0;
6538
6377
  targetY = targetY || 0;
6539
6378
  targetZ = targetZ || 0;
6540
- const prevHandle = device.gl.bindFramebuffer(import_constants28.GL.FRAMEBUFFER, handle);
6379
+ const prevHandle = device.gl.bindFramebuffer(import_constants29.GL.FRAMEBUFFER, handle);
6541
6380
  (0, import_core30.assert)(target);
6542
6381
  let texture = null;
6543
6382
  let textureTarget;
@@ -6564,8 +6403,8 @@ function copyToTexture(source, target, options) {
6564
6403
  );
6565
6404
  } else {
6566
6405
  switch (textureTarget) {
6567
- case import_constants28.GL.TEXTURE_2D:
6568
- case import_constants28.GL.TEXTURE_CUBE_MAP:
6406
+ case import_constants29.GL.TEXTURE_2D:
6407
+ case import_constants29.GL.TEXTURE_CUBE_MAP:
6569
6408
  device.gl.copyTexSubImage2D(
6570
6409
  textureTarget,
6571
6410
  targetMipmaplevel,
@@ -6577,8 +6416,8 @@ function copyToTexture(source, target, options) {
6577
6416
  height
6578
6417
  );
6579
6418
  break;
6580
- case import_constants28.GL.TEXTURE_2D_ARRAY:
6581
- case import_constants28.GL.TEXTURE_3D:
6419
+ case import_constants29.GL.TEXTURE_2D_ARRAY:
6420
+ case import_constants29.GL.TEXTURE_3D:
6582
6421
  device.assertWebGL2();
6583
6422
  device.gl2.copyTexSubImage3D(
6584
6423
  textureTarget,
@@ -6598,7 +6437,7 @@ function copyToTexture(source, target, options) {
6598
6437
  if (texture) {
6599
6438
  texture.unbind();
6600
6439
  }
6601
- device.gl.bindFramebuffer(import_constants28.GL.FRAMEBUFFER, prevHandle || null);
6440
+ device.gl.bindFramebuffer(import_constants29.GL.FRAMEBUFFER, prevHandle || null);
6602
6441
  if (deleteFramebuffer) {
6603
6442
  framebuffer.destroy();
6604
6443
  }
@@ -6624,7 +6463,7 @@ function getPixelArray(pixelArray, type, format, width, height) {
6624
6463
  if (pixelArray) {
6625
6464
  return pixelArray;
6626
6465
  }
6627
- type = type || import_constants28.GL.UNSIGNED_BYTE;
6466
+ type = type || import_constants29.GL.UNSIGNED_BYTE;
6628
6467
  const ArrayType = getTypedArrayFromGLType(type, { clamped: false });
6629
6468
  const components = glFormatToComponents(format);
6630
6469
  return new ArrayType(width * height * components);