@luma.gl/webgl 9.0.0-alpha.35 → 9.0.0-alpha.36

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 (73) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts +9 -0
  2. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  3. package/dist/adapter/converters/device-parameters.js +15 -2
  4. package/dist/adapter/converters/device-parameters.js.map +1 -1
  5. package/dist/adapter/resources/webgl-command-buffer.js +0 -1
  6. package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
  7. package/dist/adapter/resources/webgl-render-pass.d.ts +2 -2
  8. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  9. package/dist/adapter/resources/webgl-render-pass.js +5 -3
  10. package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
  11. package/dist/adapter/resources/webgl-render-pipeline.d.ts +23 -28
  12. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  13. package/dist/adapter/resources/webgl-render-pipeline.js +41 -110
  14. package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
  15. package/dist/adapter/resources/webgl-sampler.js.map +1 -1
  16. package/dist/adapter/resources/webgl-shader.js +3 -1
  17. package/dist/adapter/resources/webgl-shader.js.map +1 -1
  18. package/dist/adapter/resources/webgl-texture.js +5 -5
  19. package/dist/adapter/resources/webgl-texture.js.map +1 -1
  20. package/dist/adapter/resources/webgl-vertex-array.d.ts +67 -0
  21. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -0
  22. package/dist/adapter/resources/webgl-vertex-array.js +166 -0
  23. package/dist/adapter/resources/webgl-vertex-array.js.map +1 -0
  24. package/dist/adapter/webgl-device.d.ts +11 -1
  25. package/dist/adapter/webgl-device.d.ts.map +1 -1
  26. package/dist/adapter/webgl-device.js +66 -1
  27. package/dist/adapter/webgl-device.js.map +1 -1
  28. package/dist/classic/clear.js +3 -3
  29. package/dist/classic/clear.js.map +1 -1
  30. package/dist/classic/copy-and-blit.d.ts.map +1 -1
  31. package/dist/classic/copy-and-blit.js +7 -9
  32. package/dist/classic/copy-and-blit.js.map +1 -1
  33. package/dist/context/context/create-browser-context.d.ts.map +1 -1
  34. package/dist/context/context/create-browser-context.js.map +1 -1
  35. package/dist/context/parameters/unified-parameter-api.d.ts +3 -3
  36. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  37. package/dist/context/parameters/unified-parameter-api.js +4 -4
  38. package/dist/context/parameters/unified-parameter-api.js.map +1 -1
  39. package/dist/context/state-tracker/track-context-state.js +3 -3
  40. package/dist/context/state-tracker/track-context-state.js.map +1 -1
  41. package/dist/context/state-tracker/with-parameters.d.ts +1 -1
  42. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  43. package/dist/context/state-tracker/with-parameters.js +3 -3
  44. package/dist/context/state-tracker/with-parameters.js.map +1 -1
  45. package/dist/dist.dev.js +1273 -1179
  46. package/dist/index.cjs +1026 -972
  47. package/dist/index.d.ts +5 -5
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +5 -5
  50. package/dist/index.js.map +1 -1
  51. package/dist.min.js +22 -22
  52. package/package.json +5 -5
  53. package/src/adapter/converters/device-parameters.ts +34 -2
  54. package/src/adapter/resources/webgl-command-buffer.ts +2 -2
  55. package/src/adapter/resources/webgl-render-pass.ts +8 -6
  56. package/src/adapter/resources/webgl-render-pipeline.ts +141 -174
  57. package/src/adapter/resources/webgl-sampler.ts +1 -1
  58. package/src/adapter/resources/webgl-shader.ts +1 -1
  59. package/src/adapter/resources/webgl-texture.ts +5 -5
  60. package/src/adapter/resources/webgl-vertex-array.ts +278 -0
  61. package/src/adapter/webgl-device.ts +137 -11
  62. package/src/classic/clear.ts +3 -3
  63. package/src/classic/copy-and-blit.ts +19 -15
  64. package/src/context/context/create-browser-context.ts +12 -0
  65. package/src/context/parameters/unified-parameter-api.ts +4 -4
  66. package/src/context/state-tracker/track-context-state.ts +3 -3
  67. package/src/context/state-tracker/with-parameters.ts +3 -3
  68. package/src/index.ts +38 -16
  69. package/dist/adapter/objects/webgl-vertex-array-object.d.ts +0 -55
  70. package/dist/adapter/objects/webgl-vertex-array-object.d.ts.map +0 -1
  71. package/dist/adapter/objects/webgl-vertex-array-object.js +0 -173
  72. package/dist/adapter/objects/webgl-vertex-array-object.js.map +0 -1
  73. package/src/adapter/objects/webgl-vertex-array-object.ts +0 -276
package/dist/dist.dev.js CHANGED
@@ -43,7 +43,7 @@ var __exports__ = (() => {
43
43
  WEBGLSampler: () => WEBGLSampler,
44
44
  WEBGLShader: () => WEBGLShader,
45
45
  WEBGLTexture: () => WEBGLTexture,
46
- WEBGLVertexArrayObject: () => WEBGLVertexArrayObject,
46
+ WEBGLVertexArray: () => WEBGLVertexArray,
47
47
  WebGLCanvasContext: () => WebGLCanvasContext,
48
48
  WebGLDevice: () => WebGLDevice,
49
49
  WebGLResource: () => WebGLResource,
@@ -54,7 +54,7 @@ var __exports__ = (() => {
54
54
  clear: () => clear,
55
55
  convertGLToTextureFormat: () => convertGLToTextureFormat,
56
56
  copyToTexture: () => copyToTexture,
57
- getParameters: () => getParameters,
57
+ getGLParameters: () => getGLParameters,
58
58
  getShaderLayout: () => getShaderLayout,
59
59
  getWebGL2Context: () => getWebGL2Context,
60
60
  isWebGL: () => isWebGL,
@@ -65,12 +65,12 @@ var __exports__ = (() => {
65
65
  readPixelsToArray: () => readPixelsToArray,
66
66
  readPixelsToBuffer: () => readPixelsToBuffer,
67
67
  registerHeadlessGL: () => registerHeadlessGL,
68
- resetParameters: () => resetParameters,
68
+ resetGLParameters: () => resetGLParameters,
69
69
  setDeviceParameters: () => setDeviceParameters,
70
- setParameters: () => setParameters,
70
+ setGLParameters: () => setGLParameters,
71
71
  trackContextState: () => trackContextState,
72
72
  withDeviceParameters: () => withDeviceParameters,
73
- withParameters: () => withParameters
73
+ withGLParameters: () => withGLParameters
74
74
  });
75
75
 
76
76
  // src/context/context/create-headless-context.ts
@@ -106,11 +106,11 @@ var __exports__ = (() => {
106
106
  if (!headlessGL) {
107
107
  throw new Error(ERR_HEADLESSGL_LOAD);
108
108
  }
109
- const gl2 = headlessGL(width, height, options);
110
- if (!gl2) {
109
+ const gl = headlessGL(width, height, options);
110
+ if (!gl) {
111
111
  throw new Error(ERR_HEADLESSGL_FAILED);
112
112
  }
113
- return gl2;
113
+ return gl;
114
114
  }
115
115
 
116
116
  // ../../node_modules/@probe.gl/env/dist/lib/is-electron.js
@@ -1150,9 +1150,13 @@ var __exports__ = (() => {
1150
1150
  __publicField(Buffer2, "MAP_WRITE", 2);
1151
1151
  __publicField(Buffer2, "COPY_SRC", 4);
1152
1152
  __publicField(Buffer2, "COPY_DST", 8);
1153
+ /** Index buffer */
1153
1154
  __publicField(Buffer2, "INDEX", 16);
1155
+ /** Vertex buffer */
1154
1156
  __publicField(Buffer2, "VERTEX", 32);
1157
+ /** Uniform buffer */
1155
1158
  __publicField(Buffer2, "UNIFORM", 64);
1159
+ /** Storage buffer */
1156
1160
  __publicField(Buffer2, "STORAGE", 128);
1157
1161
  __publicField(Buffer2, "INDIRECT", 256);
1158
1162
  __publicField(Buffer2, "QUERY_RESOLVE", 512);
@@ -1243,6 +1247,7 @@ var __exports__ = (() => {
1243
1247
  createCommandEncoder(props = {}) {
1244
1248
  throw new Error("not implemented");
1245
1249
  }
1250
+ /** Create a vertex array */
1246
1251
  /** Create a RenderPass */
1247
1252
  /** Create a ComputePass */
1248
1253
  /** Get a renderpass that is set up to render to the primary CanvasContext */
@@ -1448,11 +1453,11 @@ var __exports__ = (() => {
1448
1453
  // PRIVATE
1449
1454
  /** @todo Major hack done to port the CSS methods above, base canvas context should not depend on WebGL */
1450
1455
  getDrawingBufferSize() {
1451
- const gl2 = this.device.gl;
1452
- if (!gl2) {
1456
+ const gl = this.device.gl;
1457
+ if (!gl) {
1453
1458
  throw new Error("canvas size");
1454
1459
  }
1455
- return [gl2.drawingBufferWidth, gl2.drawingBufferHeight];
1460
+ return [gl.drawingBufferWidth, gl.drawingBufferHeight];
1456
1461
  }
1457
1462
  /** Perform platform specific updates (WebGPU vs WebGL) */
1458
1463
  /**
@@ -1612,7 +1617,7 @@ var __exports__ = (() => {
1612
1617
  stage: "vertex",
1613
1618
  source: "",
1614
1619
  sourceMap: null,
1615
- language: "glsl",
1620
+ language: "auto",
1616
1621
  shaderType: 0
1617
1622
  });
1618
1623
 
@@ -1837,12 +1842,13 @@ var __exports__ = (() => {
1837
1842
  return "RenderPipeline";
1838
1843
  }
1839
1844
  hash = "";
1845
+ /** The merged layout */
1846
+ /** Buffer map describing buffer interleaving etc */
1840
1847
  constructor(device, props) {
1841
1848
  super(device, props, _RenderPipeline.defaultProps);
1849
+ this.shaderLayout = this.props.shaderLayout;
1850
+ this.bufferLayout = this.props.bufferLayout || [];
1842
1851
  }
1843
- /** Set attributes (stored on pipeline and set before each call) */
1844
- /** Set attributes (stored on pipeline and set before each call) */
1845
- /** Set constant attributes (WebGL only) */
1846
1852
  /** Set bindings (stored on pipeline and set before each call) */
1847
1853
  /** Uniforms
1848
1854
  * @deprecated Only supported on WebGL devices.
@@ -1868,8 +1874,6 @@ var __exports__ = (() => {
1868
1874
  parameters: {},
1869
1875
  vertexCount: 0,
1870
1876
  instanceCount: 0,
1871
- indices: null,
1872
- attributes: {},
1873
1877
  bindings: {},
1874
1878
  uniforms: {}
1875
1879
  });
@@ -1978,12 +1982,67 @@ var __exports__ = (() => {
1978
1982
  ...Resource.defaultProps
1979
1983
  });
1980
1984
 
1981
- // ../core/src/lib/utils/assert.ts
1982
- function assert2(condition, message2) {
1983
- if (!condition) {
1984
- throw new Error(message2 || "luma.gl: assertion failed.");
1985
+ // ../core/src/adapter/type-utils/decode-attribute-type.ts
1986
+ function decodeShaderAttributeType(attributeType) {
1987
+ const [dataType, components] = TYPE_INFO[attributeType];
1988
+ const integer = dataType === "i32" || dataType === "u32";
1989
+ const signed = dataType !== "u32";
1990
+ const byteLength = TYPE_SIZES[dataType] * components;
1991
+ const defaultVertexFormat = getCompatibleVertexFormat(dataType, components);
1992
+ return {
1993
+ dataType,
1994
+ components,
1995
+ defaultVertexFormat,
1996
+ byteLength,
1997
+ integer,
1998
+ signed
1999
+ };
2000
+ }
2001
+ function getCompatibleVertexFormat(dataType, components) {
2002
+ let vertexType;
2003
+ switch (dataType) {
2004
+ case "f32":
2005
+ vertexType = "float32";
2006
+ break;
2007
+ case "i32":
2008
+ vertexType = "sint32";
2009
+ break;
2010
+ case "u32":
2011
+ vertexType = "uint32";
2012
+ break;
2013
+ case "f16":
2014
+ return components <= 2 ? "float16x2" : "float16x4";
2015
+ }
2016
+ if (components === 1) {
2017
+ return vertexType;
1985
2018
  }
2019
+ return `${vertexType}x${components}`;
1986
2020
  }
2021
+ var TYPE_INFO = {
2022
+ f32: ["f32", 1],
2023
+ "vec2<f32>": ["f32", 2],
2024
+ "vec3<f32>": ["f32", 3],
2025
+ "vec4<f32>": ["f32", 4],
2026
+ f16: ["f16", 1],
2027
+ "vec2<f16>": ["f16", 2],
2028
+ "vec3<f16>": ["f16", 3],
2029
+ "vec4<f16>": ["f16", 4],
2030
+ i32: ["i32", 1],
2031
+ "vec2<i32>": ["i32", 2],
2032
+ "vec3<i32>": ["i32", 3],
2033
+ "vec4<i32>": ["i32", 4],
2034
+ u32: ["u32", 1],
2035
+ "vec2<u32>": ["u32", 2],
2036
+ "vec3<u32>": ["u32", 3],
2037
+ "vec4<u32>": ["u32", 4]
2038
+ };
2039
+ var TYPE_SIZES = {
2040
+ f32: 4,
2041
+ f16: 2,
2042
+ i32: 4,
2043
+ u32: 4
2044
+ // 'bool-webgl': 4,
2045
+ };
1987
2046
 
1988
2047
  // ../core/src/adapter/type-utils/decode-data-type.ts
1989
2048
  function decodeVertexType(type) {
@@ -2001,7 +2060,7 @@ var __exports__ = (() => {
2001
2060
  };
2002
2061
  }
2003
2062
  function getDataTypeBytes(type) {
2004
- const bytes = TYPE_SIZES[type];
2063
+ const bytes = TYPE_SIZES2[type];
2005
2064
  return bytes;
2006
2065
  }
2007
2066
  var TYPE_MAP = {
@@ -2018,7 +2077,7 @@ var __exports__ = (() => {
2018
2077
  uint32: "uint32",
2019
2078
  sint32: "sint32"
2020
2079
  };
2021
- var TYPE_SIZES = {
2080
+ var TYPE_SIZES2 = {
2022
2081
  uint8: 1,
2023
2082
  sint8: 1,
2024
2083
  uint16: 2,
@@ -2054,6 +2113,203 @@ var __exports__ = (() => {
2054
2113
  return result;
2055
2114
  }
2056
2115
 
2116
+ // ../core/src/adapter/attribute-utils/get-attribute-from-layouts.ts
2117
+ function getAttributeInfosFromLayouts(shaderLayout, bufferLayout) {
2118
+ const attributeInfos = {};
2119
+ for (const attribute of shaderLayout.attributes) {
2120
+ attributeInfos[attribute.name] = getAttributeInfoFromLayouts(shaderLayout, bufferLayout, attribute.name);
2121
+ }
2122
+ return attributeInfos;
2123
+ }
2124
+ function getAttributeInfosByLocation(shaderLayout, bufferLayout, maxVertexAttributes = 16) {
2125
+ const attributeInfos = getAttributeInfosFromLayouts(shaderLayout, bufferLayout);
2126
+ const locationInfos = new Array(maxVertexAttributes).fill(null);
2127
+ for (const attributeInfo of Object.values(attributeInfos)) {
2128
+ locationInfos[attributeInfo.location] = attributeInfo;
2129
+ }
2130
+ return locationInfos;
2131
+ }
2132
+ function getAttributeInfoFromLayouts(shaderLayout, bufferLayout, name2) {
2133
+ const shaderDeclaration = getAttributeFromShaderLayout(shaderLayout, name2);
2134
+ const bufferMapping = getAttributeFromBufferLayout(bufferLayout, name2);
2135
+ if (!shaderDeclaration) {
2136
+ return null;
2137
+ }
2138
+ const attributeTypeInfo = decodeShaderAttributeType(shaderDeclaration.type);
2139
+ const vertexFormat = bufferMapping?.vertexFormat || attributeTypeInfo.defaultVertexFormat;
2140
+ const vertexFormatInfo = decodeVertexFormat(vertexFormat);
2141
+ return {
2142
+ attributeName: bufferMapping?.attributeName || shaderDeclaration.name,
2143
+ bufferName: bufferMapping?.bufferName || shaderDeclaration.name,
2144
+ location: shaderDeclaration.location,
2145
+ shaderType: shaderDeclaration.type,
2146
+ shaderDataType: attributeTypeInfo.dataType,
2147
+ shaderComponents: attributeTypeInfo.components,
2148
+ vertexFormat,
2149
+ bufferDataType: vertexFormatInfo.type,
2150
+ bufferComponents: vertexFormatInfo.components,
2151
+ // normalized is a property of the buffer's vertex format
2152
+ normalized: vertexFormatInfo.normalized,
2153
+ // integer is a property of the shader declaration
2154
+ integer: attributeTypeInfo.integer,
2155
+ stepMode: bufferMapping?.stepMode || shaderDeclaration.stepMode,
2156
+ byteOffset: bufferMapping?.byteOffset || 0,
2157
+ byteStride: bufferMapping?.byteStride || 0
2158
+ };
2159
+ }
2160
+ function getAttributeFromShaderLayout(shaderLayout, name2) {
2161
+ const attribute = shaderLayout.attributes.find((attr) => attr.name === name2);
2162
+ if (!attribute) {
2163
+ log.warn(`shader layout attribute "${name2}" not present in shader`);
2164
+ }
2165
+ return attribute || null;
2166
+ }
2167
+ function getAttributeFromBufferLayout(bufferLayouts, name2) {
2168
+ checkBufferLayouts(bufferLayouts);
2169
+ let bufferLayoutInfo = getAttributeFromShortHand(bufferLayouts, name2);
2170
+ if (bufferLayoutInfo) {
2171
+ return bufferLayoutInfo;
2172
+ }
2173
+ bufferLayoutInfo = getAttributeFromAttributesList(bufferLayouts, name2);
2174
+ if (bufferLayoutInfo) {
2175
+ return bufferLayoutInfo;
2176
+ }
2177
+ log.warn(`layout for attribute "${name2}" not present in buffer layout`);
2178
+ return null;
2179
+ }
2180
+ function checkBufferLayouts(bufferLayouts) {
2181
+ for (const bufferLayout of bufferLayouts) {
2182
+ if (bufferLayout.attributes && bufferLayout.format || !bufferLayout.attributes && !bufferLayout.format) {
2183
+ log.warn(`BufferLayout ${name} must have either 'attributes' or 'format' field`);
2184
+ }
2185
+ }
2186
+ }
2187
+ function getAttributeFromShortHand(bufferLayouts, name2) {
2188
+ for (const bufferLayout of bufferLayouts) {
2189
+ if (bufferLayout.format && bufferLayout.name === name2) {
2190
+ return {
2191
+ attributeName: bufferLayout.name,
2192
+ bufferName: name2,
2193
+ stepMode: bufferLayout.stepMode,
2194
+ vertexFormat: bufferLayout.format,
2195
+ // If offset is needed, use `attributes` field.
2196
+ byteOffset: 0,
2197
+ byteStride: bufferLayout.byteStride || 0
2198
+ };
2199
+ }
2200
+ }
2201
+ return null;
2202
+ }
2203
+ function getAttributeFromAttributesList(bufferLayouts, name2) {
2204
+ for (const bufferLayout of bufferLayouts) {
2205
+ let byteStride = bufferLayout.byteStride;
2206
+ if (typeof bufferLayout.byteStride !== "number") {
2207
+ for (const attributeMapping2 of bufferLayout.attributes || []) {
2208
+ const info = decodeVertexFormat(attributeMapping2.format);
2209
+ byteStride += info.byteLength;
2210
+ }
2211
+ }
2212
+ const attributeMapping = bufferLayout.attributes?.find((mapping) => mapping.attribute === name2);
2213
+ if (attributeMapping) {
2214
+ return {
2215
+ attributeName: attributeMapping.attribute,
2216
+ bufferName: bufferLayout.name,
2217
+ stepMode: bufferLayout.stepMode,
2218
+ vertexFormat: attributeMapping.format,
2219
+ byteOffset: attributeMapping.byteOffset,
2220
+ byteStride
2221
+ };
2222
+ }
2223
+ }
2224
+ return null;
2225
+ }
2226
+ function mergeShaderLayout(baseLayout, overrideLayout) {
2227
+ const mergedLayout = {
2228
+ ...baseLayout,
2229
+ attributes: baseLayout.attributes.map((attribute) => ({
2230
+ ...attribute
2231
+ }))
2232
+ };
2233
+ for (const attribute of overrideLayout?.attributes || []) {
2234
+ const baseAttribute = mergedLayout.attributes.find((attr) => attr.name === attribute.name);
2235
+ if (!baseAttribute) {
2236
+ log.warn(`shader layout attribute ${attribute.name} not present in shader`);
2237
+ } else {
2238
+ baseAttribute.type = attribute.type || baseAttribute.type;
2239
+ baseAttribute.stepMode = attribute.stepMode || baseAttribute.stepMode;
2240
+ }
2241
+ }
2242
+ return mergedLayout;
2243
+ }
2244
+
2245
+ // ../core/src/adapter/resources/vertex-array.ts
2246
+ var _VertexArray = class extends Resource {
2247
+ get [Symbol.toStringTag]() {
2248
+ return "VertexArray";
2249
+ }
2250
+ /** Max number of vertex attributes */
2251
+ /** Attribute infos indexed by location - TODO only needed by webgl module? */
2252
+ indexBuffer = null;
2253
+ constructor(device, props) {
2254
+ super(device, props, _VertexArray.defaultProps);
2255
+ this.maxVertexAttributes = device.limits.maxVertexAttributes;
2256
+ this.attributes = new Array(this.maxVertexAttributes).fill(null);
2257
+ this.attributeInfos = getAttributeInfosByLocation(props.renderPipeline.shaderLayout, props.renderPipeline.bufferLayout, this.maxVertexAttributes);
2258
+ }
2259
+ /** Set attributes (stored on pipeline and set before each call) */
2260
+ /** Set attributes (stored on pipeline and set before each call) */
2261
+ /** Set constant attributes (WebGL only) */
2262
+ };
2263
+ var VertexArray = _VertexArray;
2264
+ __publicField(VertexArray, "defaultProps", {
2265
+ ...Resource.defaultProps,
2266
+ renderPipeline: null
2267
+ });
2268
+
2269
+ // ../core/src/lib/utils/assert.ts
2270
+ function assert2(condition, message2) {
2271
+ if (!condition) {
2272
+ throw new Error(message2 || "luma.gl: assertion failed.");
2273
+ }
2274
+ }
2275
+
2276
+ // ../core/src/lib/utils/array-utils-flat.ts
2277
+ var arrayBuffer;
2278
+ function getScratchArrayBuffer(byteLength) {
2279
+ if (!arrayBuffer || arrayBuffer.byteLength < byteLength) {
2280
+ arrayBuffer = new ArrayBuffer(byteLength);
2281
+ }
2282
+ return arrayBuffer;
2283
+ }
2284
+ function getScratchArray(Type, length) {
2285
+ const scratchArrayBuffer = getScratchArrayBuffer(Type.BYTES_PER_ELEMENT * length);
2286
+ return new Type(scratchArrayBuffer, 0, length);
2287
+ }
2288
+ function fillArray(options) {
2289
+ const {
2290
+ target,
2291
+ source,
2292
+ start = 0,
2293
+ count = 1
2294
+ } = options;
2295
+ const length = source.length;
2296
+ const total = count * length;
2297
+ let copied = 0;
2298
+ for (let i = start; copied < length; copied++) {
2299
+ target[i++] = source[copied];
2300
+ }
2301
+ while (copied < total) {
2302
+ if (copied < total - copied) {
2303
+ target.copyWithin(start + copied, start, start + copied);
2304
+ copied *= 2;
2305
+ } else {
2306
+ target.copyWithin(start + copied, start, start + total - copied);
2307
+ copied = total;
2308
+ }
2309
+ }
2310
+ return options.target;
2311
+ }
2312
+
2057
2313
  // ../core/src/adapter/type-utils/decode-texture-format.ts
2058
2314
  var REGEX = /^(rg?b?a?)([0-9]*)([a-z]*)(-srgb)?(-webgl|-unsized)?$/;
2059
2315
  function decodeTextureFormat(format) {
@@ -2160,68 +2416,6 @@ var __exports__ = (() => {
2160
2416
  };
2161
2417
  }
2162
2418
 
2163
- // ../core/src/adapter/type-utils/decode-attribute-type.ts
2164
- function decodeShaderAttributeType(attributeType) {
2165
- const [dataType, components] = TYPE_INFO[attributeType];
2166
- const integer = dataType === "i32" || dataType === "u32";
2167
- const signed = dataType !== "u32";
2168
- const byteLength = TYPE_SIZES2[dataType] * components;
2169
- const defaultVertexFormat = getCompatibleVertexFormat(dataType, components);
2170
- return {
2171
- dataType,
2172
- components,
2173
- defaultVertexFormat,
2174
- byteLength,
2175
- integer,
2176
- signed
2177
- };
2178
- }
2179
- function getCompatibleVertexFormat(dataType, components) {
2180
- let vertexType;
2181
- switch (dataType) {
2182
- case "f32":
2183
- vertexType = "float32";
2184
- break;
2185
- case "i32":
2186
- vertexType = "sint32";
2187
- break;
2188
- case "u32":
2189
- vertexType = "uint32";
2190
- break;
2191
- case "f16":
2192
- return components <= 2 ? "float16x2" : "float16x4";
2193
- }
2194
- if (components === 1) {
2195
- return vertexType;
2196
- }
2197
- return `${vertexType}x${components}`;
2198
- }
2199
- var TYPE_INFO = {
2200
- f32: ["f32", 1],
2201
- "vec2<f32>": ["f32", 2],
2202
- "vec3<f32>": ["f32", 3],
2203
- "vec4<f32>": ["f32", 4],
2204
- f16: ["f16", 1],
2205
- "vec2<f16>": ["f16", 2],
2206
- "vec3<f16>": ["f16", 3],
2207
- "vec4<f16>": ["f16", 4],
2208
- i32: ["i32", 1],
2209
- "vec2<i32>": ["i32", 2],
2210
- "vec3<i32>": ["i32", 3],
2211
- "vec4<i32>": ["i32", 4],
2212
- u32: ["u32", 1],
2213
- "vec2<u32>": ["u32", 2],
2214
- "vec3<u32>": ["u32", 3],
2215
- "vec4<u32>": ["u32", 4]
2216
- };
2217
- var TYPE_SIZES2 = {
2218
- f32: 4,
2219
- f16: 2,
2220
- i32: 4,
2221
- u32: 4
2222
- // 'bool-webgl': 4,
2223
- };
2224
-
2225
2419
  // ../core/src/lib/compiler-log/format-compiler-log.ts
2226
2420
  function formatCompilerLog(shaderLog, source, options) {
2227
2421
  const lines = source.split(/\r?\n/);
@@ -2234,153 +2428,32 @@ var __exports__ = (() => {
2234
2428
  function formatCompilerMessage(message2, lines, lineNum, options) {
2235
2429
  if (options?.showSourceCode) {
2236
2430
  const positionIndicator = message2.linePos > 0 ? `${" ".repeat(message2.linePos + 5)}^^^
2237
- ` : "";
2238
- const numberedLines = getNumberedLines(lines, lineNum);
2239
- return `${numberedLines}${positionIndicator}${message2.type.toUpperCase()}: ${message2.message}
2240
-
2241
- `;
2242
- }
2243
- return `${message2.type.toUpperCase()}: ${message2.message}
2244
- `;
2245
- }
2246
- function getNumberedLines(lines, lineNum) {
2247
- let numberedLines = "";
2248
- for (let line = lineNum - 2; line <= lineNum; line++) {
2249
- const sourceLine = lines[line];
2250
- if (sourceLine !== void 0) {
2251
- numberedLines += `${padLeft(String(line), 4)}: ${sourceLine}
2252
- `;
2253
- }
2254
- }
2255
- return numberedLines;
2256
- }
2257
- function padLeft(string, paddedLength) {
2258
- let result = "";
2259
- for (let i = string.length; i < paddedLength; ++i) {
2260
- result += " ";
2261
- }
2262
- return result + string;
2263
- }
2264
-
2265
- // ../core/src/adapter/attribute-utils/get-attribute-from-layouts.ts
2266
- function getAttributeInfosFromLayouts(shaderLayout, bufferLayout) {
2267
- const attributeInfos = {};
2268
- for (const attribute of shaderLayout.attributes) {
2269
- attributeInfos[attribute.name] = getAttributeInfoFromLayouts(shaderLayout, bufferLayout, attribute.name);
2270
- }
2271
- return attributeInfos;
2272
- }
2273
- function getAttributeInfoFromLayouts(shaderLayout, bufferLayout, name2) {
2274
- const shaderDeclaration = getAttributeFromShaderLayout(shaderLayout, name2);
2275
- const bufferMapping = getAttributeFromBufferLayout(bufferLayout, name2);
2276
- if (!shaderDeclaration) {
2277
- return null;
2278
- }
2279
- const attributeTypeInfo = decodeShaderAttributeType(shaderDeclaration.type);
2280
- const vertexFormat = bufferMapping?.vertexFormat || attributeTypeInfo.defaultVertexFormat;
2281
- const vertexFormatInfo = decodeVertexFormat(vertexFormat);
2282
- return {
2283
- attributeName: bufferMapping?.attributeName || shaderDeclaration.name,
2284
- bufferName: bufferMapping?.bufferName || shaderDeclaration.name,
2285
- location: shaderDeclaration.location,
2286
- shaderType: shaderDeclaration.type,
2287
- shaderDataType: attributeTypeInfo.dataType,
2288
- shaderComponents: attributeTypeInfo.components,
2289
- vertexFormat,
2290
- bufferDataType: vertexFormatInfo.type,
2291
- bufferComponents: vertexFormatInfo.components,
2292
- // normalized is a property of the buffer's vertex format
2293
- normalized: vertexFormatInfo.normalized,
2294
- // integer is a property of the shader declaration
2295
- integer: attributeTypeInfo.integer,
2296
- stepMode: bufferMapping?.stepMode || shaderDeclaration.stepMode,
2297
- byteOffset: bufferMapping?.byteOffset || 0,
2298
- byteStride: bufferMapping?.byteStride || 0
2299
- };
2300
- }
2301
- function getAttributeFromShaderLayout(shaderLayout, name2) {
2302
- const attribute = shaderLayout.attributes.find((attr) => attr.name === name2);
2303
- if (!attribute) {
2304
- log.warn(`shader layout attribute "${name2}" not present in shader`);
2305
- }
2306
- return attribute || null;
2307
- }
2308
- function getAttributeFromBufferLayout(bufferLayouts, name2) {
2309
- checkBufferLayouts(bufferLayouts);
2310
- let bufferLayoutInfo = getAttributeFromShortHand(bufferLayouts, name2);
2311
- if (bufferLayoutInfo) {
2312
- return bufferLayoutInfo;
2313
- }
2314
- bufferLayoutInfo = getAttributeFromAttributesList(bufferLayouts, name2);
2315
- if (bufferLayoutInfo) {
2316
- return bufferLayoutInfo;
2317
- }
2318
- log.warn(`layout for attribute "${name2}" not present in buffer layout`);
2319
- return null;
2320
- }
2321
- function checkBufferLayouts(bufferLayouts) {
2322
- for (const bufferLayout of bufferLayouts) {
2323
- if (bufferLayout.attributes && bufferLayout.format || !bufferLayout.attributes && !bufferLayout.format) {
2324
- log.warn(`BufferLayout ${name} must have either 'attributes' or 'format' field`);
2325
- }
2326
- }
2327
- }
2328
- function getAttributeFromShortHand(bufferLayouts, name2) {
2329
- for (const bufferLayout of bufferLayouts) {
2330
- if (bufferLayout.format && bufferLayout.name === name2) {
2331
- return {
2332
- attributeName: bufferLayout.name,
2333
- bufferName: name2,
2334
- stepMode: bufferLayout.stepMode,
2335
- vertexFormat: bufferLayout.format,
2336
- // If offset is needed, use `attributes` field.
2337
- byteOffset: 0,
2338
- byteStride: bufferLayout.byteStride || 0
2339
- };
2340
- }
2341
- }
2342
- return null;
2343
- }
2344
- function getAttributeFromAttributesList(bufferLayouts, name2) {
2345
- for (const bufferLayout of bufferLayouts) {
2346
- let byteStride = bufferLayout.byteStride;
2347
- if (typeof bufferLayout.byteStride !== "number") {
2348
- for (const attributeMapping2 of bufferLayout.attributes || []) {
2349
- const info = decodeVertexFormat(attributeMapping2.format);
2350
- byteStride += info.byteLength;
2351
- }
2352
- }
2353
- const attributeMapping = bufferLayout.attributes?.find((mapping) => mapping.attribute === name2);
2354
- if (attributeMapping) {
2355
- return {
2356
- attributeName: attributeMapping.attribute,
2357
- bufferName: bufferLayout.name,
2358
- stepMode: bufferLayout.stepMode,
2359
- vertexFormat: attributeMapping.format,
2360
- byteOffset: attributeMapping.byteOffset,
2361
- byteStride
2362
- };
2363
- }
2431
+ ` : "";
2432
+ const numberedLines = getNumberedLines(lines, lineNum);
2433
+ return `${numberedLines}${positionIndicator}${message2.type.toUpperCase()}: ${message2.message}
2434
+
2435
+ `;
2364
2436
  }
2365
- return null;
2437
+ return `${message2.type.toUpperCase()}: ${message2.message}
2438
+ `;
2366
2439
  }
2367
- function mergeShaderLayout(baseLayout, overrideLayout) {
2368
- const mergedLayout = {
2369
- ...baseLayout,
2370
- attributes: baseLayout.attributes.map((attribute) => ({
2371
- ...attribute
2372
- }))
2373
- };
2374
- for (const attribute of overrideLayout?.attributes || []) {
2375
- const baseAttribute = mergedLayout.attributes.find((attr) => attr.name === attribute.name);
2376
- if (!baseAttribute) {
2377
- log.warn(`shader layout attribute ${attribute.name} not present in shader`);
2378
- } else {
2379
- baseAttribute.type = attribute.type || baseAttribute.type;
2380
- baseAttribute.stepMode = attribute.stepMode || baseAttribute.stepMode;
2440
+ function getNumberedLines(lines, lineNum) {
2441
+ let numberedLines = "";
2442
+ for (let line = lineNum - 2; line <= lineNum; line++) {
2443
+ const sourceLine = lines[line];
2444
+ if (sourceLine !== void 0) {
2445
+ numberedLines += `${padLeft(String(line), 4)}: ${sourceLine}
2446
+ `;
2381
2447
  }
2382
2448
  }
2383
- return mergedLayout;
2449
+ return numberedLines;
2450
+ }
2451
+ function padLeft(string, paddedLength) {
2452
+ let result = "";
2453
+ for (let i = string.length; i < paddedLength; ++i) {
2454
+ result += " ";
2455
+ }
2456
+ return result + string;
2384
2457
  }
2385
2458
 
2386
2459
  // ../core/src/lib/utils/cast.ts
@@ -2468,43 +2541,6 @@ var __exports__ = (() => {
2468
2541
  });
2469
2542
  }
2470
2543
 
2471
- // ../core/src/lib/utils/array-utils-flat.ts
2472
- var arrayBuffer;
2473
- function getScratchArrayBuffer(byteLength) {
2474
- if (!arrayBuffer || arrayBuffer.byteLength < byteLength) {
2475
- arrayBuffer = new ArrayBuffer(byteLength);
2476
- }
2477
- return arrayBuffer;
2478
- }
2479
- function getScratchArray(Type, length) {
2480
- const scratchArrayBuffer = getScratchArrayBuffer(Type.BYTES_PER_ELEMENT * length);
2481
- return new Type(scratchArrayBuffer, 0, length);
2482
- }
2483
- function fillArray(options) {
2484
- const {
2485
- target,
2486
- source,
2487
- start = 0,
2488
- count = 1
2489
- } = options;
2490
- const length = source.length;
2491
- const total = count * length;
2492
- let copied = 0;
2493
- for (let i = start; copied < length; copied++) {
2494
- target[i++] = source[copied];
2495
- }
2496
- while (copied < total) {
2497
- if (copied < total - copied) {
2498
- target.copyWithin(start + copied, start, start + copied);
2499
- copied *= 2;
2500
- } else {
2501
- target.copyWithin(start + copied, start, start + total - copied);
2502
- copied = total;
2503
- }
2504
- }
2505
- return options.target;
2506
- }
2507
-
2508
2544
  // src/context/polyfill/polyfill-vertex-array-object.ts
2509
2545
  var glErrorShadow = {};
2510
2546
  function error(msg) {
@@ -2523,43 +2559,43 @@ var __exports__ = (() => {
2523
2559
  error(opt_msg);
2524
2560
  }
2525
2561
  }
2526
- function wrapGLError(gl2) {
2527
- const f = gl2.getError;
2528
- gl2.getError = function getError() {
2562
+ function wrapGLError(gl) {
2563
+ const f = gl.getError;
2564
+ gl.getError = function getError() {
2529
2565
  let err;
2530
2566
  do {
2531
- err = f.apply(gl2);
2532
- if (err !== gl2.NO_ERROR) {
2567
+ err = f.apply(gl);
2568
+ if (err !== gl.NO_ERROR) {
2533
2569
  glErrorShadow[err] = true;
2534
2570
  }
2535
- } while (err !== gl2.NO_ERROR);
2571
+ } while (err !== gl.NO_ERROR);
2536
2572
  for (err in glErrorShadow) {
2537
2573
  if (glErrorShadow[err]) {
2538
2574
  delete glErrorShadow[err];
2539
2575
  return parseInt(err, 10);
2540
2576
  }
2541
2577
  }
2542
- return gl2.NO_ERROR;
2578
+ return gl.NO_ERROR;
2543
2579
  };
2544
2580
  }
2545
2581
  var WebGLVertexArrayObjectOES = function WebGLVertexArrayObjectOES2(ext) {
2546
- const gl2 = ext.gl;
2582
+ const gl = ext.gl;
2547
2583
  this.ext = ext;
2548
2584
  this.isAlive = true;
2549
2585
  this.hasBeenBound = false;
2550
2586
  this.elementArrayBuffer = null;
2551
2587
  this.attribs = new Array(ext.maxVertexAttribs);
2552
2588
  for (let n = 0; n < this.attribs.length; n++) {
2553
- const attrib = new WebGLVertexArrayObjectOES2.VertexAttrib(gl2);
2589
+ const attrib = new WebGLVertexArrayObjectOES2.VertexAttrib(gl);
2554
2590
  this.attribs[n] = attrib;
2555
2591
  }
2556
2592
  this.maxAttrib = 0;
2557
2593
  };
2558
- WebGLVertexArrayObjectOES.VertexAttrib = function VertexAttrib(gl2) {
2594
+ WebGLVertexArrayObjectOES.VertexAttrib = function VertexAttrib(gl) {
2559
2595
  this.enabled = false;
2560
2596
  this.buffer = null;
2561
2597
  this.size = 4;
2562
- this.type = gl2.FLOAT;
2598
+ this.type = gl.FLOAT;
2563
2599
  this.normalized = false;
2564
2600
  this.stride = 16;
2565
2601
  this.offset = 0;
@@ -2569,19 +2605,19 @@ var __exports__ = (() => {
2569
2605
  WebGLVertexArrayObjectOES.VertexAttrib.prototype.recache = function recache() {
2570
2606
  this.cached = [this.size, this.type, this.normalized, this.stride, this.offset].join(":");
2571
2607
  };
2572
- var OESVertexArrayObject = function OESVertexArrayObject2(gl2) {
2608
+ var OESVertexArrayObject = function OESVertexArrayObject2(gl) {
2573
2609
  const self = this;
2574
- this.gl = gl2;
2575
- wrapGLError(gl2);
2610
+ this.gl = gl;
2611
+ wrapGLError(gl);
2576
2612
  const original = this.original = {
2577
- getParameter: gl2.getParameter,
2578
- enableVertexAttribArray: gl2.enableVertexAttribArray,
2579
- disableVertexAttribArray: gl2.disableVertexAttribArray,
2580
- bindBuffer: gl2.bindBuffer,
2581
- getVertexAttrib: gl2.getVertexAttrib,
2582
- vertexAttribPointer: gl2.vertexAttribPointer
2613
+ getParameter: gl.getParameter,
2614
+ enableVertexAttribArray: gl.enableVertexAttribArray,
2615
+ disableVertexAttribArray: gl.disableVertexAttribArray,
2616
+ bindBuffer: gl.bindBuffer,
2617
+ getVertexAttrib: gl.getVertexAttrib,
2618
+ vertexAttribPointer: gl.vertexAttribPointer
2583
2619
  };
2584
- gl2.getParameter = function getParameter(pname) {
2620
+ gl.getParameter = function getParameter(pname) {
2585
2621
  if (pname === self.VERTEX_ARRAY_BINDING_OES) {
2586
2622
  if (self.currentVertexArrayObject === self.defaultVertexArrayObject) {
2587
2623
  return null;
@@ -2590,53 +2626,53 @@ var __exports__ = (() => {
2590
2626
  }
2591
2627
  return original.getParameter.apply(this, arguments);
2592
2628
  };
2593
- gl2.enableVertexAttribArray = function enableVertexAttribArray(index) {
2629
+ gl.enableVertexAttribArray = function enableVertexAttribArray(index) {
2594
2630
  const vao = self.currentVertexArrayObject;
2595
2631
  vao.maxAttrib = Math.max(vao.maxAttrib, index);
2596
2632
  const attrib = vao.attribs[index];
2597
2633
  attrib.enabled = true;
2598
2634
  return original.enableVertexAttribArray.apply(this, arguments);
2599
2635
  };
2600
- gl2.disableVertexAttribArray = function disableVertexAttribArray(index) {
2636
+ gl.disableVertexAttribArray = function disableVertexAttribArray(index) {
2601
2637
  const vao = self.currentVertexArrayObject;
2602
2638
  vao.maxAttrib = Math.max(vao.maxAttrib, index);
2603
2639
  const attrib = vao.attribs[index];
2604
2640
  attrib.enabled = false;
2605
2641
  return original.disableVertexAttribArray.apply(this, arguments);
2606
2642
  };
2607
- gl2.bindBuffer = function bindBuffer2(target, buffer) {
2643
+ gl.bindBuffer = function bindBuffer2(target, buffer) {
2608
2644
  switch (target) {
2609
- case gl2.ARRAY_BUFFER:
2645
+ case gl.ARRAY_BUFFER:
2610
2646
  self.currentArrayBuffer = buffer;
2611
2647
  break;
2612
- case gl2.ELEMENT_ARRAY_BUFFER:
2648
+ case gl.ELEMENT_ARRAY_BUFFER:
2613
2649
  self.currentVertexArrayObject.elementArrayBuffer = buffer;
2614
2650
  break;
2615
2651
  default:
2616
2652
  }
2617
2653
  return original.bindBuffer.apply(this, arguments);
2618
2654
  };
2619
- gl2.getVertexAttrib = function getVertexAttrib(index, pname) {
2655
+ gl.getVertexAttrib = function getVertexAttrib(index, pname) {
2620
2656
  const vao = self.currentVertexArrayObject;
2621
2657
  const attrib = vao.attribs[index];
2622
2658
  switch (pname) {
2623
- case gl2.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
2659
+ case gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
2624
2660
  return attrib.buffer;
2625
- case gl2.VERTEX_ATTRIB_ARRAY_ENABLED:
2661
+ case gl.VERTEX_ATTRIB_ARRAY_ENABLED:
2626
2662
  return attrib.enabled;
2627
- case gl2.VERTEX_ATTRIB_ARRAY_SIZE:
2663
+ case gl.VERTEX_ATTRIB_ARRAY_SIZE:
2628
2664
  return attrib.size;
2629
- case gl2.VERTEX_ATTRIB_ARRAY_STRIDE:
2665
+ case gl.VERTEX_ATTRIB_ARRAY_STRIDE:
2630
2666
  return attrib.stride;
2631
- case gl2.VERTEX_ATTRIB_ARRAY_TYPE:
2667
+ case gl.VERTEX_ATTRIB_ARRAY_TYPE:
2632
2668
  return attrib.type;
2633
- case gl2.VERTEX_ATTRIB_ARRAY_NORMALIZED:
2669
+ case gl.VERTEX_ATTRIB_ARRAY_NORMALIZED:
2634
2670
  return attrib.normalized;
2635
2671
  default:
2636
2672
  return original.getVertexAttrib.apply(this, arguments);
2637
2673
  }
2638
2674
  };
2639
- gl2.vertexAttribPointer = function vertexAttribPointer(indx, size, type, normalized, stride, offset) {
2675
+ gl.vertexAttribPointer = function vertexAttribPointer(indx, size, type, normalized, stride, offset) {
2640
2676
  const vao = self.currentVertexArrayObject;
2641
2677
  vao.maxAttrib = Math.max(vao.maxAttrib, indx);
2642
2678
  const attrib = vao.attribs[indx];
@@ -2649,11 +2685,11 @@ var __exports__ = (() => {
2649
2685
  attrib.recache();
2650
2686
  return original.vertexAttribPointer.apply(this, arguments);
2651
2687
  };
2652
- if (gl2.instrumentExtension) {
2653
- gl2.instrumentExtension(this, "OES_vertex_array_object");
2688
+ if (gl.instrumentExtension) {
2689
+ gl.instrumentExtension(this, "OES_vertex_array_object");
2654
2690
  }
2655
- if (gl2.canvas) {
2656
- gl2.canvas.addEventListener("webglcontextrestored", () => {
2691
+ if (gl.canvas) {
2692
+ gl.canvas.addEventListener("webglcontextrestored", () => {
2657
2693
  log2("OESVertexArrayObject emulation library context restored");
2658
2694
  self.reset_();
2659
2695
  }, true);
@@ -2668,8 +2704,8 @@ var __exports__ = (() => {
2668
2704
  this.vertexArrayObjects.isAlive = false;
2669
2705
  }
2670
2706
  }
2671
- const gl2 = this.gl;
2672
- this.maxVertexAttribs = gl2.getParameter(gl2.MAX_VERTEX_ATTRIBS);
2707
+ const gl = this.gl;
2708
+ this.maxVertexAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
2673
2709
  this.defaultVertexArrayObject = new WebGLVertexArrayObjectOES(this);
2674
2710
  this.currentVertexArrayObject = null;
2675
2711
  this.currentArrayBuffer = null;
@@ -2697,9 +2733,9 @@ var __exports__ = (() => {
2697
2733
  return false;
2698
2734
  };
2699
2735
  OESVertexArrayObject.prototype.bindVertexArrayOES = function bindVertexArrayOES(arrayObject) {
2700
- const gl2 = this.gl;
2736
+ const gl = this.gl;
2701
2737
  if (arrayObject && !arrayObject.isAlive) {
2702
- synthesizeGLError(gl2.INVALID_OPERATION, "bindVertexArrayOES: attempt to bind deleted arrayObject");
2738
+ synthesizeGLError(gl.INVALID_OPERATION, "bindVertexArrayOES: attempt to bind deleted arrayObject");
2703
2739
  return;
2704
2740
  }
2705
2741
  const original = this.original;
@@ -2711,7 +2747,7 @@ var __exports__ = (() => {
2711
2747
  return;
2712
2748
  }
2713
2749
  if (!oldVAO || newVAO.elementArrayBuffer !== oldVAO.elementArrayBuffer) {
2714
- original.bindBuffer.call(gl2, gl2.ELEMENT_ARRAY_BUFFER, newVAO.elementArrayBuffer);
2750
+ original.bindBuffer.call(gl, gl.ELEMENT_ARRAY_BUFFER, newVAO.elementArrayBuffer);
2715
2751
  }
2716
2752
  let currentBinding = this.currentArrayBuffer;
2717
2753
  const maxAttrib = Math.max(oldVAO ? oldVAO.maxAttrib : 0, newVAO.maxAttrib);
@@ -2720,43 +2756,43 @@ var __exports__ = (() => {
2720
2756
  const oldAttrib = oldVAO ? oldVAO.attribs[n] : null;
2721
2757
  if (!oldVAO || attrib.enabled !== oldAttrib.enabled) {
2722
2758
  if (attrib.enabled) {
2723
- original.enableVertexAttribArray.call(gl2, n);
2759
+ original.enableVertexAttribArray.call(gl, n);
2724
2760
  } else {
2725
- original.disableVertexAttribArray.call(gl2, n);
2761
+ original.disableVertexAttribArray.call(gl, n);
2726
2762
  }
2727
2763
  }
2728
2764
  if (attrib.enabled) {
2729
2765
  let bufferChanged = false;
2730
2766
  if (!oldVAO || attrib.buffer !== oldAttrib.buffer) {
2731
2767
  if (currentBinding !== attrib.buffer) {
2732
- original.bindBuffer.call(gl2, gl2.ARRAY_BUFFER, attrib.buffer);
2768
+ original.bindBuffer.call(gl, gl.ARRAY_BUFFER, attrib.buffer);
2733
2769
  currentBinding = attrib.buffer;
2734
2770
  }
2735
2771
  bufferChanged = true;
2736
2772
  }
2737
2773
  if (bufferChanged || attrib.cached !== oldAttrib.cached) {
2738
- original.vertexAttribPointer.call(gl2, n, attrib.size, attrib.type, attrib.normalized, attrib.stride, attrib.offset);
2774
+ original.vertexAttribPointer.call(gl, n, attrib.size, attrib.type, attrib.normalized, attrib.stride, attrib.offset);
2739
2775
  }
2740
2776
  }
2741
2777
  }
2742
2778
  if (this.currentArrayBuffer !== currentBinding) {
2743
- original.bindBuffer.call(gl2, gl2.ARRAY_BUFFER, this.currentArrayBuffer);
2779
+ original.bindBuffer.call(gl, gl.ARRAY_BUFFER, this.currentArrayBuffer);
2744
2780
  }
2745
2781
  };
2746
- function polyfillVertexArrayObject(gl2) {
2747
- if (typeof gl2.createVertexArray === "function") {
2782
+ function polyfillVertexArrayObject(gl) {
2783
+ if (typeof gl.createVertexArray === "function") {
2748
2784
  return;
2749
2785
  }
2750
- const original_getSupportedExtensions = gl2.getSupportedExtensions;
2751
- gl2.getSupportedExtensions = function getSupportedExtensions() {
2786
+ const original_getSupportedExtensions = gl.getSupportedExtensions;
2787
+ gl.getSupportedExtensions = function getSupportedExtensions() {
2752
2788
  const list = original_getSupportedExtensions.call(this) || [];
2753
2789
  if (list.indexOf("OES_vertex_array_object") < 0) {
2754
2790
  list.push("OES_vertex_array_object");
2755
2791
  }
2756
2792
  return list;
2757
2793
  };
2758
- const original_getExtension = gl2.getExtension;
2759
- gl2.getExtension = function getExtension(name2) {
2794
+ const original_getExtension = gl.getExtension;
2795
+ gl.getExtension = function getExtension(name2) {
2760
2796
  const ext = original_getExtension.call(this, name2);
2761
2797
  if (ext) {
2762
2798
  return ext;
@@ -2764,7 +2800,7 @@ var __exports__ = (() => {
2764
2800
  if (name2 !== "OES_vertex_array_object") {
2765
2801
  return null;
2766
2802
  }
2767
- if (!gl2.__OESVertexArrayObject) {
2803
+ if (!gl.__OESVertexArrayObject) {
2768
2804
  this.__OESVertexArrayObject = new OESVertexArrayObject(this);
2769
2805
  }
2770
2806
  return this.__OESVertexArrayObject;
@@ -3441,31 +3477,31 @@ var __exports__ = (() => {
3441
3477
  // src/context/context/webgl-checks.ts
3442
3478
  var ERR_CONTEXT = "Invalid WebGLRenderingContext";
3443
3479
  var ERR_WEBGL2 = "Requires WebGL2";
3444
- function isWebGL(gl2) {
3445
- if (typeof WebGLRenderingContext !== "undefined" && gl2 instanceof WebGLRenderingContext) {
3480
+ function isWebGL(gl) {
3481
+ if (typeof WebGLRenderingContext !== "undefined" && gl instanceof WebGLRenderingContext) {
3446
3482
  return true;
3447
3483
  }
3448
- if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
3484
+ if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
3449
3485
  return true;
3450
3486
  }
3451
- return Boolean(gl2 && Number.isFinite(gl2._version));
3487
+ return Boolean(gl && Number.isFinite(gl._version));
3452
3488
  }
3453
- function isWebGL2(gl2) {
3454
- if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
3489
+ function isWebGL2(gl) {
3490
+ if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
3455
3491
  return true;
3456
3492
  }
3457
- return Boolean(gl2 && gl2._version === 2);
3493
+ return Boolean(gl && gl._version === 2);
3458
3494
  }
3459
- function getWebGL2Context(gl2) {
3460
- return isWebGL2(gl2) ? gl2 : null;
3495
+ function getWebGL2Context(gl) {
3496
+ return isWebGL2(gl) ? gl : null;
3461
3497
  }
3462
- function assertWebGLContext(gl2) {
3463
- assert2(isWebGL(gl2), ERR_CONTEXT);
3464
- return gl2;
3498
+ function assertWebGLContext(gl) {
3499
+ assert2(isWebGL(gl), ERR_CONTEXT);
3500
+ return gl;
3465
3501
  }
3466
- function assertWebGL2Context(gl2) {
3467
- assert2(isWebGL2(gl2), ERR_WEBGL2);
3468
- return gl2;
3502
+ function assertWebGL2Context(gl) {
3503
+ assert2(isWebGL2(gl), ERR_WEBGL2);
3504
+ return gl;
3469
3505
  }
3470
3506
 
3471
3507
  // src/context/polyfill/get-parameter-polyfill.ts
@@ -3481,39 +3517,39 @@ var __exports__ = (() => {
3481
3517
  var GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT = 34047;
3482
3518
  var GL_UNMASKED_VENDOR_WEBGL = 37445;
3483
3519
  var GL_UNMASKED_RENDERER_WEBGL = 37446;
3484
- var getWebGL2ValueOrZero = (gl2) => !isWebGL2(gl2) ? 0 : void 0;
3520
+ var getWebGL2ValueOrZero = (gl) => !isWebGL2(gl) ? 0 : void 0;
3485
3521
  var WEBGL_PARAMETERS = {
3486
- [GL.READ_BUFFER]: (gl2) => !isWebGL2(gl2) ? GL.COLOR_ATTACHMENT0 : void 0,
3522
+ [GL.READ_BUFFER]: (gl) => !isWebGL2(gl) ? GL.COLOR_ATTACHMENT0 : void 0,
3487
3523
  // WebGL2 context parameters
3488
- [GL_FRAGMENT_SHADER_DERIVATIVE_HINT]: (gl2) => !isWebGL2(gl2) ? GL_DONT_CARE : void 0,
3524
+ [GL_FRAGMENT_SHADER_DERIVATIVE_HINT]: (gl) => !isWebGL2(gl) ? GL_DONT_CARE : void 0,
3489
3525
  [GL.RASTERIZER_DISCARD]: getWebGL2ValueOrZero,
3490
3526
  [GL.SAMPLES]: getWebGL2ValueOrZero,
3491
3527
  // WebGL2 extension context parameters
3492
- [GL_GPU_DISJOINT_EXT]: (gl2, getParameter) => {
3493
- const ext = isWebGL2(gl2) ? gl2.getExtension(EXT_disjoint_timer_query_webgl2) : gl2.getExtension(EXT_disjoint_timer_query);
3528
+ [GL_GPU_DISJOINT_EXT]: (gl, getParameter) => {
3529
+ const ext = isWebGL2(gl) ? gl.getExtension(EXT_disjoint_timer_query_webgl2) : gl.getExtension(EXT_disjoint_timer_query);
3494
3530
  return ext && ext.GPU_DISJOINT_EXT ? getParameter(ext.GPU_DISJOINT_EXT) : 0;
3495
3531
  },
3496
3532
  // Extension fixed values
3497
- [GL_UNMASKED_VENDOR_WEBGL]: (gl2, getParameter) => {
3498
- const ext = gl2.getExtension(WEBGL_debug_renderer_info);
3533
+ [GL_UNMASKED_VENDOR_WEBGL]: (gl, getParameter) => {
3534
+ const ext = gl.getExtension(WEBGL_debug_renderer_info);
3499
3535
  return getParameter(ext && ext.UNMASKED_VENDOR_WEBGL || GL.VENDOR);
3500
3536
  },
3501
- [GL_UNMASKED_RENDERER_WEBGL]: (gl2, getParameter) => {
3502
- const ext = gl2.getExtension(WEBGL_debug_renderer_info);
3537
+ [GL_UNMASKED_RENDERER_WEBGL]: (gl, getParameter) => {
3538
+ const ext = gl.getExtension(WEBGL_debug_renderer_info);
3503
3539
  return getParameter(ext && ext.UNMASKED_RENDERER_WEBGL || GL.RENDERER);
3504
3540
  },
3505
3541
  // Extension LIMITS
3506
- [GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT]: (gl2, getParameter) => {
3507
- const ext = gl2.luma?.extensions?.[EXT_texture_filter_anisotropic] || gl2.getExtension("EXT_texture_filter_anisotropic");
3542
+ [GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT]: (gl, getParameter) => {
3543
+ const ext = gl.luma?.extensions?.[EXT_texture_filter_anisotropic] || gl.getExtension("EXT_texture_filter_anisotropic");
3508
3544
  return ext ? getParameter(ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 1;
3509
3545
  },
3510
3546
  // WebGL2 Limits
3511
3547
  [GL.MAX_3D_TEXTURE_SIZE]: getWebGL2ValueOrZero,
3512
3548
  [GL.MAX_ARRAY_TEXTURE_LAYERS]: getWebGL2ValueOrZero,
3513
3549
  [GL.MAX_CLIENT_WAIT_TIMEOUT_WEBGL]: getWebGL2ValueOrZero,
3514
- [GL.MAX_COLOR_ATTACHMENTS]: (gl2, getParameter) => {
3515
- if (!isWebGL2(gl2)) {
3516
- const ext = gl2.getExtension(WEBGL_draw_buffers);
3550
+ [GL.MAX_COLOR_ATTACHMENTS]: (gl, getParameter) => {
3551
+ if (!isWebGL2(gl)) {
3552
+ const ext = gl.getExtension(WEBGL_draw_buffers);
3517
3553
  return ext ? getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL) : 0;
3518
3554
  }
3519
3555
  return void 0;
@@ -3521,24 +3557,24 @@ var __exports__ = (() => {
3521
3557
  [GL.MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
3522
3558
  [GL.MAX_COMBINED_UNIFORM_BLOCKS]: getWebGL2ValueOrZero,
3523
3559
  [GL.MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
3524
- [GL.MAX_DRAW_BUFFERS]: (gl2) => {
3525
- if (!isWebGL2(gl2)) {
3526
- const ext = gl2.getExtension(WEBGL_draw_buffers);
3560
+ [GL.MAX_DRAW_BUFFERS]: (gl) => {
3561
+ if (!isWebGL2(gl)) {
3562
+ const ext = gl.getExtension(WEBGL_draw_buffers);
3527
3563
  return ext ? ext.MAX_DRAW_BUFFERS_WEBGL : 0;
3528
3564
  }
3529
3565
  return void 0;
3530
3566
  },
3531
3567
  [GL.MAX_ELEMENT_INDEX]: (
3532
3568
  // Guess: per webglstats.com 99.6% of webgl2 supports 2147483647
3533
- (gl2) => gl2.getExtension(OES_element_index) ? 2147483647 : 65535
3569
+ (gl) => gl.getExtension(OES_element_index) ? 2147483647 : 65535
3534
3570
  ),
3535
3571
  [GL.MAX_ELEMENTS_INDICES]: (
3536
3572
  // Guess: "Reasonably safe" per webglstats.com - could be higher/lower (on some mobile devices)
3537
- (gl2) => gl2.getExtension(OES_element_index) ? 16777216 : 65535
3573
+ (gl) => gl.getExtension(OES_element_index) ? 16777216 : 65535
3538
3574
  ),
3539
3575
  [GL.MAX_ELEMENTS_VERTICES]: (
3540
3576
  // Guess: "Reasonably safe" per webglstats.com - could be higher/lower (on some mobile devices)
3541
- (gl2) => 16777216
3577
+ (gl) => 16777216
3542
3578
  ),
3543
3579
  [GL.MAX_FRAGMENT_INPUT_COMPONENTS]: getWebGL2ValueOrZero,
3544
3580
  [GL.MAX_FRAGMENT_UNIFORM_BLOCKS]: getWebGL2ValueOrZero,
@@ -3559,24 +3595,24 @@ var __exports__ = (() => {
3559
3595
  [GL.MAX_PROGRAM_TEXEL_OFFSET]: getWebGL2ValueOrZero,
3560
3596
  [GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT]: getWebGL2ValueOrZero
3561
3597
  };
3562
- function getParameterPolyfill(gl2, originalGetParameter, pname) {
3598
+ function getParameterPolyfill(gl, originalGetParameter, pname) {
3563
3599
  const limit = WEBGL_PARAMETERS[pname];
3564
- const value = typeof limit === "function" ? limit(gl2, originalGetParameter, pname) : limit;
3600
+ const value = typeof limit === "function" ? limit(gl, originalGetParameter, pname) : limit;
3565
3601
  const result = value !== void 0 ? value : originalGetParameter(pname);
3566
3602
  return result;
3567
3603
  }
3568
3604
 
3569
3605
  // src/context/polyfill/context-data.ts
3570
- function getContextData(gl2) {
3571
- const luma = gl2.luma;
3606
+ function getContextData(gl) {
3607
+ const luma = gl.luma;
3572
3608
  if (!luma) {
3573
3609
  const contextState = {
3574
3610
  _polyfilled: false,
3575
3611
  _extensions: {}
3576
3612
  };
3577
- gl2.luma = contextState;
3613
+ gl.luma = contextState;
3578
3614
  }
3579
- return gl2.luma;
3615
+ return gl.luma;
3580
3616
  }
3581
3617
 
3582
3618
  // src/context/polyfill/polyfill-table.ts
@@ -3586,10 +3622,10 @@ var __exports__ = (() => {
3586
3622
  var EXT_disjoint_timer_query2 = "EXT_disjoint_timer_query";
3587
3623
  var EXT_texture_filter_anisotropic2 = "EXT_texture_filter_anisotropic";
3588
3624
  var ERR_VAO_NOT_SUPPORTED = "VertexArray requires WebGL2 or OES_vertex_array_object extension";
3589
- function getExtensionData(gl2, extension) {
3625
+ function getExtensionData(gl, extension) {
3590
3626
  return {
3591
- webgl2: isWebGL2(gl2),
3592
- ext: gl2.getExtension(extension)
3627
+ webgl2: isWebGL2(gl),
3628
+ ext: gl.getExtension(extension)
3593
3629
  };
3594
3630
  }
3595
3631
  var WEBGL2_CONTEXT_POLYFILLS = {
@@ -3660,18 +3696,18 @@ var __exports__ = (() => {
3660
3696
  };
3661
3697
  var WEBGL2_CONTEXT_OVERRIDES = {
3662
3698
  // Ensure readBuffer is a no-op
3663
- readBuffer: (gl2, originalFunc, attachment) => {
3664
- if (isWebGL2(gl2)) {
3699
+ readBuffer: (gl, originalFunc, attachment) => {
3700
+ if (isWebGL2(gl)) {
3665
3701
  originalFunc(attachment);
3666
3702
  } else {
3667
3703
  }
3668
3704
  },
3669
3705
  // Override for getVertexAttrib that returns sane values for non-WebGL1 constants
3670
- getVertexAttrib: (gl2, originalFunc, location, pname) => {
3706
+ getVertexAttrib: (gl, originalFunc, location, pname) => {
3671
3707
  const {
3672
3708
  webgl2,
3673
3709
  ext
3674
- } = getExtensionData(gl2, ANGLE_instanced_arrays);
3710
+ } = getExtensionData(gl, ANGLE_instanced_arrays);
3675
3711
  let result;
3676
3712
  switch (pname) {
3677
3713
  case GL.VERTEX_ATTRIB_ARRAY_INTEGER:
@@ -3685,8 +3721,8 @@ var __exports__ = (() => {
3685
3721
  return result !== void 0 ? result : originalFunc(location, pname);
3686
3722
  },
3687
3723
  // Handle transform feedback and uniform block queries in WebGL1
3688
- getProgramParameter: (gl2, originalFunc, program, pname) => {
3689
- if (!isWebGL2(gl2)) {
3724
+ getProgramParameter: (gl, originalFunc, program, pname) => {
3725
+ if (!isWebGL2(gl)) {
3690
3726
  switch (pname) {
3691
3727
  case GL.TRANSFORM_FEEDBACK_BUFFER_MODE:
3692
3728
  return GL.SEPARATE_ATTRIBS;
@@ -3699,21 +3735,21 @@ var __exports__ = (() => {
3699
3735
  }
3700
3736
  return originalFunc(program, pname);
3701
3737
  },
3702
- getInternalformatParameter: (gl2, originalFunc, target, format, pname) => {
3703
- if (!isWebGL2(gl2)) {
3738
+ getInternalformatParameter: (gl, originalFunc, target, format, pname) => {
3739
+ if (!isWebGL2(gl)) {
3704
3740
  switch (pname) {
3705
3741
  case GL.SAMPLES:
3706
3742
  return new Int32Array([0]);
3707
3743
  default:
3708
3744
  }
3709
3745
  }
3710
- const gl22 = gl2;
3711
- return gl22.getInternalformatParameter(target, format, pname);
3746
+ const gl2 = gl;
3747
+ return gl2.getInternalformatParameter(target, format, pname);
3712
3748
  },
3713
- getTexParameter(gl2, originalFunc, target, pname) {
3749
+ getTexParameter(gl, originalFunc, target, pname) {
3714
3750
  switch (pname) {
3715
3751
  case GL.TEXTURE_MAX_ANISOTROPY_EXT:
3716
- const contextData = getContextData(gl2);
3752
+ const contextData = getContextData(gl);
3717
3753
  const {
3718
3754
  _extensions
3719
3755
  } = contextData;
@@ -3725,47 +3761,47 @@ var __exports__ = (() => {
3725
3761
  return originalFunc(target, pname);
3726
3762
  },
3727
3763
  getParameter: getParameterPolyfill,
3728
- hint(gl2, originalFunc, pname, value) {
3764
+ hint(gl, originalFunc, pname, value) {
3729
3765
  return originalFunc(pname, value);
3730
3766
  }
3731
3767
  };
3732
3768
 
3733
3769
  // src/context/polyfill/polyfill-context.ts
3734
- function polyfillContext(gl2) {
3735
- const contextState = getContextData(gl2);
3770
+ function polyfillContext(gl) {
3771
+ const contextState = getContextData(gl);
3736
3772
  if (!contextState._polyfilled) {
3737
- polyfillVertexArrayObject(gl2);
3738
- initializeExtensions(gl2);
3739
- installPolyfills(gl2, WEBGL2_CONTEXT_POLYFILLS);
3740
- installOverrides(gl2, {
3773
+ polyfillVertexArrayObject(gl);
3774
+ initializeExtensions(gl);
3775
+ installPolyfills(gl, WEBGL2_CONTEXT_POLYFILLS);
3776
+ installOverrides(gl, {
3741
3777
  target: contextState,
3742
- target2: gl2
3778
+ target2: gl
3743
3779
  });
3744
3780
  contextState._polyfilled = true;
3745
3781
  }
3746
- return gl2;
3782
+ return gl;
3747
3783
  }
3748
- function initializeExtensions(gl2) {
3749
- const contextState = getContextData(gl2);
3750
- const EXTENSIONS = gl2.getSupportedExtensions() || [];
3784
+ function initializeExtensions(gl) {
3785
+ const contextState = getContextData(gl);
3786
+ const EXTENSIONS = gl.getSupportedExtensions() || [];
3751
3787
  for (const extensionName of EXTENSIONS) {
3752
- const extension = gl2.getExtension(extensionName);
3788
+ const extension = gl.getExtension(extensionName);
3753
3789
  contextState._extensions[extensionName] = extension;
3754
3790
  }
3755
3791
  }
3756
- function installPolyfills(gl2, polyfills) {
3757
- const contextState = getContextData(gl2);
3792
+ function installPolyfills(gl, polyfills) {
3793
+ const contextState = getContextData(gl);
3758
3794
  for (const extension of Object.getOwnPropertyNames(polyfills)) {
3759
3795
  if (extension !== "overrides") {
3760
- polyfillExtension(gl2, {
3796
+ polyfillExtension(gl, {
3761
3797
  extension,
3762
3798
  target: contextState,
3763
- target2: gl2
3799
+ target2: gl
3764
3800
  });
3765
3801
  }
3766
3802
  }
3767
3803
  }
3768
- function polyfillExtension(gl2, {
3804
+ function polyfillExtension(gl, {
3769
3805
  extension,
3770
3806
  target,
3771
3807
  target2
@@ -3778,12 +3814,12 @@ var __exports__ = (() => {
3778
3814
  const {
3779
3815
  suffix = ""
3780
3816
  } = meta;
3781
- const ext = gl2.getExtension(extension);
3817
+ const ext = gl.getExtension(extension);
3782
3818
  for (const key of Object.keys(defaults)) {
3783
3819
  const extKey = `${key}${suffix}`;
3784
3820
  let polyfill = null;
3785
3821
  if (key === "meta") {
3786
- } else if (typeof gl2[key] === "function") {
3822
+ } else if (typeof gl[key] === "function") {
3787
3823
  } else if (ext && typeof ext[extKey] === "function") {
3788
3824
  polyfill = (...args) => ext[extKey](...args);
3789
3825
  } else if (typeof defaults[key] === "function") {
@@ -3795,15 +3831,15 @@ var __exports__ = (() => {
3795
3831
  }
3796
3832
  }
3797
3833
  }
3798
- function installOverrides(gl2, {
3834
+ function installOverrides(gl, {
3799
3835
  target,
3800
3836
  target2
3801
3837
  }) {
3802
3838
  Object.keys(WEBGL2_CONTEXT_OVERRIDES).forEach((key) => {
3803
3839
  if (typeof WEBGL2_CONTEXT_OVERRIDES[key] === "function") {
3804
- const originalFunc = gl2[key] ? gl2[key].bind(gl2) : () => {
3840
+ const originalFunc = gl[key] ? gl[key].bind(gl) : () => {
3805
3841
  };
3806
- const polyfill = WEBGL2_CONTEXT_OVERRIDES[key].bind(null, gl2, originalFunc);
3842
+ const polyfill = WEBGL2_CONTEXT_OVERRIDES[key].bind(null, gl, originalFunc);
3807
3843
  target[key] = polyfill;
3808
3844
  target2[key] = polyfill;
3809
3845
  }
@@ -3894,19 +3930,19 @@ var __exports__ = (() => {
3894
3930
  [GL.UNPACK_SKIP_ROWS]: 0,
3895
3931
  [GL.UNPACK_SKIP_IMAGES]: 0
3896
3932
  };
3897
- var enable = (gl2, value, key) => value ? gl2.enable(key) : gl2.disable(key);
3898
- var hint = (gl2, value, key) => gl2.hint(key, value);
3899
- var pixelStorei = (gl2, value, key) => gl2.pixelStorei(key, value);
3900
- var bindFramebuffer = (gl2, value, key) => {
3933
+ var enable = (gl, value, key) => value ? gl.enable(key) : gl.disable(key);
3934
+ var hint = (gl, value, key) => gl.hint(key, value);
3935
+ var pixelStorei = (gl, value, key) => gl.pixelStorei(key, value);
3936
+ var bindFramebuffer = (gl, value, key) => {
3901
3937
  let target;
3902
3938
  if (key === GL.FRAMEBUFFER_BINDING) {
3903
- target = isWebGL2(gl2) ? GL.DRAW_FRAMEBUFFER : GL.FRAMEBUFFER;
3939
+ target = isWebGL2(gl) ? GL.DRAW_FRAMEBUFFER : GL.FRAMEBUFFER;
3904
3940
  } else {
3905
3941
  target = GL.READ_FRAMEBUFFER;
3906
3942
  }
3907
- return gl2.bindFramebuffer(target, value);
3943
+ return gl.bindFramebuffer(target, value);
3908
3944
  };
3909
- var bindBuffer = (gl2, value, key) => {
3945
+ var bindBuffer = (gl, value, key) => {
3910
3946
  const bindingMap = {
3911
3947
  [GL.ARRAY_BUFFER_BINDING]: GL.ARRAY_BUFFER,
3912
3948
  [GL.COPY_READ_BUFFER_BINDING]: GL.COPY_READ_BUFFER,
@@ -3915,35 +3951,35 @@ var __exports__ = (() => {
3915
3951
  [GL.PIXEL_UNPACK_BUFFER_BINDING]: GL.PIXEL_UNPACK_BUFFER
3916
3952
  };
3917
3953
  const glTarget = bindingMap[key];
3918
- gl2.bindBuffer(glTarget, value);
3954
+ gl.bindBuffer(glTarget, value);
3919
3955
  };
3920
3956
  function isArray(array) {
3921
3957
  return Array.isArray(array) || ArrayBuffer.isView(array) && !(array instanceof DataView);
3922
3958
  }
3923
3959
  var GL_PARAMETER_SETTERS = {
3924
3960
  [GL.BLEND]: enable,
3925
- [GL.BLEND_COLOR]: (gl2, value) => gl2.blendColor(...value),
3961
+ [GL.BLEND_COLOR]: (gl, value) => gl.blendColor(...value),
3926
3962
  [GL.BLEND_EQUATION_RGB]: "blendEquation",
3927
3963
  [GL.BLEND_EQUATION_ALPHA]: "blendEquation",
3928
3964
  [GL.BLEND_SRC_RGB]: "blendFunc",
3929
3965
  [GL.BLEND_DST_RGB]: "blendFunc",
3930
3966
  [GL.BLEND_SRC_ALPHA]: "blendFunc",
3931
3967
  [GL.BLEND_DST_ALPHA]: "blendFunc",
3932
- [GL.COLOR_CLEAR_VALUE]: (gl2, value) => gl2.clearColor(...value),
3933
- [GL.COLOR_WRITEMASK]: (gl2, value) => gl2.colorMask(...value),
3968
+ [GL.COLOR_CLEAR_VALUE]: (gl, value) => gl.clearColor(...value),
3969
+ [GL.COLOR_WRITEMASK]: (gl, value) => gl.colorMask(...value),
3934
3970
  [GL.CULL_FACE]: enable,
3935
- [GL.CULL_FACE_MODE]: (gl2, value) => gl2.cullFace(value),
3971
+ [GL.CULL_FACE_MODE]: (gl, value) => gl.cullFace(value),
3936
3972
  [GL.DEPTH_TEST]: enable,
3937
- [GL.DEPTH_CLEAR_VALUE]: (gl2, value) => gl2.clearDepth(value),
3938
- [GL.DEPTH_FUNC]: (gl2, value) => gl2.depthFunc(value),
3939
- [GL.DEPTH_RANGE]: (gl2, value) => gl2.depthRange(...value),
3940
- [GL.DEPTH_WRITEMASK]: (gl2, value) => gl2.depthMask(value),
3973
+ [GL.DEPTH_CLEAR_VALUE]: (gl, value) => gl.clearDepth(value),
3974
+ [GL.DEPTH_FUNC]: (gl, value) => gl.depthFunc(value),
3975
+ [GL.DEPTH_RANGE]: (gl, value) => gl.depthRange(...value),
3976
+ [GL.DEPTH_WRITEMASK]: (gl, value) => gl.depthMask(value),
3941
3977
  [GL.DITHER]: enable,
3942
3978
  [GL.FRAGMENT_SHADER_DERIVATIVE_HINT]: hint,
3943
- [GL.CURRENT_PROGRAM]: (gl2, value) => gl2.useProgram(value),
3944
- [GL.RENDERBUFFER_BINDING]: (gl2, value) => gl2.bindRenderbuffer(GL.RENDERBUFFER, value),
3945
- [GL.TRANSFORM_FEEDBACK_BINDING]: (gl2, value) => gl2.bindTransformFeedback?.(GL.TRANSFORM_FEEDBACK, value),
3946
- [GL.VERTEX_ARRAY_BINDING]: (gl2, value) => gl2.bindVertexArray(value),
3979
+ [GL.CURRENT_PROGRAM]: (gl, value) => gl.useProgram(value),
3980
+ [GL.RENDERBUFFER_BINDING]: (gl, value) => gl.bindRenderbuffer(GL.RENDERBUFFER, value),
3981
+ [GL.TRANSFORM_FEEDBACK_BINDING]: (gl, value) => gl.bindTransformFeedback?.(GL.TRANSFORM_FEEDBACK, value),
3982
+ [GL.VERTEX_ARRAY_BINDING]: (gl, value) => gl.bindVertexArray(value),
3947
3983
  // NOTE: FRAMEBUFFER_BINDING and DRAW_FRAMEBUFFER_BINDING(WebGL2) refer same state.
3948
3984
  [GL.FRAMEBUFFER_BINDING]: bindFramebuffer,
3949
3985
  [GL.READ_FRAMEBUFFER_BINDING]: bindFramebuffer,
@@ -3953,9 +3989,9 @@ var __exports__ = (() => {
3953
3989
  [GL.COPY_WRITE_BUFFER_BINDING]: bindBuffer,
3954
3990
  [GL.PIXEL_PACK_BUFFER_BINDING]: bindBuffer,
3955
3991
  [GL.PIXEL_UNPACK_BUFFER_BINDING]: bindBuffer,
3956
- [GL.FRONT_FACE]: (gl2, value) => gl2.frontFace(value),
3992
+ [GL.FRONT_FACE]: (gl, value) => gl.frontFace(value),
3957
3993
  [GL.GENERATE_MIPMAP_HINT]: hint,
3958
- [GL.LINE_WIDTH]: (gl2, value) => gl2.lineWidth(value),
3994
+ [GL.LINE_WIDTH]: (gl, value) => gl.lineWidth(value),
3959
3995
  [GL.POLYGON_OFFSET_FILL]: enable,
3960
3996
  [GL.POLYGON_OFFSET_FACTOR]: "polygonOffset",
3961
3997
  [GL.POLYGON_OFFSET_UNITS]: "polygonOffset",
@@ -3965,11 +4001,11 @@ var __exports__ = (() => {
3965
4001
  [GL.SAMPLE_COVERAGE_VALUE]: "sampleCoverage",
3966
4002
  [GL.SAMPLE_COVERAGE_INVERT]: "sampleCoverage",
3967
4003
  [GL.SCISSOR_TEST]: enable,
3968
- [GL.SCISSOR_BOX]: (gl2, value) => gl2.scissor(...value),
4004
+ [GL.SCISSOR_BOX]: (gl, value) => gl.scissor(...value),
3969
4005
  [GL.STENCIL_TEST]: enable,
3970
- [GL.STENCIL_CLEAR_VALUE]: (gl2, value) => gl2.clearStencil(value),
3971
- [GL.STENCIL_WRITEMASK]: (gl2, value) => gl2.stencilMaskSeparate(GL.FRONT, value),
3972
- [GL.STENCIL_BACK_WRITEMASK]: (gl2, value) => gl2.stencilMaskSeparate(GL.BACK, value),
4006
+ [GL.STENCIL_CLEAR_VALUE]: (gl, value) => gl.clearStencil(value),
4007
+ [GL.STENCIL_WRITEMASK]: (gl, value) => gl.stencilMaskSeparate(GL.FRONT, value),
4008
+ [GL.STENCIL_BACK_WRITEMASK]: (gl, value) => gl.stencilMaskSeparate(GL.BACK, value),
3973
4009
  [GL.STENCIL_FUNC]: "stencilFuncFront",
3974
4010
  [GL.STENCIL_REF]: "stencilFuncFront",
3975
4011
  [GL.STENCIL_VALUE_MASK]: "stencilFuncFront",
@@ -3982,7 +4018,7 @@ var __exports__ = (() => {
3982
4018
  [GL.STENCIL_BACK_FAIL]: "stencilOpBack",
3983
4019
  [GL.STENCIL_BACK_PASS_DEPTH_FAIL]: "stencilOpBack",
3984
4020
  [GL.STENCIL_BACK_PASS_DEPTH_PASS]: "stencilOpBack",
3985
- [GL.VIEWPORT]: (gl2, value) => gl2.viewport(...value),
4021
+ [GL.VIEWPORT]: (gl, value) => gl.viewport(...value),
3986
4022
  // WEBGL1 PIXEL PACK/UNPACK MODES
3987
4023
  [GL.PACK_ALIGNMENT]: pixelStorei,
3988
4024
  [GL.UNPACK_ALIGNMENT]: pixelStorei,
@@ -4000,75 +4036,75 @@ var __exports__ = (() => {
4000
4036
  [GL.UNPACK_SKIP_ROWS]: pixelStorei,
4001
4037
  [GL.UNPACK_SKIP_IMAGES]: pixelStorei,
4002
4038
  // Function-style setters
4003
- framebuffer: (gl2, framebuffer) => {
4039
+ framebuffer: (gl, framebuffer) => {
4004
4040
  const handle = framebuffer && "handle" in framebuffer ? framebuffer.handle : framebuffer;
4005
- return gl2.bindFramebuffer(GL.FRAMEBUFFER, handle);
4041
+ return gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
4006
4042
  },
4007
- blend: (gl2, value) => value ? gl2.enable(GL.BLEND) : gl2.disable(GL.BLEND),
4008
- blendColor: (gl2, value) => gl2.blendColor(...value),
4009
- blendEquation: (gl2, args) => {
4043
+ blend: (gl, value) => value ? gl.enable(GL.BLEND) : gl.disable(GL.BLEND),
4044
+ blendColor: (gl, value) => gl.blendColor(...value),
4045
+ blendEquation: (gl, args) => {
4010
4046
  const separateModes = typeof args === "number" ? [args, args] : args;
4011
- gl2.blendEquationSeparate(...separateModes);
4047
+ gl.blendEquationSeparate(...separateModes);
4012
4048
  },
4013
- blendFunc: (gl2, args) => {
4049
+ blendFunc: (gl, args) => {
4014
4050
  const separateFuncs = args?.length === 2 ? [...args, ...args] : args;
4015
- gl2.blendFuncSeparate(...separateFuncs);
4016
- },
4017
- clearColor: (gl2, value) => gl2.clearColor(...value),
4018
- clearDepth: (gl2, value) => gl2.clearDepth(value),
4019
- clearStencil: (gl2, value) => gl2.clearStencil(value),
4020
- colorMask: (gl2, value) => gl2.colorMask(...value),
4021
- cull: (gl2, value) => value ? gl2.enable(GL.CULL_FACE) : gl2.disable(GL.CULL_FACE),
4022
- cullFace: (gl2, value) => gl2.cullFace(value),
4023
- depthTest: (gl2, value) => value ? gl2.enable(GL.DEPTH_TEST) : gl2.disable(GL.DEPTH_TEST),
4024
- depthFunc: (gl2, value) => gl2.depthFunc(value),
4025
- depthMask: (gl2, value) => gl2.depthMask(value),
4026
- depthRange: (gl2, value) => gl2.depthRange(...value),
4027
- dither: (gl2, value) => value ? gl2.enable(GL.DITHER) : gl2.disable(GL.DITHER),
4028
- derivativeHint: (gl2, value) => {
4029
- gl2.hint(GL.FRAGMENT_SHADER_DERIVATIVE_HINT, value);
4030
- },
4031
- frontFace: (gl2, value) => gl2.frontFace(value),
4032
- mipmapHint: (gl2, value) => gl2.hint(GL.GENERATE_MIPMAP_HINT, value),
4033
- lineWidth: (gl2, value) => gl2.lineWidth(value),
4034
- polygonOffsetFill: (gl2, value) => value ? gl2.enable(GL.POLYGON_OFFSET_FILL) : gl2.disable(GL.POLYGON_OFFSET_FILL),
4035
- polygonOffset: (gl2, value) => gl2.polygonOffset(...value),
4036
- sampleCoverage: (gl2, value) => gl2.sampleCoverage(...value),
4037
- scissorTest: (gl2, value) => value ? gl2.enable(GL.SCISSOR_TEST) : gl2.disable(GL.SCISSOR_TEST),
4038
- scissor: (gl2, value) => gl2.scissor(...value),
4039
- stencilTest: (gl2, value) => value ? gl2.enable(GL.STENCIL_TEST) : gl2.disable(GL.STENCIL_TEST),
4040
- stencilMask: (gl2, value) => {
4051
+ gl.blendFuncSeparate(...separateFuncs);
4052
+ },
4053
+ clearColor: (gl, value) => gl.clearColor(...value),
4054
+ clearDepth: (gl, value) => gl.clearDepth(value),
4055
+ clearStencil: (gl, value) => gl.clearStencil(value),
4056
+ colorMask: (gl, value) => gl.colorMask(...value),
4057
+ cull: (gl, value) => value ? gl.enable(GL.CULL_FACE) : gl.disable(GL.CULL_FACE),
4058
+ cullFace: (gl, value) => gl.cullFace(value),
4059
+ depthTest: (gl, value) => value ? gl.enable(GL.DEPTH_TEST) : gl.disable(GL.DEPTH_TEST),
4060
+ depthFunc: (gl, value) => gl.depthFunc(value),
4061
+ depthMask: (gl, value) => gl.depthMask(value),
4062
+ depthRange: (gl, value) => gl.depthRange(...value),
4063
+ dither: (gl, value) => value ? gl.enable(GL.DITHER) : gl.disable(GL.DITHER),
4064
+ derivativeHint: (gl, value) => {
4065
+ gl.hint(GL.FRAGMENT_SHADER_DERIVATIVE_HINT, value);
4066
+ },
4067
+ frontFace: (gl, value) => gl.frontFace(value),
4068
+ mipmapHint: (gl, value) => gl.hint(GL.GENERATE_MIPMAP_HINT, value),
4069
+ lineWidth: (gl, value) => gl.lineWidth(value),
4070
+ polygonOffsetFill: (gl, value) => value ? gl.enable(GL.POLYGON_OFFSET_FILL) : gl.disable(GL.POLYGON_OFFSET_FILL),
4071
+ polygonOffset: (gl, value) => gl.polygonOffset(...value),
4072
+ sampleCoverage: (gl, value) => gl.sampleCoverage(...value),
4073
+ scissorTest: (gl, value) => value ? gl.enable(GL.SCISSOR_TEST) : gl.disable(GL.SCISSOR_TEST),
4074
+ scissor: (gl, value) => gl.scissor(...value),
4075
+ stencilTest: (gl, value) => value ? gl.enable(GL.STENCIL_TEST) : gl.disable(GL.STENCIL_TEST),
4076
+ stencilMask: (gl, value) => {
4041
4077
  value = isArray(value) ? value : [value, value];
4042
4078
  const [mask, backMask] = value;
4043
- gl2.stencilMaskSeparate(GL.FRONT, mask);
4044
- gl2.stencilMaskSeparate(GL.BACK, backMask);
4079
+ gl.stencilMaskSeparate(GL.FRONT, mask);
4080
+ gl.stencilMaskSeparate(GL.BACK, backMask);
4045
4081
  },
4046
- stencilFunc: (gl2, args) => {
4082
+ stencilFunc: (gl, args) => {
4047
4083
  args = isArray(args) && args.length === 3 ? [...args, ...args] : args;
4048
4084
  const [func, ref, mask, backFunc, backRef, backMask] = args;
4049
- gl2.stencilFuncSeparate(GL.FRONT, func, ref, mask);
4050
- gl2.stencilFuncSeparate(GL.BACK, backFunc, backRef, backMask);
4085
+ gl.stencilFuncSeparate(GL.FRONT, func, ref, mask);
4086
+ gl.stencilFuncSeparate(GL.BACK, backFunc, backRef, backMask);
4051
4087
  },
4052
- stencilOp: (gl2, args) => {
4088
+ stencilOp: (gl, args) => {
4053
4089
  args = isArray(args) && args.length === 3 ? [...args, ...args] : args;
4054
4090
  const [sfail, dpfail, dppass, backSfail, backDpfail, backDppass] = args;
4055
- gl2.stencilOpSeparate(GL.FRONT, sfail, dpfail, dppass);
4056
- gl2.stencilOpSeparate(GL.BACK, backSfail, backDpfail, backDppass);
4091
+ gl.stencilOpSeparate(GL.FRONT, sfail, dpfail, dppass);
4092
+ gl.stencilOpSeparate(GL.BACK, backSfail, backDpfail, backDppass);
4057
4093
  },
4058
- viewport: (gl2, value) => gl2.viewport(...value)
4094
+ viewport: (gl, value) => gl.viewport(...value)
4059
4095
  };
4060
4096
  function getValue(glEnum, values, cache2) {
4061
4097
  return values[glEnum] !== void 0 ? values[glEnum] : cache2[glEnum];
4062
4098
  }
4063
4099
  var GL_COMPOSITE_PARAMETER_SETTERS = {
4064
- blendEquation: (gl2, values, cache2) => gl2.blendEquationSeparate(getValue(GL.BLEND_EQUATION_RGB, values, cache2), getValue(GL.BLEND_EQUATION_ALPHA, values, cache2)),
4065
- blendFunc: (gl2, values, cache2) => gl2.blendFuncSeparate(getValue(GL.BLEND_SRC_RGB, values, cache2), getValue(GL.BLEND_DST_RGB, values, cache2), getValue(GL.BLEND_SRC_ALPHA, values, cache2), getValue(GL.BLEND_DST_ALPHA, values, cache2)),
4066
- polygonOffset: (gl2, values, cache2) => gl2.polygonOffset(getValue(GL.POLYGON_OFFSET_FACTOR, values, cache2), getValue(GL.POLYGON_OFFSET_UNITS, values, cache2)),
4067
- sampleCoverage: (gl2, values, cache2) => gl2.sampleCoverage(getValue(GL.SAMPLE_COVERAGE_VALUE, values, cache2), getValue(GL.SAMPLE_COVERAGE_INVERT, values, cache2)),
4068
- stencilFuncFront: (gl2, values, cache2) => gl2.stencilFuncSeparate(GL.FRONT, getValue(GL.STENCIL_FUNC, values, cache2), getValue(GL.STENCIL_REF, values, cache2), getValue(GL.STENCIL_VALUE_MASK, values, cache2)),
4069
- stencilFuncBack: (gl2, values, cache2) => gl2.stencilFuncSeparate(GL.BACK, getValue(GL.STENCIL_BACK_FUNC, values, cache2), getValue(GL.STENCIL_BACK_REF, values, cache2), getValue(GL.STENCIL_BACK_VALUE_MASK, values, cache2)),
4070
- stencilOpFront: (gl2, values, cache2) => gl2.stencilOpSeparate(GL.FRONT, getValue(GL.STENCIL_FAIL, values, cache2), getValue(GL.STENCIL_PASS_DEPTH_FAIL, values, cache2), getValue(GL.STENCIL_PASS_DEPTH_PASS, values, cache2)),
4071
- stencilOpBack: (gl2, values, cache2) => gl2.stencilOpSeparate(GL.BACK, getValue(GL.STENCIL_BACK_FAIL, values, cache2), getValue(GL.STENCIL_BACK_PASS_DEPTH_FAIL, values, cache2), getValue(GL.STENCIL_BACK_PASS_DEPTH_PASS, values, cache2))
4100
+ blendEquation: (gl, values, cache2) => gl.blendEquationSeparate(getValue(GL.BLEND_EQUATION_RGB, values, cache2), getValue(GL.BLEND_EQUATION_ALPHA, values, cache2)),
4101
+ blendFunc: (gl, values, cache2) => gl.blendFuncSeparate(getValue(GL.BLEND_SRC_RGB, values, cache2), getValue(GL.BLEND_DST_RGB, values, cache2), getValue(GL.BLEND_SRC_ALPHA, values, cache2), getValue(GL.BLEND_DST_ALPHA, values, cache2)),
4102
+ polygonOffset: (gl, values, cache2) => gl.polygonOffset(getValue(GL.POLYGON_OFFSET_FACTOR, values, cache2), getValue(GL.POLYGON_OFFSET_UNITS, values, cache2)),
4103
+ sampleCoverage: (gl, values, cache2) => gl.sampleCoverage(getValue(GL.SAMPLE_COVERAGE_VALUE, values, cache2), getValue(GL.SAMPLE_COVERAGE_INVERT, values, cache2)),
4104
+ stencilFuncFront: (gl, values, cache2) => gl.stencilFuncSeparate(GL.FRONT, getValue(GL.STENCIL_FUNC, values, cache2), getValue(GL.STENCIL_REF, values, cache2), getValue(GL.STENCIL_VALUE_MASK, values, cache2)),
4105
+ stencilFuncBack: (gl, values, cache2) => gl.stencilFuncSeparate(GL.BACK, getValue(GL.STENCIL_BACK_FUNC, values, cache2), getValue(GL.STENCIL_BACK_REF, values, cache2), getValue(GL.STENCIL_BACK_VALUE_MASK, values, cache2)),
4106
+ stencilOpFront: (gl, values, cache2) => gl.stencilOpSeparate(GL.FRONT, getValue(GL.STENCIL_FAIL, values, cache2), getValue(GL.STENCIL_PASS_DEPTH_FAIL, values, cache2), getValue(GL.STENCIL_PASS_DEPTH_PASS, values, cache2)),
4107
+ stencilOpBack: (gl, values, cache2) => gl.stencilOpSeparate(GL.BACK, getValue(GL.STENCIL_BACK_FAIL, values, cache2), getValue(GL.STENCIL_BACK_PASS_DEPTH_FAIL, values, cache2), getValue(GL.STENCIL_BACK_PASS_DEPTH_PASS, values, cache2))
4072
4108
  };
4073
4109
  var GL_HOOKED_SETTERS = {
4074
4110
  // GENERIC SETTERS
@@ -4234,7 +4270,7 @@ var __exports__ = (() => {
4234
4270
  [GL.VIEWPORT]: [x, y, width, height]
4235
4271
  })
4236
4272
  };
4237
- var isEnabled = (gl2, key) => gl2.isEnabled(key);
4273
+ var isEnabled = (gl, key) => gl.isEnabled(key);
4238
4274
  var GL_PARAMETER_GETTERS = {
4239
4275
  [GL.BLEND]: isEnabled,
4240
4276
  [GL.CULL_FACE]: isEnabled,
@@ -4288,9 +4324,9 @@ var __exports__ = (() => {
4288
4324
  ]);
4289
4325
 
4290
4326
  // src/context/parameters/unified-parameter-api.ts
4291
- function setParameters(device, parameters) {
4327
+ function setGLParameters(device, parameters) {
4292
4328
  const webglDevice = WebGLDevice.attach(device);
4293
- const gl2 = webglDevice.gl;
4329
+ const gl = webglDevice.gl;
4294
4330
  if (isObjectEmpty2(parameters)) {
4295
4331
  return;
4296
4332
  }
@@ -4302,36 +4338,36 @@ var __exports__ = (() => {
4302
4338
  if (typeof setter === "string") {
4303
4339
  compositeSetters[setter] = true;
4304
4340
  } else {
4305
- setter(gl2, parameters[key], glConstant);
4341
+ setter(gl, parameters[key], glConstant);
4306
4342
  }
4307
4343
  }
4308
4344
  }
4309
- const cache2 = gl2.state && gl2.state.cache;
4345
+ const cache2 = gl.state && gl.state.cache;
4310
4346
  if (cache2) {
4311
4347
  for (const key in compositeSetters) {
4312
4348
  const compositeSetter = GL_COMPOSITE_PARAMETER_SETTERS[key];
4313
- compositeSetter(gl2, parameters, cache2);
4349
+ compositeSetter(gl, parameters, cache2);
4314
4350
  }
4315
4351
  }
4316
4352
  }
4317
- function getParameters(device, parameters = GL_PARAMETER_DEFAULTS) {
4353
+ function getGLParameters(device, parameters = GL_PARAMETER_DEFAULTS) {
4318
4354
  const webglDevice = WebGLDevice.attach(device);
4319
- const gl2 = webglDevice.gl;
4355
+ const gl = webglDevice.gl;
4320
4356
  if (typeof parameters === "number") {
4321
4357
  const key = parameters;
4322
4358
  const getter = GL_PARAMETER_GETTERS[key];
4323
- return getter ? getter(gl2, key) : gl2.getParameter(key);
4359
+ return getter ? getter(gl, key) : gl.getParameter(key);
4324
4360
  }
4325
4361
  const parameterKeys = Array.isArray(parameters) ? parameters : Object.keys(parameters);
4326
4362
  const state = {};
4327
4363
  for (const key of parameterKeys) {
4328
4364
  const getter = GL_PARAMETER_GETTERS[key];
4329
- state[key] = getter ? getter(gl2, Number(key)) : gl2.getParameter(Number(key));
4365
+ state[key] = getter ? getter(gl, Number(key)) : gl.getParameter(Number(key));
4330
4366
  }
4331
4367
  return state;
4332
4368
  }
4333
- function resetParameters(device) {
4334
- setParameters(device, GL_PARAMETER_DEFAULTS);
4369
+ function resetGLParameters(device) {
4370
+ setGLParameters(device, GL_PARAMETER_DEFAULTS);
4335
4371
  }
4336
4372
  function isObjectEmpty2(object) {
4337
4373
  for (const key in object) {
@@ -4363,15 +4399,15 @@ var __exports__ = (() => {
4363
4399
  program = null;
4364
4400
  stateStack = [];
4365
4401
  enable = true;
4366
- constructor(gl2, {
4402
+ constructor(gl, {
4367
4403
  copyState = false,
4368
4404
  // Copy cache from params (slow) or initialize from WebGL defaults (fast)
4369
4405
  log: log3 = () => {
4370
4406
  }
4371
4407
  // Logging function, called when gl parameter change calls are actually issued
4372
4408
  } = {}) {
4373
- this.gl = gl2;
4374
- this.cache = copyState ? getParameters(gl2) : Object.assign({}, GL_PARAMETER_DEFAULTS);
4409
+ this.gl = gl;
4410
+ this.cache = copyState ? getGLParameters(gl) : Object.assign({}, GL_PARAMETER_DEFAULTS);
4375
4411
  this.log = log3;
4376
4412
  this._updateCache = this._updateCache.bind(this);
4377
4413
  Object.seal(this);
@@ -4382,7 +4418,7 @@ var __exports__ = (() => {
4382
4418
  pop() {
4383
4419
  assert2(this.stateStack.length > 0);
4384
4420
  const oldValues = this.stateStack[this.stateStack.length - 1];
4385
- setParameters(this.gl, oldValues);
4421
+ setGLParameters(this.gl, oldValues);
4386
4422
  this.stateStack.pop();
4387
4423
  }
4388
4424
  /**
@@ -4414,53 +4450,53 @@ var __exports__ = (() => {
4414
4450
  };
4415
4451
  }
4416
4452
  };
4417
- function getContextState(gl2) {
4418
- return gl2.state;
4453
+ function getContextState(gl) {
4454
+ return gl.state;
4419
4455
  }
4420
- function trackContextState(gl2, options) {
4456
+ function trackContextState(gl, options) {
4421
4457
  const {
4422
4458
  enable: enable2 = true,
4423
4459
  copyState
4424
4460
  } = options;
4425
4461
  assert2(copyState !== void 0);
4426
- if (!gl2.state) {
4427
- gl2.state = new GLState(gl2, {
4462
+ if (!gl.state) {
4463
+ gl.state = new GLState(gl, {
4428
4464
  copyState
4429
4465
  });
4430
- installProgramSpy(gl2);
4466
+ installProgramSpy(gl);
4431
4467
  for (const key in GL_HOOKED_SETTERS) {
4432
4468
  const setter = GL_HOOKED_SETTERS[key];
4433
- installSetterSpy(gl2, key, setter);
4469
+ installSetterSpy(gl, key, setter);
4434
4470
  }
4435
- installGetterOverride(gl2, "getParameter");
4436
- installGetterOverride(gl2, "isEnabled");
4471
+ installGetterOverride(gl, "getParameter");
4472
+ installGetterOverride(gl, "isEnabled");
4437
4473
  }
4438
- const glState = getContextState(gl2);
4474
+ const glState = getContextState(gl);
4439
4475
  glState.enable = enable2;
4440
- return gl2;
4476
+ return gl;
4441
4477
  }
4442
- function pushContextState(gl2) {
4443
- let glState = getContextState(gl2);
4478
+ function pushContextState(gl) {
4479
+ let glState = getContextState(gl);
4444
4480
  if (!glState) {
4445
- trackContextState(gl2, {
4481
+ trackContextState(gl, {
4446
4482
  copyState: false
4447
4483
  });
4448
- glState = getContextState(gl2);
4484
+ glState = getContextState(gl);
4449
4485
  }
4450
4486
  glState.push();
4451
4487
  }
4452
- function popContextState(gl2) {
4453
- const glState = getContextState(gl2);
4488
+ function popContextState(gl) {
4489
+ const glState = getContextState(gl);
4454
4490
  assert2(glState);
4455
4491
  glState.pop();
4456
4492
  }
4457
- function installGetterOverride(gl2, functionName) {
4458
- const originalGetterFunc = gl2[functionName].bind(gl2);
4459
- gl2[functionName] = function get(pname) {
4493
+ function installGetterOverride(gl, functionName) {
4494
+ const originalGetterFunc = gl[functionName].bind(gl);
4495
+ gl[functionName] = function get(pname) {
4460
4496
  if (pname === void 0 || NON_CACHE_PARAMETERS.has(pname)) {
4461
4497
  return originalGetterFunc(pname);
4462
4498
  }
4463
- const glState = getContextState(gl2);
4499
+ const glState = getContextState(gl);
4464
4500
  if (!(pname in glState.cache)) {
4465
4501
  glState.cache[pname] = originalGetterFunc(pname);
4466
4502
  }
@@ -4472,18 +4508,18 @@ var __exports__ = (() => {
4472
4508
  originalGetterFunc(pname)
4473
4509
  );
4474
4510
  };
4475
- Object.defineProperty(gl2[functionName], "name", {
4511
+ Object.defineProperty(gl[functionName], "name", {
4476
4512
  value: `${functionName}-from-cache`,
4477
4513
  configurable: false
4478
4514
  });
4479
4515
  }
4480
- function installSetterSpy(gl2, functionName, setter) {
4481
- if (!gl2[functionName]) {
4516
+ function installSetterSpy(gl, functionName, setter) {
4517
+ if (!gl[functionName]) {
4482
4518
  return;
4483
4519
  }
4484
- const originalSetterFunc = gl2[functionName].bind(gl2);
4485
- gl2[functionName] = function set(...params) {
4486
- const glState = getContextState(gl2);
4520
+ const originalSetterFunc = gl[functionName].bind(gl);
4521
+ gl[functionName] = function set(...params) {
4522
+ const glState = getContextState(gl);
4487
4523
  const {
4488
4524
  valueChanged,
4489
4525
  oldValue
@@ -4493,15 +4529,15 @@ var __exports__ = (() => {
4493
4529
  }
4494
4530
  return oldValue;
4495
4531
  };
4496
- Object.defineProperty(gl2[functionName], "name", {
4532
+ Object.defineProperty(gl[functionName], "name", {
4497
4533
  value: `${functionName}-to-cache`,
4498
4534
  configurable: false
4499
4535
  });
4500
4536
  }
4501
- function installProgramSpy(gl2) {
4502
- const originalUseProgram = gl2.useProgram.bind(gl2);
4503
- gl2.useProgram = function useProgramLuma(handle) {
4504
- const glState = getContextState(gl2);
4537
+ function installProgramSpy(gl) {
4538
+ const originalUseProgram = gl.useProgram.bind(gl);
4539
+ gl.useProgram = function useProgramLuma(handle) {
4540
+ const glState = getContextState(gl);
4505
4541
  if (glState.program !== handle) {
4506
4542
  originalUseProgram(handle);
4507
4543
  glState.program = handle;
@@ -4530,7 +4566,7 @@ var __exports__ = (() => {
4530
4566
  let errorMessage = null;
4531
4567
  const onCreateError = (error2) => errorMessage = error2.statusMessage || errorMessage;
4532
4568
  canvas.addEventListener("webglcontextcreationerror", onCreateError, false);
4533
- let gl2 = null;
4569
+ let gl = null;
4534
4570
  if (props.type === "webgl2") {
4535
4571
  props = {
4536
4572
  ...props,
@@ -4543,14 +4579,14 @@ var __exports__ = (() => {
4543
4579
  webgl2: false
4544
4580
  };
4545
4581
  }
4546
- if (!gl2 && props.webgl2) {
4547
- gl2 = canvas.getContext("webgl2", props);
4582
+ if (!gl && props.webgl2) {
4583
+ gl = canvas.getContext("webgl2", props);
4548
4584
  }
4549
- if (!gl2 && props.webgl1) {
4550
- gl2 = canvas.getContext("webgl", props);
4585
+ if (!gl && props.webgl1) {
4586
+ gl = canvas.getContext("webgl", props);
4551
4587
  }
4552
4588
  canvas.removeEventListener("webglcontextcreationerror", onCreateError, false);
4553
- if (!gl2) {
4589
+ if (!gl) {
4554
4590
  throw new Error(`Failed to create ${props.webgl2 && !props.webgl1 ? "WebGL2" : "WebGL"} context: ${errorMessage || "Unknown error"}`);
4555
4591
  }
4556
4592
  if (props.onContextLost) {
@@ -4565,28 +4601,28 @@ var __exports__ = (() => {
4565
4601
  } = props;
4566
4602
  canvas.addEventListener("webglcontextrestored", (event) => onContextRestored(event), false);
4567
4603
  }
4568
- return gl2;
4604
+ return gl;
4569
4605
  }
4570
4606
 
4571
4607
  // src/adapter/device-helpers/get-device-info.ts
4572
- function getDeviceInfo(gl2) {
4573
- const vendorMasked = gl2.getParameter(GL.VENDOR);
4574
- const rendererMasked = gl2.getParameter(GL.RENDERER);
4575
- const ext = gl2.getExtension("WEBGL_debug_renderer_info");
4576
- const vendorUnmasked = gl2.getParameter(ext ? ext.UNMASKED_VENDOR_WEBGL : GL.VENDOR);
4577
- const rendererUnmasked = gl2.getParameter(ext ? ext.UNMASKED_RENDERER_WEBGL : GL.RENDERER);
4608
+ function getDeviceInfo(gl) {
4609
+ const vendorMasked = gl.getParameter(GL.VENDOR);
4610
+ const rendererMasked = gl.getParameter(GL.RENDERER);
4611
+ const ext = gl.getExtension("WEBGL_debug_renderer_info");
4612
+ const vendorUnmasked = gl.getParameter(ext ? ext.UNMASKED_VENDOR_WEBGL : GL.VENDOR);
4613
+ const rendererUnmasked = gl.getParameter(ext ? ext.UNMASKED_RENDERER_WEBGL : GL.RENDERER);
4578
4614
  const vendor = vendorUnmasked || vendorMasked;
4579
4615
  const renderer = rendererUnmasked || rendererMasked;
4580
4616
  const gpu = identifyGPUVendor(vendor, renderer);
4581
4617
  return {
4582
- type: isWebGL2(gl2) ? "webgl2" : "webgl",
4618
+ type: isWebGL2(gl) ? "webgl2" : "webgl",
4583
4619
  gpu,
4584
4620
  vendor: vendorUnmasked || vendorMasked,
4585
4621
  renderer: rendererUnmasked || rendererMasked,
4586
- version: gl2.getParameter(GL.VERSION),
4622
+ version: gl.getParameter(GL.VERSION),
4587
4623
  shadingLanguages: ["glsl"],
4588
4624
  shadingLanguageVersions: {
4589
- "glsl": gl2.getParameter(GL.SHADING_LANGUAGE_VERSION)
4625
+ "glsl": gl.getParameter(GL.SHADING_LANGUAGE_VERSION)
4590
4626
  }
4591
4627
  };
4592
4628
  }
@@ -4669,38 +4705,38 @@ var __exports__ = (() => {
4669
4705
  var EXT_TEXTURE_NORM16 = "EXT_texture_norm16";
4670
4706
  var EXT_FLOAT_WEBGL1 = "WEBGL_color_buffer_float";
4671
4707
  var EXT_FLOAT_RENDER_WEBGL2 = "EXT_color_buffer_float";
4672
- var checkExtension = (gl2, extension) => gl2.getExtension(extension);
4673
- var checkExtensions = (gl2, extensions) => extensions.every((extension) => gl2.getExtension(extension));
4708
+ var checkExtension = (gl, extension) => gl.getExtension(extension);
4709
+ var checkExtensions = (gl, extensions) => extensions.every((extension) => gl.getExtension(extension));
4674
4710
  var TEXTURE_FEATURE_CHECKS = {
4675
- "texture-blend-float-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "EXT_float_blend"),
4676
- "texture-formats-srgb-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, EXT_SRGB),
4677
- "texture-formats-depth-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "WEBGL_depth_texture"),
4678
- "texture-formats-float32-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "OES_texture_float"),
4679
- "texture-formats-float16-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "OES_texture_half_float"),
4680
- "texture-formats-norm16-webgl": (gl2) => isWebGL2(gl2) ? checkExtension(gl2, EXT_TEXTURE_NORM16) : false,
4681
- "texture-filter-linear-float32-webgl": (gl2) => checkExtension(gl2, "OES_texture_float_linear"),
4682
- "texture-filter-linear-float16-webgl": (gl2) => checkExtension(gl2, "OES_texture_half_float_linear"),
4683
- "texture-filter-anisotropic-webgl": (gl2) => checkExtension(gl2, "EXT_texture_filter_anisotropic"),
4684
- "texture-renderable-float32-webgl": (gl2) => checkExtension(gl2, "EXT_color_buffer_float"),
4711
+ "texture-blend-float-webgl1": (gl) => isWebGL2(gl) ? true : checkExtension(gl, "EXT_float_blend"),
4712
+ "texture-formats-srgb-webgl1": (gl) => isWebGL2(gl) ? true : checkExtension(gl, EXT_SRGB),
4713
+ "texture-formats-depth-webgl1": (gl) => isWebGL2(gl) ? true : checkExtension(gl, "WEBGL_depth_texture"),
4714
+ "texture-formats-float32-webgl1": (gl) => isWebGL2(gl) ? true : checkExtension(gl, "OES_texture_float"),
4715
+ "texture-formats-float16-webgl1": (gl) => isWebGL2(gl) ? true : checkExtension(gl, "OES_texture_half_float"),
4716
+ "texture-formats-norm16-webgl": (gl) => isWebGL2(gl) ? checkExtension(gl, EXT_TEXTURE_NORM16) : false,
4717
+ "texture-filter-linear-float32-webgl": (gl) => checkExtension(gl, "OES_texture_float_linear"),
4718
+ "texture-filter-linear-float16-webgl": (gl) => checkExtension(gl, "OES_texture_half_float_linear"),
4719
+ "texture-filter-anisotropic-webgl": (gl) => checkExtension(gl, "EXT_texture_filter_anisotropic"),
4720
+ "texture-renderable-float32-webgl": (gl) => checkExtension(gl, "EXT_color_buffer_float"),
4685
4721
  // [false, 'EXT_color_buffer_float'],
4686
- "texture-renderable-float16-webgl": (gl2) => checkExtension(gl2, "EXT_color_buffer_half_float"),
4687
- "texture-compression-bc": (gl2) => checkExtensions(gl2, [X_S3TC, X_S3TC_SRGB, X_RGTC, X_BPTC]),
4688
- "texture-compression-bc5-webgl": (gl2) => checkExtensions(gl2, [X_RGTC]),
4722
+ "texture-renderable-float16-webgl": (gl) => checkExtension(gl, "EXT_color_buffer_half_float"),
4723
+ "texture-compression-bc": (gl) => checkExtensions(gl, [X_S3TC, X_S3TC_SRGB, X_RGTC, X_BPTC]),
4724
+ "texture-compression-bc5-webgl": (gl) => checkExtensions(gl, [X_RGTC]),
4689
4725
  // 'texture-compression-bc7-webgl': gl => checkExtensions(gl, [X_BPTC]),
4690
4726
  // 'texture-compression-bc3-srgb-webgl': gl => checkExtensions(gl, [X_S3TC_SRGB]),
4691
4727
  // 'texture-compression-bc3-webgl': gl => checkExtensions(gl, [X_S3TC]),
4692
- "texture-compression-etc2": (gl2) => checkExtensions(gl2, [X_ETC2]),
4693
- "texture-compression-astc": (gl2) => checkExtensions(gl2, [X_ASTC]),
4694
- "texture-compression-etc1-webgl": (gl2) => checkExtensions(gl2, [X_ETC1]),
4695
- "texture-compression-pvrtc-webgl": (gl2) => checkExtensions(gl2, [X_PVRTC]),
4696
- "texture-compression-atc-webgl": (gl2) => checkExtensions(gl2, [X_ATC])
4728
+ "texture-compression-etc2": (gl) => checkExtensions(gl, [X_ETC2]),
4729
+ "texture-compression-astc": (gl) => checkExtensions(gl, [X_ASTC]),
4730
+ "texture-compression-etc1-webgl": (gl) => checkExtensions(gl, [X_ETC1]),
4731
+ "texture-compression-pvrtc-webgl": (gl) => checkExtensions(gl, [X_PVRTC]),
4732
+ "texture-compression-atc-webgl": (gl) => checkExtensions(gl, [X_ATC])
4697
4733
  };
4698
- function checkTextureFeature(gl2, feature) {
4699
- return TEXTURE_FEATURE_CHECKS[feature]?.(gl2) || false;
4734
+ function checkTextureFeature(gl, feature) {
4735
+ return TEXTURE_FEATURE_CHECKS[feature]?.(gl) || false;
4700
4736
  }
4701
- function getTextureFeatures(gl2) {
4737
+ function getTextureFeatures(gl) {
4702
4738
  const textureFeatures = Object.keys(TEXTURE_FEATURE_CHECKS);
4703
- return textureFeatures.filter((feature) => checkTextureFeature(gl2, feature));
4739
+ return textureFeatures.filter((feature) => checkTextureFeature(gl, feature));
4704
4740
  }
4705
4741
  var TEXTURE_FORMATS = {
4706
4742
  // Unsized formats that leave the precision up to the driver.
@@ -5440,23 +5476,23 @@ var __exports__ = (() => {
5440
5476
  [GL.BYTE]: 1,
5441
5477
  [GL.UNSIGNED_BYTE]: 1
5442
5478
  };
5443
- function isTextureFormatSupported(gl2, formatOrGL) {
5479
+ function isTextureFormatSupported(gl, formatOrGL) {
5444
5480
  const format = convertGLToTextureFormat(formatOrGL);
5445
5481
  const info = TEXTURE_FORMATS[format];
5446
5482
  if (!info) {
5447
5483
  return false;
5448
5484
  }
5449
- if (isWebGL2(gl2) ? info.gl === void 0 : info.gl1 === void 0) {
5485
+ if (isWebGL2(gl) ? info.gl === void 0 : info.gl1 === void 0) {
5450
5486
  return false;
5451
5487
  }
5452
- const extension = info.x || (isWebGL2(gl2) ? info.gl2ext || info.gl1ext : info.gl1ext);
5488
+ const extension = info.x || (isWebGL2(gl) ? info.gl2ext || info.gl1ext : info.gl1ext);
5453
5489
  if (extension) {
5454
- return Boolean(gl2.getExtension(extension));
5490
+ return Boolean(gl.getExtension(extension));
5455
5491
  }
5456
5492
  return true;
5457
5493
  }
5458
- function isRenderbufferFormatSupported(gl2, format) {
5459
- return isTextureFormatSupported(gl2, format) && TEXTURE_FORMATS[format]?.renderbuffer;
5494
+ function isRenderbufferFormatSupported(gl, format) {
5495
+ return isTextureFormatSupported(gl, format) && TEXTURE_FORMATS[format]?.renderbuffer;
5460
5496
  }
5461
5497
  function convertGLToTextureFormat(format) {
5462
5498
  if (typeof format === "string") {
@@ -5476,9 +5512,9 @@ var __exports__ = (() => {
5476
5512
  }
5477
5513
  return webglFormat;
5478
5514
  }
5479
- function isTextureFormatFilterable(gl2, formatOrGL) {
5515
+ function isTextureFormatFilterable(gl, formatOrGL) {
5480
5516
  const format = convertGLToTextureFormat(formatOrGL);
5481
- if (!isTextureFormatSupported(gl2, format)) {
5517
+ if (!isTextureFormatSupported(gl, format)) {
5482
5518
  return false;
5483
5519
  }
5484
5520
  try {
@@ -5490,16 +5526,16 @@ var __exports__ = (() => {
5490
5526
  return false;
5491
5527
  }
5492
5528
  if (format.endsWith("32float")) {
5493
- return Boolean(gl2.getExtension("OES_texture_float_linear"));
5529
+ return Boolean(gl.getExtension("OES_texture_float_linear"));
5494
5530
  }
5495
5531
  if (format.endsWith("16float")) {
5496
- return Boolean(gl2.getExtension("OES_texture_half_float_linear"));
5532
+ return Boolean(gl.getExtension("OES_texture_half_float_linear"));
5497
5533
  }
5498
5534
  return true;
5499
5535
  }
5500
- function isTextureFormatRenderable(gl2, formatOrGL) {
5536
+ function isTextureFormatRenderable(gl, formatOrGL) {
5501
5537
  const format = convertGLToTextureFormat(formatOrGL);
5502
- if (!isTextureFormatSupported(gl2, format)) {
5538
+ if (!isTextureFormatSupported(gl, format)) {
5503
5539
  return false;
5504
5540
  }
5505
5541
  if (typeof format === "number") {
@@ -5527,27 +5563,27 @@ var __exports__ = (() => {
5527
5563
  }
5528
5564
  return info.attachment;
5529
5565
  }
5530
- function _checkFloat32ColorAttachment(gl2, internalFormat = gl2.RGBA, srcFormat = GL.RGBA, srcType = GL.UNSIGNED_BYTE) {
5566
+ function _checkFloat32ColorAttachment(gl, internalFormat = gl.RGBA, srcFormat = GL.RGBA, srcType = GL.UNSIGNED_BYTE) {
5531
5567
  let texture = null;
5532
5568
  let framebuffer = null;
5533
5569
  try {
5534
- texture = gl2.createTexture();
5535
- gl2.bindTexture(GL.TEXTURE_2D, texture);
5570
+ texture = gl.createTexture();
5571
+ gl.bindTexture(GL.TEXTURE_2D, texture);
5536
5572
  const level = 0;
5537
5573
  const width = 1;
5538
5574
  const height = 1;
5539
5575
  const border = 0;
5540
5576
  const pixel = new Uint8Array([0, 0, 255, 255]);
5541
- gl2.texImage2D(gl2.TEXTURE_2D, level, internalFormat, width, height, border, srcFormat, srcType, pixel);
5542
- framebuffer = gl2.createFramebuffer();
5543
- gl2.bindFramebuffer(GL.FRAMEBUFFER, framebuffer);
5544
- gl2.framebufferTexture2D(GL.FRAMEBUFFER, GL.COLOR_ATTACHMENT0, GL.TEXTURE_2D, texture, 0);
5545
- const status = gl2.checkFramebufferStatus(GL.FRAMEBUFFER) === GL.FRAMEBUFFER_COMPLETE;
5546
- gl2.bindTexture(GL.TEXTURE_2D, null);
5577
+ gl.texImage2D(gl.TEXTURE_2D, level, internalFormat, width, height, border, srcFormat, srcType, pixel);
5578
+ framebuffer = gl.createFramebuffer();
5579
+ gl.bindFramebuffer(GL.FRAMEBUFFER, framebuffer);
5580
+ gl.framebufferTexture2D(GL.FRAMEBUFFER, GL.COLOR_ATTACHMENT0, GL.TEXTURE_2D, texture, 0);
5581
+ const status = gl.checkFramebufferStatus(GL.FRAMEBUFFER) === GL.FRAMEBUFFER_COMPLETE;
5582
+ gl.bindTexture(GL.TEXTURE_2D, null);
5547
5583
  return status;
5548
5584
  } finally {
5549
- gl2.deleteTexture(texture);
5550
- gl2.deleteFramebuffer(framebuffer);
5585
+ gl.deleteTexture(texture);
5586
+ gl.deleteFramebuffer(framebuffer);
5551
5587
  }
5552
5588
  }
5553
5589
  function getTextureFormatBytesPerPixel(formatOrGL, isWebGL23) {
@@ -5576,52 +5612,52 @@ var __exports__ = (() => {
5576
5612
  }
5577
5613
 
5578
5614
  // src/adapter/device-helpers/device-features.ts
5579
- function getDeviceFeatures(gl2) {
5580
- const features = getWebGLFeatures(gl2);
5581
- for (const textureFeature of getTextureFeatures(gl2)) {
5615
+ function getDeviceFeatures(gl) {
5616
+ const features = getWebGLFeatures(gl);
5617
+ for (const textureFeature of getTextureFeatures(gl)) {
5582
5618
  features.add(textureFeature);
5583
5619
  }
5584
5620
  return features;
5585
5621
  }
5586
- function getWebGLFeatures(gl2) {
5587
- gl2.getExtension("EXT_color_buffer_float");
5588
- gl2.getExtension("WEBGL_color_buffer_float");
5589
- gl2.getExtension("EXT_float_blend");
5622
+ function getWebGLFeatures(gl) {
5623
+ gl.getExtension("EXT_color_buffer_float");
5624
+ gl.getExtension("WEBGL_color_buffer_float");
5625
+ gl.getExtension("EXT_float_blend");
5590
5626
  const features = /* @__PURE__ */ new Set();
5591
5627
  for (const feature of Object.keys(WEBGL_FEATURES)) {
5592
- if (isFeatureSupported(gl2, feature)) {
5628
+ if (isFeatureSupported(gl, feature)) {
5593
5629
  features.add(feature);
5594
5630
  }
5595
5631
  }
5596
5632
  return features;
5597
5633
  }
5598
- function isFeatureSupported(gl2, feature) {
5634
+ function isFeatureSupported(gl, feature) {
5599
5635
  const featureInfo = WEBGL_FEATURES[feature];
5600
5636
  if (!featureInfo) {
5601
5637
  return false;
5602
5638
  }
5603
5639
  const [webgl1Feature, webgl2Feature] = featureInfo || [];
5604
- const featureDefinition = isWebGL2(gl2) ? webgl2Feature : webgl1Feature;
5640
+ const featureDefinition = isWebGL2(gl) ? webgl2Feature : webgl1Feature;
5605
5641
  if (typeof featureDefinition === "boolean") {
5606
5642
  return featureDefinition;
5607
5643
  }
5608
5644
  switch (feature) {
5609
5645
  case "texture-renderable-rgba32float-webgl":
5610
- return isWebGL2(gl2) ? Boolean(gl2.getExtension(featureDefinition)) : _checkFloat32ColorAttachment(gl2);
5646
+ return isWebGL2(gl) ? Boolean(gl.getExtension(featureDefinition)) : _checkFloat32ColorAttachment(gl);
5611
5647
  case "glsl-derivatives":
5612
- return canCompileGLSLExtension(gl2, featureDefinition);
5648
+ return canCompileGLSLExtension(gl, featureDefinition);
5613
5649
  case "glsl-frag-data":
5614
- return canCompileGLSLExtension(gl2, featureDefinition, {
5650
+ return canCompileGLSLExtension(gl, featureDefinition, {
5615
5651
  behavior: "require"
5616
5652
  });
5617
5653
  case "glsl-frag-depth":
5618
- return canCompileGLSLExtension(gl2, featureDefinition);
5654
+ return canCompileGLSLExtension(gl, featureDefinition);
5619
5655
  default:
5620
- return Boolean(gl2.getExtension(featureDefinition));
5656
+ return Boolean(gl.getExtension(featureDefinition));
5621
5657
  }
5622
5658
  }
5623
5659
  var compiledGLSLExtensions = {};
5624
- function canCompileGLSLExtension(gl2, extensionName, opts = {}) {
5660
+ function canCompileGLSLExtension(gl, extensionName, opts = {}) {
5625
5661
  if (!isOldIE(opts)) {
5626
5662
  return true;
5627
5663
  }
@@ -5631,14 +5667,14 @@ var __exports__ = (() => {
5631
5667
  const behavior = opts.behavior || "enable";
5632
5668
  const source = `#extension GL_${extensionName} : ${behavior}
5633
5669
  void main(void) {}`;
5634
- const shader = gl2.createShader(gl2.VERTEX_SHADER);
5670
+ const shader = gl.createShader(gl.VERTEX_SHADER);
5635
5671
  if (!shader) {
5636
5672
  throw new Error("shader");
5637
5673
  }
5638
- gl2.shaderSource(shader, source);
5639
- gl2.compileShader(shader);
5640
- const canCompile = gl2.getShaderParameter(shader, gl2.COMPILE_STATUS);
5641
- gl2.deleteShader(shader);
5674
+ gl.shaderSource(shader, source);
5675
+ gl.compileShader(shader);
5676
+ const canCompile = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
5677
+ gl.deleteShader(shader);
5642
5678
  compiledGLSLExtensions[extensionName] = canCompile;
5643
5679
  return canCompile;
5644
5680
  }
@@ -5675,38 +5711,38 @@ void main(void) {}`;
5675
5711
  };
5676
5712
 
5677
5713
  // src/adapter/device-helpers/device-limits.ts
5678
- function getDeviceLimits(gl2) {
5679
- const gl22 = getWebGL2Context(gl2);
5714
+ function getDeviceLimits(gl) {
5715
+ const gl2 = getWebGL2Context(gl);
5680
5716
  return {
5681
5717
  maxTextureDimension1D: 0,
5682
5718
  // WebGL does not support 1D textures
5683
- maxTextureDimension2D: gl2.getParameter(GL.MAX_TEXTURE_SIZE),
5684
- maxTextureDimension3D: gl22 ? gl22.getParameter(GL.MAX_3D_TEXTURE_SIZE) : 0,
5685
- maxTextureArrayLayers: gl22 ? gl22.getParameter(GL.MAX_ARRAY_TEXTURE_LAYERS) : 0,
5719
+ maxTextureDimension2D: gl.getParameter(GL.MAX_TEXTURE_SIZE),
5720
+ maxTextureDimension3D: gl2 ? gl2.getParameter(GL.MAX_3D_TEXTURE_SIZE) : 0,
5721
+ maxTextureArrayLayers: gl2 ? gl2.getParameter(GL.MAX_ARRAY_TEXTURE_LAYERS) : 0,
5686
5722
  maxBindGroups: 1,
5687
5723
  // TBD
5688
5724
  maxDynamicUniformBuffersPerPipelineLayout: 0,
5689
5725
  // TBD
5690
5726
  maxDynamicStorageBuffersPerPipelineLayout: 0,
5691
5727
  // TBD
5692
- maxSampledTexturesPerShaderStage: gl2.getParameter(GL.MAX_VERTEX_TEXTURE_IMAGE_UNITS),
5728
+ maxSampledTexturesPerShaderStage: gl.getParameter(GL.MAX_VERTEX_TEXTURE_IMAGE_UNITS),
5693
5729
  // TBD
5694
- maxSamplersPerShaderStage: gl2.getParameter(GL.MAX_COMBINED_TEXTURE_IMAGE_UNITS),
5730
+ maxSamplersPerShaderStage: gl.getParameter(GL.MAX_COMBINED_TEXTURE_IMAGE_UNITS),
5695
5731
  maxStorageBuffersPerShaderStage: 0,
5696
5732
  // TBD
5697
5733
  maxStorageTexturesPerShaderStage: 0,
5698
5734
  // TBD
5699
- maxUniformBuffersPerShaderStage: gl22 ? gl22.getParameter(GL.MAX_UNIFORM_BUFFER_BINDINGS) : 0,
5700
- maxUniformBufferBindingSize: gl22 ? gl22.getParameter(GL.MAX_UNIFORM_BLOCK_SIZE) : 0,
5735
+ maxUniformBuffersPerShaderStage: gl2 ? gl2.getParameter(GL.MAX_UNIFORM_BUFFER_BINDINGS) : 0,
5736
+ maxUniformBufferBindingSize: gl2 ? gl2.getParameter(GL.MAX_UNIFORM_BLOCK_SIZE) : 0,
5701
5737
  maxStorageBufferBindingSize: 0,
5702
- minUniformBufferOffsetAlignment: gl22 ? gl22.getParameter(GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT) : 0,
5738
+ minUniformBufferOffsetAlignment: gl2 ? gl2.getParameter(GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT) : 0,
5703
5739
  minStorageBufferOffsetAlignment: 0,
5704
5740
  // TBD
5705
5741
  maxVertexBuffers: 0,
5706
- maxVertexAttributes: gl2.getParameter(GL.MAX_VERTEX_ATTRIBS),
5742
+ maxVertexAttributes: gl.getParameter(GL.MAX_VERTEX_ATTRIBS),
5707
5743
  maxVertexBufferArrayStride: 2048,
5708
5744
  // TBD, this is just the default value from WebGPU
5709
- maxInterStageShaderComponents: gl22 ? gl22.getParameter(GL.MAX_VARYING_COMPONENTS) : 0,
5745
+ maxInterStageShaderComponents: gl2 ? gl2.getParameter(GL.MAX_VARYING_COMPONENTS) : 0,
5710
5746
  maxComputeWorkgroupStorageSize: 0,
5711
5747
  // WebGL does not support compute shaders
5712
5748
  maxComputeInvocationsPerWorkgroup: 0,
@@ -5721,13 +5757,13 @@ void main(void) {}`;
5721
5757
  // WebGL does not support compute shaders
5722
5758
  };
5723
5759
  }
5724
- function getWebGLLimits(gl2) {
5725
- const gl22 = getWebGL2Context(gl2);
5760
+ function getWebGLLimits(gl) {
5761
+ const gl2 = getWebGL2Context(gl);
5726
5762
  function get(pname) {
5727
- return gl2.getParameter(pname);
5763
+ return gl.getParameter(pname);
5728
5764
  }
5729
5765
  function get2(pname, defaultValue) {
5730
- return gl22 ? gl22.getParameter(pname) : defaultValue || 0;
5766
+ return gl2 ? gl2.getParameter(pname) : defaultValue || 0;
5731
5767
  }
5732
5768
  return {
5733
5769
  [GL.ALIASED_LINE_WIDTH_RANGE]: get(GL.ALIASED_LINE_WIDTH_RANGE),
@@ -5818,26 +5854,26 @@ void main(void) {}`;
5818
5854
  }
5819
5855
 
5820
5856
  // src/context/state-tracker/with-parameters.ts
5821
- function withParameters(device, parameters, func) {
5857
+ function withGLParameters(device, parameters, func) {
5822
5858
  const webglDevice = WebGLDevice.attach(device);
5823
- const gl2 = webglDevice.gl;
5859
+ const gl = webglDevice.gl;
5824
5860
  if (isObjectEmpty3(parameters)) {
5825
5861
  return func(device);
5826
5862
  }
5827
5863
  const {
5828
5864
  nocatch = true
5829
5865
  } = parameters;
5830
- pushContextState(gl2);
5831
- setParameters(gl2, parameters);
5866
+ pushContextState(gl);
5867
+ setGLParameters(gl, parameters);
5832
5868
  let value;
5833
5869
  if (nocatch) {
5834
- value = func(gl2);
5835
- popContextState(gl2);
5870
+ value = func(gl);
5871
+ popContextState(gl);
5836
5872
  } else {
5837
5873
  try {
5838
- value = func(gl2);
5874
+ value = func(gl);
5839
5875
  } finally {
5840
- popContextState(gl2);
5876
+ popContextState(gl);
5841
5877
  }
5842
5878
  }
5843
5879
  return value;
@@ -5850,13 +5886,14 @@ void main(void) {}`;
5850
5886
  }
5851
5887
 
5852
5888
  // src/adapter/converters/device-parameters.ts
5853
- function withGLParameters(device, parameters, func) {
5889
+ function withDeviceAndGLParameters(device, parameters, glParameters, func) {
5854
5890
  if (isObjectEmpty(parameters)) {
5855
5891
  return func(device);
5856
5892
  }
5857
5893
  pushContextState(device.gl);
5858
5894
  try {
5859
- setParameters(device, parameters);
5895
+ setDeviceParameters(device, parameters);
5896
+ setGLParameters(device, glParameters);
5860
5897
  return func(device);
5861
5898
  } finally {
5862
5899
  popContextState(device.gl);
@@ -5877,43 +5914,43 @@ void main(void) {}`;
5877
5914
  function setDeviceParameters(device, parameters) {
5878
5915
  const webglDevice = WebGLDevice.attach(device);
5879
5916
  const {
5880
- gl: gl2
5917
+ gl
5881
5918
  } = webglDevice;
5882
5919
  if (parameters.cullMode) {
5883
5920
  switch (parameters.cullMode) {
5884
5921
  case "none":
5885
- gl2.disable(GL.CULL_FACE);
5922
+ gl.disable(GL.CULL_FACE);
5886
5923
  break;
5887
5924
  case "front":
5888
- gl2.enable(GL.CULL_FACE);
5889
- gl2.cullFace(GL.FRONT);
5925
+ gl.enable(GL.CULL_FACE);
5926
+ gl.cullFace(GL.FRONT);
5890
5927
  break;
5891
5928
  case "back":
5892
- gl2.enable(GL.CULL_FACE);
5893
- gl2.cullFace(GL.BACK);
5929
+ gl.enable(GL.CULL_FACE);
5930
+ gl.cullFace(GL.BACK);
5894
5931
  break;
5895
5932
  }
5896
5933
  }
5897
5934
  if (parameters.frontFace) {
5898
- gl2.frontFace(map("frontFace", parameters.frontFace, {
5935
+ gl.frontFace(map("frontFace", parameters.frontFace, {
5899
5936
  ccw: GL.CCW,
5900
5937
  cw: GL.CW
5901
5938
  }));
5902
5939
  }
5903
5940
  if (parameters.depthBias !== void 0) {
5904
- gl2.polygonOffset(parameters.depthBias, parameters.depthBiasSlopeScale || 0);
5941
+ gl.polygonOffset(parameters.depthBias, parameters.depthBiasSlopeScale || 0);
5905
5942
  }
5906
5943
  if (parameters.depthWriteEnabled !== void 0) {
5907
- gl2.depthMask(mapBoolean("depthWriteEnabled", parameters.depthWriteEnabled));
5944
+ gl.depthMask(mapBoolean("depthWriteEnabled", parameters.depthWriteEnabled));
5908
5945
  }
5909
5946
  if (parameters.depthCompare) {
5910
- parameters.depthCompare !== "always" ? gl2.enable(GL.DEPTH_TEST) : gl2.disable(GL.DEPTH_TEST);
5911
- gl2.depthFunc(convertCompareFunction("depthCompare", parameters.depthCompare));
5947
+ parameters.depthCompare !== "always" ? gl.enable(GL.DEPTH_TEST) : gl.disable(GL.DEPTH_TEST);
5948
+ gl.depthFunc(convertCompareFunction("depthCompare", parameters.depthCompare));
5912
5949
  }
5913
5950
  if (parameters.stencilWriteMask) {
5914
5951
  const mask = parameters.stencilWriteMask;
5915
- gl2.stencilMaskSeparate(GL.FRONT, mask);
5916
- gl2.stencilMaskSeparate(GL.BACK, mask);
5952
+ gl.stencilMaskSeparate(GL.FRONT, mask);
5953
+ gl.stencilMaskSeparate(GL.BACK, mask);
5917
5954
  }
5918
5955
  if (parameters.stencilReadMask) {
5919
5956
  log.warn("stencilReadMask not supported under WebGL");
@@ -5921,16 +5958,16 @@ void main(void) {}`;
5921
5958
  if (parameters.stencilCompare) {
5922
5959
  const mask = parameters.stencilReadMask || 4294967295;
5923
5960
  const glValue = convertCompareFunction("depthCompare", parameters.stencilCompare);
5924
- parameters.stencilCompare !== "always" ? gl2.enable(GL.STENCIL_TEST) : gl2.disable(GL.STENCIL_TEST);
5925
- gl2.stencilFuncSeparate(GL.FRONT, glValue, 0, mask);
5926
- gl2.stencilFuncSeparate(GL.BACK, glValue, 0, mask);
5961
+ parameters.stencilCompare !== "always" ? gl.enable(GL.STENCIL_TEST) : gl.disable(GL.STENCIL_TEST);
5962
+ gl.stencilFuncSeparate(GL.FRONT, glValue, 0, mask);
5963
+ gl.stencilFuncSeparate(GL.BACK, glValue, 0, mask);
5927
5964
  }
5928
5965
  if (parameters.stencilPassOperation && parameters.stencilFailOperation && parameters.stencilDepthFailOperation) {
5929
5966
  const dppass = convertStencilOperation("stencilPassOperation", parameters.stencilPassOperation);
5930
5967
  const sfail = convertStencilOperation("stencilFailOperation", parameters.stencilFailOperation);
5931
5968
  const dpfail = convertStencilOperation("stencilDepthFailOperation", parameters.stencilDepthFailOperation);
5932
- gl2.stencilOpSeparate(GL.FRONT, sfail, dpfail, dppass);
5933
- gl2.stencilOpSeparate(GL.BACK, sfail, dpfail, dppass);
5969
+ gl.stencilOpSeparate(GL.FRONT, sfail, dpfail, dppass);
5970
+ gl.stencilOpSeparate(GL.BACK, sfail, dpfail, dppass);
5934
5971
  }
5935
5972
  }
5936
5973
  function convertCompareFunction(parameter, value) {
@@ -6463,7 +6500,7 @@ void main(void) {}`;
6463
6500
  }
6464
6501
  this.mipmaps = true;
6465
6502
  this.gl.bindTexture(this.target, this.handle);
6466
- withParameters(this.gl, params, () => {
6503
+ withGLParameters(this.gl, params, () => {
6467
6504
  this.gl.generateMipmap(this.target);
6468
6505
  });
6469
6506
  this.gl.bindTexture(this.target, null);
@@ -6530,9 +6567,9 @@ void main(void) {}`;
6530
6567
  height
6531
6568
  }));
6532
6569
  const {
6533
- gl: gl2
6570
+ gl
6534
6571
  } = this;
6535
- gl2.bindTexture(this.target, this.handle);
6572
+ gl.bindTexture(this.target, this.handle);
6536
6573
  let dataType = null;
6537
6574
  ({
6538
6575
  data,
@@ -6541,14 +6578,14 @@ void main(void) {}`;
6541
6578
  data,
6542
6579
  compressed
6543
6580
  }));
6544
- let gl22;
6545
- withParameters(this.gl, parameters, () => {
6581
+ let gl2;
6582
+ withGLParameters(this.gl, parameters, () => {
6546
6583
  switch (dataType) {
6547
6584
  case "null":
6548
- gl2.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
6585
+ gl.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
6549
6586
  break;
6550
6587
  case "typed-array":
6551
- gl2.texImage2D(
6588
+ gl.texImage2D(
6552
6589
  target,
6553
6590
  level,
6554
6591
  glFormat,
@@ -6564,21 +6601,21 @@ void main(void) {}`;
6564
6601
  );
6565
6602
  break;
6566
6603
  case "buffer":
6567
- gl22 = this.device.assertWebGL2();
6568
- gl22.bindBuffer(GL.PIXEL_UNPACK_BUFFER, data.handle || data);
6569
- gl22.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, offset);
6570
- gl22.bindBuffer(GL.PIXEL_UNPACK_BUFFER, null);
6604
+ gl2 = this.device.assertWebGL2();
6605
+ gl2.bindBuffer(GL.PIXEL_UNPACK_BUFFER, data.handle || data);
6606
+ gl2.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, offset);
6607
+ gl2.bindBuffer(GL.PIXEL_UNPACK_BUFFER, null);
6571
6608
  break;
6572
6609
  case "browser-object":
6573
6610
  if (this.device.isWebGL2) {
6574
- gl2.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
6611
+ gl.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
6575
6612
  } else {
6576
- gl2.texImage2D(target, level, glFormat, dataFormat, type, data);
6613
+ gl.texImage2D(target, level, glFormat, dataFormat, type, data);
6577
6614
  }
6578
6615
  break;
6579
6616
  case "compressed":
6580
6617
  for (const [levelIndex, levelData] of data.entries()) {
6581
- gl2.compressedTexImage2D(target, levelIndex, levelData.format, levelData.width, levelData.height, 0, levelData.data);
6618
+ gl.compressedTexImage2D(target, levelIndex, levelData.format, levelData.width, levelData.height, 0, levelData.data);
6582
6619
  }
6583
6620
  break;
6584
6621
  default:
@@ -6644,7 +6681,7 @@ void main(void) {}`;
6644
6681
  data = data.handle;
6645
6682
  }
6646
6683
  this.gl.bindTexture(this.target, this.handle);
6647
- withParameters(this.gl, parameters, () => {
6684
+ withGLParameters(this.gl, parameters, () => {
6648
6685
  if (compressed) {
6649
6686
  this.gl.compressedTexSubImage2D(target, level, x, y, width, height, glFormat, data);
6650
6687
  } else if (data === null) {
@@ -6682,24 +6719,24 @@ void main(void) {}`;
6682
6719
  }
6683
6720
  bind(textureUnit = this.textureUnit) {
6684
6721
  const {
6685
- gl: gl2
6722
+ gl
6686
6723
  } = this;
6687
6724
  if (textureUnit !== void 0) {
6688
6725
  this.textureUnit = textureUnit;
6689
- gl2.activeTexture(gl2.TEXTURE0 + textureUnit);
6726
+ gl.activeTexture(gl.TEXTURE0 + textureUnit);
6690
6727
  }
6691
- gl2.bindTexture(this.target, this.handle);
6728
+ gl.bindTexture(this.target, this.handle);
6692
6729
  return textureUnit;
6693
6730
  }
6694
6731
  unbind(textureUnit = this.textureUnit) {
6695
6732
  const {
6696
- gl: gl2
6733
+ gl
6697
6734
  } = this;
6698
6735
  if (textureUnit !== void 0) {
6699
6736
  this.textureUnit = textureUnit;
6700
- gl2.activeTexture(gl2.TEXTURE0 + textureUnit);
6737
+ gl.activeTexture(gl.TEXTURE0 + textureUnit);
6701
6738
  }
6702
- gl2.bindTexture(this.target, null);
6739
+ gl.bindTexture(this.target, null);
6703
6740
  return textureUnit;
6704
6741
  }
6705
6742
  // PRIVATE METHODS
@@ -6821,7 +6858,7 @@ void main(void) {}`;
6821
6858
  /* eslint-disable max-statements, max-len */
6822
6859
  async setCubeMapImageData(options) {
6823
6860
  const {
6824
- gl: gl2
6861
+ gl
6825
6862
  } = this;
6826
6863
  const {
6827
6864
  width,
@@ -6843,9 +6880,9 @@ void main(void) {}`;
6843
6880
  }
6844
6881
  resolvedFaces[index].forEach((image, lodLevel) => {
6845
6882
  if (width && height) {
6846
- gl2.texImage2D(face, lodLevel, format, width, height, 0, format, type, image);
6883
+ gl.texImage2D(face, lodLevel, format, width, height, 0, format, type, image);
6847
6884
  } else {
6848
- gl2.texImage2D(face, lodLevel, format, format, type, image);
6885
+ gl.texImage2D(face, lodLevel, format, format, type, image);
6849
6886
  }
6850
6887
  });
6851
6888
  });
@@ -6864,7 +6901,7 @@ void main(void) {}`;
6864
6901
  // generateMipmap = false // TODO
6865
6902
  } = options;
6866
6903
  const {
6867
- gl: gl2
6904
+ gl
6868
6905
  } = this;
6869
6906
  const imageData = pixels || data;
6870
6907
  this.bind();
@@ -6875,9 +6912,9 @@ void main(void) {}`;
6875
6912
  pixels: resolvedImageData
6876
6913
  })));
6877
6914
  } else if (this.width || this.height) {
6878
- gl2.texImage2D(face, 0, format, width, height, 0, format, type, imageData);
6915
+ gl.texImage2D(face, 0, format, width, height, 0, format, type, imageData);
6879
6916
  } else {
6880
- gl2.texImage2D(face, 0, format, format, type, imageData);
6917
+ gl.texImage2D(face, 0, format, format, type, imageData);
6881
6918
  }
6882
6919
  return this;
6883
6920
  }
@@ -6899,7 +6936,7 @@ void main(void) {}`;
6899
6936
  this.trackDeallocatedMemory("Texture");
6900
6937
  this.gl.bindTexture(this.target, this.handle);
6901
6938
  const webglTextureFormat = getWebGLTextureParameters(format, this.device.isWebGL2);
6902
- withParameters(this.gl, parameters, () => {
6939
+ withGLParameters(this.gl, parameters, () => {
6903
6940
  if (ArrayBuffer.isView(data)) {
6904
6941
  this.gl.texImage3D(
6905
6942
  this.target,
@@ -7009,7 +7046,7 @@ void main(void) {}`;
7009
7046
  }
7010
7047
 
7011
7048
  // src/adapter/objects/constants-to-keys.ts
7012
- function getKeyValue(gl2, name2) {
7049
+ function getKeyValue(gl, name2) {
7013
7050
  if (typeof name2 !== "string") {
7014
7051
  return name2;
7015
7052
  }
@@ -7018,7 +7055,7 @@ void main(void) {}`;
7018
7055
  return number;
7019
7056
  }
7020
7057
  name2 = name2.replace(/^.*\./, "");
7021
- const value = gl2[name2];
7058
+ const value = gl[name2];
7022
7059
  assert2(value !== void 0, `Accessing undefined constant GL.${name2}`);
7023
7060
  return value;
7024
7061
  }
@@ -7032,13 +7069,13 @@ void main(void) {}`;
7032
7069
  constructor(device, props, defaultProps) {
7033
7070
  super(device, props, defaultProps);
7034
7071
  this.device = WebGLDevice.attach(device);
7035
- const gl2 = this.device.gl;
7036
- assertWebGLContext(gl2);
7072
+ const gl = this.device.gl;
7073
+ assertWebGLContext(gl);
7037
7074
  const {
7038
7075
  id
7039
7076
  } = props || {};
7040
- this.gl = gl2;
7041
- this.gl2 = gl2;
7077
+ this.gl = gl;
7078
+ this.gl2 = gl;
7042
7079
  this.id = id || uid(this.constructor.name);
7043
7080
  this._handle = props?.handle;
7044
7081
  if (this._handle === void 0) {
@@ -7356,12 +7393,12 @@ void main(void) {}`;
7356
7393
  /** Check the status */
7357
7394
  _checkStatus() {
7358
7395
  const {
7359
- gl: gl2
7396
+ gl
7360
7397
  } = this;
7361
- const prevHandle2 = gl2.bindFramebuffer(GL.FRAMEBUFFER, this.handle);
7362
- const status = gl2.checkFramebufferStatus(GL.FRAMEBUFFER);
7363
- gl2.bindFramebuffer(GL.FRAMEBUFFER, prevHandle2 || null);
7364
- if (status !== gl2.FRAMEBUFFER_COMPLETE) {
7398
+ const prevHandle = gl.bindFramebuffer(GL.FRAMEBUFFER, this.handle);
7399
+ const status = gl.checkFramebufferStatus(GL.FRAMEBUFFER);
7400
+ gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
7401
+ if (status !== gl.FRAMEBUFFER_COMPLETE) {
7365
7402
  throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);
7366
7403
  }
7367
7404
  }
@@ -7432,27 +7469,27 @@ void main(void) {}`;
7432
7469
  */
7433
7470
  _attachTexture(attachment, texture, layer, level) {
7434
7471
  const {
7435
- gl: gl2,
7436
- gl2: gl22
7472
+ gl,
7473
+ gl2
7437
7474
  } = this.device;
7438
- gl2.bindTexture(texture.target, texture.handle);
7475
+ gl.bindTexture(texture.target, texture.handle);
7439
7476
  switch (texture.target) {
7440
7477
  case GL.TEXTURE_2D_ARRAY:
7441
7478
  case GL.TEXTURE_3D:
7442
7479
  this.device.assertWebGL2();
7443
- gl22?.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.target, level, layer);
7480
+ gl2?.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.target, level, layer);
7444
7481
  break;
7445
7482
  case GL.TEXTURE_CUBE_MAP:
7446
7483
  const face = mapIndexToCubeMapFace(layer);
7447
- gl2.framebufferTexture2D(GL.FRAMEBUFFER, attachment, face, texture.handle, level);
7484
+ gl.framebufferTexture2D(GL.FRAMEBUFFER, attachment, face, texture.handle, level);
7448
7485
  break;
7449
7486
  case GL.TEXTURE_2D:
7450
- gl2.framebufferTexture2D(GL.FRAMEBUFFER, attachment, GL.TEXTURE_2D, texture.handle, level);
7487
+ gl.framebufferTexture2D(GL.FRAMEBUFFER, attachment, GL.TEXTURE_2D, texture.handle, level);
7451
7488
  break;
7452
7489
  default:
7453
7490
  assert2(false, "Illegal texture type");
7454
7491
  }
7455
- gl2.bindTexture(texture.target, null);
7492
+ gl.bindTexture(texture.target, null);
7456
7493
  }
7457
7494
  };
7458
7495
  function mapIndexToCubeMapFace(layer) {
@@ -7590,9 +7627,9 @@ void main(void) {}`;
7590
7627
 
7591
7628
  // src/context/debug/webgl-developer-tools.ts
7592
7629
  var WEBGL_DEBUG_CDN_URL = "https://unpkg.com/webgl-debug@2.0.1/index.js";
7593
- function getContextData2(gl2) {
7594
- gl2.luma = gl2.luma || {};
7595
- return gl2.luma;
7630
+ function getContextData2(gl) {
7631
+ gl.luma = gl.luma || {};
7632
+ return gl.luma;
7596
7633
  }
7597
7634
  async function loadWebGLDeveloperTools() {
7598
7635
  if (isBrowser() && !globalThis.WebGLDebugUtils) {
@@ -7601,30 +7638,30 @@ void main(void) {}`;
7601
7638
  await loadScript(WEBGL_DEBUG_CDN_URL);
7602
7639
  }
7603
7640
  }
7604
- function makeDebugContext(gl2, props = {}) {
7605
- if (!gl2) {
7641
+ function makeDebugContext(gl, props = {}) {
7642
+ if (!gl) {
7606
7643
  return null;
7607
7644
  }
7608
- return props.debug ? getDebugContext(gl2, props) : getRealContext(gl2);
7645
+ return props.debug ? getDebugContext(gl, props) : getRealContext(gl);
7609
7646
  }
7610
- function getRealContext(gl2) {
7611
- const data = getContextData2(gl2);
7612
- return data.realContext ? data.realContext : gl2;
7647
+ function getRealContext(gl) {
7648
+ const data = getContextData2(gl);
7649
+ return data.realContext ? data.realContext : gl;
7613
7650
  }
7614
- function getDebugContext(gl2, props) {
7651
+ function getDebugContext(gl, props) {
7615
7652
  if (!globalThis.WebGLDebugUtils) {
7616
7653
  log.warn("webgl-debug not loaded")();
7617
- return gl2;
7654
+ return gl;
7618
7655
  }
7619
- const data = getContextData2(gl2);
7656
+ const data = getContextData2(gl);
7620
7657
  if (data.debugContext) {
7621
7658
  return data.debugContext;
7622
7659
  }
7623
7660
  globalThis.WebGLDebugUtils.init({
7624
7661
  ...GL,
7625
- ...gl2
7662
+ ...gl
7626
7663
  });
7627
- const glDebug = globalThis.WebGLDebugUtils.makeDebugContext(gl2, onGLError.bind(null, props), onValidateGLFunc.bind(null, props));
7664
+ const glDebug = globalThis.WebGLDebugUtils.makeDebugContext(gl, onGLError.bind(null, props), onValidateGLFunc.bind(null, props));
7628
7665
  for (const key in GL) {
7629
7666
  if (!(key in glDebug) && typeof GL[key] === "number") {
7630
7667
  glDebug[key] = GL[key];
@@ -7632,10 +7669,10 @@ void main(void) {}`;
7632
7669
  }
7633
7670
  class WebGLDebugContext {
7634
7671
  }
7635
- Object.setPrototypeOf(glDebug, Object.getPrototypeOf(gl2));
7672
+ Object.setPrototypeOf(glDebug, Object.getPrototypeOf(gl));
7636
7673
  Object.setPrototypeOf(WebGLDebugContext, glDebug);
7637
7674
  const debugContext = Object.create(WebGLDebugContext);
7638
- data.realContext = gl2;
7675
+ data.realContext = gl;
7639
7676
  data.debugContext = debugContext;
7640
7677
  debugContext.debug = true;
7641
7678
  return debugContext;
@@ -8019,15 +8056,15 @@ void main(void) {}`;
8019
8056
  size
8020
8057
  } = options;
8021
8058
  const {
8022
- gl: gl2,
8023
- gl2: gl22
8059
+ gl,
8060
+ gl2
8024
8061
  } = this;
8025
- assertWebGL2Context(gl2);
8026
- gl2.bindBuffer(GL.COPY_READ_BUFFER, sourceBuffer.handle);
8027
- gl2.bindBuffer(GL.COPY_WRITE_BUFFER, this.handle);
8028
- gl22?.copyBufferSubData(GL.COPY_READ_BUFFER, GL.COPY_WRITE_BUFFER, readOffset, writeOffset, size);
8029
- gl2.bindBuffer(GL.COPY_READ_BUFFER, null);
8030
- gl2.bindBuffer(GL.COPY_WRITE_BUFFER, null);
8062
+ assertWebGL2Context(gl);
8063
+ gl.bindBuffer(GL.COPY_READ_BUFFER, sourceBuffer.handle);
8064
+ gl.bindBuffer(GL.COPY_WRITE_BUFFER, this.handle);
8065
+ gl2?.copyBufferSubData(GL.COPY_READ_BUFFER, GL.COPY_WRITE_BUFFER, readOffset, writeOffset, size);
8066
+ gl.bindBuffer(GL.COPY_READ_BUFFER, null);
8067
+ gl.bindBuffer(GL.COPY_WRITE_BUFFER, null);
8031
8068
  this.debugData = null;
8032
8069
  return this;
8033
8070
  }
@@ -8297,16 +8334,18 @@ void main(void) {}`;
8297
8334
  ${source2}`;
8298
8335
  source = addGLSLVersion(source);
8299
8336
  const {
8300
- gl: gl2
8337
+ gl
8301
8338
  } = this.device;
8302
- gl2.shaderSource(this.handle, source);
8303
- gl2.compileShader(this.handle);
8304
- const compileStatus = gl2.getShaderParameter(this.handle, GL.COMPILE_STATUS);
8339
+ gl.shaderSource(this.handle, source);
8340
+ gl.compileShader(this.handle);
8341
+ const compileStatus = gl.getShaderParameter(this.handle, GL.COMPILE_STATUS);
8305
8342
  if (!compileStatus) {
8306
- const shaderLog = gl2.getShaderInfoLog(this.handle);
8343
+ const shaderLog = gl.getShaderInfoLog(this.handle);
8307
8344
  const parsedLog = shaderLog ? parseShaderCompilerLog(shaderLog) : [];
8308
8345
  const messages = parsedLog.filter((message2) => message2.type === "error");
8309
- const formattedLog = formatCompilerLog(messages, source);
8346
+ const formattedLog = formatCompilerLog(messages, source, {
8347
+ showSourceCode: true
8348
+ });
8310
8349
  const shaderName = getShaderInfo(source).name;
8311
8350
  const shaderDescription = `${this.stage} shader ${shaderName}`;
8312
8351
  log.error(`GLSL compilation errors in ${shaderDescription}
@@ -8377,6 +8416,7 @@ ${formattedLog}`)();
8377
8416
  parameters[GL.STENCIL_REF] = parameters.stencilReference;
8378
8417
  }
8379
8418
  this.glParameters = glParameters;
8419
+ setGLParameters(this.device, glParameters);
8380
8420
  }
8381
8421
  // Internal
8382
8422
  /**
@@ -8400,7 +8440,7 @@ ${formattedLog}`)();
8400
8440
  glParameters.clearStencil = this.props.clearStencil;
8401
8441
  }
8402
8442
  if (clearMask !== 0) {
8403
- withParameters(this.device, glParameters, () => {
8443
+ withGLParameters(this.device, glParameters, () => {
8404
8444
  this.device.gl.clear(clearMask);
8405
8445
  });
8406
8446
  }
@@ -8409,7 +8449,7 @@ ${formattedLog}`)();
8409
8449
  * WebGL2 - clear a specific color buffer
8410
8450
  */
8411
8451
  clearColorBuffer(drawBuffer = 0, value = [0, 0, 0, 0]) {
8412
- withParameters(this.device.gl2, {
8452
+ withGLParameters(this.device.gl2, {
8413
8453
  framebuffer: this.props.framebuffer
8414
8454
  }, () => {
8415
8455
  switch (value.constructor) {
@@ -8515,13 +8555,13 @@ ${formattedLog}`)();
8515
8555
  }
8516
8556
 
8517
8557
  // src/adapter/helpers/get-shader-layout.ts
8518
- function getShaderLayout(gl2, program) {
8558
+ function getShaderLayout(gl, program) {
8519
8559
  const shaderLayout = {
8520
8560
  attributes: [],
8521
8561
  bindings: []
8522
8562
  };
8523
- shaderLayout.attributes = readAttributeDeclarations(gl2, program);
8524
- const uniformBlocks = readUniformBlocks(gl2, program);
8563
+ shaderLayout.attributes = readAttributeDeclarations(gl, program);
8564
+ const uniformBlocks = readUniformBlocks(gl, program);
8525
8565
  for (const uniformBlock of uniformBlocks) {
8526
8566
  const uniforms2 = uniformBlock.uniforms.map((uniform) => ({
8527
8567
  name: uniform.name,
@@ -8539,7 +8579,7 @@ ${formattedLog}`)();
8539
8579
  uniforms: uniforms2
8540
8580
  });
8541
8581
  }
8542
- const uniforms = readUniformBindings(gl2, program);
8582
+ const uniforms = readUniformBindings(gl, program);
8543
8583
  let textureUnit = 0;
8544
8584
  for (const uniform of uniforms) {
8545
8585
  if (isSamplerUniform(uniform.type)) {
@@ -8561,17 +8601,17 @@ ${formattedLog}`)();
8561
8601
  if (uniforms.length) {
8562
8602
  shaderLayout.uniforms = uniforms;
8563
8603
  }
8564
- const varyings = readVaryings(gl2, program);
8604
+ const varyings = readVaryings(gl, program);
8565
8605
  if (varyings?.length) {
8566
8606
  shaderLayout.varyings = varyings;
8567
8607
  }
8568
8608
  return shaderLayout;
8569
8609
  }
8570
- function readAttributeDeclarations(gl2, program) {
8610
+ function readAttributeDeclarations(gl, program) {
8571
8611
  const attributes = [];
8572
- const count = gl2.getProgramParameter(program, gl2.ACTIVE_ATTRIBUTES);
8612
+ const count = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
8573
8613
  for (let index = 0; index < count; index++) {
8574
- const activeInfo = gl2.getActiveAttrib(program, index);
8614
+ const activeInfo = gl.getActiveAttrib(program, index);
8575
8615
  if (!activeInfo) {
8576
8616
  throw new Error("activeInfo");
8577
8617
  }
@@ -8580,7 +8620,7 @@ ${formattedLog}`)();
8580
8620
  type: compositeType
8581
8621
  /* , size*/
8582
8622
  } = activeInfo;
8583
- const location = gl2.getAttribLocation(program, name2);
8623
+ const location = gl.getAttribLocation(program, name2);
8584
8624
  if (location >= 0) {
8585
8625
  const {
8586
8626
  attributeType
@@ -8598,15 +8638,15 @@ ${formattedLog}`)();
8598
8638
  attributes.sort((a, b) => a.location - b.location);
8599
8639
  return attributes;
8600
8640
  }
8601
- function readVaryings(gl2, program) {
8602
- if (!isWebGL2(gl2)) {
8641
+ function readVaryings(gl, program) {
8642
+ if (!isWebGL2(gl)) {
8603
8643
  return [];
8604
8644
  }
8605
- const gl22 = gl2;
8645
+ const gl2 = gl;
8606
8646
  const varyings = [];
8607
- const count = gl2.getProgramParameter(program, GL.TRANSFORM_FEEDBACK_VARYINGS);
8647
+ const count = gl.getProgramParameter(program, GL.TRANSFORM_FEEDBACK_VARYINGS);
8608
8648
  for (let location = 0; location < count; location++) {
8609
- const activeInfo = gl22.getTransformFeedbackVarying(program, location);
8649
+ const activeInfo = gl2.getTransformFeedbackVarying(program, location);
8610
8650
  if (!activeInfo) {
8611
8651
  throw new Error("activeInfo");
8612
8652
  }
@@ -8633,11 +8673,11 @@ ${formattedLog}`)();
8633
8673
  varyings.sort((a, b) => a.location - b.location);
8634
8674
  return varyings;
8635
8675
  }
8636
- function readUniformBindings(gl2, program) {
8676
+ function readUniformBindings(gl, program) {
8637
8677
  const uniforms = [];
8638
- const uniformCount = gl2.getProgramParameter(program, GL.ACTIVE_UNIFORMS);
8678
+ const uniformCount = gl.getProgramParameter(program, GL.ACTIVE_UNIFORMS);
8639
8679
  for (let i = 0; i < uniformCount; i++) {
8640
- const activeInfo = gl2.getActiveUniform(program, i);
8680
+ const activeInfo = gl.getActiveUniform(program, i);
8641
8681
  if (!activeInfo) {
8642
8682
  throw new Error("activeInfo");
8643
8683
  }
@@ -8650,7 +8690,7 @@ ${formattedLog}`)();
8650
8690
  name: name2,
8651
8691
  isArray: isArray2
8652
8692
  } = parseUniformName(rawName);
8653
- let webglLocation = gl2.getUniformLocation(program, name2);
8693
+ let webglLocation = gl.getUniformLocation(program, name2);
8654
8694
  const uniformInfo = {
8655
8695
  // WebGL locations are uniquely typed but just numbers
8656
8696
  location: webglLocation,
@@ -8663,7 +8703,7 @@ ${formattedLog}`)();
8663
8703
  if (uniformInfo.size > 1) {
8664
8704
  for (let j = 0; j < uniformInfo.size; j++) {
8665
8705
  const elementName = `${name2}[${j}]`;
8666
- webglLocation = gl2.getUniformLocation(program, elementName);
8706
+ webglLocation = gl.getUniformLocation(program, elementName);
8667
8707
  const arrayElementUniformInfo = {
8668
8708
  ...uniformInfo,
8669
8709
  name: elementName,
@@ -8675,17 +8715,17 @@ ${formattedLog}`)();
8675
8715
  }
8676
8716
  return uniforms;
8677
8717
  }
8678
- function readUniformBlocks(gl2, program) {
8679
- if (!isWebGL2(gl2)) {
8718
+ function readUniformBlocks(gl, program) {
8719
+ if (!isWebGL2(gl)) {
8680
8720
  return [];
8681
8721
  }
8682
- const gl22 = gl2;
8683
- const getBlockParameter = (blockIndex, pname) => gl22.getActiveUniformBlockParameter(program, blockIndex, pname);
8722
+ const gl2 = gl;
8723
+ const getBlockParameter = (blockIndex, pname) => gl2.getActiveUniformBlockParameter(program, blockIndex, pname);
8684
8724
  const uniformBlocks = [];
8685
- const blockCount = gl22.getProgramParameter(program, GL.ACTIVE_UNIFORM_BLOCKS);
8725
+ const blockCount = gl2.getProgramParameter(program, GL.ACTIVE_UNIFORM_BLOCKS);
8686
8726
  for (let blockIndex = 0; blockIndex < blockCount; blockIndex++) {
8687
8727
  const blockInfo = {
8688
- name: gl22.getActiveUniformBlockName(program, blockIndex) || "",
8728
+ name: gl2.getActiveUniformBlockName(program, blockIndex) || "",
8689
8729
  location: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_BINDING),
8690
8730
  byteLength: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_DATA_SIZE),
8691
8731
  vertex: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER),
@@ -8694,12 +8734,12 @@ ${formattedLog}`)();
8694
8734
  uniforms: []
8695
8735
  };
8696
8736
  const uniformIndices = getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) || [];
8697
- const uniformType = gl22.getActiveUniforms(program, uniformIndices, GL.UNIFORM_TYPE);
8698
- const uniformArrayLength = gl22.getActiveUniforms(program, uniformIndices, GL.UNIFORM_SIZE);
8699
- const uniformOffset = gl22.getActiveUniforms(program, uniformIndices, GL.UNIFORM_OFFSET);
8700
- const uniformStride = gl22.getActiveUniforms(program, uniformIndices, GL.UNIFORM_ARRAY_STRIDE);
8737
+ const uniformType = gl2.getActiveUniforms(program, uniformIndices, GL.UNIFORM_TYPE);
8738
+ const uniformArrayLength = gl2.getActiveUniforms(program, uniformIndices, GL.UNIFORM_SIZE);
8739
+ const uniformOffset = gl2.getActiveUniforms(program, uniformIndices, GL.UNIFORM_OFFSET);
8740
+ const uniformStride = gl2.getActiveUniforms(program, uniformIndices, GL.UNIFORM_ARRAY_STRIDE);
8701
8741
  for (let i = 0; i < blockInfo.uniformCount; ++i) {
8702
- const activeInfo = gl22.getActiveUniform(program, uniformIndices[i]);
8742
+ const activeInfo = gl2.getActiveUniform(program, uniformIndices[i]);
8703
8743
  if (!activeInfo) {
8704
8744
  throw new Error("activeInfo");
8705
8745
  }
@@ -8768,8 +8808,8 @@ ${formattedLog}`)();
8768
8808
  }
8769
8809
 
8770
8810
  // src/adapter/helpers/set-uniform.ts
8771
- function setUniform(gl2, location, type, value) {
8772
- const gl22 = gl2;
8811
+ function setUniform(gl, location, type, value) {
8812
+ const gl2 = gl;
8773
8813
  let uniformValue = value;
8774
8814
  if (uniformValue === true) {
8775
8815
  uniformValue = 1;
@@ -8795,251 +8835,61 @@ ${formattedLog}`)();
8795
8835
  case GL.UNSIGNED_INT_SAMPLER_CUBE:
8796
8836
  case GL.UNSIGNED_INT_SAMPLER_2D_ARRAY:
8797
8837
  if (typeof value !== "number") {
8798
- throw new Error("samplers must be set to integers");
8799
- }
8800
- return gl2.uniform1i(location, value);
8801
- case GL.FLOAT:
8802
- return gl2.uniform1fv(location, arrayValue);
8803
- case GL.FLOAT_VEC2:
8804
- return gl2.uniform2fv(location, arrayValue);
8805
- case GL.FLOAT_VEC3:
8806
- return gl2.uniform3fv(location, arrayValue);
8807
- case GL.FLOAT_VEC4:
8808
- return gl2.uniform4fv(location, arrayValue);
8809
- case GL.INT:
8810
- return gl2.uniform1iv(location, arrayValue);
8811
- case GL.INT_VEC2:
8812
- return gl2.uniform2iv(location, arrayValue);
8813
- case GL.INT_VEC3:
8814
- return gl2.uniform3iv(location, arrayValue);
8815
- case GL.INT_VEC4:
8816
- return gl2.uniform4iv(location, arrayValue);
8817
- case GL.BOOL:
8818
- return gl2.uniform1iv(location, arrayValue);
8819
- case GL.BOOL_VEC2:
8820
- return gl2.uniform2iv(location, arrayValue);
8821
- case GL.BOOL_VEC3:
8822
- return gl2.uniform3iv(location, arrayValue);
8823
- case GL.BOOL_VEC4:
8824
- return gl2.uniform4iv(location, arrayValue);
8825
- case GL.UNSIGNED_INT:
8826
- return gl22.uniform1uiv(location, arrayValue, 1);
8827
- case GL.UNSIGNED_INT_VEC2:
8828
- return gl22.uniform2uiv(location, arrayValue, 2);
8829
- case GL.UNSIGNED_INT_VEC3:
8830
- return gl22.uniform3uiv(location, arrayValue, 3);
8831
- case GL.UNSIGNED_INT_VEC4:
8832
- return gl22.uniform4uiv(location, arrayValue, 4);
8833
- case GL.FLOAT_MAT2:
8834
- return gl2.uniformMatrix2fv(location, false, arrayValue);
8835
- case GL.FLOAT_MAT3:
8836
- return gl2.uniformMatrix3fv(location, false, arrayValue);
8837
- case GL.FLOAT_MAT4:
8838
- return gl2.uniformMatrix4fv(location, false, arrayValue);
8839
- case GL.FLOAT_MAT2x3:
8840
- return gl22.uniformMatrix2x3fv(location, false, arrayValue);
8841
- case GL.FLOAT_MAT2x4:
8842
- return gl22.uniformMatrix2x4fv(location, false, arrayValue);
8843
- case GL.FLOAT_MAT3x2:
8844
- return gl22.uniformMatrix3x2fv(location, false, arrayValue);
8845
- case GL.FLOAT_MAT3x4:
8846
- return gl22.uniformMatrix3x4fv(location, false, arrayValue);
8847
- case GL.FLOAT_MAT4x2:
8848
- return gl22.uniformMatrix4x2fv(location, false, arrayValue);
8849
- case GL.FLOAT_MAT4x3:
8850
- return gl22.uniformMatrix4x3fv(location, false, arrayValue);
8851
- }
8852
- throw new Error("Illegal uniform");
8853
- }
8854
-
8855
- // src/adapter/objects/webgl-vertex-array-object.ts
8856
- var ERR_ELEMENTS = "elements must be GL.ELEMENT_ARRAY_BUFFER";
8857
- var WEBGLVertexArrayObject = class extends WebGLResource {
8858
- get [Symbol.toStringTag]() {
8859
- return "BaseVertexArrayObject";
8860
- }
8861
- /** Buffer constant */
8862
- buffer = null;
8863
- bufferValue = null;
8864
- static isConstantAttributeZeroSupported(device) {
8865
- return device.info.type === "webgl2" || getBrowser() === "Chrome";
8866
- }
8867
- // Create a VertexArray
8868
- constructor(device, props) {
8869
- super(device, props, {
8870
- ...Resource.defaultProps,
8871
- constantAttributeZero: false
8872
- });
8873
- Object.seal(this);
8874
- }
8875
- destroy() {
8876
- super.destroy();
8877
- if (this.buffer) {
8878
- this.buffer?.destroy();
8879
- }
8880
- }
8881
- _createHandle() {
8882
- return this.gl2.createVertexArray();
8883
- }
8884
- _deleteHandle() {
8885
- this.gl2.deleteVertexArray(this.handle);
8886
- return [this.elements];
8887
- }
8888
- _bindHandle(handle) {
8889
- this.gl2.bindVertexArray(handle);
8890
- }
8891
- /**
8892
- * Enabling an attribute location makes it reference the currently bound buffer
8893
- * Disabling an attribute location makes it reference the global constant value
8894
- * TODO - handle single values for size 1 attributes?
8895
- * TODO - convert classic arrays based on known type?
8896
- */
8897
- enable(location, enable2 = true) {
8898
- const canDisableAttributeZero = this.device.isWebGL2 || getBrowser() === "Chrome";
8899
- const canDisableAttribute = canDisableAttributeZero || location !== 0;
8900
- if (enable2 || canDisableAttribute) {
8901
- location = Number(location);
8902
- this.bind(() => enable2 ? this.gl.enableVertexAttribArray(location) : this.gl.disableVertexAttribArray(location));
8903
- }
8904
- }
8905
- // Set (bind) an elements buffer, for indexed rendering.
8906
- // Must be a Buffer bound to GL.ELEMENT_ARRAY_BUFFER. Constants not supported
8907
- setElementBuffer(elementBuffer = null, opts = {}) {
8908
- assert2(!elementBuffer || elementBuffer.glTarget === GL.ELEMENT_ARRAY_BUFFER, ERR_ELEMENTS);
8909
- this.bind(() => {
8910
- this.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, elementBuffer ? elementBuffer.handle : null);
8911
- });
8912
- }
8913
- /** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */
8914
- setBuffer(location, buffer, accessor) {
8915
- if (buffer.glTarget === GL.ELEMENT_ARRAY_BUFFER) {
8916
- this.setElementBuffer(buffer, accessor);
8917
- return;
8918
- }
8919
- const {
8920
- size,
8921
- type,
8922
- stride,
8923
- offset,
8924
- normalized,
8925
- integer,
8926
- divisor
8927
- } = accessor;
8928
- const {
8929
- gl: gl2,
8930
- gl2: gl22
8931
- } = this;
8932
- location = Number(location);
8933
- this.bind(() => {
8934
- gl2.bindBuffer(gl2.ARRAY_BUFFER, buffer.handle);
8935
- if (integer) {
8936
- this.device.assertWebGL2();
8937
- gl22.vertexAttribIPointer(location, size, type, stride, offset);
8938
- } else {
8939
- gl2.vertexAttribPointer(location, size, type, normalized, stride, offset);
8940
- }
8941
- gl2.enableVertexAttribArray(location);
8942
- gl22.vertexAttribDivisor(location, divisor || 0);
8943
- });
8944
- }
8945
- /**
8946
- * Set an attribute to a constant value
8947
- * @param device
8948
- * @param location
8949
- * @param array
8950
- *
8951
- * @note Constants are stored globally on the WebGL context, not the VAO
8952
- * so they need to be updated before every render
8953
- * @todo - use known type (in configuration or passed in) to allow non-typed arrays?
8954
- * @todo - remember/cache values to avoid setting them unnecessarily?
8955
- */
8956
- setConstant(location, array) {
8957
- switch (array.constructor) {
8958
- case Float32Array:
8959
- setConstantFloatArray(this.device, location, array);
8960
- break;
8961
- case Int32Array:
8962
- setConstantIntArray(this.device, location, array);
8963
- break;
8964
- case Uint32Array:
8965
- setConstantUintArray(this.device, location, array);
8966
- break;
8967
- default:
8968
- assert2(false);
8969
- }
8970
- }
8971
- /**
8972
- * Provide a means to create a buffer that is equivalent to a constant.
8973
- * NOTE: Desktop OpenGL cannot disable attribute 0.
8974
- * https://stackoverflow.com/questions/20305231/webgl-warning-attribute-0-is-disabled-
8975
- * this-has-significant-performance-penalty
8976
- */
8977
- getConstantBuffer(elementCount, value) {
8978
- const constantValue = normalizeConstantArrayValue(value);
8979
- const byteLength = constantValue.byteLength * elementCount;
8980
- const length = constantValue.length * elementCount;
8981
- let updateNeeded = !this.buffer;
8982
- this.buffer = this.buffer || this.device.createBuffer({
8983
- byteLength
8984
- });
8985
- updateNeeded = updateNeeded || this.buffer.reallocate(byteLength);
8986
- updateNeeded = updateNeeded || !compareConstantArrayValues(constantValue, this.bufferValue);
8987
- if (updateNeeded) {
8988
- const typedArray = getScratchArray(value.constructor, length);
8989
- fillArray({
8990
- target: typedArray,
8991
- source: constantValue,
8992
- start: 0,
8993
- count: length
8994
- });
8995
- this.buffer.subData(typedArray);
8996
- this.bufferValue = value;
8997
- }
8998
- return this.buffer;
8999
- }
9000
- };
9001
- function setConstantFloatArray(device, location, array) {
9002
- switch (array.length) {
9003
- case 1:
9004
- device.gl.vertexAttrib1fv(location, array);
9005
- break;
9006
- case 2:
9007
- device.gl.vertexAttrib2fv(location, array);
9008
- break;
9009
- case 3:
9010
- device.gl.vertexAttrib3fv(location, array);
9011
- break;
9012
- case 4:
9013
- device.gl.vertexAttrib4fv(location, array);
9014
- break;
9015
- default:
9016
- assert2(false);
9017
- }
9018
- }
9019
- function setConstantIntArray(device, location, array) {
9020
- device.assertWebGL2();
9021
- device.gl2?.vertexAttribI4iv(location, array);
9022
- }
9023
- function setConstantUintArray(device, location, array) {
9024
- device.assertWebGL2();
9025
- device.gl2?.vertexAttribI4uiv(location, array);
9026
- }
9027
- function normalizeConstantArrayValue(arrayValue) {
9028
- if (Array.isArray(arrayValue)) {
9029
- return new Float32Array(arrayValue);
9030
- }
9031
- return arrayValue;
9032
- }
9033
- function compareConstantArrayValues(v1, v2) {
9034
- if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {
9035
- return false;
9036
- }
9037
- for (let i = 0; i < v1.length; ++i) {
9038
- if (v1[i] !== v2[i]) {
9039
- return false;
9040
- }
8838
+ throw new Error("samplers must be set to integers");
8839
+ }
8840
+ return gl.uniform1i(location, value);
8841
+ case GL.FLOAT:
8842
+ return gl.uniform1fv(location, arrayValue);
8843
+ case GL.FLOAT_VEC2:
8844
+ return gl.uniform2fv(location, arrayValue);
8845
+ case GL.FLOAT_VEC3:
8846
+ return gl.uniform3fv(location, arrayValue);
8847
+ case GL.FLOAT_VEC4:
8848
+ return gl.uniform4fv(location, arrayValue);
8849
+ case GL.INT:
8850
+ return gl.uniform1iv(location, arrayValue);
8851
+ case GL.INT_VEC2:
8852
+ return gl.uniform2iv(location, arrayValue);
8853
+ case GL.INT_VEC3:
8854
+ return gl.uniform3iv(location, arrayValue);
8855
+ case GL.INT_VEC4:
8856
+ return gl.uniform4iv(location, arrayValue);
8857
+ case GL.BOOL:
8858
+ return gl.uniform1iv(location, arrayValue);
8859
+ case GL.BOOL_VEC2:
8860
+ return gl.uniform2iv(location, arrayValue);
8861
+ case GL.BOOL_VEC3:
8862
+ return gl.uniform3iv(location, arrayValue);
8863
+ case GL.BOOL_VEC4:
8864
+ return gl.uniform4iv(location, arrayValue);
8865
+ case GL.UNSIGNED_INT:
8866
+ return gl2.uniform1uiv(location, arrayValue, 1);
8867
+ case GL.UNSIGNED_INT_VEC2:
8868
+ return gl2.uniform2uiv(location, arrayValue, 2);
8869
+ case GL.UNSIGNED_INT_VEC3:
8870
+ return gl2.uniform3uiv(location, arrayValue, 3);
8871
+ case GL.UNSIGNED_INT_VEC4:
8872
+ return gl2.uniform4uiv(location, arrayValue, 4);
8873
+ case GL.FLOAT_MAT2:
8874
+ return gl.uniformMatrix2fv(location, false, arrayValue);
8875
+ case GL.FLOAT_MAT3:
8876
+ return gl.uniformMatrix3fv(location, false, arrayValue);
8877
+ case GL.FLOAT_MAT4:
8878
+ return gl.uniformMatrix4fv(location, false, arrayValue);
8879
+ case GL.FLOAT_MAT2x3:
8880
+ return gl2.uniformMatrix2x3fv(location, false, arrayValue);
8881
+ case GL.FLOAT_MAT2x4:
8882
+ return gl2.uniformMatrix2x4fv(location, false, arrayValue);
8883
+ case GL.FLOAT_MAT3x2:
8884
+ return gl2.uniformMatrix3x2fv(location, false, arrayValue);
8885
+ case GL.FLOAT_MAT3x4:
8886
+ return gl2.uniformMatrix3x4fv(location, false, arrayValue);
8887
+ case GL.FLOAT_MAT4x2:
8888
+ return gl2.uniformMatrix4x2fv(location, false, arrayValue);
8889
+ case GL.FLOAT_MAT4x3:
8890
+ return gl2.uniformMatrix4x3fv(location, false, arrayValue);
9041
8891
  }
9042
- return true;
8892
+ throw new Error("Illegal uniform");
9043
8893
  }
9044
8894
 
9045
8895
  // src/adapter/resources/webgl-render-pipeline.ts
@@ -9050,18 +8900,12 @@ ${formattedLog}`)();
9050
8900
  /** vertex shader */
9051
8901
  /** fragment shader */
9052
8902
  /** The layout extracted from shader by WebGL introspection APIs */
9053
- /** The merged layout */
9054
- /** Buffer map describing buffer interleaving etc */
9055
8903
  /** Uniforms set on this model */
9056
8904
  uniforms = {};
9057
8905
  /** Bindings set on this model */
9058
8906
  bindings = {};
9059
- /** Any constant attributes */
9060
- constantAttributes = {};
9061
- /** Index buffer is stored separately */
9062
8907
  /** WebGL varyings */
9063
8908
  varyings = null;
9064
- /** Stores attribute bindings */
9065
8909
  _textureUniforms = {};
9066
8910
  _textureIndexCounter = 0;
9067
8911
  _uniformCount = 0;
@@ -9088,8 +8932,6 @@ ${formattedLog}`)();
9088
8932
  this._compileAndLink();
9089
8933
  this.introspectedLayout = getShaderLayout(this.device.gl, this.handle);
9090
8934
  this.shaderLayout = mergeShaderLayout(this.introspectedLayout, props.shaderLayout);
9091
- this.bufferLayout = props.bufferLayout || [];
9092
- this.vertexArrayObject = new WEBGLVertexArrayObject(this.device);
9093
8935
  }
9094
8936
  destroy() {
9095
8937
  if (this.handle) {
@@ -9097,68 +8939,37 @@ ${formattedLog}`)();
9097
8939
  this.destroyed = true;
9098
8940
  }
9099
8941
  }
9100
- setIndexBuffer(indexBuffer) {
9101
- const webglBuffer = cast(indexBuffer);
9102
- this.vertexArrayObject.setElementBuffer(webglBuffer);
9103
- this._indexBuffer = webglBuffer;
9104
- }
9105
- /** @todo needed for portable model */
9106
- setAttributes(buffers) {
9107
- const attributeInfos = getAttributeInfosFromLayouts(this.shaderLayout, this.bufferLayout);
9108
- for (const [bufferName, buffer] of Object.entries(buffers)) {
9109
- let set = false;
9110
- for (const attributeInfo of Object.values(attributeInfos)) {
9111
- if (attributeInfo.bufferName !== bufferName) {
9112
- continue;
9113
- }
9114
- const webglBuffer = cast(buffer);
9115
- const glType = getGLFromVertexType(attributeInfo.bufferDataType);
9116
- log.log(2, {
9117
- setAttribute: attributeInfo.attributeName,
9118
- toBuffer: bufferName,
9119
- size: attributeInfo.bufferComponents,
9120
- type: glType,
9121
- stride: attributeInfo.byteStride,
9122
- offset: attributeInfo.byteOffset,
9123
- normalized: attributeInfo.normalized,
9124
- // it is the shader attribute declaration, not the vertex memory format,
9125
- // that determines if the data in the buffer will be treated as integers.
9126
- // /
9127
- // Also note that WebGL supports assigning non-normalized integer data to floating point attributes,
9128
- // but as far as we can tell, WebGPU does not.
9129
- integer: attributeInfo.integer,
9130
- divisor: attributeInfo.stepMode === "instance" ? 1 : 0
9131
- })();
9132
- this.vertexArrayObject.setBuffer(attributeInfo.location, webglBuffer, {
9133
- size: attributeInfo.bufferComponents,
9134
- type: glType,
9135
- stride: attributeInfo.byteStride,
9136
- offset: attributeInfo.byteOffset,
9137
- normalized: attributeInfo.normalized,
9138
- // it is the shader attribute declaration, not the vertex memory format,
9139
- // that determines if the data in the buffer will be treated as integers.
9140
- // /
9141
- // Also note that WebGL supports assigning non-normalized integer data to floating point attributes,
9142
- // but as far as we can tell, WebGPU does not.
9143
- integer: attributeInfo.integer,
9144
- divisor: attributeInfo.stepMode === "instance" ? 1 : 0
9145
- });
9146
- set = true;
9147
- }
9148
- if (!set) {
9149
- log.warn(`setAttributes(): Ignoring (buffer "${buffer.id}" for unknown attribute "${name}" in pipeline "${this.id}"`)();
9150
- }
9151
- }
9152
- }
9153
- /**
9154
- * Constant attributes are only supported in WebGL, not in WebGPU
9155
- * Any attribute that is disabled in the current vertex array object
9156
- * is read from the context's global constant value for that attribute location.
9157
- * @param attributes
9158
- */
9159
- setConstantAttributes(attributes) {
9160
- Object.assign(this.constantAttributes, attributes);
9161
- }
8942
+ // setIndexBuffer(indexBuffer: Buffer): void {
8943
+ // const webglBuffer = cast<WEBGLBuffer>(indexBuffer);
8944
+ // this.vertexArrayObject.setElementBuffer(webglBuffer);
8945
+ // this._indexBuffer = indexBuffer;
8946
+ // }
8947
+ // /** @todo needed for portable model */
8948
+ // setAttributes(attributes: Record<string, Buffer>): void {
8949
+ // for (const [name, buffer] of Object.entries(attributes)) {
8950
+ // const webglBuffer = cast<WEBGLBuffer>(buffer);
8951
+ // const attribute = getAttributeLayout(this.layout, name);
8952
+ // if (!attribute) {
8953
+ // log.warn(
8954
+ // `Ignoring buffer supplied for unknown attribute "${name}" in pipeline "${this.id}" (buffer "${buffer.id}")`
8955
+ // )();
8956
+ // continue;
8957
+ // }
8958
+ // const decoded = decodeVertexFormat(attribute.format);
8959
+ // const {type: typeString, components: size, byteLength: stride, normalized, integer} = decoded;
8960
+ // const divisor = attribute.stepMode === 'instance' ? 1 : 0;
8961
+ // const type = getWebGLDataType(typeString);
8962
+ // this.vertexArrayObject.setBuffer(attribute.location, webglBuffer, {
8963
+ // size,
8964
+ // type,
8965
+ // stride,
8966
+ // offset: 0,
8967
+ // normalized,
8968
+ // integer,
8969
+ // divisor
8970
+ // });
8971
+ // }
8972
+ // }
9162
8973
  /**
9163
8974
  * Bindings include: textures, samplers and uniform buffers
9164
8975
  * @todo needed for portable model
@@ -9203,6 +9014,7 @@ ${formattedLog}`)();
9203
9014
  draw(options) {
9204
9015
  const {
9205
9016
  renderPass,
9017
+ vertexArray,
9206
9018
  vertexCount,
9207
9019
  // indexCount,
9208
9020
  instanceCount,
@@ -9211,71 +9023,68 @@ ${formattedLog}`)();
9211
9023
  // firstInstance,
9212
9024
  // baseVertex
9213
9025
  } = options;
9214
- const drawMode = getGLDrawMode(this.props.topology);
9215
- const isIndexed = Boolean(this._indexBuffer);
9216
- const indexType = this._indexBuffer?.glIndexType;
9217
- const isInstanced = Number(options.instanceCount) > 0;
9218
- if (!this._areTexturesRenderable() || options.vertexCount === 0) {
9026
+ const glDrawMode = getGLDrawMode(this.props.topology);
9027
+ const isIndexed = Boolean(vertexArray.indexBuffer);
9028
+ const glIndexType = vertexArray.indexBuffer?.glIndexType;
9029
+ const isInstanced = Number(instanceCount) > 0;
9030
+ if (!this._areTexturesRenderable() || vertexCount === 0) {
9219
9031
  return false;
9220
9032
  }
9221
9033
  this.device.gl.useProgram(this.handle);
9222
- this.vertexArrayObject.bind(() => {
9223
- const primitiveMode = getGLPrimitive(this.props.topology);
9224
- const transformFeedback = null;
9034
+ vertexArray.bindBeforeRender(renderPass);
9035
+ const primitiveMode = getGLPrimitive(this.props.topology);
9036
+ const transformFeedback = null;
9037
+ if (transformFeedback) {
9038
+ transformFeedback.begin(primitiveMode);
9039
+ }
9040
+ this._applyBindings();
9041
+ this._applyUniforms();
9042
+ const webglRenderPass = renderPass;
9043
+ withDeviceAndGLParameters(this.device, this.props.parameters, webglRenderPass.glParameters, () => {
9044
+ if (isIndexed && isInstanced) {
9045
+ this.device.gl2?.drawElementsInstanced(
9046
+ glDrawMode,
9047
+ vertexCount || 0,
9048
+ // indexCount?
9049
+ glIndexType,
9050
+ firstVertex,
9051
+ instanceCount || 0
9052
+ );
9053
+ } else if (isIndexed) {
9054
+ this.device.gl.drawElements(glDrawMode, vertexCount || 0, glIndexType, firstVertex);
9055
+ } else if (isInstanced) {
9056
+ this.device.gl2?.drawArraysInstanced(glDrawMode, firstVertex, vertexCount || 0, instanceCount || 0);
9057
+ } else {
9058
+ this.device.gl.drawArrays(glDrawMode, firstVertex, vertexCount || 0);
9059
+ }
9225
9060
  if (transformFeedback) {
9226
- transformFeedback.begin(primitiveMode);
9061
+ transformFeedback.end();
9227
9062
  }
9228
- this._applyBindings();
9229
- this._applyUniforms();
9230
- this._applyConstantAttributes();
9231
- const webglRenderPass = renderPass;
9232
- withDeviceParameters(this.device, this.props.parameters, () => {
9233
- withGLParameters(this.device, webglRenderPass.glParameters, () => {
9234
- if (isIndexed && isInstanced) {
9235
- this.device.gl2?.drawElementsInstanced(
9236
- drawMode,
9237
- vertexCount || 0,
9238
- // indexCount?
9239
- indexType,
9240
- firstVertex,
9241
- instanceCount || 0
9242
- );
9243
- } else if (isIndexed) {
9244
- this.device.gl.drawElements(drawMode, vertexCount || 0, indexType, firstVertex);
9245
- } else if (isInstanced) {
9246
- this.device.gl2?.drawArraysInstanced(drawMode, firstVertex, vertexCount || 0, instanceCount || 0);
9247
- } else {
9248
- this.device.gl.drawArrays(drawMode, firstVertex, vertexCount || 0);
9249
- }
9250
- });
9251
- if (transformFeedback) {
9252
- transformFeedback.end();
9253
- }
9254
- });
9255
9063
  });
9064
+ vertexArray.unbindAfterRender(renderPass);
9256
9065
  return true;
9257
9066
  }
9258
9067
  // setAttributes(attributes: Record<string, Buffer>): void {}
9259
9068
  // setBindings(bindings: Record<string, Binding>): void {}
9260
9069
  _compileAndLink() {
9261
9070
  const {
9262
- gl: gl2
9071
+ gl
9263
9072
  } = this.device;
9264
- gl2.attachShader(this.handle, this.vs.handle);
9265
- gl2.attachShader(this.handle, this.fs.handle);
9073
+ gl.attachShader(this.handle, this.vs.handle);
9074
+ gl.attachShader(this.handle, this.fs.handle);
9266
9075
  log.time(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
9267
- gl2.linkProgram(this.handle);
9076
+ gl.linkProgram(this.handle);
9268
9077
  log.timeEnd(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
9269
- if (gl2.debug || log.level > 0) {
9270
- const linked = gl2.getProgramParameter(this.handle, gl2.LINK_STATUS);
9271
- if (!linked) {
9272
- throw new Error(`Error linking: ${gl2.getProgramInfoLog(this.handle)}`);
9273
- }
9274
- gl2.validateProgram(this.handle);
9275
- const validated = gl2.getProgramParameter(this.handle, gl2.VALIDATE_STATUS);
9276
- if (!validated) {
9277
- throw new Error(`Error validating: ${gl2.getProgramInfoLog(this.handle)}`);
9278
- }
9078
+ if (!gl.debug && log.level === 0) {
9079
+ }
9080
+ const linked = gl.getProgramParameter(this.handle, gl.LINK_STATUS);
9081
+ if (!linked) {
9082
+ throw new Error(`Error linking: ${gl.getProgramInfoLog(this.handle)}`);
9083
+ }
9084
+ gl.validateProgram(this.handle);
9085
+ const validated = gl.getProgramParameter(this.handle, gl.VALIDATE_STATUS);
9086
+ if (!validated) {
9087
+ throw new Error(`Error validating: ${gl.getProgramInfoLog(this.handle)}`);
9279
9088
  }
9280
9089
  }
9281
9090
  // PRIVATE METHODS
@@ -9302,19 +9111,22 @@ ${formattedLog}`)();
9302
9111
  * Any attribute that is disabled in the current vertex array object
9303
9112
  * is read from the context's global constant value for that attribute location.
9304
9113
  * @note Constant attributes are only supported in WebGL, not in WebGPU
9305
- */
9306
- _applyConstantAttributes() {
9114
+ *
9115
+ _applyConstantAttributes(vertexArray: WEBGLVertexArray): void {
9307
9116
  const attributeInfos = getAttributeInfosFromLayouts(this.shaderLayout, this.bufferLayout);
9308
- for (const [name2, value] of Object.entries(this.constantAttributes)) {
9309
- const attributeInfo = attributeInfos[name2];
9117
+ for (const [name, value] of Object.entries(this.)) {
9118
+ const attributeInfo = attributeInfos[name];
9310
9119
  if (!attributeInfo) {
9311
- log.warn(`Ignoring constant value supplied for unknown attribute "${name2}" in pipeline "${this.id}"`)();
9312
- continue;
9120
+ log.warn(
9121
+ `Ignoring constant value supplied for unknown attribute "${name}" in pipeline "${this.id}"`
9122
+ )();
9123
+ continue; // eslint-disable-line no-continue
9313
9124
  }
9314
- this.vertexArrayObject.setConstant(attributeInfo.location, value);
9315
- this.vertexArrayObject.enable(attributeInfo.location, false);
9125
+ vertexArray.setConstant(attributeInfo.location, value);
9126
+ vertexArray.enable(attributeInfo.location, false);
9316
9127
  }
9317
9128
  }
9129
+ */
9318
9130
  /** Apply any bindings (before each draw call) */
9319
9131
  _applyBindings() {
9320
9132
  this.device.gl.useProgram(this.handle);
@@ -9344,7 +9156,16 @@ ${formattedLog}`)();
9344
9156
  if (value instanceof WEBGLBuffer) {
9345
9157
  gl2.bindBufferBase(GL.UNIFORM_BUFFER, uniformBufferIndex, value.handle);
9346
9158
  } else {
9347
- gl2.bindBufferRange(GL.UNIFORM_BUFFER, uniformBufferIndex, value.buffer.handle, value.offset || 0, value.size || value.buffer.byteLength - value.offset);
9159
+ gl2.bindBufferRange(
9160
+ GL.UNIFORM_BUFFER,
9161
+ uniformBufferIndex,
9162
+ // @ts-expect-error
9163
+ value.buffer.handle,
9164
+ // @ts-expect-error
9165
+ value.offset || 0,
9166
+ // @ts-expect-error
9167
+ value.size || value.buffer.byteLength - value.offset
9168
+ );
9348
9169
  }
9349
9170
  uniformBufferIndex += 1;
9350
9171
  break;
@@ -9591,7 +9412,6 @@ ${formattedLog}`)();
9591
9412
  if (texture) {
9592
9413
  texture.unbind();
9593
9414
  }
9594
- device.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
9595
9415
  if (destroyFramebuffer) {
9596
9416
  framebuffer.destroy();
9597
9417
  }
@@ -9676,6 +9496,215 @@ ${formattedLog}`)();
9676
9496
  // }): void;
9677
9497
  };
9678
9498
 
9499
+ // src/adapter/resources/webgl-vertex-array.ts
9500
+ var WEBGLVertexArray = class extends VertexArray {
9501
+ get [Symbol.toStringTag]() {
9502
+ return "VertexArray";
9503
+ }
9504
+ /** Attribute 0 buffer constant */
9505
+ buffer = null;
9506
+ bufferValue = null;
9507
+ /** * Attribute 0 can not be disable on most desktop OpenGL based browsers */
9508
+ static isConstantAttributeZeroSupported(device) {
9509
+ return device.info.type === "webgl2" || getBrowser() === "Chrome";
9510
+ }
9511
+ // Create a VertexArray
9512
+ constructor(device, props) {
9513
+ super(device, props);
9514
+ this.device = device;
9515
+ this.handle = this.device.gl2.createVertexArray();
9516
+ }
9517
+ destroy() {
9518
+ super.destroy();
9519
+ if (this.buffer) {
9520
+ this.buffer?.destroy();
9521
+ }
9522
+ if (this.handle) {
9523
+ this.device.gl2.deleteVertexArray(this.handle);
9524
+ this.handle = void 0;
9525
+ }
9526
+ }
9527
+ /**
9528
+ // Set (bind) an elements buffer, for indexed rendering.
9529
+ // Must be a Buffer bound to GL.ELEMENT_ARRAY_BUFFER. Constants not supported
9530
+ *
9531
+ * @param elementBuffer
9532
+ */
9533
+ setIndexBuffer(indexBuffer) {
9534
+ const buffer = indexBuffer;
9535
+ if (buffer && buffer.glTarget !== GL.ELEMENT_ARRAY_BUFFER) {
9536
+ throw new Error("Use .setBuffer()");
9537
+ }
9538
+ this.device.gl2.bindVertexArray(this.handle);
9539
+ this.device.gl2.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, buffer ? buffer.handle : null);
9540
+ this.indexBuffer = buffer;
9541
+ }
9542
+ /** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */
9543
+ setBuffer(location, attributeBuffer) {
9544
+ const buffer = attributeBuffer;
9545
+ if (buffer.glTarget === GL.ELEMENT_ARRAY_BUFFER) {
9546
+ throw new Error("Use .setIndexBuffer()");
9547
+ }
9548
+ const {
9549
+ size,
9550
+ type,
9551
+ stride,
9552
+ offset,
9553
+ normalized,
9554
+ integer,
9555
+ divisor
9556
+ } = this._getAccessor(location);
9557
+ this.device.gl2.bindVertexArray(this.handle);
9558
+ this.device.gl.bindBuffer(GL.ARRAY_BUFFER, buffer.handle);
9559
+ if (integer) {
9560
+ this.device.assertWebGL2();
9561
+ this.device.gl2.vertexAttribIPointer(location, size, type, stride, offset);
9562
+ } else {
9563
+ this.device.gl.vertexAttribPointer(location, size, type, normalized, stride, offset);
9564
+ }
9565
+ this.device.gl.enableVertexAttribArray(location);
9566
+ this.device.gl2.vertexAttribDivisor(location, divisor || 0);
9567
+ this.attributes[location] = buffer;
9568
+ }
9569
+ /** Set a location in vertex attributes array to a constant value, disables the location */
9570
+ setConstant(location, value) {
9571
+ this._enable(location, false);
9572
+ this.attributes[location] = value;
9573
+ }
9574
+ init = false;
9575
+ bindBeforeRender() {
9576
+ this.device.gl2.bindVertexArray(this.handle);
9577
+ if (!this.init) {
9578
+ const webglBuffer = this.indexBuffer;
9579
+ this.device.gl2.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, webglBuffer?.handle || null);
9580
+ this.init = true;
9581
+ }
9582
+ this._applyConstantAttributes();
9583
+ }
9584
+ unbindAfterRender() {
9585
+ this.device.gl2.bindVertexArray(null);
9586
+ }
9587
+ // Internal methods
9588
+ /**
9589
+ * Constant attributes need to be reset before every draw call
9590
+ * Any attribute that is disabled in the current vertex array object
9591
+ * is read from the context's global constant value for that attribute location.
9592
+ * @note Constant attributes are only supported in WebGL, not in WebGPU
9593
+ */
9594
+ _applyConstantAttributes() {
9595
+ for (let location = 0; location < this.maxVertexAttributes; ++location) {
9596
+ const constant = this.attributes[location];
9597
+ if (ArrayBuffer.isView(constant)) {
9598
+ this.device.setConstantAttribute(location, constant);
9599
+ }
9600
+ }
9601
+ }
9602
+ /**
9603
+ * Set a location in vertex attributes array to a buffer, enables the location, sets divisor
9604
+ * @note requires vertex array to be bound
9605
+ */
9606
+ // protected _setAttributeLayout(location: number): void {
9607
+ // const {size, type, stride, offset, normalized, integer, divisor} = this._getAccessor(location);
9608
+ // // WebGL2 supports *integer* data formats, i.e. GPU will see integer values
9609
+ // if (integer) {
9610
+ // this.device.assertWebGL2();
9611
+ // this.device.gl2.vertexAttribIPointer(location, size, type, stride, offset);
9612
+ // } else {
9613
+ // // Attaches ARRAY_BUFFER with specified buffer format to location
9614
+ // this.device.gl.vertexAttribPointer(location, size, type, normalized, stride, offset);
9615
+ // }
9616
+ // this.device.gl2.vertexAttribDivisor(location, divisor || 0);
9617
+ // }
9618
+ /** Get an accessor from the */
9619
+ _getAccessor(location) {
9620
+ const attributeInfo = this.attributeInfos[location];
9621
+ if (!attributeInfo) {
9622
+ throw new Error(`Unknown attribute location ${location}`);
9623
+ }
9624
+ const glType = getGLFromVertexType(attributeInfo.bufferDataType);
9625
+ return {
9626
+ size: attributeInfo.bufferComponents,
9627
+ type: glType,
9628
+ stride: attributeInfo.byteStride,
9629
+ offset: attributeInfo.byteOffset,
9630
+ normalized: attributeInfo.normalized,
9631
+ // it is the shader attribute declaration, not the vertex memory format,
9632
+ // that determines if the data in the buffer will be treated as integers.
9633
+ //
9634
+ // Also note that WebGL supports assigning non-normalized integer data to floating point attributes,
9635
+ // but as far as we can tell, WebGPU does not.
9636
+ integer: attributeInfo.integer,
9637
+ divisor: attributeInfo.stepMode === "instance" ? 1 : 0
9638
+ };
9639
+ }
9640
+ /**
9641
+ * Enabling an attribute location makes it reference the currently bound buffer
9642
+ * Disabling an attribute location makes it reference the global constant value
9643
+ * TODO - handle single values for size 1 attributes?
9644
+ * TODO - convert classic arrays based on known type?
9645
+ */
9646
+ _enable(location, enable2 = true) {
9647
+ const canDisableAttributeZero = WEBGLVertexArray.isConstantAttributeZeroSupported(this.device);
9648
+ const canDisableAttribute = canDisableAttributeZero || location !== 0;
9649
+ if (enable2 || canDisableAttribute) {
9650
+ location = Number(location);
9651
+ this.device.gl2.bindVertexArray(this.handle);
9652
+ if (enable2) {
9653
+ this.device.gl.enableVertexAttribArray(location);
9654
+ } else {
9655
+ this.device.gl.disableVertexAttribArray(location);
9656
+ }
9657
+ this.device.gl2.bindVertexArray(null);
9658
+ }
9659
+ }
9660
+ /**
9661
+ * Provide a means to create a buffer that is equivalent to a constant.
9662
+ * NOTE: Desktop OpenGL cannot disable attribute 0.
9663
+ * https://stackoverflow.com/questions/20305231/webgl-warning-attribute-0-is-disabled-
9664
+ * this-has-significant-performance-penalty
9665
+ */
9666
+ getConstantBuffer(elementCount, value) {
9667
+ const constantValue = normalizeConstantArrayValue(value);
9668
+ const byteLength = constantValue.byteLength * elementCount;
9669
+ const length = constantValue.length * elementCount;
9670
+ let updateNeeded = !this.buffer;
9671
+ this.buffer = this.buffer || this.device.createBuffer({
9672
+ byteLength
9673
+ });
9674
+ updateNeeded = updateNeeded || this.buffer.reallocate(byteLength);
9675
+ updateNeeded = updateNeeded || !compareConstantArrayValues(constantValue, this.bufferValue);
9676
+ if (updateNeeded) {
9677
+ const typedArray = getScratchArray(value.constructor, length);
9678
+ fillArray({
9679
+ target: typedArray,
9680
+ source: constantValue,
9681
+ start: 0,
9682
+ count: length
9683
+ });
9684
+ this.buffer.subData(typedArray);
9685
+ this.bufferValue = value;
9686
+ }
9687
+ return this.buffer;
9688
+ }
9689
+ };
9690
+ function normalizeConstantArrayValue(arrayValue) {
9691
+ if (Array.isArray(arrayValue)) {
9692
+ return new Float32Array(arrayValue);
9693
+ }
9694
+ return arrayValue;
9695
+ }
9696
+ function compareConstantArrayValues(v1, v2) {
9697
+ if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {
9698
+ return false;
9699
+ }
9700
+ for (let i = 0; i < v1.length; ++i) {
9701
+ if (v1[i] !== v2[i]) {
9702
+ return false;
9703
+ }
9704
+ }
9705
+ return true;
9706
+ }
9707
+
9679
9708
  // src/adapter/webgl-device.ts
9680
9709
  var LOG_LEVEL2 = 1;
9681
9710
  var _WebGLDevice = class extends Device {
@@ -9699,18 +9728,18 @@ ${formattedLog}`)();
9699
9728
  * @param gl
9700
9729
  * @returns
9701
9730
  */
9702
- static attach(gl2) {
9703
- if (gl2 instanceof _WebGLDevice) {
9704
- return gl2;
9731
+ static attach(gl) {
9732
+ if (gl instanceof _WebGLDevice) {
9733
+ return gl;
9705
9734
  }
9706
- if (gl2?.device instanceof Device) {
9707
- return gl2.device;
9735
+ if (gl?.device instanceof Device) {
9736
+ return gl.device;
9708
9737
  }
9709
- if (!isWebGL3(gl2)) {
9738
+ if (!isWebGL3(gl)) {
9710
9739
  throw new Error("Invalid WebGLRenderingContext");
9711
9740
  }
9712
9741
  return new _WebGLDevice({
9713
- gl: gl2
9742
+ gl
9714
9743
  });
9715
9744
  }
9716
9745
  static async create(props = {}) {
@@ -9753,19 +9782,19 @@ ${formattedLog}`)();
9753
9782
  reason: "destroyed",
9754
9783
  message: "Computer entered sleep mode, or too many apps or browser tabs are using the GPU."
9755
9784
  });
9756
- let gl2 = props.gl || null;
9757
- gl2 = gl2 || (isBrowser() ? createBrowserContext(this.canvasContext.canvas, {
9785
+ let gl = props.gl || null;
9786
+ gl = gl || (isBrowser() ? createBrowserContext(this.canvasContext.canvas, {
9758
9787
  ...props,
9759
9788
  onContextLost
9760
9789
  }) : null);
9761
- gl2 = gl2 || (!isBrowser() ? createHeadlessContext({
9790
+ gl = gl || (!isBrowser() ? createHeadlessContext({
9762
9791
  ...props,
9763
9792
  onContextLost
9764
9793
  }) : null);
9765
- if (!gl2) {
9794
+ if (!gl) {
9766
9795
  throw new Error("WebGL context creation failed");
9767
9796
  }
9768
- this.handle = gl2;
9797
+ this.handle = gl;
9769
9798
  this.gl = this.handle;
9770
9799
  this.gl2 = this.gl;
9771
9800
  this.isWebGL2 = isWebGL22(this.gl);
@@ -9864,6 +9893,9 @@ ${formattedLog}`)();
9864
9893
  createRenderPipeline(props) {
9865
9894
  return new WEBGLRenderPipeline(this, props);
9866
9895
  }
9896
+ createVertexArray(props) {
9897
+ return new WEBGLVertexArray(this, props);
9898
+ }
9867
9899
  beginRenderPass(props) {
9868
9900
  return new WEBGLRenderPass(this, props);
9869
9901
  }
@@ -9941,48 +9973,113 @@ ${formattedLog}`)();
9941
9973
  popState() {
9942
9974
  popContextState(this.gl);
9943
9975
  }
9944
- /**
9945
- * Storing data on a special field on WebGLObjects makes that data visible in SPECTOR chrome debug extension
9976
+ /**
9977
+ * Storing data on a special field on WebGLObjects makes that data visible in SPECTOR chrome debug extension
9946
9978
  * luma.gl ids and props can be inspected
9947
9979
  */
9948
9980
  setSpectorMetadata(handle, props) {
9949
9981
  handle.__SPECTOR_Metadata = props;
9950
9982
  }
9951
- /**
9983
+ /**
9952
9984
  * Returns the GL.<KEY> constant that corresponds to a numeric value of a GL constant
9953
9985
  * Be aware that there are some duplicates especially for constants that are 0,
9954
9986
  * so this isn't guaranteed to return the right key in all cases.
9955
9987
  */
9956
- getGLKey(value, gl2) {
9957
- gl2 = gl2 || this.gl2 || this.gl;
9988
+ getGLKey(value, gl) {
9989
+ gl = gl || this.gl2 || this.gl;
9958
9990
  const number = Number(value);
9959
- for (const key in gl2) {
9960
- if (gl2[key] === number) {
9991
+ for (const key in gl) {
9992
+ if (gl[key] === number) {
9961
9993
  return `GL.${key}`;
9962
9994
  }
9963
9995
  }
9964
9996
  return String(value);
9965
9997
  }
9998
+ /** Store constants */
9999
+ /**
10000
+ * Set a constant value for a location. Disabled attributes at that location will read from this value
10001
+ * @note WebGL constants are stored globally on the WebGL context, not the VertexArray
10002
+ * so they need to be updated before every render
10003
+ * @todo - remember/cache values to avoid setting them unnecessarily?
10004
+ */
10005
+ setConstantAttribute(location, constant) {
10006
+ this._constants = this._constants || new Array(this.limits.maxVertexAttributes).fill(null);
10007
+ const currentConstant = this._constants[location];
10008
+ if (currentConstant && compareConstantArrayValues2(currentConstant, constant)) {
10009
+ log.info(1, `setConstantAttribute(${location}) could have been skipped, value unchanged`)();
10010
+ }
10011
+ this._constants[location] = constant;
10012
+ switch (constant.constructor) {
10013
+ case Float32Array:
10014
+ setConstantFloatArray(this, location, constant);
10015
+ break;
10016
+ case Int32Array:
10017
+ setConstantIntArray(this, location, constant);
10018
+ break;
10019
+ case Uint32Array:
10020
+ setConstantUintArray(this, location, constant);
10021
+ break;
10022
+ default:
10023
+ assert2(false);
10024
+ }
10025
+ }
9966
10026
  };
9967
10027
  var WebGLDevice = _WebGLDevice;
9968
10028
  //
9969
10029
  // Public `Device` API
9970
10030
  //
9971
10031
  __publicField(WebGLDevice, "type", "webgl");
9972
- function isWebGL3(gl2) {
9973
- if (typeof WebGLRenderingContext !== "undefined" && gl2 instanceof WebGLRenderingContext) {
10032
+ function isWebGL3(gl) {
10033
+ if (typeof WebGLRenderingContext !== "undefined" && gl instanceof WebGLRenderingContext) {
9974
10034
  return true;
9975
10035
  }
9976
- if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
10036
+ if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
9977
10037
  return true;
9978
10038
  }
9979
- return Boolean(gl2 && Number.isFinite(gl2._version));
10039
+ return Boolean(gl && Number.isFinite(gl._version));
9980
10040
  }
9981
- function isWebGL22(gl2) {
9982
- if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
10041
+ function isWebGL22(gl) {
10042
+ if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
9983
10043
  return true;
9984
10044
  }
9985
- return Boolean(gl2 && gl2._version === 2);
10045
+ return Boolean(gl && gl._version === 2);
10046
+ }
10047
+ function setConstantFloatArray(device, location, array) {
10048
+ switch (array.length) {
10049
+ case 1:
10050
+ device.gl.vertexAttrib1fv(location, array);
10051
+ break;
10052
+ case 2:
10053
+ device.gl.vertexAttrib2fv(location, array);
10054
+ break;
10055
+ case 3:
10056
+ device.gl.vertexAttrib3fv(location, array);
10057
+ break;
10058
+ case 4:
10059
+ device.gl.vertexAttrib4fv(location, array);
10060
+ break;
10061
+ default:
10062
+ assert2(false);
10063
+ }
10064
+ }
10065
+ function setConstantIntArray(device, location, array) {
10066
+ device.assertWebGL2();
10067
+ device.gl2?.vertexAttribI4iv(location, array);
10068
+ }
10069
+ function setConstantUintArray(device, location, array) {
10070
+ device.assertWebGL2();
10071
+ device.gl2?.vertexAttribI4uiv(location, array);
10072
+ }
10073
+ function compareConstantArrayValues2(v1, v2) {
10074
+ if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {
10075
+ return false;
10076
+ }
10077
+ for (let i = 0; i < v1.length; ++i) {
10078
+ if (v1[i] !== v2[i]) {
10079
+ return false;
10080
+ }
10081
+ }
10082
+ return true;
9986
10083
  }
9987
10084
 
9988
10085
  // src/classic/clear.ts
@@ -9990,8 +10087,8 @@ ${formattedLog}`)();
9990
10087
  var GL_STENCIL_BUFFER_BIT2 = 1024;
9991
10088
  var GL_COLOR_BUFFER_BIT2 = 16384;
9992
10089
  var ERR_ARGUMENTS = "clear: bad arguments";
9993
- function clear(gl2, options) {
9994
- const device = WebGLDevice.attach(gl2);
10090
+ function clear(gl, options) {
10091
+ const device = WebGLDevice.attach(gl);
9995
10092
  const {
9996
10093
  framebuffer = null,
9997
10094
  color = null,
@@ -10022,7 +10119,7 @@ ${formattedLog}`)();
10022
10119
  }
10023
10120
  }
10024
10121
  assert2(clearFlags !== 0, ERR_ARGUMENTS);
10025
- withParameters(device.gl, parameters, () => {
10122
+ withGLParameters(device.gl, parameters, () => {
10026
10123
  device.gl.clear(clearFlags);
10027
10124
  });
10028
10125
  }
@@ -10069,11 +10166,11 @@ ${formattedLog}`)();
10069
10166
  const {
10070
10167
  sourceX = 0,
10071
10168
  sourceY = 0,
10072
- sourceFormat = GL.RGBA
10169
+ sourceFormat = GL.RGBA,
10170
+ sourceAttachment = GL.COLOR_ATTACHMENT0
10171
+ // TODO - support gl.readBuffer
10073
10172
  } = options || {};
10074
10173
  let {
10075
- sourceAttachment = GL.COLOR_ATTACHMENT0,
10076
- // TODO - support gl.readBuffer
10077
10174
  target = null,
10078
10175
  // following parameters are auto deduced if not provided
10079
10176
  sourceWidth,
@@ -10086,21 +10183,18 @@ ${formattedLog}`)();
10086
10183
  } = getFramebuffer2(source);
10087
10184
  assert2(framebuffer);
10088
10185
  const {
10089
- gl: gl2,
10186
+ gl,
10090
10187
  handle
10091
10188
  } = framebuffer;
10092
10189
  sourceWidth = sourceWidth || framebuffer.width;
10093
10190
  sourceHeight = sourceHeight || framebuffer.height;
10094
- if (sourceAttachment === GL.COLOR_ATTACHMENT0 && handle === null) {
10095
- sourceAttachment = GL.FRONT;
10096
- }
10097
10191
  const attachment = sourceAttachment - GL.COLOR_ATTACHMENT0;
10098
- sourceType = sourceType || framebuffer.colorAttachments[attachment].type;
10192
+ sourceType = sourceType || framebuffer.colorAttachments[attachment]?.type || GL.UNSIGNED_BYTE;
10099
10193
  target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
10100
10194
  sourceType = sourceType || getGLTypeFromTypedArray(target);
10101
- const prevHandle2 = gl2.bindFramebuffer(GL.FRAMEBUFFER, handle);
10102
- gl2.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
10103
- gl2.bindFramebuffer(GL.FRAMEBUFFER, prevHandle2 || null);
10195
+ const prevHandle = gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
10196
+ gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
10197
+ gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
10104
10198
  if (deleteFramebuffer) {
10105
10199
  framebuffer.destroy();
10106
10200
  }
@@ -10144,7 +10238,7 @@ ${formattedLog}`)();
10144
10238
  target.bind({
10145
10239
  glTarget: GL.PIXEL_PACK_BUFFER
10146
10240
  });
10147
- withParameters(gl2, {
10241
+ withGLParameters(gl2, {
10148
10242
  framebuffer
10149
10243
  }, () => {
10150
10244
  gl2.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, targetByteOffset);
@@ -10188,7 +10282,7 @@ ${formattedLog}`)();
10188
10282
  targetX = targetX || 0;
10189
10283
  targetY = targetY || 0;
10190
10284
  targetZ = targetZ || 0;
10191
- const prevHandle2 = device.gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
10285
+ const prevHandle = device.gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
10192
10286
  assert2(target);
10193
10287
  let texture = null;
10194
10288
  let textureTarget;
@@ -10230,7 +10324,7 @@ ${formattedLog}`)();
10230
10324
  if (texture) {
10231
10325
  texture.unbind();
10232
10326
  }
10233
- gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle2 || null);
10327
+ device.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
10234
10328
  if (deleteFramebuffer) {
10235
10329
  framebuffer.destroy();
10236
10330
  }