@luma.gl/webgl 9.0.0-alpha.25 → 9.0.0-alpha.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgl-canvas-context.js +1 -0
- package/dist/adapter/webgl-canvas-context.js.map +1 -1
- package/dist/classic/copy-and-blit.d.ts +17 -0
- package/dist/classic/copy-and-blit.d.ts.map +1 -1
- package/dist/classic/copy-and-blit.js +67 -1
- package/dist/classic/copy-and-blit.js.map +1 -1
- package/dist/dist.dev.js +655 -570
- package/dist/index.cjs +648 -554
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist.min.js +22 -22
- package/package.json +5 -5
- package/src/adapter/webgl-canvas-context.ts +2 -1
- package/src/classic/copy-and-blit.ts +120 -0
- package/src/index.ts +1 -1
package/dist/dist.dev.js
CHANGED
|
@@ -53,6 +53,7 @@ var __exports__ = (() => {
|
|
|
53
53
|
assertWebGLContext: () => assertWebGLContext,
|
|
54
54
|
clear: () => clear,
|
|
55
55
|
convertGLToTextureFormat: () => convertGLToTextureFormat,
|
|
56
|
+
copyToTexture: () => copyToTexture,
|
|
56
57
|
getParameters: () => getParameters,
|
|
57
58
|
getProgramBindings: () => getProgramBindings,
|
|
58
59
|
getShaderLayout: () => getShaderLayout,
|
|
@@ -106,11 +107,11 @@ var __exports__ = (() => {
|
|
|
106
107
|
if (!headlessGL) {
|
|
107
108
|
throw new Error(ERR_HEADLESSGL_LOAD);
|
|
108
109
|
}
|
|
109
|
-
const
|
|
110
|
-
if (!
|
|
110
|
+
const gl2 = headlessGL(width, height, options);
|
|
111
|
+
if (!gl2) {
|
|
111
112
|
throw new Error(ERR_HEADLESSGL_FAILED);
|
|
112
113
|
}
|
|
113
|
-
return
|
|
114
|
+
return gl2;
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
// ../../node_modules/@probe.gl/env/dist/lib/is-electron.js
|
|
@@ -1249,9 +1250,9 @@ var __exports__ = (() => {
|
|
|
1249
1250
|
};
|
|
1250
1251
|
if ((props.usage || 0) & Buffer2.INDEX && !props.indexType) {
|
|
1251
1252
|
if (props.data instanceof Uint32Array) {
|
|
1252
|
-
|
|
1253
|
+
newProps.indexType = "uint32";
|
|
1253
1254
|
} else if (props.data instanceof Uint16Array) {
|
|
1254
|
-
|
|
1255
|
+
newProps.indexType = "uint16";
|
|
1255
1256
|
}
|
|
1256
1257
|
}
|
|
1257
1258
|
return newProps;
|
|
@@ -1403,7 +1404,7 @@ var __exports__ = (() => {
|
|
|
1403
1404
|
* Use devicePixelRatio to set canvas width and height
|
|
1404
1405
|
* @note this is a raw port of luma.gl v8 code. Might be worth a review
|
|
1405
1406
|
*/
|
|
1406
|
-
setDevicePixelRatio(
|
|
1407
|
+
setDevicePixelRatio(devicePixelRatio, options = {}) {
|
|
1407
1408
|
if (!this.htmlCanvas) {
|
|
1408
1409
|
return;
|
|
1409
1410
|
}
|
|
@@ -1411,13 +1412,13 @@ var __exports__ = (() => {
|
|
|
1411
1412
|
let clientHeight = "height" in options ? options.height : this.htmlCanvas.clientHeight;
|
|
1412
1413
|
if (!clientWidth || !clientHeight) {
|
|
1413
1414
|
log.log(1, "Canvas clientWidth/clientHeight is 0")();
|
|
1414
|
-
|
|
1415
|
+
devicePixelRatio = 1;
|
|
1415
1416
|
clientWidth = this.htmlCanvas.width || 1;
|
|
1416
1417
|
clientHeight = this.htmlCanvas.height || 1;
|
|
1417
1418
|
}
|
|
1418
1419
|
const cachedSize = this._canvasSizeInfo;
|
|
1419
|
-
if (cachedSize.clientWidth !== clientWidth || cachedSize.clientHeight !== clientHeight || cachedSize.devicePixelRatio !==
|
|
1420
|
-
let clampedPixelRatio =
|
|
1420
|
+
if (cachedSize.clientWidth !== clientWidth || cachedSize.clientHeight !== clientHeight || cachedSize.devicePixelRatio !== devicePixelRatio) {
|
|
1421
|
+
let clampedPixelRatio = devicePixelRatio;
|
|
1421
1422
|
const canvasWidth = Math.floor(clientWidth * clampedPixelRatio);
|
|
1422
1423
|
const canvasHeight = Math.floor(clientHeight * clampedPixelRatio);
|
|
1423
1424
|
this.htmlCanvas.width = canvasWidth;
|
|
@@ -1431,17 +1432,17 @@ var __exports__ = (() => {
|
|
|
1431
1432
|
}
|
|
1432
1433
|
this._canvasSizeInfo.clientWidth = clientWidth;
|
|
1433
1434
|
this._canvasSizeInfo.clientHeight = clientHeight;
|
|
1434
|
-
this._canvasSizeInfo.devicePixelRatio =
|
|
1435
|
+
this._canvasSizeInfo.devicePixelRatio = devicePixelRatio;
|
|
1435
1436
|
}
|
|
1436
1437
|
}
|
|
1437
1438
|
// PRIVATE
|
|
1438
1439
|
/** @todo Major hack done to port the CSS methods above, base canvas context should not depend on WebGL */
|
|
1439
1440
|
getDrawingBufferSize() {
|
|
1440
|
-
const
|
|
1441
|
-
if (!
|
|
1441
|
+
const gl2 = this.device.gl;
|
|
1442
|
+
if (!gl2) {
|
|
1442
1443
|
throw new Error("canvas size");
|
|
1443
1444
|
}
|
|
1444
|
-
return [
|
|
1445
|
+
return [gl2.drawingBufferWidth, gl2.drawingBufferHeight];
|
|
1445
1446
|
}
|
|
1446
1447
|
/** Perform platform specific updates (WebGPU vs WebGL) */
|
|
1447
1448
|
/**
|
|
@@ -1864,7 +1865,11 @@ var __exports__ = (() => {
|
|
|
1864
1865
|
constructor(device, props) {
|
|
1865
1866
|
super(device, props, _RenderPass.defaultProps);
|
|
1866
1867
|
}
|
|
1867
|
-
/**
|
|
1868
|
+
/** Call when rendering is done in this pass. */
|
|
1869
|
+
/**
|
|
1870
|
+
* A small set of parameters can be changed between every draw call
|
|
1871
|
+
* (viewport, scissorRect, blendColor, stencilReference)
|
|
1872
|
+
*/
|
|
1868
1873
|
// writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;
|
|
1869
1874
|
// beginOcclusionQuery(queryIndex: number): void;
|
|
1870
1875
|
// endOcclusionQuery(): void;
|
|
@@ -2269,43 +2274,43 @@ var __exports__ = (() => {
|
|
|
2269
2274
|
error(opt_msg);
|
|
2270
2275
|
}
|
|
2271
2276
|
}
|
|
2272
|
-
function wrapGLError(
|
|
2273
|
-
const f =
|
|
2274
|
-
|
|
2277
|
+
function wrapGLError(gl2) {
|
|
2278
|
+
const f = gl2.getError;
|
|
2279
|
+
gl2.getError = function getError() {
|
|
2275
2280
|
let err;
|
|
2276
2281
|
do {
|
|
2277
|
-
err = f.apply(
|
|
2278
|
-
if (err !==
|
|
2282
|
+
err = f.apply(gl2);
|
|
2283
|
+
if (err !== gl2.NO_ERROR) {
|
|
2279
2284
|
glErrorShadow[err] = true;
|
|
2280
2285
|
}
|
|
2281
|
-
} while (err !==
|
|
2286
|
+
} while (err !== gl2.NO_ERROR);
|
|
2282
2287
|
for (err in glErrorShadow) {
|
|
2283
2288
|
if (glErrorShadow[err]) {
|
|
2284
2289
|
delete glErrorShadow[err];
|
|
2285
2290
|
return parseInt(err, 10);
|
|
2286
2291
|
}
|
|
2287
2292
|
}
|
|
2288
|
-
return
|
|
2293
|
+
return gl2.NO_ERROR;
|
|
2289
2294
|
};
|
|
2290
2295
|
}
|
|
2291
2296
|
var WebGLVertexArrayObjectOES = function WebGLVertexArrayObjectOES2(ext) {
|
|
2292
|
-
const
|
|
2297
|
+
const gl2 = ext.gl;
|
|
2293
2298
|
this.ext = ext;
|
|
2294
2299
|
this.isAlive = true;
|
|
2295
2300
|
this.hasBeenBound = false;
|
|
2296
2301
|
this.elementArrayBuffer = null;
|
|
2297
2302
|
this.attribs = new Array(ext.maxVertexAttribs);
|
|
2298
2303
|
for (let n = 0; n < this.attribs.length; n++) {
|
|
2299
|
-
const attrib = new WebGLVertexArrayObjectOES2.VertexAttrib(
|
|
2304
|
+
const attrib = new WebGLVertexArrayObjectOES2.VertexAttrib(gl2);
|
|
2300
2305
|
this.attribs[n] = attrib;
|
|
2301
2306
|
}
|
|
2302
2307
|
this.maxAttrib = 0;
|
|
2303
2308
|
};
|
|
2304
|
-
WebGLVertexArrayObjectOES.VertexAttrib = function VertexAttrib(
|
|
2309
|
+
WebGLVertexArrayObjectOES.VertexAttrib = function VertexAttrib(gl2) {
|
|
2305
2310
|
this.enabled = false;
|
|
2306
2311
|
this.buffer = null;
|
|
2307
2312
|
this.size = 4;
|
|
2308
|
-
this.type =
|
|
2313
|
+
this.type = gl2.FLOAT;
|
|
2309
2314
|
this.normalized = false;
|
|
2310
2315
|
this.stride = 16;
|
|
2311
2316
|
this.offset = 0;
|
|
@@ -2315,19 +2320,19 @@ var __exports__ = (() => {
|
|
|
2315
2320
|
WebGLVertexArrayObjectOES.VertexAttrib.prototype.recache = function recache() {
|
|
2316
2321
|
this.cached = [this.size, this.type, this.normalized, this.stride, this.offset].join(":");
|
|
2317
2322
|
};
|
|
2318
|
-
var OESVertexArrayObject = function OESVertexArrayObject2(
|
|
2323
|
+
var OESVertexArrayObject = function OESVertexArrayObject2(gl2) {
|
|
2319
2324
|
const self = this;
|
|
2320
|
-
this.gl =
|
|
2321
|
-
wrapGLError(
|
|
2325
|
+
this.gl = gl2;
|
|
2326
|
+
wrapGLError(gl2);
|
|
2322
2327
|
const original = this.original = {
|
|
2323
|
-
getParameter:
|
|
2324
|
-
enableVertexAttribArray:
|
|
2325
|
-
disableVertexAttribArray:
|
|
2326
|
-
bindBuffer:
|
|
2327
|
-
getVertexAttrib:
|
|
2328
|
-
vertexAttribPointer:
|
|
2328
|
+
getParameter: gl2.getParameter,
|
|
2329
|
+
enableVertexAttribArray: gl2.enableVertexAttribArray,
|
|
2330
|
+
disableVertexAttribArray: gl2.disableVertexAttribArray,
|
|
2331
|
+
bindBuffer: gl2.bindBuffer,
|
|
2332
|
+
getVertexAttrib: gl2.getVertexAttrib,
|
|
2333
|
+
vertexAttribPointer: gl2.vertexAttribPointer
|
|
2329
2334
|
};
|
|
2330
|
-
|
|
2335
|
+
gl2.getParameter = function getParameter(pname) {
|
|
2331
2336
|
if (pname === self.VERTEX_ARRAY_BINDING_OES) {
|
|
2332
2337
|
if (self.currentVertexArrayObject === self.defaultVertexArrayObject) {
|
|
2333
2338
|
return null;
|
|
@@ -2336,53 +2341,53 @@ var __exports__ = (() => {
|
|
|
2336
2341
|
}
|
|
2337
2342
|
return original.getParameter.apply(this, arguments);
|
|
2338
2343
|
};
|
|
2339
|
-
|
|
2344
|
+
gl2.enableVertexAttribArray = function enableVertexAttribArray(index) {
|
|
2340
2345
|
const vao = self.currentVertexArrayObject;
|
|
2341
2346
|
vao.maxAttrib = Math.max(vao.maxAttrib, index);
|
|
2342
2347
|
const attrib = vao.attribs[index];
|
|
2343
2348
|
attrib.enabled = true;
|
|
2344
2349
|
return original.enableVertexAttribArray.apply(this, arguments);
|
|
2345
2350
|
};
|
|
2346
|
-
|
|
2351
|
+
gl2.disableVertexAttribArray = function disableVertexAttribArray(index) {
|
|
2347
2352
|
const vao = self.currentVertexArrayObject;
|
|
2348
2353
|
vao.maxAttrib = Math.max(vao.maxAttrib, index);
|
|
2349
2354
|
const attrib = vao.attribs[index];
|
|
2350
2355
|
attrib.enabled = false;
|
|
2351
2356
|
return original.disableVertexAttribArray.apply(this, arguments);
|
|
2352
2357
|
};
|
|
2353
|
-
|
|
2358
|
+
gl2.bindBuffer = function bindBuffer2(target, buffer) {
|
|
2354
2359
|
switch (target) {
|
|
2355
|
-
case
|
|
2360
|
+
case gl2.ARRAY_BUFFER:
|
|
2356
2361
|
self.currentArrayBuffer = buffer;
|
|
2357
2362
|
break;
|
|
2358
|
-
case
|
|
2363
|
+
case gl2.ELEMENT_ARRAY_BUFFER:
|
|
2359
2364
|
self.currentVertexArrayObject.elementArrayBuffer = buffer;
|
|
2360
2365
|
break;
|
|
2361
2366
|
default:
|
|
2362
2367
|
}
|
|
2363
2368
|
return original.bindBuffer.apply(this, arguments);
|
|
2364
2369
|
};
|
|
2365
|
-
|
|
2370
|
+
gl2.getVertexAttrib = function getVertexAttrib(index, pname) {
|
|
2366
2371
|
const vao = self.currentVertexArrayObject;
|
|
2367
2372
|
const attrib = vao.attribs[index];
|
|
2368
2373
|
switch (pname) {
|
|
2369
|
-
case
|
|
2374
|
+
case gl2.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
|
|
2370
2375
|
return attrib.buffer;
|
|
2371
|
-
case
|
|
2376
|
+
case gl2.VERTEX_ATTRIB_ARRAY_ENABLED:
|
|
2372
2377
|
return attrib.enabled;
|
|
2373
|
-
case
|
|
2378
|
+
case gl2.VERTEX_ATTRIB_ARRAY_SIZE:
|
|
2374
2379
|
return attrib.size;
|
|
2375
|
-
case
|
|
2380
|
+
case gl2.VERTEX_ATTRIB_ARRAY_STRIDE:
|
|
2376
2381
|
return attrib.stride;
|
|
2377
|
-
case
|
|
2382
|
+
case gl2.VERTEX_ATTRIB_ARRAY_TYPE:
|
|
2378
2383
|
return attrib.type;
|
|
2379
|
-
case
|
|
2384
|
+
case gl2.VERTEX_ATTRIB_ARRAY_NORMALIZED:
|
|
2380
2385
|
return attrib.normalized;
|
|
2381
2386
|
default:
|
|
2382
2387
|
return original.getVertexAttrib.apply(this, arguments);
|
|
2383
2388
|
}
|
|
2384
2389
|
};
|
|
2385
|
-
|
|
2390
|
+
gl2.vertexAttribPointer = function vertexAttribPointer(indx, size, type, normalized, stride, offset) {
|
|
2386
2391
|
const vao = self.currentVertexArrayObject;
|
|
2387
2392
|
vao.maxAttrib = Math.max(vao.maxAttrib, indx);
|
|
2388
2393
|
const attrib = vao.attribs[indx];
|
|
@@ -2395,11 +2400,11 @@ var __exports__ = (() => {
|
|
|
2395
2400
|
attrib.recache();
|
|
2396
2401
|
return original.vertexAttribPointer.apply(this, arguments);
|
|
2397
2402
|
};
|
|
2398
|
-
if (
|
|
2399
|
-
|
|
2403
|
+
if (gl2.instrumentExtension) {
|
|
2404
|
+
gl2.instrumentExtension(this, "OES_vertex_array_object");
|
|
2400
2405
|
}
|
|
2401
|
-
if (
|
|
2402
|
-
|
|
2406
|
+
if (gl2.canvas) {
|
|
2407
|
+
gl2.canvas.addEventListener("webglcontextrestored", () => {
|
|
2403
2408
|
log2("OESVertexArrayObject emulation library context restored");
|
|
2404
2409
|
self.reset_();
|
|
2405
2410
|
}, true);
|
|
@@ -2414,8 +2419,8 @@ var __exports__ = (() => {
|
|
|
2414
2419
|
this.vertexArrayObjects.isAlive = false;
|
|
2415
2420
|
}
|
|
2416
2421
|
}
|
|
2417
|
-
const
|
|
2418
|
-
this.maxVertexAttribs =
|
|
2422
|
+
const gl2 = this.gl;
|
|
2423
|
+
this.maxVertexAttribs = gl2.getParameter(gl2.MAX_VERTEX_ATTRIBS);
|
|
2419
2424
|
this.defaultVertexArrayObject = new WebGLVertexArrayObjectOES(this);
|
|
2420
2425
|
this.currentVertexArrayObject = null;
|
|
2421
2426
|
this.currentArrayBuffer = null;
|
|
@@ -2443,9 +2448,9 @@ var __exports__ = (() => {
|
|
|
2443
2448
|
return false;
|
|
2444
2449
|
};
|
|
2445
2450
|
OESVertexArrayObject.prototype.bindVertexArrayOES = function bindVertexArrayOES(arrayObject) {
|
|
2446
|
-
const
|
|
2451
|
+
const gl2 = this.gl;
|
|
2447
2452
|
if (arrayObject && !arrayObject.isAlive) {
|
|
2448
|
-
synthesizeGLError(
|
|
2453
|
+
synthesizeGLError(gl2.INVALID_OPERATION, "bindVertexArrayOES: attempt to bind deleted arrayObject");
|
|
2449
2454
|
return;
|
|
2450
2455
|
}
|
|
2451
2456
|
const original = this.original;
|
|
@@ -2457,7 +2462,7 @@ var __exports__ = (() => {
|
|
|
2457
2462
|
return;
|
|
2458
2463
|
}
|
|
2459
2464
|
if (!oldVAO || newVAO.elementArrayBuffer !== oldVAO.elementArrayBuffer) {
|
|
2460
|
-
original.bindBuffer.call(
|
|
2465
|
+
original.bindBuffer.call(gl2, gl2.ELEMENT_ARRAY_BUFFER, newVAO.elementArrayBuffer);
|
|
2461
2466
|
}
|
|
2462
2467
|
let currentBinding = this.currentArrayBuffer;
|
|
2463
2468
|
const maxAttrib = Math.max(oldVAO ? oldVAO.maxAttrib : 0, newVAO.maxAttrib);
|
|
@@ -2466,43 +2471,43 @@ var __exports__ = (() => {
|
|
|
2466
2471
|
const oldAttrib = oldVAO ? oldVAO.attribs[n] : null;
|
|
2467
2472
|
if (!oldVAO || attrib.enabled !== oldAttrib.enabled) {
|
|
2468
2473
|
if (attrib.enabled) {
|
|
2469
|
-
original.enableVertexAttribArray.call(
|
|
2474
|
+
original.enableVertexAttribArray.call(gl2, n);
|
|
2470
2475
|
} else {
|
|
2471
|
-
original.disableVertexAttribArray.call(
|
|
2476
|
+
original.disableVertexAttribArray.call(gl2, n);
|
|
2472
2477
|
}
|
|
2473
2478
|
}
|
|
2474
2479
|
if (attrib.enabled) {
|
|
2475
2480
|
let bufferChanged = false;
|
|
2476
2481
|
if (!oldVAO || attrib.buffer !== oldAttrib.buffer) {
|
|
2477
2482
|
if (currentBinding !== attrib.buffer) {
|
|
2478
|
-
original.bindBuffer.call(
|
|
2483
|
+
original.bindBuffer.call(gl2, gl2.ARRAY_BUFFER, attrib.buffer);
|
|
2479
2484
|
currentBinding = attrib.buffer;
|
|
2480
2485
|
}
|
|
2481
2486
|
bufferChanged = true;
|
|
2482
2487
|
}
|
|
2483
2488
|
if (bufferChanged || attrib.cached !== oldAttrib.cached) {
|
|
2484
|
-
original.vertexAttribPointer.call(
|
|
2489
|
+
original.vertexAttribPointer.call(gl2, n, attrib.size, attrib.type, attrib.normalized, attrib.stride, attrib.offset);
|
|
2485
2490
|
}
|
|
2486
2491
|
}
|
|
2487
2492
|
}
|
|
2488
2493
|
if (this.currentArrayBuffer !== currentBinding) {
|
|
2489
|
-
original.bindBuffer.call(
|
|
2494
|
+
original.bindBuffer.call(gl2, gl2.ARRAY_BUFFER, this.currentArrayBuffer);
|
|
2490
2495
|
}
|
|
2491
2496
|
};
|
|
2492
|
-
function polyfillVertexArrayObject(
|
|
2493
|
-
if (typeof
|
|
2497
|
+
function polyfillVertexArrayObject(gl2) {
|
|
2498
|
+
if (typeof gl2.createVertexArray === "function") {
|
|
2494
2499
|
return;
|
|
2495
2500
|
}
|
|
2496
|
-
const original_getSupportedExtensions =
|
|
2497
|
-
|
|
2501
|
+
const original_getSupportedExtensions = gl2.getSupportedExtensions;
|
|
2502
|
+
gl2.getSupportedExtensions = function getSupportedExtensions() {
|
|
2498
2503
|
const list = original_getSupportedExtensions.call(this) || [];
|
|
2499
2504
|
if (list.indexOf("OES_vertex_array_object") < 0) {
|
|
2500
2505
|
list.push("OES_vertex_array_object");
|
|
2501
2506
|
}
|
|
2502
2507
|
return list;
|
|
2503
2508
|
};
|
|
2504
|
-
const original_getExtension =
|
|
2505
|
-
|
|
2509
|
+
const original_getExtension = gl2.getExtension;
|
|
2510
|
+
gl2.getExtension = function getExtension(name) {
|
|
2506
2511
|
const ext = original_getExtension.call(this, name);
|
|
2507
2512
|
if (ext) {
|
|
2508
2513
|
return ext;
|
|
@@ -2510,7 +2515,7 @@ var __exports__ = (() => {
|
|
|
2510
2515
|
if (name !== "OES_vertex_array_object") {
|
|
2511
2516
|
return null;
|
|
2512
2517
|
}
|
|
2513
|
-
if (!
|
|
2518
|
+
if (!gl2.__OESVertexArrayObject) {
|
|
2514
2519
|
this.__OESVertexArrayObject = new OESVertexArrayObject(this);
|
|
2515
2520
|
}
|
|
2516
2521
|
return this.__OESVertexArrayObject;
|
|
@@ -3187,31 +3192,31 @@ var __exports__ = (() => {
|
|
|
3187
3192
|
// src/context/context/webgl-checks.ts
|
|
3188
3193
|
var ERR_CONTEXT = "Invalid WebGLRenderingContext";
|
|
3189
3194
|
var ERR_WEBGL2 = "Requires WebGL2";
|
|
3190
|
-
function isWebGL(
|
|
3191
|
-
if (typeof WebGLRenderingContext !== "undefined" &&
|
|
3195
|
+
function isWebGL(gl2) {
|
|
3196
|
+
if (typeof WebGLRenderingContext !== "undefined" && gl2 instanceof WebGLRenderingContext) {
|
|
3192
3197
|
return true;
|
|
3193
3198
|
}
|
|
3194
|
-
if (typeof WebGL2RenderingContext !== "undefined" &&
|
|
3199
|
+
if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
|
|
3195
3200
|
return true;
|
|
3196
3201
|
}
|
|
3197
|
-
return Boolean(
|
|
3202
|
+
return Boolean(gl2 && Number.isFinite(gl2._version));
|
|
3198
3203
|
}
|
|
3199
|
-
function isWebGL2(
|
|
3200
|
-
if (typeof WebGL2RenderingContext !== "undefined" &&
|
|
3204
|
+
function isWebGL2(gl2) {
|
|
3205
|
+
if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
|
|
3201
3206
|
return true;
|
|
3202
3207
|
}
|
|
3203
|
-
return Boolean(
|
|
3208
|
+
return Boolean(gl2 && gl2._version === 2);
|
|
3204
3209
|
}
|
|
3205
|
-
function getWebGL2Context(
|
|
3206
|
-
return isWebGL2(
|
|
3210
|
+
function getWebGL2Context(gl2) {
|
|
3211
|
+
return isWebGL2(gl2) ? gl2 : null;
|
|
3207
3212
|
}
|
|
3208
|
-
function assertWebGLContext(
|
|
3209
|
-
assert2(isWebGL(
|
|
3210
|
-
return
|
|
3213
|
+
function assertWebGLContext(gl2) {
|
|
3214
|
+
assert2(isWebGL(gl2), ERR_CONTEXT);
|
|
3215
|
+
return gl2;
|
|
3211
3216
|
}
|
|
3212
|
-
function assertWebGL2Context(
|
|
3213
|
-
assert2(isWebGL2(
|
|
3214
|
-
return
|
|
3217
|
+
function assertWebGL2Context(gl2) {
|
|
3218
|
+
assert2(isWebGL2(gl2), ERR_WEBGL2);
|
|
3219
|
+
return gl2;
|
|
3215
3220
|
}
|
|
3216
3221
|
|
|
3217
3222
|
// src/context/polyfill/get-parameter-polyfill.ts
|
|
@@ -3227,39 +3232,39 @@ var __exports__ = (() => {
|
|
|
3227
3232
|
var GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT = 34047;
|
|
3228
3233
|
var GL_UNMASKED_VENDOR_WEBGL = 37445;
|
|
3229
3234
|
var GL_UNMASKED_RENDERER_WEBGL = 37446;
|
|
3230
|
-
var getWebGL2ValueOrZero = (
|
|
3235
|
+
var getWebGL2ValueOrZero = (gl2) => !isWebGL2(gl2) ? 0 : void 0;
|
|
3231
3236
|
var WEBGL_PARAMETERS = {
|
|
3232
|
-
[GL.READ_BUFFER]: (
|
|
3237
|
+
[GL.READ_BUFFER]: (gl2) => !isWebGL2(gl2) ? GL.COLOR_ATTACHMENT0 : void 0,
|
|
3233
3238
|
// WebGL2 context parameters
|
|
3234
|
-
[GL_FRAGMENT_SHADER_DERIVATIVE_HINT]: (
|
|
3239
|
+
[GL_FRAGMENT_SHADER_DERIVATIVE_HINT]: (gl2) => !isWebGL2(gl2) ? GL_DONT_CARE : void 0,
|
|
3235
3240
|
[GL.RASTERIZER_DISCARD]: getWebGL2ValueOrZero,
|
|
3236
3241
|
[GL.SAMPLES]: getWebGL2ValueOrZero,
|
|
3237
3242
|
// WebGL2 extension context parameters
|
|
3238
|
-
[GL_GPU_DISJOINT_EXT]: (
|
|
3239
|
-
const ext = isWebGL2(
|
|
3243
|
+
[GL_GPU_DISJOINT_EXT]: (gl2, getParameter) => {
|
|
3244
|
+
const ext = isWebGL2(gl2) ? gl2.getExtension(EXT_disjoint_timer_query_webgl2) : gl2.getExtension(EXT_disjoint_timer_query);
|
|
3240
3245
|
return ext && ext.GPU_DISJOINT_EXT ? getParameter(ext.GPU_DISJOINT_EXT) : 0;
|
|
3241
3246
|
},
|
|
3242
3247
|
// Extension fixed values
|
|
3243
|
-
[GL_UNMASKED_VENDOR_WEBGL]: (
|
|
3244
|
-
const ext =
|
|
3248
|
+
[GL_UNMASKED_VENDOR_WEBGL]: (gl2, getParameter) => {
|
|
3249
|
+
const ext = gl2.getExtension(WEBGL_debug_renderer_info);
|
|
3245
3250
|
return getParameter(ext && ext.UNMASKED_VENDOR_WEBGL || GL.VENDOR);
|
|
3246
3251
|
},
|
|
3247
|
-
[GL_UNMASKED_RENDERER_WEBGL]: (
|
|
3248
|
-
const ext =
|
|
3252
|
+
[GL_UNMASKED_RENDERER_WEBGL]: (gl2, getParameter) => {
|
|
3253
|
+
const ext = gl2.getExtension(WEBGL_debug_renderer_info);
|
|
3249
3254
|
return getParameter(ext && ext.UNMASKED_RENDERER_WEBGL || GL.RENDERER);
|
|
3250
3255
|
},
|
|
3251
3256
|
// Extension LIMITS
|
|
3252
|
-
[GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT]: (
|
|
3253
|
-
const ext =
|
|
3257
|
+
[GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT]: (gl2, getParameter) => {
|
|
3258
|
+
const ext = gl2.luma?.extensions?.[EXT_texture_filter_anisotropic] || gl2.getExtension("EXT_texture_filter_anisotropic");
|
|
3254
3259
|
return ext ? getParameter(ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 1;
|
|
3255
3260
|
},
|
|
3256
3261
|
// WebGL2 Limits
|
|
3257
3262
|
[GL.MAX_3D_TEXTURE_SIZE]: getWebGL2ValueOrZero,
|
|
3258
3263
|
[GL.MAX_ARRAY_TEXTURE_LAYERS]: getWebGL2ValueOrZero,
|
|
3259
3264
|
[GL.MAX_CLIENT_WAIT_TIMEOUT_WEBGL]: getWebGL2ValueOrZero,
|
|
3260
|
-
[GL.MAX_COLOR_ATTACHMENTS]: (
|
|
3261
|
-
if (!isWebGL2(
|
|
3262
|
-
const ext =
|
|
3265
|
+
[GL.MAX_COLOR_ATTACHMENTS]: (gl2, getParameter) => {
|
|
3266
|
+
if (!isWebGL2(gl2)) {
|
|
3267
|
+
const ext = gl2.getExtension(WEBGL_draw_buffers);
|
|
3263
3268
|
return ext ? getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL) : 0;
|
|
3264
3269
|
}
|
|
3265
3270
|
return void 0;
|
|
@@ -3267,24 +3272,24 @@ var __exports__ = (() => {
|
|
|
3267
3272
|
[GL.MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
|
|
3268
3273
|
[GL.MAX_COMBINED_UNIFORM_BLOCKS]: getWebGL2ValueOrZero,
|
|
3269
3274
|
[GL.MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
|
|
3270
|
-
[GL.MAX_DRAW_BUFFERS]: (
|
|
3271
|
-
if (!isWebGL2(
|
|
3272
|
-
const ext =
|
|
3275
|
+
[GL.MAX_DRAW_BUFFERS]: (gl2) => {
|
|
3276
|
+
if (!isWebGL2(gl2)) {
|
|
3277
|
+
const ext = gl2.getExtension(WEBGL_draw_buffers);
|
|
3273
3278
|
return ext ? ext.MAX_DRAW_BUFFERS_WEBGL : 0;
|
|
3274
3279
|
}
|
|
3275
3280
|
return void 0;
|
|
3276
3281
|
},
|
|
3277
3282
|
[GL.MAX_ELEMENT_INDEX]: (
|
|
3278
3283
|
// Guess: per webglstats.com 99.6% of webgl2 supports 2147483647
|
|
3279
|
-
(
|
|
3284
|
+
(gl2) => gl2.getExtension(OES_element_index) ? 2147483647 : 65535
|
|
3280
3285
|
),
|
|
3281
3286
|
[GL.MAX_ELEMENTS_INDICES]: (
|
|
3282
3287
|
// Guess: "Reasonably safe" per webglstats.com - could be higher/lower (on some mobile devices)
|
|
3283
|
-
(
|
|
3288
|
+
(gl2) => gl2.getExtension(OES_element_index) ? 16777216 : 65535
|
|
3284
3289
|
),
|
|
3285
3290
|
[GL.MAX_ELEMENTS_VERTICES]: (
|
|
3286
3291
|
// Guess: "Reasonably safe" per webglstats.com - could be higher/lower (on some mobile devices)
|
|
3287
|
-
(
|
|
3292
|
+
(gl2) => 16777216
|
|
3288
3293
|
),
|
|
3289
3294
|
[GL.MAX_FRAGMENT_INPUT_COMPONENTS]: getWebGL2ValueOrZero,
|
|
3290
3295
|
[GL.MAX_FRAGMENT_UNIFORM_BLOCKS]: getWebGL2ValueOrZero,
|
|
@@ -3305,24 +3310,24 @@ var __exports__ = (() => {
|
|
|
3305
3310
|
[GL.MAX_PROGRAM_TEXEL_OFFSET]: getWebGL2ValueOrZero,
|
|
3306
3311
|
[GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT]: getWebGL2ValueOrZero
|
|
3307
3312
|
};
|
|
3308
|
-
function getParameterPolyfill(
|
|
3313
|
+
function getParameterPolyfill(gl2, originalGetParameter, pname) {
|
|
3309
3314
|
const limit = WEBGL_PARAMETERS[pname];
|
|
3310
|
-
const value = typeof limit === "function" ? limit(
|
|
3315
|
+
const value = typeof limit === "function" ? limit(gl2, originalGetParameter, pname) : limit;
|
|
3311
3316
|
const result = value !== void 0 ? value : originalGetParameter(pname);
|
|
3312
3317
|
return result;
|
|
3313
3318
|
}
|
|
3314
3319
|
|
|
3315
3320
|
// src/context/polyfill/context-data.ts
|
|
3316
|
-
function getContextData(
|
|
3317
|
-
const luma =
|
|
3321
|
+
function getContextData(gl2) {
|
|
3322
|
+
const luma = gl2.luma;
|
|
3318
3323
|
if (!luma) {
|
|
3319
3324
|
const contextState = {
|
|
3320
3325
|
_polyfilled: false,
|
|
3321
3326
|
_extensions: {}
|
|
3322
3327
|
};
|
|
3323
|
-
|
|
3328
|
+
gl2.luma = contextState;
|
|
3324
3329
|
}
|
|
3325
|
-
return
|
|
3330
|
+
return gl2.luma;
|
|
3326
3331
|
}
|
|
3327
3332
|
|
|
3328
3333
|
// src/context/polyfill/polyfill-table.ts
|
|
@@ -3332,10 +3337,10 @@ var __exports__ = (() => {
|
|
|
3332
3337
|
var EXT_disjoint_timer_query2 = "EXT_disjoint_timer_query";
|
|
3333
3338
|
var EXT_texture_filter_anisotropic2 = "EXT_texture_filter_anisotropic";
|
|
3334
3339
|
var ERR_VAO_NOT_SUPPORTED = "VertexArray requires WebGL2 or OES_vertex_array_object extension";
|
|
3335
|
-
function getExtensionData(
|
|
3340
|
+
function getExtensionData(gl2, extension) {
|
|
3336
3341
|
return {
|
|
3337
|
-
webgl2: isWebGL2(
|
|
3338
|
-
ext:
|
|
3342
|
+
webgl2: isWebGL2(gl2),
|
|
3343
|
+
ext: gl2.getExtension(extension)
|
|
3339
3344
|
};
|
|
3340
3345
|
}
|
|
3341
3346
|
var WEBGL2_CONTEXT_POLYFILLS = {
|
|
@@ -3406,18 +3411,18 @@ var __exports__ = (() => {
|
|
|
3406
3411
|
};
|
|
3407
3412
|
var WEBGL2_CONTEXT_OVERRIDES = {
|
|
3408
3413
|
// Ensure readBuffer is a no-op
|
|
3409
|
-
readBuffer: (
|
|
3410
|
-
if (isWebGL2(
|
|
3414
|
+
readBuffer: (gl2, originalFunc, attachment) => {
|
|
3415
|
+
if (isWebGL2(gl2)) {
|
|
3411
3416
|
originalFunc(attachment);
|
|
3412
3417
|
} else {
|
|
3413
3418
|
}
|
|
3414
3419
|
},
|
|
3415
3420
|
// Override for getVertexAttrib that returns sane values for non-WebGL1 constants
|
|
3416
|
-
getVertexAttrib: (
|
|
3421
|
+
getVertexAttrib: (gl2, originalFunc, location, pname) => {
|
|
3417
3422
|
const {
|
|
3418
3423
|
webgl2,
|
|
3419
3424
|
ext
|
|
3420
|
-
} = getExtensionData(
|
|
3425
|
+
} = getExtensionData(gl2, ANGLE_instanced_arrays);
|
|
3421
3426
|
let result;
|
|
3422
3427
|
switch (pname) {
|
|
3423
3428
|
case GL.VERTEX_ATTRIB_ARRAY_INTEGER:
|
|
@@ -3431,8 +3436,8 @@ var __exports__ = (() => {
|
|
|
3431
3436
|
return result !== void 0 ? result : originalFunc(location, pname);
|
|
3432
3437
|
},
|
|
3433
3438
|
// Handle transform feedback and uniform block queries in WebGL1
|
|
3434
|
-
getProgramParameter: (
|
|
3435
|
-
if (!isWebGL2(
|
|
3439
|
+
getProgramParameter: (gl2, originalFunc, program, pname) => {
|
|
3440
|
+
if (!isWebGL2(gl2)) {
|
|
3436
3441
|
switch (pname) {
|
|
3437
3442
|
case GL.TRANSFORM_FEEDBACK_BUFFER_MODE:
|
|
3438
3443
|
return GL.SEPARATE_ATTRIBS;
|
|
@@ -3445,21 +3450,21 @@ var __exports__ = (() => {
|
|
|
3445
3450
|
}
|
|
3446
3451
|
return originalFunc(program, pname);
|
|
3447
3452
|
},
|
|
3448
|
-
getInternalformatParameter: (
|
|
3449
|
-
if (!isWebGL2(
|
|
3453
|
+
getInternalformatParameter: (gl2, originalFunc, target, format, pname) => {
|
|
3454
|
+
if (!isWebGL2(gl2)) {
|
|
3450
3455
|
switch (pname) {
|
|
3451
3456
|
case GL.SAMPLES:
|
|
3452
3457
|
return new Int32Array([0]);
|
|
3453
3458
|
default:
|
|
3454
3459
|
}
|
|
3455
3460
|
}
|
|
3456
|
-
const
|
|
3457
|
-
return
|
|
3461
|
+
const gl22 = gl2;
|
|
3462
|
+
return gl22.getInternalformatParameter(target, format, pname);
|
|
3458
3463
|
},
|
|
3459
|
-
getTexParameter(
|
|
3464
|
+
getTexParameter(gl2, originalFunc, target, pname) {
|
|
3460
3465
|
switch (pname) {
|
|
3461
3466
|
case GL.TEXTURE_MAX_ANISOTROPY_EXT:
|
|
3462
|
-
const contextData = getContextData(
|
|
3467
|
+
const contextData = getContextData(gl2);
|
|
3463
3468
|
const {
|
|
3464
3469
|
_extensions
|
|
3465
3470
|
} = contextData;
|
|
@@ -3471,47 +3476,47 @@ var __exports__ = (() => {
|
|
|
3471
3476
|
return originalFunc(target, pname);
|
|
3472
3477
|
},
|
|
3473
3478
|
getParameter: getParameterPolyfill,
|
|
3474
|
-
hint(
|
|
3479
|
+
hint(gl2, originalFunc, pname, value) {
|
|
3475
3480
|
return originalFunc(pname, value);
|
|
3476
3481
|
}
|
|
3477
3482
|
};
|
|
3478
3483
|
|
|
3479
3484
|
// src/context/polyfill/polyfill-context.ts
|
|
3480
|
-
function polyfillContext(
|
|
3481
|
-
const contextState = getContextData(
|
|
3485
|
+
function polyfillContext(gl2) {
|
|
3486
|
+
const contextState = getContextData(gl2);
|
|
3482
3487
|
if (!contextState._polyfilled) {
|
|
3483
|
-
polyfillVertexArrayObject(
|
|
3484
|
-
initializeExtensions(
|
|
3485
|
-
installPolyfills(
|
|
3486
|
-
installOverrides(
|
|
3488
|
+
polyfillVertexArrayObject(gl2);
|
|
3489
|
+
initializeExtensions(gl2);
|
|
3490
|
+
installPolyfills(gl2, WEBGL2_CONTEXT_POLYFILLS);
|
|
3491
|
+
installOverrides(gl2, {
|
|
3487
3492
|
target: contextState,
|
|
3488
|
-
target2:
|
|
3493
|
+
target2: gl2
|
|
3489
3494
|
});
|
|
3490
3495
|
contextState._polyfilled = true;
|
|
3491
3496
|
}
|
|
3492
|
-
return
|
|
3497
|
+
return gl2;
|
|
3493
3498
|
}
|
|
3494
|
-
function initializeExtensions(
|
|
3495
|
-
const contextState = getContextData(
|
|
3496
|
-
const EXTENSIONS =
|
|
3499
|
+
function initializeExtensions(gl2) {
|
|
3500
|
+
const contextState = getContextData(gl2);
|
|
3501
|
+
const EXTENSIONS = gl2.getSupportedExtensions() || [];
|
|
3497
3502
|
for (const extensionName of EXTENSIONS) {
|
|
3498
|
-
const extension =
|
|
3503
|
+
const extension = gl2.getExtension(extensionName);
|
|
3499
3504
|
contextState._extensions[extensionName] = extension;
|
|
3500
3505
|
}
|
|
3501
3506
|
}
|
|
3502
|
-
function installPolyfills(
|
|
3503
|
-
const contextState = getContextData(
|
|
3507
|
+
function installPolyfills(gl2, polyfills) {
|
|
3508
|
+
const contextState = getContextData(gl2);
|
|
3504
3509
|
for (const extension of Object.getOwnPropertyNames(polyfills)) {
|
|
3505
3510
|
if (extension !== "overrides") {
|
|
3506
|
-
polyfillExtension(
|
|
3511
|
+
polyfillExtension(gl2, {
|
|
3507
3512
|
extension,
|
|
3508
3513
|
target: contextState,
|
|
3509
|
-
target2:
|
|
3514
|
+
target2: gl2
|
|
3510
3515
|
});
|
|
3511
3516
|
}
|
|
3512
3517
|
}
|
|
3513
3518
|
}
|
|
3514
|
-
function polyfillExtension(
|
|
3519
|
+
function polyfillExtension(gl2, {
|
|
3515
3520
|
extension,
|
|
3516
3521
|
target,
|
|
3517
3522
|
target2
|
|
@@ -3524,12 +3529,12 @@ var __exports__ = (() => {
|
|
|
3524
3529
|
const {
|
|
3525
3530
|
suffix = ""
|
|
3526
3531
|
} = meta;
|
|
3527
|
-
const ext =
|
|
3532
|
+
const ext = gl2.getExtension(extension);
|
|
3528
3533
|
for (const key of Object.keys(defaults)) {
|
|
3529
3534
|
const extKey = `${key}${suffix}`;
|
|
3530
3535
|
let polyfill = null;
|
|
3531
3536
|
if (key === "meta") {
|
|
3532
|
-
} else if (typeof
|
|
3537
|
+
} else if (typeof gl2[key] === "function") {
|
|
3533
3538
|
} else if (ext && typeof ext[extKey] === "function") {
|
|
3534
3539
|
polyfill = (...args) => ext[extKey](...args);
|
|
3535
3540
|
} else if (typeof defaults[key] === "function") {
|
|
@@ -3541,15 +3546,15 @@ var __exports__ = (() => {
|
|
|
3541
3546
|
}
|
|
3542
3547
|
}
|
|
3543
3548
|
}
|
|
3544
|
-
function installOverrides(
|
|
3549
|
+
function installOverrides(gl2, {
|
|
3545
3550
|
target,
|
|
3546
3551
|
target2
|
|
3547
3552
|
}) {
|
|
3548
3553
|
Object.keys(WEBGL2_CONTEXT_OVERRIDES).forEach((key) => {
|
|
3549
3554
|
if (typeof WEBGL2_CONTEXT_OVERRIDES[key] === "function") {
|
|
3550
|
-
const originalFunc =
|
|
3555
|
+
const originalFunc = gl2[key] ? gl2[key].bind(gl2) : () => {
|
|
3551
3556
|
};
|
|
3552
|
-
const polyfill = WEBGL2_CONTEXT_OVERRIDES[key].bind(null,
|
|
3557
|
+
const polyfill = WEBGL2_CONTEXT_OVERRIDES[key].bind(null, gl2, originalFunc);
|
|
3553
3558
|
target[key] = polyfill;
|
|
3554
3559
|
target2[key] = polyfill;
|
|
3555
3560
|
}
|
|
@@ -3640,19 +3645,19 @@ var __exports__ = (() => {
|
|
|
3640
3645
|
[GL.UNPACK_SKIP_ROWS]: 0,
|
|
3641
3646
|
[GL.UNPACK_SKIP_IMAGES]: 0
|
|
3642
3647
|
};
|
|
3643
|
-
var enable = (
|
|
3644
|
-
var hint = (
|
|
3645
|
-
var pixelStorei = (
|
|
3646
|
-
var bindFramebuffer = (
|
|
3648
|
+
var enable = (gl2, value, key) => value ? gl2.enable(key) : gl2.disable(key);
|
|
3649
|
+
var hint = (gl2, value, key) => gl2.hint(key, value);
|
|
3650
|
+
var pixelStorei = (gl2, value, key) => gl2.pixelStorei(key, value);
|
|
3651
|
+
var bindFramebuffer = (gl2, value, key) => {
|
|
3647
3652
|
let target;
|
|
3648
3653
|
if (key === GL.FRAMEBUFFER_BINDING) {
|
|
3649
|
-
target = isWebGL2(
|
|
3654
|
+
target = isWebGL2(gl2) ? GL.DRAW_FRAMEBUFFER : GL.FRAMEBUFFER;
|
|
3650
3655
|
} else {
|
|
3651
3656
|
target = GL.READ_FRAMEBUFFER;
|
|
3652
3657
|
}
|
|
3653
|
-
return
|
|
3658
|
+
return gl2.bindFramebuffer(target, value);
|
|
3654
3659
|
};
|
|
3655
|
-
var bindBuffer = (
|
|
3660
|
+
var bindBuffer = (gl2, value, key) => {
|
|
3656
3661
|
const bindingMap = {
|
|
3657
3662
|
[GL.ARRAY_BUFFER_BINDING]: GL.ARRAY_BUFFER,
|
|
3658
3663
|
[GL.COPY_READ_BUFFER_BINDING]: GL.COPY_READ_BUFFER,
|
|
@@ -3661,35 +3666,35 @@ var __exports__ = (() => {
|
|
|
3661
3666
|
[GL.PIXEL_UNPACK_BUFFER_BINDING]: GL.PIXEL_UNPACK_BUFFER
|
|
3662
3667
|
};
|
|
3663
3668
|
const target = bindingMap[key];
|
|
3664
|
-
|
|
3669
|
+
gl2.bindBuffer(target, value);
|
|
3665
3670
|
};
|
|
3666
3671
|
function isArray(array) {
|
|
3667
3672
|
return Array.isArray(array) || ArrayBuffer.isView(array) && !(array instanceof DataView);
|
|
3668
3673
|
}
|
|
3669
3674
|
var GL_PARAMETER_SETTERS = {
|
|
3670
3675
|
[GL.BLEND]: enable,
|
|
3671
|
-
[GL.BLEND_COLOR]: (
|
|
3676
|
+
[GL.BLEND_COLOR]: (gl2, value) => gl2.blendColor(...value),
|
|
3672
3677
|
[GL.BLEND_EQUATION_RGB]: "blendEquation",
|
|
3673
3678
|
[GL.BLEND_EQUATION_ALPHA]: "blendEquation",
|
|
3674
3679
|
[GL.BLEND_SRC_RGB]: "blendFunc",
|
|
3675
3680
|
[GL.BLEND_DST_RGB]: "blendFunc",
|
|
3676
3681
|
[GL.BLEND_SRC_ALPHA]: "blendFunc",
|
|
3677
3682
|
[GL.BLEND_DST_ALPHA]: "blendFunc",
|
|
3678
|
-
[GL.COLOR_CLEAR_VALUE]: (
|
|
3679
|
-
[GL.COLOR_WRITEMASK]: (
|
|
3683
|
+
[GL.COLOR_CLEAR_VALUE]: (gl2, value) => gl2.clearColor(...value),
|
|
3684
|
+
[GL.COLOR_WRITEMASK]: (gl2, value) => gl2.colorMask(...value),
|
|
3680
3685
|
[GL.CULL_FACE]: enable,
|
|
3681
|
-
[GL.CULL_FACE_MODE]: (
|
|
3686
|
+
[GL.CULL_FACE_MODE]: (gl2, value) => gl2.cullFace(value),
|
|
3682
3687
|
[GL.DEPTH_TEST]: enable,
|
|
3683
|
-
[GL.DEPTH_CLEAR_VALUE]: (
|
|
3684
|
-
[GL.DEPTH_FUNC]: (
|
|
3685
|
-
[GL.DEPTH_RANGE]: (
|
|
3686
|
-
[GL.DEPTH_WRITEMASK]: (
|
|
3688
|
+
[GL.DEPTH_CLEAR_VALUE]: (gl2, value) => gl2.clearDepth(value),
|
|
3689
|
+
[GL.DEPTH_FUNC]: (gl2, value) => gl2.depthFunc(value),
|
|
3690
|
+
[GL.DEPTH_RANGE]: (gl2, value) => gl2.depthRange(...value),
|
|
3691
|
+
[GL.DEPTH_WRITEMASK]: (gl2, value) => gl2.depthMask(value),
|
|
3687
3692
|
[GL.DITHER]: enable,
|
|
3688
3693
|
[GL.FRAGMENT_SHADER_DERIVATIVE_HINT]: hint,
|
|
3689
|
-
[GL.CURRENT_PROGRAM]: (
|
|
3690
|
-
[GL.RENDERBUFFER_BINDING]: (
|
|
3691
|
-
[GL.TRANSFORM_FEEDBACK_BINDING]: (
|
|
3692
|
-
[GL.VERTEX_ARRAY_BINDING]: (
|
|
3694
|
+
[GL.CURRENT_PROGRAM]: (gl2, value) => gl2.useProgram(value),
|
|
3695
|
+
[GL.RENDERBUFFER_BINDING]: (gl2, value) => gl2.bindRenderbuffer(GL.RENDERBUFFER, value),
|
|
3696
|
+
[GL.TRANSFORM_FEEDBACK_BINDING]: (gl2, value) => gl2.bindTransformFeedback?.(GL.TRANSFORM_FEEDBACK, value),
|
|
3697
|
+
[GL.VERTEX_ARRAY_BINDING]: (gl2, value) => gl2.bindVertexArray(value),
|
|
3693
3698
|
// NOTE: FRAMEBUFFER_BINDING and DRAW_FRAMEBUFFER_BINDING(WebGL2) refer same state.
|
|
3694
3699
|
[GL.FRAMEBUFFER_BINDING]: bindFramebuffer,
|
|
3695
3700
|
[GL.READ_FRAMEBUFFER_BINDING]: bindFramebuffer,
|
|
@@ -3699,9 +3704,9 @@ var __exports__ = (() => {
|
|
|
3699
3704
|
[GL.COPY_WRITE_BUFFER_BINDING]: bindBuffer,
|
|
3700
3705
|
[GL.PIXEL_PACK_BUFFER_BINDING]: bindBuffer,
|
|
3701
3706
|
[GL.PIXEL_UNPACK_BUFFER_BINDING]: bindBuffer,
|
|
3702
|
-
[GL.FRONT_FACE]: (
|
|
3707
|
+
[GL.FRONT_FACE]: (gl2, value) => gl2.frontFace(value),
|
|
3703
3708
|
[GL.GENERATE_MIPMAP_HINT]: hint,
|
|
3704
|
-
[GL.LINE_WIDTH]: (
|
|
3709
|
+
[GL.LINE_WIDTH]: (gl2, value) => gl2.lineWidth(value),
|
|
3705
3710
|
[GL.POLYGON_OFFSET_FILL]: enable,
|
|
3706
3711
|
[GL.POLYGON_OFFSET_FACTOR]: "polygonOffset",
|
|
3707
3712
|
[GL.POLYGON_OFFSET_UNITS]: "polygonOffset",
|
|
@@ -3711,11 +3716,11 @@ var __exports__ = (() => {
|
|
|
3711
3716
|
[GL.SAMPLE_COVERAGE_VALUE]: "sampleCoverage",
|
|
3712
3717
|
[GL.SAMPLE_COVERAGE_INVERT]: "sampleCoverage",
|
|
3713
3718
|
[GL.SCISSOR_TEST]: enable,
|
|
3714
|
-
[GL.SCISSOR_BOX]: (
|
|
3719
|
+
[GL.SCISSOR_BOX]: (gl2, value) => gl2.scissor(...value),
|
|
3715
3720
|
[GL.STENCIL_TEST]: enable,
|
|
3716
|
-
[GL.STENCIL_CLEAR_VALUE]: (
|
|
3717
|
-
[GL.STENCIL_WRITEMASK]: (
|
|
3718
|
-
[GL.STENCIL_BACK_WRITEMASK]: (
|
|
3721
|
+
[GL.STENCIL_CLEAR_VALUE]: (gl2, value) => gl2.clearStencil(value),
|
|
3722
|
+
[GL.STENCIL_WRITEMASK]: (gl2, value) => gl2.stencilMaskSeparate(GL.FRONT, value),
|
|
3723
|
+
[GL.STENCIL_BACK_WRITEMASK]: (gl2, value) => gl2.stencilMaskSeparate(GL.BACK, value),
|
|
3719
3724
|
[GL.STENCIL_FUNC]: "stencilFuncFront",
|
|
3720
3725
|
[GL.STENCIL_REF]: "stencilFuncFront",
|
|
3721
3726
|
[GL.STENCIL_VALUE_MASK]: "stencilFuncFront",
|
|
@@ -3728,7 +3733,7 @@ var __exports__ = (() => {
|
|
|
3728
3733
|
[GL.STENCIL_BACK_FAIL]: "stencilOpBack",
|
|
3729
3734
|
[GL.STENCIL_BACK_PASS_DEPTH_FAIL]: "stencilOpBack",
|
|
3730
3735
|
[GL.STENCIL_BACK_PASS_DEPTH_PASS]: "stencilOpBack",
|
|
3731
|
-
[GL.VIEWPORT]: (
|
|
3736
|
+
[GL.VIEWPORT]: (gl2, value) => gl2.viewport(...value),
|
|
3732
3737
|
// WEBGL1 PIXEL PACK/UNPACK MODES
|
|
3733
3738
|
[GL.PACK_ALIGNMENT]: pixelStorei,
|
|
3734
3739
|
[GL.UNPACK_ALIGNMENT]: pixelStorei,
|
|
@@ -3746,75 +3751,75 @@ var __exports__ = (() => {
|
|
|
3746
3751
|
[GL.UNPACK_SKIP_ROWS]: pixelStorei,
|
|
3747
3752
|
[GL.UNPACK_SKIP_IMAGES]: pixelStorei,
|
|
3748
3753
|
// Function-style setters
|
|
3749
|
-
framebuffer: (
|
|
3754
|
+
framebuffer: (gl2, framebuffer) => {
|
|
3750
3755
|
const handle = framebuffer && "handle" in framebuffer ? framebuffer.handle : framebuffer;
|
|
3751
|
-
return
|
|
3756
|
+
return gl2.bindFramebuffer(GL.FRAMEBUFFER, handle);
|
|
3752
3757
|
},
|
|
3753
|
-
blend: (
|
|
3754
|
-
blendColor: (
|
|
3755
|
-
blendEquation: (
|
|
3758
|
+
blend: (gl2, value) => value ? gl2.enable(GL.BLEND) : gl2.disable(GL.BLEND),
|
|
3759
|
+
blendColor: (gl2, value) => gl2.blendColor(...value),
|
|
3760
|
+
blendEquation: (gl2, args) => {
|
|
3756
3761
|
const separateModes = typeof args === "number" ? [args, args] : args;
|
|
3757
|
-
|
|
3762
|
+
gl2.blendEquationSeparate(...separateModes);
|
|
3758
3763
|
},
|
|
3759
|
-
blendFunc: (
|
|
3764
|
+
blendFunc: (gl2, args) => {
|
|
3760
3765
|
const separateFuncs = args?.length === 2 ? [...args, ...args] : args;
|
|
3761
|
-
|
|
3762
|
-
},
|
|
3763
|
-
clearColor: (
|
|
3764
|
-
clearDepth: (
|
|
3765
|
-
clearStencil: (
|
|
3766
|
-
colorMask: (
|
|
3767
|
-
cull: (
|
|
3768
|
-
cullFace: (
|
|
3769
|
-
depthTest: (
|
|
3770
|
-
depthFunc: (
|
|
3771
|
-
depthMask: (
|
|
3772
|
-
depthRange: (
|
|
3773
|
-
dither: (
|
|
3774
|
-
derivativeHint: (
|
|
3775
|
-
|
|
3776
|
-
},
|
|
3777
|
-
frontFace: (
|
|
3778
|
-
mipmapHint: (
|
|
3779
|
-
lineWidth: (
|
|
3780
|
-
polygonOffsetFill: (
|
|
3781
|
-
polygonOffset: (
|
|
3782
|
-
sampleCoverage: (
|
|
3783
|
-
scissorTest: (
|
|
3784
|
-
scissor: (
|
|
3785
|
-
stencilTest: (
|
|
3786
|
-
stencilMask: (
|
|
3766
|
+
gl2.blendFuncSeparate(...separateFuncs);
|
|
3767
|
+
},
|
|
3768
|
+
clearColor: (gl2, value) => gl2.clearColor(...value),
|
|
3769
|
+
clearDepth: (gl2, value) => gl2.clearDepth(value),
|
|
3770
|
+
clearStencil: (gl2, value) => gl2.clearStencil(value),
|
|
3771
|
+
colorMask: (gl2, value) => gl2.colorMask(...value),
|
|
3772
|
+
cull: (gl2, value) => value ? gl2.enable(GL.CULL_FACE) : gl2.disable(GL.CULL_FACE),
|
|
3773
|
+
cullFace: (gl2, value) => gl2.cullFace(value),
|
|
3774
|
+
depthTest: (gl2, value) => value ? gl2.enable(GL.DEPTH_TEST) : gl2.disable(GL.DEPTH_TEST),
|
|
3775
|
+
depthFunc: (gl2, value) => gl2.depthFunc(value),
|
|
3776
|
+
depthMask: (gl2, value) => gl2.depthMask(value),
|
|
3777
|
+
depthRange: (gl2, value) => gl2.depthRange(...value),
|
|
3778
|
+
dither: (gl2, value) => value ? gl2.enable(GL.DITHER) : gl2.disable(GL.DITHER),
|
|
3779
|
+
derivativeHint: (gl2, value) => {
|
|
3780
|
+
gl2.hint(GL.FRAGMENT_SHADER_DERIVATIVE_HINT, value);
|
|
3781
|
+
},
|
|
3782
|
+
frontFace: (gl2, value) => gl2.frontFace(value),
|
|
3783
|
+
mipmapHint: (gl2, value) => gl2.hint(GL.GENERATE_MIPMAP_HINT, value),
|
|
3784
|
+
lineWidth: (gl2, value) => gl2.lineWidth(value),
|
|
3785
|
+
polygonOffsetFill: (gl2, value) => value ? gl2.enable(GL.POLYGON_OFFSET_FILL) : gl2.disable(GL.POLYGON_OFFSET_FILL),
|
|
3786
|
+
polygonOffset: (gl2, value) => gl2.polygonOffset(...value),
|
|
3787
|
+
sampleCoverage: (gl2, value) => gl2.sampleCoverage(...value),
|
|
3788
|
+
scissorTest: (gl2, value) => value ? gl2.enable(GL.SCISSOR_TEST) : gl2.disable(GL.SCISSOR_TEST),
|
|
3789
|
+
scissor: (gl2, value) => gl2.scissor(...value),
|
|
3790
|
+
stencilTest: (gl2, value) => value ? gl2.enable(GL.STENCIL_TEST) : gl2.disable(GL.STENCIL_TEST),
|
|
3791
|
+
stencilMask: (gl2, value) => {
|
|
3787
3792
|
value = isArray(value) ? value : [value, value];
|
|
3788
3793
|
const [mask, backMask] = value;
|
|
3789
|
-
|
|
3790
|
-
|
|
3794
|
+
gl2.stencilMaskSeparate(GL.FRONT, mask);
|
|
3795
|
+
gl2.stencilMaskSeparate(GL.BACK, backMask);
|
|
3791
3796
|
},
|
|
3792
|
-
stencilFunc: (
|
|
3797
|
+
stencilFunc: (gl2, args) => {
|
|
3793
3798
|
args = isArray(args) && args.length === 3 ? [...args, ...args] : args;
|
|
3794
3799
|
const [func, ref, mask, backFunc, backRef, backMask] = args;
|
|
3795
|
-
|
|
3796
|
-
|
|
3800
|
+
gl2.stencilFuncSeparate(GL.FRONT, func, ref, mask);
|
|
3801
|
+
gl2.stencilFuncSeparate(GL.BACK, backFunc, backRef, backMask);
|
|
3797
3802
|
},
|
|
3798
|
-
stencilOp: (
|
|
3803
|
+
stencilOp: (gl2, args) => {
|
|
3799
3804
|
args = isArray(args) && args.length === 3 ? [...args, ...args] : args;
|
|
3800
3805
|
const [sfail, dpfail, dppass, backSfail, backDpfail, backDppass] = args;
|
|
3801
|
-
|
|
3802
|
-
|
|
3806
|
+
gl2.stencilOpSeparate(GL.FRONT, sfail, dpfail, dppass);
|
|
3807
|
+
gl2.stencilOpSeparate(GL.BACK, backSfail, backDpfail, backDppass);
|
|
3803
3808
|
},
|
|
3804
|
-
viewport: (
|
|
3809
|
+
viewport: (gl2, value) => gl2.viewport(...value)
|
|
3805
3810
|
};
|
|
3806
3811
|
function getValue(glEnum, values, cache2) {
|
|
3807
3812
|
return values[glEnum] !== void 0 ? values[glEnum] : cache2[glEnum];
|
|
3808
3813
|
}
|
|
3809
3814
|
var GL_COMPOSITE_PARAMETER_SETTERS = {
|
|
3810
|
-
blendEquation: (
|
|
3811
|
-
blendFunc: (
|
|
3812
|
-
polygonOffset: (
|
|
3813
|
-
sampleCoverage: (
|
|
3814
|
-
stencilFuncFront: (
|
|
3815
|
-
stencilFuncBack: (
|
|
3816
|
-
stencilOpFront: (
|
|
3817
|
-
stencilOpBack: (
|
|
3815
|
+
blendEquation: (gl2, values, cache2) => gl2.blendEquationSeparate(getValue(GL.BLEND_EQUATION_RGB, values, cache2), getValue(GL.BLEND_EQUATION_ALPHA, values, cache2)),
|
|
3816
|
+
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)),
|
|
3817
|
+
polygonOffset: (gl2, values, cache2) => gl2.polygonOffset(getValue(GL.POLYGON_OFFSET_FACTOR, values, cache2), getValue(GL.POLYGON_OFFSET_UNITS, values, cache2)),
|
|
3818
|
+
sampleCoverage: (gl2, values, cache2) => gl2.sampleCoverage(getValue(GL.SAMPLE_COVERAGE_VALUE, values, cache2), getValue(GL.SAMPLE_COVERAGE_INVERT, values, cache2)),
|
|
3819
|
+
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)),
|
|
3820
|
+
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)),
|
|
3821
|
+
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)),
|
|
3822
|
+
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))
|
|
3818
3823
|
};
|
|
3819
3824
|
var GL_HOOKED_SETTERS = {
|
|
3820
3825
|
// GENERIC SETTERS
|
|
@@ -3980,7 +3985,7 @@ var __exports__ = (() => {
|
|
|
3980
3985
|
[GL.VIEWPORT]: [x, y, width, height]
|
|
3981
3986
|
})
|
|
3982
3987
|
};
|
|
3983
|
-
var isEnabled = (
|
|
3988
|
+
var isEnabled = (gl2, key) => gl2.isEnabled(key);
|
|
3984
3989
|
var GL_PARAMETER_GETTERS = {
|
|
3985
3990
|
[GL.BLEND]: isEnabled,
|
|
3986
3991
|
[GL.CULL_FACE]: isEnabled,
|
|
@@ -4036,7 +4041,7 @@ var __exports__ = (() => {
|
|
|
4036
4041
|
// src/context/parameters/unified-parameter-api.ts
|
|
4037
4042
|
function setParameters(device, parameters) {
|
|
4038
4043
|
const webglDevice = WebGLDevice.attach(device);
|
|
4039
|
-
const
|
|
4044
|
+
const gl2 = webglDevice.gl;
|
|
4040
4045
|
if (isObjectEmpty2(parameters)) {
|
|
4041
4046
|
return;
|
|
4042
4047
|
}
|
|
@@ -4048,31 +4053,31 @@ var __exports__ = (() => {
|
|
|
4048
4053
|
if (typeof setter === "string") {
|
|
4049
4054
|
compositeSetters[setter] = true;
|
|
4050
4055
|
} else {
|
|
4051
|
-
setter(
|
|
4056
|
+
setter(gl2, parameters[key], glConstant);
|
|
4052
4057
|
}
|
|
4053
4058
|
}
|
|
4054
4059
|
}
|
|
4055
|
-
const cache2 =
|
|
4060
|
+
const cache2 = gl2.state && gl2.state.cache;
|
|
4056
4061
|
if (cache2) {
|
|
4057
4062
|
for (const key in compositeSetters) {
|
|
4058
4063
|
const compositeSetter = GL_COMPOSITE_PARAMETER_SETTERS[key];
|
|
4059
|
-
compositeSetter(
|
|
4064
|
+
compositeSetter(gl2, parameters, cache2);
|
|
4060
4065
|
}
|
|
4061
4066
|
}
|
|
4062
4067
|
}
|
|
4063
4068
|
function getParameters(device, parameters = GL_PARAMETER_DEFAULTS) {
|
|
4064
4069
|
const webglDevice = WebGLDevice.attach(device);
|
|
4065
|
-
const
|
|
4070
|
+
const gl2 = webglDevice.gl;
|
|
4066
4071
|
if (typeof parameters === "number") {
|
|
4067
4072
|
const key = parameters;
|
|
4068
4073
|
const getter = GL_PARAMETER_GETTERS[key];
|
|
4069
|
-
return getter ? getter(
|
|
4074
|
+
return getter ? getter(gl2, key) : gl2.getParameter(key);
|
|
4070
4075
|
}
|
|
4071
4076
|
const parameterKeys = Array.isArray(parameters) ? parameters : Object.keys(parameters);
|
|
4072
4077
|
const state = {};
|
|
4073
4078
|
for (const key of parameterKeys) {
|
|
4074
4079
|
const getter = GL_PARAMETER_GETTERS[key];
|
|
4075
|
-
state[key] = getter ? getter(
|
|
4080
|
+
state[key] = getter ? getter(gl2, Number(key)) : gl2.getParameter(Number(key));
|
|
4076
4081
|
}
|
|
4077
4082
|
return state;
|
|
4078
4083
|
}
|
|
@@ -4109,15 +4114,15 @@ var __exports__ = (() => {
|
|
|
4109
4114
|
program = null;
|
|
4110
4115
|
stateStack = [];
|
|
4111
4116
|
enable = true;
|
|
4112
|
-
constructor(
|
|
4117
|
+
constructor(gl2, {
|
|
4113
4118
|
copyState = false,
|
|
4114
4119
|
// Copy cache from params (slow) or initialize from WebGL defaults (fast)
|
|
4115
4120
|
log: log3 = () => {
|
|
4116
4121
|
}
|
|
4117
4122
|
// Logging function, called when gl parameter change calls are actually issued
|
|
4118
4123
|
} = {}) {
|
|
4119
|
-
this.gl =
|
|
4120
|
-
this.cache = copyState ? getParameters(
|
|
4124
|
+
this.gl = gl2;
|
|
4125
|
+
this.cache = copyState ? getParameters(gl2) : Object.assign({}, GL_PARAMETER_DEFAULTS);
|
|
4121
4126
|
this.log = log3;
|
|
4122
4127
|
this._updateCache = this._updateCache.bind(this);
|
|
4123
4128
|
Object.seal(this);
|
|
@@ -4160,53 +4165,53 @@ var __exports__ = (() => {
|
|
|
4160
4165
|
};
|
|
4161
4166
|
}
|
|
4162
4167
|
};
|
|
4163
|
-
function getContextState(
|
|
4164
|
-
return
|
|
4168
|
+
function getContextState(gl2) {
|
|
4169
|
+
return gl2.state;
|
|
4165
4170
|
}
|
|
4166
|
-
function trackContextState(
|
|
4171
|
+
function trackContextState(gl2, options) {
|
|
4167
4172
|
const {
|
|
4168
4173
|
enable: enable2 = true,
|
|
4169
4174
|
copyState
|
|
4170
4175
|
} = options;
|
|
4171
4176
|
assert2(copyState !== void 0);
|
|
4172
|
-
if (!
|
|
4173
|
-
|
|
4177
|
+
if (!gl2.state) {
|
|
4178
|
+
gl2.state = new GLState(gl2, {
|
|
4174
4179
|
copyState
|
|
4175
4180
|
});
|
|
4176
|
-
installProgramSpy(
|
|
4181
|
+
installProgramSpy(gl2);
|
|
4177
4182
|
for (const key in GL_HOOKED_SETTERS) {
|
|
4178
4183
|
const setter = GL_HOOKED_SETTERS[key];
|
|
4179
|
-
installSetterSpy(
|
|
4184
|
+
installSetterSpy(gl2, key, setter);
|
|
4180
4185
|
}
|
|
4181
|
-
installGetterOverride(
|
|
4182
|
-
installGetterOverride(
|
|
4186
|
+
installGetterOverride(gl2, "getParameter");
|
|
4187
|
+
installGetterOverride(gl2, "isEnabled");
|
|
4183
4188
|
}
|
|
4184
|
-
const glState = getContextState(
|
|
4189
|
+
const glState = getContextState(gl2);
|
|
4185
4190
|
glState.enable = enable2;
|
|
4186
|
-
return
|
|
4191
|
+
return gl2;
|
|
4187
4192
|
}
|
|
4188
|
-
function pushContextState(
|
|
4189
|
-
let glState = getContextState(
|
|
4193
|
+
function pushContextState(gl2) {
|
|
4194
|
+
let glState = getContextState(gl2);
|
|
4190
4195
|
if (!glState) {
|
|
4191
|
-
trackContextState(
|
|
4196
|
+
trackContextState(gl2, {
|
|
4192
4197
|
copyState: false
|
|
4193
4198
|
});
|
|
4194
|
-
glState = getContextState(
|
|
4199
|
+
glState = getContextState(gl2);
|
|
4195
4200
|
}
|
|
4196
4201
|
glState.push();
|
|
4197
4202
|
}
|
|
4198
|
-
function popContextState(
|
|
4199
|
-
const glState = getContextState(
|
|
4203
|
+
function popContextState(gl2) {
|
|
4204
|
+
const glState = getContextState(gl2);
|
|
4200
4205
|
assert2(glState);
|
|
4201
4206
|
glState.pop();
|
|
4202
4207
|
}
|
|
4203
|
-
function installGetterOverride(
|
|
4204
|
-
const originalGetterFunc =
|
|
4205
|
-
|
|
4208
|
+
function installGetterOverride(gl2, functionName) {
|
|
4209
|
+
const originalGetterFunc = gl2[functionName].bind(gl2);
|
|
4210
|
+
gl2[functionName] = function get(pname) {
|
|
4206
4211
|
if (pname === void 0 || NON_CACHE_PARAMETERS.has(pname)) {
|
|
4207
4212
|
return originalGetterFunc(pname);
|
|
4208
4213
|
}
|
|
4209
|
-
const glState = getContextState(
|
|
4214
|
+
const glState = getContextState(gl2);
|
|
4210
4215
|
if (!(pname in glState.cache)) {
|
|
4211
4216
|
glState.cache[pname] = originalGetterFunc(pname);
|
|
4212
4217
|
}
|
|
@@ -4218,18 +4223,18 @@ var __exports__ = (() => {
|
|
|
4218
4223
|
originalGetterFunc(pname)
|
|
4219
4224
|
);
|
|
4220
4225
|
};
|
|
4221
|
-
Object.defineProperty(
|
|
4226
|
+
Object.defineProperty(gl2[functionName], "name", {
|
|
4222
4227
|
value: `${functionName}-from-cache`,
|
|
4223
4228
|
configurable: false
|
|
4224
4229
|
});
|
|
4225
4230
|
}
|
|
4226
|
-
function installSetterSpy(
|
|
4227
|
-
if (!
|
|
4231
|
+
function installSetterSpy(gl2, functionName, setter) {
|
|
4232
|
+
if (!gl2[functionName]) {
|
|
4228
4233
|
return;
|
|
4229
4234
|
}
|
|
4230
|
-
const originalSetterFunc =
|
|
4231
|
-
|
|
4232
|
-
const glState = getContextState(
|
|
4235
|
+
const originalSetterFunc = gl2[functionName].bind(gl2);
|
|
4236
|
+
gl2[functionName] = function set(...params) {
|
|
4237
|
+
const glState = getContextState(gl2);
|
|
4233
4238
|
const {
|
|
4234
4239
|
valueChanged,
|
|
4235
4240
|
oldValue
|
|
@@ -4239,15 +4244,15 @@ var __exports__ = (() => {
|
|
|
4239
4244
|
}
|
|
4240
4245
|
return oldValue;
|
|
4241
4246
|
};
|
|
4242
|
-
Object.defineProperty(
|
|
4247
|
+
Object.defineProperty(gl2[functionName], "name", {
|
|
4243
4248
|
value: `${functionName}-to-cache`,
|
|
4244
4249
|
configurable: false
|
|
4245
4250
|
});
|
|
4246
4251
|
}
|
|
4247
|
-
function installProgramSpy(
|
|
4248
|
-
const originalUseProgram =
|
|
4249
|
-
|
|
4250
|
-
const glState = getContextState(
|
|
4252
|
+
function installProgramSpy(gl2) {
|
|
4253
|
+
const originalUseProgram = gl2.useProgram.bind(gl2);
|
|
4254
|
+
gl2.useProgram = function useProgramLuma(handle) {
|
|
4255
|
+
const glState = getContextState(gl2);
|
|
4251
4256
|
if (glState.program !== handle) {
|
|
4252
4257
|
originalUseProgram(handle);
|
|
4253
4258
|
glState.program = handle;
|
|
@@ -4276,7 +4281,7 @@ var __exports__ = (() => {
|
|
|
4276
4281
|
let errorMessage = null;
|
|
4277
4282
|
const onCreateError = (error2) => errorMessage = error2.statusMessage || errorMessage;
|
|
4278
4283
|
canvas.addEventListener("webglcontextcreationerror", onCreateError, false);
|
|
4279
|
-
let
|
|
4284
|
+
let gl2 = null;
|
|
4280
4285
|
if (props.type === "webgl2") {
|
|
4281
4286
|
props = {
|
|
4282
4287
|
...props,
|
|
@@ -4289,14 +4294,14 @@ var __exports__ = (() => {
|
|
|
4289
4294
|
webgl2: false
|
|
4290
4295
|
};
|
|
4291
4296
|
}
|
|
4292
|
-
if (!
|
|
4293
|
-
|
|
4297
|
+
if (!gl2 && props.webgl2) {
|
|
4298
|
+
gl2 = canvas.getContext("webgl2", props);
|
|
4294
4299
|
}
|
|
4295
|
-
if (!
|
|
4296
|
-
|
|
4300
|
+
if (!gl2 && props.webgl1) {
|
|
4301
|
+
gl2 = canvas.getContext("webgl", props);
|
|
4297
4302
|
}
|
|
4298
4303
|
canvas.removeEventListener("webglcontextcreationerror", onCreateError, false);
|
|
4299
|
-
if (!
|
|
4304
|
+
if (!gl2) {
|
|
4300
4305
|
throw new Error(`Failed to create ${props.webgl2 && !props.webgl1 ? "WebGL2" : "WebGL"} context: ${errorMessage || "Unknown error"}`);
|
|
4301
4306
|
}
|
|
4302
4307
|
if (props.onContextLost) {
|
|
@@ -4311,28 +4316,28 @@ var __exports__ = (() => {
|
|
|
4311
4316
|
} = props;
|
|
4312
4317
|
canvas.addEventListener("webglcontextrestored", (event) => onContextRestored(event), false);
|
|
4313
4318
|
}
|
|
4314
|
-
return
|
|
4319
|
+
return gl2;
|
|
4315
4320
|
}
|
|
4316
4321
|
|
|
4317
4322
|
// src/adapter/device-helpers/get-device-info.ts
|
|
4318
|
-
function getDeviceInfo(
|
|
4319
|
-
const vendorMasked =
|
|
4320
|
-
const rendererMasked =
|
|
4321
|
-
const ext =
|
|
4322
|
-
const vendorUnmasked =
|
|
4323
|
-
const rendererUnmasked =
|
|
4323
|
+
function getDeviceInfo(gl2) {
|
|
4324
|
+
const vendorMasked = gl2.getParameter(GL.VENDOR);
|
|
4325
|
+
const rendererMasked = gl2.getParameter(GL.RENDERER);
|
|
4326
|
+
const ext = gl2.getExtension("WEBGL_debug_renderer_info");
|
|
4327
|
+
const vendorUnmasked = gl2.getParameter(ext ? ext.UNMASKED_VENDOR_WEBGL : GL.VENDOR);
|
|
4328
|
+
const rendererUnmasked = gl2.getParameter(ext ? ext.UNMASKED_RENDERER_WEBGL : GL.RENDERER);
|
|
4324
4329
|
const vendor = vendorUnmasked || vendorMasked;
|
|
4325
4330
|
const renderer = rendererUnmasked || rendererMasked;
|
|
4326
4331
|
const gpu = identifyGPUVendor(vendor, renderer);
|
|
4327
4332
|
return {
|
|
4328
|
-
type: isWebGL2(
|
|
4333
|
+
type: isWebGL2(gl2) ? "webgl2" : "webgl",
|
|
4329
4334
|
gpu,
|
|
4330
4335
|
vendor: vendorUnmasked || vendorMasked,
|
|
4331
4336
|
renderer: rendererUnmasked || rendererMasked,
|
|
4332
|
-
version:
|
|
4337
|
+
version: gl2.getParameter(GL.VERSION),
|
|
4333
4338
|
shadingLanguages: ["glsl"],
|
|
4334
4339
|
shadingLanguageVersions: {
|
|
4335
|
-
"glsl":
|
|
4340
|
+
"glsl": gl2.getParameter(GL.SHADING_LANGUAGE_VERSION)
|
|
4336
4341
|
}
|
|
4337
4342
|
};
|
|
4338
4343
|
}
|
|
@@ -4384,38 +4389,38 @@ var __exports__ = (() => {
|
|
|
4384
4389
|
var EXT_TEXTURE_NORM16 = "EXT_texture_norm16";
|
|
4385
4390
|
var EXT_FLOAT_WEBGL1 = "WEBGL_color_buffer_float";
|
|
4386
4391
|
var EXT_FLOAT_RENDER_WEBGL2 = "EXT_color_buffer_float";
|
|
4387
|
-
var checkExtension = (
|
|
4388
|
-
var checkExtensions = (
|
|
4392
|
+
var checkExtension = (gl2, extension) => gl2.getExtension(extension);
|
|
4393
|
+
var checkExtensions = (gl2, extensions) => extensions.every((extension) => gl2.getExtension(extension));
|
|
4389
4394
|
var TEXTURE_FEATURE_CHECKS = {
|
|
4390
|
-
"texture-blend-float-webgl1": (
|
|
4391
|
-
"texture-formats-srgb-webgl1": (
|
|
4392
|
-
"texture-formats-depth-webgl1": (
|
|
4393
|
-
"texture-formats-float32-webgl1": (
|
|
4394
|
-
"texture-formats-float16-webgl1": (
|
|
4395
|
-
"texture-formats-norm16-webgl": (
|
|
4396
|
-
"texture-filter-linear-float32-webgl": (
|
|
4397
|
-
"texture-filter-linear-float16-webgl": (
|
|
4398
|
-
"texture-filter-anisotropic-webgl": (
|
|
4399
|
-
"texture-renderable-float32-webgl": (
|
|
4395
|
+
"texture-blend-float-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "EXT_float_blend"),
|
|
4396
|
+
"texture-formats-srgb-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, EXT_SRGB),
|
|
4397
|
+
"texture-formats-depth-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "WEBGL_depth_texture"),
|
|
4398
|
+
"texture-formats-float32-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "OES_texture_float"),
|
|
4399
|
+
"texture-formats-float16-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "OES_texture_half_float"),
|
|
4400
|
+
"texture-formats-norm16-webgl": (gl2) => isWebGL2(gl2) ? checkExtension(gl2, EXT_TEXTURE_NORM16) : false,
|
|
4401
|
+
"texture-filter-linear-float32-webgl": (gl2) => checkExtension(gl2, "OES_texture_float_linear"),
|
|
4402
|
+
"texture-filter-linear-float16-webgl": (gl2) => checkExtension(gl2, "OES_texture_half_float_linear"),
|
|
4403
|
+
"texture-filter-anisotropic-webgl": (gl2) => checkExtension(gl2, "EXT_texture_filter_anisotropic"),
|
|
4404
|
+
"texture-renderable-float32-webgl": (gl2) => checkExtension(gl2, "EXT_color_buffer_float"),
|
|
4400
4405
|
// [false, 'EXT_color_buffer_float'],
|
|
4401
|
-
"texture-renderable-float16-webgl": (
|
|
4402
|
-
"texture-compression-bc": (
|
|
4403
|
-
"texture-compression-bc5-webgl": (
|
|
4406
|
+
"texture-renderable-float16-webgl": (gl2) => checkExtension(gl2, "EXT_color_buffer_half_float"),
|
|
4407
|
+
"texture-compression-bc": (gl2) => checkExtensions(gl2, [X_S3TC, X_S3TC_SRGB, X_RGTC, X_BPTC]),
|
|
4408
|
+
"texture-compression-bc5-webgl": (gl2) => checkExtensions(gl2, [X_RGTC]),
|
|
4404
4409
|
// 'texture-compression-bc7-webgl': gl => checkExtensions(gl, [X_BPTC]),
|
|
4405
4410
|
// 'texture-compression-bc3-srgb-webgl': gl => checkExtensions(gl, [X_S3TC_SRGB]),
|
|
4406
4411
|
// 'texture-compression-bc3-webgl': gl => checkExtensions(gl, [X_S3TC]),
|
|
4407
|
-
"texture-compression-etc2": (
|
|
4408
|
-
"texture-compression-astc": (
|
|
4409
|
-
"texture-compression-etc1-webgl": (
|
|
4410
|
-
"texture-compression-pvrtc-webgl": (
|
|
4411
|
-
"texture-compression-atc-webgl": (
|
|
4412
|
+
"texture-compression-etc2": (gl2) => checkExtensions(gl2, [X_ETC2]),
|
|
4413
|
+
"texture-compression-astc": (gl2) => checkExtensions(gl2, [X_ASTC]),
|
|
4414
|
+
"texture-compression-etc1-webgl": (gl2) => checkExtensions(gl2, [X_ETC1]),
|
|
4415
|
+
"texture-compression-pvrtc-webgl": (gl2) => checkExtensions(gl2, [X_PVRTC]),
|
|
4416
|
+
"texture-compression-atc-webgl": (gl2) => checkExtensions(gl2, [X_ATC])
|
|
4412
4417
|
};
|
|
4413
|
-
function checkTextureFeature(
|
|
4414
|
-
return TEXTURE_FEATURE_CHECKS[feature]?.(
|
|
4418
|
+
function checkTextureFeature(gl2, feature) {
|
|
4419
|
+
return TEXTURE_FEATURE_CHECKS[feature]?.(gl2) || false;
|
|
4415
4420
|
}
|
|
4416
|
-
function getTextureFeatures(
|
|
4421
|
+
function getTextureFeatures(gl2) {
|
|
4417
4422
|
const textureFeatures = Object.keys(TEXTURE_FEATURE_CHECKS);
|
|
4418
|
-
return textureFeatures.filter((feature) => checkTextureFeature(
|
|
4423
|
+
return textureFeatures.filter((feature) => checkTextureFeature(gl2, feature));
|
|
4419
4424
|
}
|
|
4420
4425
|
var TEXTURE_FORMATS = {
|
|
4421
4426
|
// Unsized formats that leave the precision up to the driver.
|
|
@@ -5155,23 +5160,23 @@ var __exports__ = (() => {
|
|
|
5155
5160
|
[GL.BYTE]: 1,
|
|
5156
5161
|
[GL.UNSIGNED_BYTE]: 1
|
|
5157
5162
|
};
|
|
5158
|
-
function isTextureFormatSupported(
|
|
5163
|
+
function isTextureFormatSupported(gl2, formatOrGL) {
|
|
5159
5164
|
const format = convertGLToTextureFormat(formatOrGL);
|
|
5160
5165
|
const info = TEXTURE_FORMATS[format];
|
|
5161
5166
|
if (!info) {
|
|
5162
5167
|
return false;
|
|
5163
5168
|
}
|
|
5164
|
-
if (isWebGL2(
|
|
5169
|
+
if (isWebGL2(gl2) ? info.gl === void 0 : info.gl1 === void 0) {
|
|
5165
5170
|
return false;
|
|
5166
5171
|
}
|
|
5167
|
-
const extension = info.x || (isWebGL2(
|
|
5172
|
+
const extension = info.x || (isWebGL2(gl2) ? info.gl2ext || info.gl1ext : info.gl1ext);
|
|
5168
5173
|
if (extension) {
|
|
5169
|
-
return Boolean(
|
|
5174
|
+
return Boolean(gl2.getExtension(extension));
|
|
5170
5175
|
}
|
|
5171
5176
|
return true;
|
|
5172
5177
|
}
|
|
5173
|
-
function isRenderbufferFormatSupported(
|
|
5174
|
-
return isTextureFormatSupported(
|
|
5178
|
+
function isRenderbufferFormatSupported(gl2, format) {
|
|
5179
|
+
return isTextureFormatSupported(gl2, format) && TEXTURE_FORMATS[format]?.renderbuffer;
|
|
5175
5180
|
}
|
|
5176
5181
|
function convertGLToTextureFormat(format) {
|
|
5177
5182
|
if (typeof format === "string") {
|
|
@@ -5191,9 +5196,9 @@ var __exports__ = (() => {
|
|
|
5191
5196
|
}
|
|
5192
5197
|
return webglFormat;
|
|
5193
5198
|
}
|
|
5194
|
-
function isTextureFormatFilterable(
|
|
5199
|
+
function isTextureFormatFilterable(gl2, formatOrGL) {
|
|
5195
5200
|
const format = convertGLToTextureFormat(formatOrGL);
|
|
5196
|
-
if (!isTextureFormatSupported(
|
|
5201
|
+
if (!isTextureFormatSupported(gl2, format)) {
|
|
5197
5202
|
return false;
|
|
5198
5203
|
}
|
|
5199
5204
|
try {
|
|
@@ -5205,16 +5210,16 @@ var __exports__ = (() => {
|
|
|
5205
5210
|
return false;
|
|
5206
5211
|
}
|
|
5207
5212
|
if (format.endsWith("32float")) {
|
|
5208
|
-
return Boolean(
|
|
5213
|
+
return Boolean(gl2.getExtension("OES_texture_float_linear"));
|
|
5209
5214
|
}
|
|
5210
5215
|
if (format.endsWith("16float")) {
|
|
5211
|
-
return Boolean(
|
|
5216
|
+
return Boolean(gl2.getExtension("OES_texture_half_float_linear"));
|
|
5212
5217
|
}
|
|
5213
5218
|
return true;
|
|
5214
5219
|
}
|
|
5215
|
-
function isTextureFormatRenderable(
|
|
5220
|
+
function isTextureFormatRenderable(gl2, formatOrGL) {
|
|
5216
5221
|
const format = convertGLToTextureFormat(formatOrGL);
|
|
5217
|
-
if (!isTextureFormatSupported(
|
|
5222
|
+
if (!isTextureFormatSupported(gl2, format)) {
|
|
5218
5223
|
return false;
|
|
5219
5224
|
}
|
|
5220
5225
|
if (typeof format === "number") {
|
|
@@ -5241,27 +5246,27 @@ var __exports__ = (() => {
|
|
|
5241
5246
|
}
|
|
5242
5247
|
return info.attachment;
|
|
5243
5248
|
}
|
|
5244
|
-
function _checkFloat32ColorAttachment(
|
|
5249
|
+
function _checkFloat32ColorAttachment(gl2, internalFormat = gl2.RGBA, srcFormat = GL.RGBA, srcType = GL.UNSIGNED_BYTE) {
|
|
5245
5250
|
let texture = null;
|
|
5246
5251
|
let framebuffer = null;
|
|
5247
5252
|
try {
|
|
5248
|
-
texture =
|
|
5249
|
-
|
|
5253
|
+
texture = gl2.createTexture();
|
|
5254
|
+
gl2.bindTexture(GL.TEXTURE_2D, texture);
|
|
5250
5255
|
const level = 0;
|
|
5251
5256
|
const width = 1;
|
|
5252
5257
|
const height = 1;
|
|
5253
5258
|
const border = 0;
|
|
5254
5259
|
const pixel = new Uint8Array([0, 0, 255, 255]);
|
|
5255
|
-
|
|
5256
|
-
framebuffer =
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
const status =
|
|
5260
|
-
|
|
5260
|
+
gl2.texImage2D(gl2.TEXTURE_2D, level, internalFormat, width, height, border, srcFormat, srcType, pixel);
|
|
5261
|
+
framebuffer = gl2.createFramebuffer();
|
|
5262
|
+
gl2.bindFramebuffer(GL.FRAMEBUFFER, framebuffer);
|
|
5263
|
+
gl2.framebufferTexture2D(GL.FRAMEBUFFER, GL.COLOR_ATTACHMENT0, GL.TEXTURE_2D, texture, 0);
|
|
5264
|
+
const status = gl2.checkFramebufferStatus(GL.FRAMEBUFFER) === GL.FRAMEBUFFER_COMPLETE;
|
|
5265
|
+
gl2.bindTexture(GL.TEXTURE_2D, null);
|
|
5261
5266
|
return status;
|
|
5262
5267
|
} finally {
|
|
5263
|
-
|
|
5264
|
-
|
|
5268
|
+
gl2.deleteTexture(texture);
|
|
5269
|
+
gl2.deleteFramebuffer(framebuffer);
|
|
5265
5270
|
}
|
|
5266
5271
|
}
|
|
5267
5272
|
function getTextureFormatBytesPerPixel(formatOrGL, isWebGL23) {
|
|
@@ -5312,52 +5317,52 @@ var __exports__ = (() => {
|
|
|
5312
5317
|
}
|
|
5313
5318
|
|
|
5314
5319
|
// src/adapter/device-helpers/device-features.ts
|
|
5315
|
-
function getDeviceFeatures(
|
|
5316
|
-
const features = getWebGLFeatures(
|
|
5317
|
-
for (const textureFeature of getTextureFeatures(
|
|
5320
|
+
function getDeviceFeatures(gl2) {
|
|
5321
|
+
const features = getWebGLFeatures(gl2);
|
|
5322
|
+
for (const textureFeature of getTextureFeatures(gl2)) {
|
|
5318
5323
|
features.add(textureFeature);
|
|
5319
5324
|
}
|
|
5320
5325
|
return features;
|
|
5321
5326
|
}
|
|
5322
|
-
function getWebGLFeatures(
|
|
5323
|
-
|
|
5324
|
-
|
|
5325
|
-
|
|
5327
|
+
function getWebGLFeatures(gl2) {
|
|
5328
|
+
gl2.getExtension("EXT_color_buffer_float");
|
|
5329
|
+
gl2.getExtension("WEBGL_color_buffer_float");
|
|
5330
|
+
gl2.getExtension("EXT_float_blend");
|
|
5326
5331
|
const features = /* @__PURE__ */ new Set();
|
|
5327
5332
|
for (const feature of Object.keys(WEBGL_FEATURES)) {
|
|
5328
|
-
if (isFeatureSupported(
|
|
5333
|
+
if (isFeatureSupported(gl2, feature)) {
|
|
5329
5334
|
features.add(feature);
|
|
5330
5335
|
}
|
|
5331
5336
|
}
|
|
5332
5337
|
return features;
|
|
5333
5338
|
}
|
|
5334
|
-
function isFeatureSupported(
|
|
5339
|
+
function isFeatureSupported(gl2, feature) {
|
|
5335
5340
|
const featureInfo = WEBGL_FEATURES[feature];
|
|
5336
5341
|
if (!featureInfo) {
|
|
5337
5342
|
return false;
|
|
5338
5343
|
}
|
|
5339
5344
|
const [webgl1Feature, webgl2Feature] = featureInfo || [];
|
|
5340
|
-
const featureDefinition = isWebGL2(
|
|
5345
|
+
const featureDefinition = isWebGL2(gl2) ? webgl2Feature : webgl1Feature;
|
|
5341
5346
|
if (typeof featureDefinition === "boolean") {
|
|
5342
5347
|
return featureDefinition;
|
|
5343
5348
|
}
|
|
5344
5349
|
switch (feature) {
|
|
5345
5350
|
case "texture-renderable-rgba32float-webgl":
|
|
5346
|
-
return isWebGL2(
|
|
5351
|
+
return isWebGL2(gl2) ? Boolean(gl2.getExtension(featureDefinition)) : _checkFloat32ColorAttachment(gl2);
|
|
5347
5352
|
case "glsl-derivatives":
|
|
5348
|
-
return canCompileGLSLExtension(
|
|
5353
|
+
return canCompileGLSLExtension(gl2, featureDefinition);
|
|
5349
5354
|
case "glsl-frag-data":
|
|
5350
|
-
return canCompileGLSLExtension(
|
|
5355
|
+
return canCompileGLSLExtension(gl2, featureDefinition, {
|
|
5351
5356
|
behavior: "require"
|
|
5352
5357
|
});
|
|
5353
5358
|
case "glsl-frag-depth":
|
|
5354
|
-
return canCompileGLSLExtension(
|
|
5359
|
+
return canCompileGLSLExtension(gl2, featureDefinition);
|
|
5355
5360
|
default:
|
|
5356
|
-
return Boolean(
|
|
5361
|
+
return Boolean(gl2.getExtension(featureDefinition));
|
|
5357
5362
|
}
|
|
5358
5363
|
}
|
|
5359
5364
|
var compiledGLSLExtensions = {};
|
|
5360
|
-
function canCompileGLSLExtension(
|
|
5365
|
+
function canCompileGLSLExtension(gl2, extensionName, opts = {}) {
|
|
5361
5366
|
if (!isOldIE(opts)) {
|
|
5362
5367
|
return true;
|
|
5363
5368
|
}
|
|
@@ -5367,14 +5372,14 @@ var __exports__ = (() => {
|
|
|
5367
5372
|
const behavior = opts.behavior || "enable";
|
|
5368
5373
|
const source = `#extension GL_${extensionName} : ${behavior}
|
|
5369
5374
|
void main(void) {}`;
|
|
5370
|
-
const shader =
|
|
5375
|
+
const shader = gl2.createShader(gl2.VERTEX_SHADER);
|
|
5371
5376
|
if (!shader) {
|
|
5372
5377
|
throw new Error("shader");
|
|
5373
5378
|
}
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
const canCompile =
|
|
5377
|
-
|
|
5379
|
+
gl2.shaderSource(shader, source);
|
|
5380
|
+
gl2.compileShader(shader);
|
|
5381
|
+
const canCompile = gl2.getShaderParameter(shader, gl2.COMPILE_STATUS);
|
|
5382
|
+
gl2.deleteShader(shader);
|
|
5378
5383
|
compiledGLSLExtensions[extensionName] = canCompile;
|
|
5379
5384
|
return canCompile;
|
|
5380
5385
|
}
|
|
@@ -5411,38 +5416,38 @@ void main(void) {}`;
|
|
|
5411
5416
|
};
|
|
5412
5417
|
|
|
5413
5418
|
// src/adapter/device-helpers/device-limits.ts
|
|
5414
|
-
function getDeviceLimits(
|
|
5415
|
-
const
|
|
5419
|
+
function getDeviceLimits(gl2) {
|
|
5420
|
+
const gl22 = getWebGL2Context(gl2);
|
|
5416
5421
|
return {
|
|
5417
5422
|
maxTextureDimension1D: 0,
|
|
5418
5423
|
// WebGL does not support 1D textures
|
|
5419
|
-
maxTextureDimension2D:
|
|
5420
|
-
maxTextureDimension3D:
|
|
5421
|
-
maxTextureArrayLayers:
|
|
5424
|
+
maxTextureDimension2D: gl2.getParameter(GL.MAX_TEXTURE_SIZE),
|
|
5425
|
+
maxTextureDimension3D: gl22 ? gl22.getParameter(GL.MAX_3D_TEXTURE_SIZE) : 0,
|
|
5426
|
+
maxTextureArrayLayers: gl22 ? gl22.getParameter(GL.MAX_ARRAY_TEXTURE_LAYERS) : 0,
|
|
5422
5427
|
maxBindGroups: 1,
|
|
5423
5428
|
// TBD
|
|
5424
5429
|
maxDynamicUniformBuffersPerPipelineLayout: 0,
|
|
5425
5430
|
// TBD
|
|
5426
5431
|
maxDynamicStorageBuffersPerPipelineLayout: 0,
|
|
5427
5432
|
// TBD
|
|
5428
|
-
maxSampledTexturesPerShaderStage:
|
|
5433
|
+
maxSampledTexturesPerShaderStage: gl2.getParameter(GL.MAX_VERTEX_TEXTURE_IMAGE_UNITS),
|
|
5429
5434
|
// TBD
|
|
5430
|
-
maxSamplersPerShaderStage:
|
|
5435
|
+
maxSamplersPerShaderStage: gl2.getParameter(GL.MAX_COMBINED_TEXTURE_IMAGE_UNITS),
|
|
5431
5436
|
maxStorageBuffersPerShaderStage: 0,
|
|
5432
5437
|
// TBD
|
|
5433
5438
|
maxStorageTexturesPerShaderStage: 0,
|
|
5434
5439
|
// TBD
|
|
5435
|
-
maxUniformBuffersPerShaderStage:
|
|
5436
|
-
maxUniformBufferBindingSize:
|
|
5440
|
+
maxUniformBuffersPerShaderStage: gl22 ? gl22.getParameter(GL.MAX_UNIFORM_BUFFER_BINDINGS) : 0,
|
|
5441
|
+
maxUniformBufferBindingSize: gl22 ? gl22.getParameter(GL.MAX_UNIFORM_BLOCK_SIZE) : 0,
|
|
5437
5442
|
maxStorageBufferBindingSize: 0,
|
|
5438
|
-
minUniformBufferOffsetAlignment:
|
|
5443
|
+
minUniformBufferOffsetAlignment: gl22 ? gl22.getParameter(GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT) : 0,
|
|
5439
5444
|
minStorageBufferOffsetAlignment: 0,
|
|
5440
5445
|
// TBD
|
|
5441
5446
|
maxVertexBuffers: 0,
|
|
5442
|
-
maxVertexAttributes:
|
|
5447
|
+
maxVertexAttributes: gl2.getParameter(GL.MAX_VERTEX_ATTRIBS),
|
|
5443
5448
|
maxVertexBufferArrayStride: 2048,
|
|
5444
5449
|
// TBD, this is just the default value from WebGPU
|
|
5445
|
-
maxInterStageShaderComponents:
|
|
5450
|
+
maxInterStageShaderComponents: gl22 ? gl22.getParameter(GL.MAX_VARYING_COMPONENTS) : 0,
|
|
5446
5451
|
maxComputeWorkgroupStorageSize: 0,
|
|
5447
5452
|
// WebGL does not support compute shaders
|
|
5448
5453
|
maxComputeInvocationsPerWorkgroup: 0,
|
|
@@ -5457,13 +5462,13 @@ void main(void) {}`;
|
|
|
5457
5462
|
// WebGL does not support compute shaders
|
|
5458
5463
|
};
|
|
5459
5464
|
}
|
|
5460
|
-
function getWebGLLimits(
|
|
5461
|
-
const
|
|
5465
|
+
function getWebGLLimits(gl2) {
|
|
5466
|
+
const gl22 = getWebGL2Context(gl2);
|
|
5462
5467
|
function get(pname) {
|
|
5463
|
-
return
|
|
5468
|
+
return gl2.getParameter(pname);
|
|
5464
5469
|
}
|
|
5465
5470
|
function get2(pname, defaultValue) {
|
|
5466
|
-
return
|
|
5471
|
+
return gl22 ? gl22.getParameter(pname) : defaultValue || 0;
|
|
5467
5472
|
}
|
|
5468
5473
|
return {
|
|
5469
5474
|
[GL.ALIASED_LINE_WIDTH_RANGE]: get(GL.ALIASED_LINE_WIDTH_RANGE),
|
|
@@ -5556,24 +5561,24 @@ void main(void) {}`;
|
|
|
5556
5561
|
// src/context/state-tracker/with-parameters.ts
|
|
5557
5562
|
function withParameters(device, parameters, func) {
|
|
5558
5563
|
const webglDevice = WebGLDevice.attach(device);
|
|
5559
|
-
const
|
|
5564
|
+
const gl2 = webglDevice.gl;
|
|
5560
5565
|
if (isObjectEmpty3(parameters)) {
|
|
5561
5566
|
return func(device);
|
|
5562
5567
|
}
|
|
5563
5568
|
const {
|
|
5564
5569
|
nocatch = true
|
|
5565
5570
|
} = parameters;
|
|
5566
|
-
pushContextState(
|
|
5567
|
-
setParameters(
|
|
5571
|
+
pushContextState(gl2);
|
|
5572
|
+
setParameters(gl2, parameters);
|
|
5568
5573
|
let value;
|
|
5569
5574
|
if (nocatch) {
|
|
5570
|
-
value = func(
|
|
5571
|
-
popContextState(
|
|
5575
|
+
value = func(gl2);
|
|
5576
|
+
popContextState(gl2);
|
|
5572
5577
|
} else {
|
|
5573
5578
|
try {
|
|
5574
|
-
value = func(
|
|
5579
|
+
value = func(gl2);
|
|
5575
5580
|
} finally {
|
|
5576
|
-
popContextState(
|
|
5581
|
+
popContextState(gl2);
|
|
5577
5582
|
}
|
|
5578
5583
|
}
|
|
5579
5584
|
return value;
|
|
@@ -5613,43 +5618,43 @@ void main(void) {}`;
|
|
|
5613
5618
|
function setDeviceParameters(device, parameters) {
|
|
5614
5619
|
const webglDevice = WebGLDevice.attach(device);
|
|
5615
5620
|
const {
|
|
5616
|
-
gl
|
|
5621
|
+
gl: gl2
|
|
5617
5622
|
} = webglDevice;
|
|
5618
5623
|
if (parameters.cullMode) {
|
|
5619
5624
|
switch (parameters.cullMode) {
|
|
5620
5625
|
case "none":
|
|
5621
|
-
|
|
5626
|
+
gl2.disable(GL.CULL_FACE);
|
|
5622
5627
|
break;
|
|
5623
5628
|
case "front":
|
|
5624
|
-
|
|
5625
|
-
|
|
5629
|
+
gl2.enable(GL.CULL_FACE);
|
|
5630
|
+
gl2.cullFace(GL.FRONT);
|
|
5626
5631
|
break;
|
|
5627
5632
|
case "back":
|
|
5628
|
-
|
|
5629
|
-
|
|
5633
|
+
gl2.enable(GL.CULL_FACE);
|
|
5634
|
+
gl2.cullFace(GL.BACK);
|
|
5630
5635
|
break;
|
|
5631
5636
|
}
|
|
5632
5637
|
}
|
|
5633
5638
|
if (parameters.frontFace) {
|
|
5634
|
-
|
|
5639
|
+
gl2.frontFace(map("frontFace", parameters.frontFace, {
|
|
5635
5640
|
ccw: GL.CCW,
|
|
5636
5641
|
cw: GL.CW
|
|
5637
5642
|
}));
|
|
5638
5643
|
}
|
|
5639
5644
|
if (parameters.depthBias !== void 0) {
|
|
5640
|
-
|
|
5645
|
+
gl2.polygonOffset(parameters.depthBias, parameters.depthBiasSlopeScale || 0);
|
|
5641
5646
|
}
|
|
5642
5647
|
if (parameters.depthWriteEnabled !== void 0) {
|
|
5643
|
-
|
|
5648
|
+
gl2.depthMask(mapBoolean("depthWriteEnabled", parameters.depthWriteEnabled));
|
|
5644
5649
|
}
|
|
5645
5650
|
if (parameters.depthCompare) {
|
|
5646
|
-
parameters.depthCompare !== "always" ?
|
|
5647
|
-
|
|
5651
|
+
parameters.depthCompare !== "always" ? gl2.enable(GL.DEPTH_TEST) : gl2.disable(GL.DEPTH_TEST);
|
|
5652
|
+
gl2.depthFunc(convertCompareFunction("depthCompare", parameters.depthCompare));
|
|
5648
5653
|
}
|
|
5649
5654
|
if (parameters.stencilWriteMask) {
|
|
5650
5655
|
const mask = parameters.stencilWriteMask;
|
|
5651
|
-
|
|
5652
|
-
|
|
5656
|
+
gl2.stencilMaskSeparate(GL.FRONT, mask);
|
|
5657
|
+
gl2.stencilMaskSeparate(GL.BACK, mask);
|
|
5653
5658
|
}
|
|
5654
5659
|
if (parameters.stencilReadMask) {
|
|
5655
5660
|
log.warn("stencilReadMask not supported under WebGL");
|
|
@@ -5657,16 +5662,16 @@ void main(void) {}`;
|
|
|
5657
5662
|
if (parameters.stencilCompare) {
|
|
5658
5663
|
const mask = parameters.stencilReadMask || 4294967295;
|
|
5659
5664
|
const glValue = convertCompareFunction("depthCompare", parameters.stencilCompare);
|
|
5660
|
-
parameters.stencilCompare !== "always" ?
|
|
5661
|
-
|
|
5662
|
-
|
|
5665
|
+
parameters.stencilCompare !== "always" ? gl2.enable(GL.STENCIL_TEST) : gl2.disable(GL.STENCIL_TEST);
|
|
5666
|
+
gl2.stencilFuncSeparate(GL.FRONT, glValue, 0, mask);
|
|
5667
|
+
gl2.stencilFuncSeparate(GL.BACK, glValue, 0, mask);
|
|
5663
5668
|
}
|
|
5664
5669
|
if (parameters.stencilPassOperation && parameters.stencilFailOperation && parameters.stencilDepthFailOperation) {
|
|
5665
5670
|
const dppass = convertStencilOperation("stencilPassOperation", parameters.stencilPassOperation);
|
|
5666
5671
|
const sfail = convertStencilOperation("stencilFailOperation", parameters.stencilFailOperation);
|
|
5667
5672
|
const dpfail = convertStencilOperation("stencilDepthFailOperation", parameters.stencilDepthFailOperation);
|
|
5668
|
-
|
|
5669
|
-
|
|
5673
|
+
gl2.stencilOpSeparate(GL.FRONT, sfail, dpfail, dppass);
|
|
5674
|
+
gl2.stencilOpSeparate(GL.BACK, sfail, dpfail, dppass);
|
|
5670
5675
|
}
|
|
5671
5676
|
}
|
|
5672
5677
|
function convertCompareFunction(parameter, value) {
|
|
@@ -6259,9 +6264,9 @@ void main(void) {}`;
|
|
|
6259
6264
|
height
|
|
6260
6265
|
}));
|
|
6261
6266
|
const {
|
|
6262
|
-
gl
|
|
6267
|
+
gl: gl2
|
|
6263
6268
|
} = this;
|
|
6264
|
-
|
|
6269
|
+
gl2.bindTexture(this.target, this.handle);
|
|
6265
6270
|
let dataType = null;
|
|
6266
6271
|
({
|
|
6267
6272
|
data,
|
|
@@ -6270,14 +6275,14 @@ void main(void) {}`;
|
|
|
6270
6275
|
data,
|
|
6271
6276
|
compressed
|
|
6272
6277
|
}));
|
|
6273
|
-
let
|
|
6278
|
+
let gl22;
|
|
6274
6279
|
withParameters(this.gl, parameters, () => {
|
|
6275
6280
|
switch (dataType) {
|
|
6276
6281
|
case "null":
|
|
6277
|
-
|
|
6282
|
+
gl2.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
|
|
6278
6283
|
break;
|
|
6279
6284
|
case "typed-array":
|
|
6280
|
-
|
|
6285
|
+
gl2.texImage2D(
|
|
6281
6286
|
target,
|
|
6282
6287
|
level,
|
|
6283
6288
|
glFormat,
|
|
@@ -6293,21 +6298,21 @@ void main(void) {}`;
|
|
|
6293
6298
|
);
|
|
6294
6299
|
break;
|
|
6295
6300
|
case "buffer":
|
|
6296
|
-
|
|
6297
|
-
|
|
6298
|
-
|
|
6299
|
-
|
|
6301
|
+
gl22 = this.device.assertWebGL2();
|
|
6302
|
+
gl22.bindBuffer(GL.PIXEL_UNPACK_BUFFER, data.handle || data);
|
|
6303
|
+
gl22.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, offset);
|
|
6304
|
+
gl22.bindBuffer(GL.PIXEL_UNPACK_BUFFER, null);
|
|
6300
6305
|
break;
|
|
6301
6306
|
case "browser-object":
|
|
6302
6307
|
if (this.device.isWebGL2) {
|
|
6303
|
-
|
|
6308
|
+
gl2.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
|
|
6304
6309
|
} else {
|
|
6305
|
-
|
|
6310
|
+
gl2.texImage2D(target, level, glFormat, dataFormat, type, data);
|
|
6306
6311
|
}
|
|
6307
6312
|
break;
|
|
6308
6313
|
case "compressed":
|
|
6309
6314
|
for (const [levelIndex, levelData] of data.entries()) {
|
|
6310
|
-
|
|
6315
|
+
gl2.compressedTexImage2D(target, levelIndex, levelData.format, levelData.width, levelData.height, 0, levelData.data);
|
|
6311
6316
|
}
|
|
6312
6317
|
break;
|
|
6313
6318
|
default:
|
|
@@ -6411,24 +6416,24 @@ void main(void) {}`;
|
|
|
6411
6416
|
}
|
|
6412
6417
|
bind(textureUnit = this.textureUnit) {
|
|
6413
6418
|
const {
|
|
6414
|
-
gl
|
|
6419
|
+
gl: gl2
|
|
6415
6420
|
} = this;
|
|
6416
6421
|
if (textureUnit !== void 0) {
|
|
6417
6422
|
this.textureUnit = textureUnit;
|
|
6418
|
-
|
|
6423
|
+
gl2.activeTexture(gl2.TEXTURE0 + textureUnit);
|
|
6419
6424
|
}
|
|
6420
|
-
|
|
6425
|
+
gl2.bindTexture(this.target, this.handle);
|
|
6421
6426
|
return textureUnit;
|
|
6422
6427
|
}
|
|
6423
6428
|
unbind(textureUnit = this.textureUnit) {
|
|
6424
6429
|
const {
|
|
6425
|
-
gl
|
|
6430
|
+
gl: gl2
|
|
6426
6431
|
} = this;
|
|
6427
6432
|
if (textureUnit !== void 0) {
|
|
6428
6433
|
this.textureUnit = textureUnit;
|
|
6429
|
-
|
|
6434
|
+
gl2.activeTexture(gl2.TEXTURE0 + textureUnit);
|
|
6430
6435
|
}
|
|
6431
|
-
|
|
6436
|
+
gl2.bindTexture(this.target, null);
|
|
6432
6437
|
return textureUnit;
|
|
6433
6438
|
}
|
|
6434
6439
|
// PRIVATE METHODS
|
|
@@ -6550,7 +6555,7 @@ void main(void) {}`;
|
|
|
6550
6555
|
/* eslint-disable max-statements, max-len */
|
|
6551
6556
|
async setCubeMapImageData(options) {
|
|
6552
6557
|
const {
|
|
6553
|
-
gl
|
|
6558
|
+
gl: gl2
|
|
6554
6559
|
} = this;
|
|
6555
6560
|
const {
|
|
6556
6561
|
width,
|
|
@@ -6572,9 +6577,9 @@ void main(void) {}`;
|
|
|
6572
6577
|
}
|
|
6573
6578
|
resolvedFaces[index].forEach((image, lodLevel) => {
|
|
6574
6579
|
if (width && height) {
|
|
6575
|
-
|
|
6580
|
+
gl2.texImage2D(face, lodLevel, format, width, height, 0, format, type, image);
|
|
6576
6581
|
} else {
|
|
6577
|
-
|
|
6582
|
+
gl2.texImage2D(face, lodLevel, format, format, type, image);
|
|
6578
6583
|
}
|
|
6579
6584
|
});
|
|
6580
6585
|
});
|
|
@@ -6593,7 +6598,7 @@ void main(void) {}`;
|
|
|
6593
6598
|
// generateMipmap = false // TODO
|
|
6594
6599
|
} = options;
|
|
6595
6600
|
const {
|
|
6596
|
-
gl
|
|
6601
|
+
gl: gl2
|
|
6597
6602
|
} = this;
|
|
6598
6603
|
const imageData = pixels || data;
|
|
6599
6604
|
this.bind();
|
|
@@ -6604,9 +6609,9 @@ void main(void) {}`;
|
|
|
6604
6609
|
pixels: resolvedImageData
|
|
6605
6610
|
})));
|
|
6606
6611
|
} else if (this.width || this.height) {
|
|
6607
|
-
|
|
6612
|
+
gl2.texImage2D(face, 0, format, width, height, 0, format, type, imageData);
|
|
6608
6613
|
} else {
|
|
6609
|
-
|
|
6614
|
+
gl2.texImage2D(face, 0, format, format, type, imageData);
|
|
6610
6615
|
}
|
|
6611
6616
|
return this;
|
|
6612
6617
|
}
|
|
@@ -6738,7 +6743,7 @@ void main(void) {}`;
|
|
|
6738
6743
|
}
|
|
6739
6744
|
|
|
6740
6745
|
// src/adapter/objects/constants-to-keys.ts
|
|
6741
|
-
function getKeyValue(
|
|
6746
|
+
function getKeyValue(gl2, name) {
|
|
6742
6747
|
if (typeof name !== "string") {
|
|
6743
6748
|
return name;
|
|
6744
6749
|
}
|
|
@@ -6747,7 +6752,7 @@ void main(void) {}`;
|
|
|
6747
6752
|
return number;
|
|
6748
6753
|
}
|
|
6749
6754
|
name = name.replace(/^.*\./, "");
|
|
6750
|
-
const value =
|
|
6755
|
+
const value = gl2[name];
|
|
6751
6756
|
assert2(value !== void 0, `Accessing undefined constant GL.${name}`);
|
|
6752
6757
|
return value;
|
|
6753
6758
|
}
|
|
@@ -6761,13 +6766,13 @@ void main(void) {}`;
|
|
|
6761
6766
|
constructor(device, props, defaultProps) {
|
|
6762
6767
|
super(device, props, defaultProps);
|
|
6763
6768
|
this.device = WebGLDevice.attach(device);
|
|
6764
|
-
const
|
|
6765
|
-
assertWebGLContext(
|
|
6769
|
+
const gl2 = this.device.gl;
|
|
6770
|
+
assertWebGLContext(gl2);
|
|
6766
6771
|
const {
|
|
6767
6772
|
id
|
|
6768
6773
|
} = props || {};
|
|
6769
|
-
this.gl =
|
|
6770
|
-
this.gl2 =
|
|
6774
|
+
this.gl = gl2;
|
|
6775
|
+
this.gl2 = gl2;
|
|
6771
6776
|
this.id = id || uid(this.constructor.name);
|
|
6772
6777
|
this._handle = props?.handle;
|
|
6773
6778
|
if (this._handle === void 0) {
|
|
@@ -7085,12 +7090,12 @@ void main(void) {}`;
|
|
|
7085
7090
|
/** Check the status */
|
|
7086
7091
|
_checkStatus() {
|
|
7087
7092
|
const {
|
|
7088
|
-
gl
|
|
7093
|
+
gl: gl2
|
|
7089
7094
|
} = this;
|
|
7090
|
-
const prevHandle2 =
|
|
7091
|
-
const status =
|
|
7092
|
-
|
|
7093
|
-
if (status !==
|
|
7095
|
+
const prevHandle2 = gl2.bindFramebuffer(GL.FRAMEBUFFER, this.handle);
|
|
7096
|
+
const status = gl2.checkFramebufferStatus(GL.FRAMEBUFFER);
|
|
7097
|
+
gl2.bindFramebuffer(GL.FRAMEBUFFER, prevHandle2 || null);
|
|
7098
|
+
if (status !== gl2.FRAMEBUFFER_COMPLETE) {
|
|
7094
7099
|
throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);
|
|
7095
7100
|
}
|
|
7096
7101
|
}
|
|
@@ -7161,27 +7166,27 @@ void main(void) {}`;
|
|
|
7161
7166
|
*/
|
|
7162
7167
|
_attachTexture(attachment, texture, layer, level) {
|
|
7163
7168
|
const {
|
|
7164
|
-
gl,
|
|
7165
|
-
gl2
|
|
7169
|
+
gl: gl2,
|
|
7170
|
+
gl2: gl22
|
|
7166
7171
|
} = this.device;
|
|
7167
|
-
|
|
7172
|
+
gl2.bindTexture(texture.target, texture.handle);
|
|
7168
7173
|
switch (texture.target) {
|
|
7169
7174
|
case GL.TEXTURE_2D_ARRAY:
|
|
7170
7175
|
case GL.TEXTURE_3D:
|
|
7171
7176
|
this.device.assertWebGL2();
|
|
7172
|
-
|
|
7177
|
+
gl22?.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.target, level, layer);
|
|
7173
7178
|
break;
|
|
7174
7179
|
case GL.TEXTURE_CUBE_MAP:
|
|
7175
7180
|
const face = mapIndexToCubeMapFace(layer);
|
|
7176
|
-
|
|
7181
|
+
gl2.framebufferTexture2D(GL.FRAMEBUFFER, attachment, face, texture.handle, level);
|
|
7177
7182
|
break;
|
|
7178
7183
|
case GL.TEXTURE_2D:
|
|
7179
|
-
|
|
7184
|
+
gl2.framebufferTexture2D(GL.FRAMEBUFFER, attachment, GL.TEXTURE_2D, texture.handle, level);
|
|
7180
7185
|
break;
|
|
7181
7186
|
default:
|
|
7182
7187
|
assert2(false, "Illegal texture type");
|
|
7183
7188
|
}
|
|
7184
|
-
|
|
7189
|
+
gl2.bindTexture(texture.target, null);
|
|
7185
7190
|
}
|
|
7186
7191
|
};
|
|
7187
7192
|
function mapIndexToCubeMapFace(layer) {
|
|
@@ -7245,6 +7250,7 @@ void main(void) {}`;
|
|
|
7245
7250
|
*/
|
|
7246
7251
|
resize(options) {
|
|
7247
7252
|
if (this.canvas) {
|
|
7253
|
+
const devicePixelRatio = this.getDevicePixelRatio(options?.useDevicePixels);
|
|
7248
7254
|
this.setDevicePixelRatio(devicePixelRatio, options);
|
|
7249
7255
|
return;
|
|
7250
7256
|
}
|
|
@@ -7318,9 +7324,9 @@ void main(void) {}`;
|
|
|
7318
7324
|
|
|
7319
7325
|
// src/context/debug/webgl-developer-tools.ts
|
|
7320
7326
|
var WEBGL_DEBUG_CDN_URL = "https://unpkg.com/webgl-debug@2.0.1/index.js";
|
|
7321
|
-
function getContextData2(
|
|
7322
|
-
|
|
7323
|
-
return
|
|
7327
|
+
function getContextData2(gl2) {
|
|
7328
|
+
gl2.luma = gl2.luma || {};
|
|
7329
|
+
return gl2.luma;
|
|
7324
7330
|
}
|
|
7325
7331
|
async function loadWebGLDeveloperTools() {
|
|
7326
7332
|
if (!globalThis.WebGLDebugUtils) {
|
|
@@ -7329,30 +7335,30 @@ void main(void) {}`;
|
|
|
7329
7335
|
await loadScript(WEBGL_DEBUG_CDN_URL);
|
|
7330
7336
|
}
|
|
7331
7337
|
}
|
|
7332
|
-
function makeDebugContext(
|
|
7333
|
-
if (!
|
|
7338
|
+
function makeDebugContext(gl2, props = {}) {
|
|
7339
|
+
if (!gl2) {
|
|
7334
7340
|
return null;
|
|
7335
7341
|
}
|
|
7336
|
-
return props.debug ? getDebugContext(
|
|
7342
|
+
return props.debug ? getDebugContext(gl2, props) : getRealContext(gl2);
|
|
7337
7343
|
}
|
|
7338
|
-
function getRealContext(
|
|
7339
|
-
const data = getContextData2(
|
|
7340
|
-
return data.realContext ? data.realContext :
|
|
7344
|
+
function getRealContext(gl2) {
|
|
7345
|
+
const data = getContextData2(gl2);
|
|
7346
|
+
return data.realContext ? data.realContext : gl2;
|
|
7341
7347
|
}
|
|
7342
|
-
function getDebugContext(
|
|
7348
|
+
function getDebugContext(gl2, props) {
|
|
7343
7349
|
if (!globalThis.WebGLDebugUtils) {
|
|
7344
7350
|
log.warn("webgl-debug not loaded")();
|
|
7345
|
-
return
|
|
7351
|
+
return gl2;
|
|
7346
7352
|
}
|
|
7347
|
-
const data = getContextData2(
|
|
7353
|
+
const data = getContextData2(gl2);
|
|
7348
7354
|
if (data.debugContext) {
|
|
7349
7355
|
return data.debugContext;
|
|
7350
7356
|
}
|
|
7351
7357
|
globalThis.WebGLDebugUtils.init({
|
|
7352
7358
|
...GL,
|
|
7353
|
-
...
|
|
7359
|
+
...gl2
|
|
7354
7360
|
});
|
|
7355
|
-
const glDebug = globalThis.WebGLDebugUtils.makeDebugContext(
|
|
7361
|
+
const glDebug = globalThis.WebGLDebugUtils.makeDebugContext(gl2, onGLError.bind(null, props), onValidateGLFunc.bind(null, props));
|
|
7356
7362
|
for (const key in GL) {
|
|
7357
7363
|
if (!(key in glDebug) && typeof GL[key] === "number") {
|
|
7358
7364
|
glDebug[key] = GL[key];
|
|
@@ -7360,10 +7366,10 @@ void main(void) {}`;
|
|
|
7360
7366
|
}
|
|
7361
7367
|
class WebGLDebugContext {
|
|
7362
7368
|
}
|
|
7363
|
-
Object.setPrototypeOf(glDebug, Object.getPrototypeOf(
|
|
7369
|
+
Object.setPrototypeOf(glDebug, Object.getPrototypeOf(gl2));
|
|
7364
7370
|
Object.setPrototypeOf(WebGLDebugContext, glDebug);
|
|
7365
7371
|
const debugContext = Object.create(WebGLDebugContext);
|
|
7366
|
-
data.realContext =
|
|
7372
|
+
data.realContext = gl2;
|
|
7367
7373
|
data.debugContext = debugContext;
|
|
7368
7374
|
debugContext.debug = true;
|
|
7369
7375
|
return debugContext;
|
|
@@ -7750,15 +7756,15 @@ void main(void) {}`;
|
|
|
7750
7756
|
size
|
|
7751
7757
|
} = options;
|
|
7752
7758
|
const {
|
|
7753
|
-
gl,
|
|
7754
|
-
gl2
|
|
7759
|
+
gl: gl2,
|
|
7760
|
+
gl2: gl22
|
|
7755
7761
|
} = this;
|
|
7756
|
-
assertWebGL2Context(
|
|
7757
|
-
|
|
7758
|
-
|
|
7759
|
-
|
|
7760
|
-
|
|
7761
|
-
|
|
7762
|
+
assertWebGL2Context(gl2);
|
|
7763
|
+
gl2.bindBuffer(GL.COPY_READ_BUFFER, sourceBuffer.handle);
|
|
7764
|
+
gl2.bindBuffer(GL.COPY_WRITE_BUFFER, this.handle);
|
|
7765
|
+
gl22?.copyBufferSubData(GL.COPY_READ_BUFFER, GL.COPY_WRITE_BUFFER, readOffset, writeOffset, size);
|
|
7766
|
+
gl2.bindBuffer(GL.COPY_READ_BUFFER, null);
|
|
7767
|
+
gl2.bindBuffer(GL.COPY_WRITE_BUFFER, null);
|
|
7762
7768
|
this.debugData = null;
|
|
7763
7769
|
return this;
|
|
7764
7770
|
}
|
|
@@ -8029,13 +8035,13 @@ void main(void) {}`;
|
|
|
8029
8035
|
${source2}`;
|
|
8030
8036
|
source = addGLSLVersion(source);
|
|
8031
8037
|
const {
|
|
8032
|
-
gl
|
|
8038
|
+
gl: gl2
|
|
8033
8039
|
} = this.device;
|
|
8034
|
-
|
|
8035
|
-
|
|
8036
|
-
const compileStatus =
|
|
8040
|
+
gl2.shaderSource(this.handle, source);
|
|
8041
|
+
gl2.compileShader(this.handle);
|
|
8042
|
+
const compileStatus = gl2.getShaderParameter(this.handle, GL.COMPILE_STATUS);
|
|
8037
8043
|
if (!compileStatus) {
|
|
8038
|
-
const shaderLog =
|
|
8044
|
+
const shaderLog = gl2.getShaderInfoLog(this.handle);
|
|
8039
8045
|
const parsedLog = shaderLog ? parseShaderCompilerLog(shaderLog) : [];
|
|
8040
8046
|
const messages = parsedLog.filter((message2) => message2.type === "error");
|
|
8041
8047
|
const formattedLog = formatCompilerLog(messages, source);
|
|
@@ -8270,8 +8276,8 @@ ${formattedLog}`)();
|
|
|
8270
8276
|
}
|
|
8271
8277
|
|
|
8272
8278
|
// src/adapter/helpers/get-shader-layout.ts
|
|
8273
|
-
function getShaderLayout(
|
|
8274
|
-
const programBindings = getProgramBindings(
|
|
8279
|
+
function getShaderLayout(gl2, program) {
|
|
8280
|
+
const programBindings = getProgramBindings(gl2, program);
|
|
8275
8281
|
const shaderLayout = {
|
|
8276
8282
|
attributes: [],
|
|
8277
8283
|
bindings: []
|
|
@@ -8333,21 +8339,21 @@ ${formattedLog}`)();
|
|
|
8333
8339
|
}
|
|
8334
8340
|
return shaderLayout;
|
|
8335
8341
|
}
|
|
8336
|
-
function getProgramBindings(
|
|
8342
|
+
function getProgramBindings(gl2, program) {
|
|
8337
8343
|
const config = {
|
|
8338
|
-
attributes: readAttributeBindings(
|
|
8339
|
-
uniforms: readUniformBindings(
|
|
8340
|
-
uniformBlocks: readUniformBlocks(
|
|
8341
|
-
varyings: readVaryings(
|
|
8344
|
+
attributes: readAttributeBindings(gl2, program),
|
|
8345
|
+
uniforms: readUniformBindings(gl2, program),
|
|
8346
|
+
uniformBlocks: readUniformBlocks(gl2, program),
|
|
8347
|
+
varyings: readVaryings(gl2, program)
|
|
8342
8348
|
};
|
|
8343
8349
|
Object.seal(config);
|
|
8344
8350
|
return config;
|
|
8345
8351
|
}
|
|
8346
|
-
function readAttributeBindings(
|
|
8352
|
+
function readAttributeBindings(gl2, program) {
|
|
8347
8353
|
const attributes = [];
|
|
8348
|
-
const count =
|
|
8354
|
+
const count = gl2.getProgramParameter(program, gl2.ACTIVE_ATTRIBUTES);
|
|
8349
8355
|
for (let index = 0; index < count; index++) {
|
|
8350
|
-
const activeInfo =
|
|
8356
|
+
const activeInfo = gl2.getActiveAttrib(program, index);
|
|
8351
8357
|
if (!activeInfo) {
|
|
8352
8358
|
throw new Error("activeInfo");
|
|
8353
8359
|
}
|
|
@@ -8356,7 +8362,7 @@ ${formattedLog}`)();
|
|
|
8356
8362
|
type: compositeType,
|
|
8357
8363
|
size
|
|
8358
8364
|
} = activeInfo;
|
|
8359
|
-
const location =
|
|
8365
|
+
const location = gl2.getAttribLocation(program, name);
|
|
8360
8366
|
if (location >= 0) {
|
|
8361
8367
|
const {
|
|
8362
8368
|
glType,
|
|
@@ -8380,15 +8386,15 @@ ${formattedLog}`)();
|
|
|
8380
8386
|
attributes.sort((a, b) => a.location - b.location);
|
|
8381
8387
|
return attributes;
|
|
8382
8388
|
}
|
|
8383
|
-
function readVaryings(
|
|
8384
|
-
if (!isWebGL2(
|
|
8389
|
+
function readVaryings(gl2, program) {
|
|
8390
|
+
if (!isWebGL2(gl2)) {
|
|
8385
8391
|
return [];
|
|
8386
8392
|
}
|
|
8387
|
-
const
|
|
8393
|
+
const gl22 = gl2;
|
|
8388
8394
|
const varyings = [];
|
|
8389
|
-
const count =
|
|
8395
|
+
const count = gl2.getProgramParameter(program, GL.TRANSFORM_FEEDBACK_VARYINGS);
|
|
8390
8396
|
for (let location = 0; location < count; location++) {
|
|
8391
|
-
const activeInfo =
|
|
8397
|
+
const activeInfo = gl22.getTransformFeedbackVarying(program, location);
|
|
8392
8398
|
if (!activeInfo) {
|
|
8393
8399
|
throw new Error("activeInfo");
|
|
8394
8400
|
}
|
|
@@ -8415,11 +8421,11 @@ ${formattedLog}`)();
|
|
|
8415
8421
|
varyings.sort((a, b) => a.location - b.location);
|
|
8416
8422
|
return varyings;
|
|
8417
8423
|
}
|
|
8418
|
-
function readUniformBindings(
|
|
8424
|
+
function readUniformBindings(gl2, program) {
|
|
8419
8425
|
const uniforms = [];
|
|
8420
|
-
const uniformCount =
|
|
8426
|
+
const uniformCount = gl2.getProgramParameter(program, GL.ACTIVE_UNIFORMS);
|
|
8421
8427
|
for (let i = 0; i < uniformCount; i++) {
|
|
8422
|
-
const activeInfo =
|
|
8428
|
+
const activeInfo = gl2.getActiveUniform(program, i);
|
|
8423
8429
|
if (!activeInfo) {
|
|
8424
8430
|
throw new Error("activeInfo");
|
|
8425
8431
|
}
|
|
@@ -8432,7 +8438,7 @@ ${formattedLog}`)();
|
|
|
8432
8438
|
name,
|
|
8433
8439
|
isArray: isArray2
|
|
8434
8440
|
} = parseUniformName(rawName);
|
|
8435
|
-
let webglLocation =
|
|
8441
|
+
let webglLocation = gl2.getUniformLocation(program, name);
|
|
8436
8442
|
const uniformInfo = {
|
|
8437
8443
|
// WebGL locations are uniquely typed but just numbers
|
|
8438
8444
|
location: webglLocation,
|
|
@@ -8445,7 +8451,7 @@ ${formattedLog}`)();
|
|
|
8445
8451
|
if (uniformInfo.size > 1) {
|
|
8446
8452
|
for (let j = 0; j < uniformInfo.size; j++) {
|
|
8447
8453
|
const elementName = `${name}[${j}]`;
|
|
8448
|
-
webglLocation =
|
|
8454
|
+
webglLocation = gl2.getUniformLocation(program, elementName);
|
|
8449
8455
|
const arrayElementUniformInfo = {
|
|
8450
8456
|
...uniformInfo,
|
|
8451
8457
|
name: elementName,
|
|
@@ -8457,17 +8463,17 @@ ${formattedLog}`)();
|
|
|
8457
8463
|
}
|
|
8458
8464
|
return uniforms;
|
|
8459
8465
|
}
|
|
8460
|
-
function readUniformBlocks(
|
|
8461
|
-
if (!isWebGL2(
|
|
8466
|
+
function readUniformBlocks(gl2, program) {
|
|
8467
|
+
if (!isWebGL2(gl2)) {
|
|
8462
8468
|
return [];
|
|
8463
8469
|
}
|
|
8464
|
-
const
|
|
8465
|
-
const getBlockParameter = (blockIndex, pname) =>
|
|
8470
|
+
const gl22 = gl2;
|
|
8471
|
+
const getBlockParameter = (blockIndex, pname) => gl22.getActiveUniformBlockParameter(program, blockIndex, pname);
|
|
8466
8472
|
const uniformBlocks = [];
|
|
8467
|
-
const blockCount =
|
|
8473
|
+
const blockCount = gl22.getProgramParameter(program, GL.ACTIVE_UNIFORM_BLOCKS);
|
|
8468
8474
|
for (let blockIndex = 0; blockIndex < blockCount; blockIndex++) {
|
|
8469
8475
|
const blockInfo = {
|
|
8470
|
-
name:
|
|
8476
|
+
name: gl22.getActiveUniformBlockName(program, blockIndex) || "",
|
|
8471
8477
|
location: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_BINDING),
|
|
8472
8478
|
byteLength: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_DATA_SIZE),
|
|
8473
8479
|
vertex: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER),
|
|
@@ -8476,12 +8482,12 @@ ${formattedLog}`)();
|
|
|
8476
8482
|
uniforms: []
|
|
8477
8483
|
};
|
|
8478
8484
|
const uniformIndices = getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) || [];
|
|
8479
|
-
const uniformType =
|
|
8480
|
-
const uniformArrayLength =
|
|
8481
|
-
const uniformOffset =
|
|
8482
|
-
const uniformStride =
|
|
8485
|
+
const uniformType = gl22.getActiveUniforms(program, uniformIndices, GL.UNIFORM_TYPE);
|
|
8486
|
+
const uniformArrayLength = gl22.getActiveUniforms(program, uniformIndices, GL.UNIFORM_SIZE);
|
|
8487
|
+
const uniformOffset = gl22.getActiveUniforms(program, uniformIndices, GL.UNIFORM_OFFSET);
|
|
8488
|
+
const uniformStride = gl22.getActiveUniforms(program, uniformIndices, GL.UNIFORM_ARRAY_STRIDE);
|
|
8483
8489
|
for (let i = 0; i < blockInfo.uniformCount; ++i) {
|
|
8484
|
-
const activeInfo =
|
|
8490
|
+
const activeInfo = gl22.getActiveUniform(program, uniformIndices[i]);
|
|
8485
8491
|
if (!activeInfo) {
|
|
8486
8492
|
throw new Error("activeInfo");
|
|
8487
8493
|
}
|
|
@@ -8550,8 +8556,8 @@ ${formattedLog}`)();
|
|
|
8550
8556
|
}
|
|
8551
8557
|
|
|
8552
8558
|
// src/adapter/helpers/set-uniform.ts
|
|
8553
|
-
function setUniform(
|
|
8554
|
-
const
|
|
8559
|
+
function setUniform(gl2, location, type, value) {
|
|
8560
|
+
const gl22 = gl2;
|
|
8555
8561
|
if (typeof value === "number") {
|
|
8556
8562
|
switch (type) {
|
|
8557
8563
|
case GL.SAMPLER_2D:
|
|
@@ -8569,7 +8575,7 @@ ${formattedLog}`)();
|
|
|
8569
8575
|
case GL.UNSIGNED_INT_SAMPLER_3D:
|
|
8570
8576
|
case GL.UNSIGNED_INT_SAMPLER_CUBE:
|
|
8571
8577
|
case GL.UNSIGNED_INT_SAMPLER_2D_ARRAY:
|
|
8572
|
-
return
|
|
8578
|
+
return gl2.uniform1i(location, value);
|
|
8573
8579
|
}
|
|
8574
8580
|
}
|
|
8575
8581
|
if (value === true) {
|
|
@@ -8581,55 +8587,55 @@ ${formattedLog}`)();
|
|
|
8581
8587
|
const arrayValue = typeof value === "number" ? [value] : value;
|
|
8582
8588
|
switch (type) {
|
|
8583
8589
|
case GL.FLOAT:
|
|
8584
|
-
return
|
|
8590
|
+
return gl2.uniform1fv(location, arrayValue);
|
|
8585
8591
|
case GL.FLOAT_VEC2:
|
|
8586
|
-
return
|
|
8592
|
+
return gl2.uniform2fv(location, arrayValue);
|
|
8587
8593
|
case GL.FLOAT_VEC3:
|
|
8588
|
-
return
|
|
8594
|
+
return gl2.uniform3fv(location, arrayValue);
|
|
8589
8595
|
case GL.FLOAT_VEC4:
|
|
8590
|
-
return
|
|
8596
|
+
return gl2.uniform4fv(location, arrayValue);
|
|
8591
8597
|
case GL.INT:
|
|
8592
|
-
return
|
|
8598
|
+
return gl2.uniform1iv(location, arrayValue);
|
|
8593
8599
|
case GL.INT_VEC2:
|
|
8594
|
-
return
|
|
8600
|
+
return gl2.uniform2iv(location, arrayValue);
|
|
8595
8601
|
case GL.INT_VEC3:
|
|
8596
|
-
return
|
|
8602
|
+
return gl2.uniform3iv(location, arrayValue);
|
|
8597
8603
|
case GL.INT_VEC4:
|
|
8598
|
-
return
|
|
8604
|
+
return gl2.uniform4iv(location, arrayValue);
|
|
8599
8605
|
case GL.BOOL:
|
|
8600
|
-
return
|
|
8606
|
+
return gl2.uniform1iv(location, arrayValue);
|
|
8601
8607
|
case GL.BOOL_VEC2:
|
|
8602
|
-
return
|
|
8608
|
+
return gl2.uniform2iv(location, arrayValue);
|
|
8603
8609
|
case GL.BOOL_VEC3:
|
|
8604
|
-
return
|
|
8610
|
+
return gl2.uniform3iv(location, arrayValue);
|
|
8605
8611
|
case GL.BOOL_VEC4:
|
|
8606
|
-
return
|
|
8612
|
+
return gl2.uniform4iv(location, arrayValue);
|
|
8607
8613
|
case GL.UNSIGNED_INT:
|
|
8608
|
-
return
|
|
8614
|
+
return gl22.uniform1uiv(location, arrayValue, 1);
|
|
8609
8615
|
case GL.UNSIGNED_INT_VEC2:
|
|
8610
|
-
return
|
|
8616
|
+
return gl22.uniform2uiv(location, arrayValue, 2);
|
|
8611
8617
|
case GL.UNSIGNED_INT_VEC3:
|
|
8612
|
-
return
|
|
8618
|
+
return gl22.uniform3uiv(location, arrayValue, 3);
|
|
8613
8619
|
case GL.UNSIGNED_INT_VEC4:
|
|
8614
|
-
return
|
|
8620
|
+
return gl22.uniform4uiv(location, arrayValue, 4);
|
|
8615
8621
|
case GL.FLOAT_MAT2:
|
|
8616
|
-
return
|
|
8622
|
+
return gl2.uniformMatrix2fv(location, false, arrayValue);
|
|
8617
8623
|
case GL.FLOAT_MAT3:
|
|
8618
|
-
return
|
|
8624
|
+
return gl2.uniformMatrix3fv(location, false, arrayValue);
|
|
8619
8625
|
case GL.FLOAT_MAT4:
|
|
8620
|
-
return
|
|
8626
|
+
return gl2.uniformMatrix4fv(location, false, arrayValue);
|
|
8621
8627
|
case GL.FLOAT_MAT2x3:
|
|
8622
|
-
return
|
|
8628
|
+
return gl22.uniformMatrix2x3fv(location, false, arrayValue);
|
|
8623
8629
|
case GL.FLOAT_MAT2x4:
|
|
8624
|
-
return
|
|
8630
|
+
return gl22.uniformMatrix2x4fv(location, false, arrayValue);
|
|
8625
8631
|
case GL.FLOAT_MAT3x2:
|
|
8626
|
-
return
|
|
8632
|
+
return gl22.uniformMatrix3x2fv(location, false, arrayValue);
|
|
8627
8633
|
case GL.FLOAT_MAT3x4:
|
|
8628
|
-
return
|
|
8634
|
+
return gl22.uniformMatrix3x4fv(location, false, arrayValue);
|
|
8629
8635
|
case GL.FLOAT_MAT4x2:
|
|
8630
|
-
return
|
|
8636
|
+
return gl22.uniformMatrix4x2fv(location, false, arrayValue);
|
|
8631
8637
|
case GL.FLOAT_MAT4x3:
|
|
8632
|
-
return
|
|
8638
|
+
return gl22.uniformMatrix4x3fv(location, false, arrayValue);
|
|
8633
8639
|
}
|
|
8634
8640
|
throw new Error("Illegal uniform");
|
|
8635
8641
|
}
|
|
@@ -8677,20 +8683,20 @@ ${formattedLog}`)();
|
|
|
8677
8683
|
divisor
|
|
8678
8684
|
} = accessor;
|
|
8679
8685
|
const {
|
|
8680
|
-
gl,
|
|
8681
|
-
gl2
|
|
8686
|
+
gl: gl2,
|
|
8687
|
+
gl2: gl22
|
|
8682
8688
|
} = this;
|
|
8683
8689
|
location = Number(location);
|
|
8684
8690
|
this.bind(() => {
|
|
8685
|
-
|
|
8691
|
+
gl2.bindBuffer(gl2.ARRAY_BUFFER, buffer.handle);
|
|
8686
8692
|
if (integer) {
|
|
8687
8693
|
this.device.assertWebGL2();
|
|
8688
|
-
|
|
8694
|
+
gl22.vertexAttribIPointer(location, size, type, stride, offset);
|
|
8689
8695
|
} else {
|
|
8690
|
-
|
|
8696
|
+
gl2.vertexAttribPointer(location, size, type, normalized, stride, offset);
|
|
8691
8697
|
}
|
|
8692
|
-
|
|
8693
|
-
|
|
8698
|
+
gl2.enableVertexAttribArray(location);
|
|
8699
|
+
gl22.vertexAttribDivisor(location, divisor || 0);
|
|
8694
8700
|
});
|
|
8695
8701
|
return this;
|
|
8696
8702
|
}
|
|
@@ -8883,22 +8889,22 @@ ${formattedLog}`)();
|
|
|
8883
8889
|
// setBindings(bindings: Record<string, Binding>): void {}
|
|
8884
8890
|
_compileAndLink() {
|
|
8885
8891
|
const {
|
|
8886
|
-
gl
|
|
8892
|
+
gl: gl2
|
|
8887
8893
|
} = this.device;
|
|
8888
|
-
|
|
8889
|
-
|
|
8894
|
+
gl2.attachShader(this.handle, this.vs.handle);
|
|
8895
|
+
gl2.attachShader(this.handle, this.fs.handle);
|
|
8890
8896
|
log.time(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
|
|
8891
|
-
|
|
8897
|
+
gl2.linkProgram(this.handle);
|
|
8892
8898
|
log.timeEnd(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
|
|
8893
|
-
if (
|
|
8894
|
-
const linked =
|
|
8899
|
+
if (gl2.debug || log.level > 0) {
|
|
8900
|
+
const linked = gl2.getProgramParameter(this.handle, gl2.LINK_STATUS);
|
|
8895
8901
|
if (!linked) {
|
|
8896
|
-
throw new Error(`Error linking: ${
|
|
8902
|
+
throw new Error(`Error linking: ${gl2.getProgramInfoLog(this.handle)}`);
|
|
8897
8903
|
}
|
|
8898
|
-
|
|
8899
|
-
const validated =
|
|
8904
|
+
gl2.validateProgram(this.handle);
|
|
8905
|
+
const validated = gl2.getProgramParameter(this.handle, gl2.VALIDATE_STATUS);
|
|
8900
8906
|
if (!validated) {
|
|
8901
|
-
throw new Error(`Error validating: ${
|
|
8907
|
+
throw new Error(`Error validating: ${gl2.getProgramInfoLog(this.handle)}`);
|
|
8902
8908
|
}
|
|
8903
8909
|
}
|
|
8904
8910
|
}
|
|
@@ -9304,18 +9310,18 @@ ${formattedLog}`)();
|
|
|
9304
9310
|
* @param gl
|
|
9305
9311
|
* @returns
|
|
9306
9312
|
*/
|
|
9307
|
-
static attach(
|
|
9308
|
-
if (
|
|
9309
|
-
return
|
|
9313
|
+
static attach(gl2) {
|
|
9314
|
+
if (gl2 instanceof _WebGLDevice) {
|
|
9315
|
+
return gl2;
|
|
9310
9316
|
}
|
|
9311
|
-
if (
|
|
9312
|
-
return
|
|
9317
|
+
if (gl2?.device instanceof Device) {
|
|
9318
|
+
return gl2.device;
|
|
9313
9319
|
}
|
|
9314
|
-
if (!isWebGL3(
|
|
9320
|
+
if (!isWebGL3(gl2)) {
|
|
9315
9321
|
throw new Error("Invalid WebGLRenderingContext");
|
|
9316
9322
|
}
|
|
9317
9323
|
return new _WebGLDevice({
|
|
9318
|
-
gl
|
|
9324
|
+
gl: gl2
|
|
9319
9325
|
});
|
|
9320
9326
|
}
|
|
9321
9327
|
static async create(props = {}) {
|
|
@@ -9355,19 +9361,19 @@ ${formattedLog}`)();
|
|
|
9355
9361
|
reason: "destroyed",
|
|
9356
9362
|
message: "Computer entered sleep mode, or too many apps or browser tabs are using the GPU."
|
|
9357
9363
|
});
|
|
9358
|
-
let
|
|
9359
|
-
|
|
9364
|
+
let gl2 = props.gl || null;
|
|
9365
|
+
gl2 = gl2 || (isBrowser() ? createBrowserContext(this.canvasContext.canvas, {
|
|
9360
9366
|
...props,
|
|
9361
9367
|
onContextLost
|
|
9362
9368
|
}) : null);
|
|
9363
|
-
|
|
9369
|
+
gl2 = gl2 || (!isBrowser() ? createHeadlessContext({
|
|
9364
9370
|
...props,
|
|
9365
9371
|
onContextLost
|
|
9366
9372
|
}) : null);
|
|
9367
|
-
if (!
|
|
9373
|
+
if (!gl2) {
|
|
9368
9374
|
throw new Error("WebGL context creation failed");
|
|
9369
9375
|
}
|
|
9370
|
-
this.handle =
|
|
9376
|
+
this.handle = gl2;
|
|
9371
9377
|
this.gl = this.handle;
|
|
9372
9378
|
this.gl2 = this.gl;
|
|
9373
9379
|
this.isWebGL2 = isWebGL22(this.gl);
|
|
@@ -9555,11 +9561,11 @@ ${formattedLog}`)();
|
|
|
9555
9561
|
* Be aware that there are some duplicates especially for constants that are 0,
|
|
9556
9562
|
* so this isn't guaranteed to return the right key in all cases.
|
|
9557
9563
|
*/
|
|
9558
|
-
getGLKey(value,
|
|
9559
|
-
|
|
9564
|
+
getGLKey(value, gl2) {
|
|
9565
|
+
gl2 = gl2 || this.gl2 || this.gl;
|
|
9560
9566
|
const number = Number(value);
|
|
9561
|
-
for (const key in
|
|
9562
|
-
if (
|
|
9567
|
+
for (const key in gl2) {
|
|
9568
|
+
if (gl2[key] === number) {
|
|
9563
9569
|
return `GL.${key}`;
|
|
9564
9570
|
}
|
|
9565
9571
|
}
|
|
@@ -9571,20 +9577,20 @@ ${formattedLog}`)();
|
|
|
9571
9577
|
// Public `Device` API
|
|
9572
9578
|
//
|
|
9573
9579
|
__publicField(WebGLDevice, "type", "webgl");
|
|
9574
|
-
function isWebGL3(
|
|
9575
|
-
if (typeof WebGLRenderingContext !== "undefined" &&
|
|
9580
|
+
function isWebGL3(gl2) {
|
|
9581
|
+
if (typeof WebGLRenderingContext !== "undefined" && gl2 instanceof WebGLRenderingContext) {
|
|
9576
9582
|
return true;
|
|
9577
9583
|
}
|
|
9578
|
-
if (typeof WebGL2RenderingContext !== "undefined" &&
|
|
9584
|
+
if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
|
|
9579
9585
|
return true;
|
|
9580
9586
|
}
|
|
9581
|
-
return Boolean(
|
|
9587
|
+
return Boolean(gl2 && Number.isFinite(gl2._version));
|
|
9582
9588
|
}
|
|
9583
|
-
function isWebGL22(
|
|
9584
|
-
if (typeof WebGL2RenderingContext !== "undefined" &&
|
|
9589
|
+
function isWebGL22(gl2) {
|
|
9590
|
+
if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
|
|
9585
9591
|
return true;
|
|
9586
9592
|
}
|
|
9587
|
-
return Boolean(
|
|
9593
|
+
return Boolean(gl2 && gl2._version === 2);
|
|
9588
9594
|
}
|
|
9589
9595
|
|
|
9590
9596
|
// src/classic/clear.ts
|
|
@@ -9592,8 +9598,8 @@ ${formattedLog}`)();
|
|
|
9592
9598
|
var GL_STENCIL_BUFFER_BIT2 = 1024;
|
|
9593
9599
|
var GL_COLOR_BUFFER_BIT2 = 16384;
|
|
9594
9600
|
var ERR_ARGUMENTS = "clear: bad arguments";
|
|
9595
|
-
function clear(
|
|
9596
|
-
const device = WebGLDevice.attach(
|
|
9601
|
+
function clear(gl2, options) {
|
|
9602
|
+
const device = WebGLDevice.attach(gl2);
|
|
9597
9603
|
const {
|
|
9598
9604
|
framebuffer = null,
|
|
9599
9605
|
color = null,
|
|
@@ -9688,7 +9694,7 @@ ${formattedLog}`)();
|
|
|
9688
9694
|
} = getFramebuffer2(source);
|
|
9689
9695
|
assert2(framebuffer);
|
|
9690
9696
|
const {
|
|
9691
|
-
gl,
|
|
9697
|
+
gl: gl2,
|
|
9692
9698
|
handle
|
|
9693
9699
|
} = framebuffer;
|
|
9694
9700
|
sourceWidth = sourceWidth || framebuffer.width;
|
|
@@ -9700,9 +9706,9 @@ ${formattedLog}`)();
|
|
|
9700
9706
|
sourceType = sourceType || framebuffer.colorAttachments[attachment].type;
|
|
9701
9707
|
target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
|
|
9702
9708
|
sourceType = sourceType || getGLTypeFromTypedArray(target);
|
|
9703
|
-
const prevHandle2 =
|
|
9704
|
-
|
|
9705
|
-
|
|
9709
|
+
const prevHandle2 = gl2.bindFramebuffer(GL.FRAMEBUFFER, handle);
|
|
9710
|
+
gl2.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
|
|
9711
|
+
gl2.bindFramebuffer(GL.FRAMEBUFFER, prevHandle2 || null);
|
|
9706
9712
|
if (deleteFramebuffer) {
|
|
9707
9713
|
framebuffer.destroy();
|
|
9708
9714
|
}
|
|
@@ -9759,6 +9765,85 @@ ${formattedLog}`)();
|
|
|
9759
9765
|
}
|
|
9760
9766
|
return target;
|
|
9761
9767
|
}
|
|
9768
|
+
function copyToTexture(source, target, options) {
|
|
9769
|
+
const {
|
|
9770
|
+
sourceX = 0,
|
|
9771
|
+
sourceY = 0,
|
|
9772
|
+
// attachment = GL.COLOR_ATTACHMENT0, // TODO - support gl.readBuffer
|
|
9773
|
+
targetMipmaplevel = 0,
|
|
9774
|
+
targetInternalFormat = GL.RGBA
|
|
9775
|
+
} = options || {};
|
|
9776
|
+
let {
|
|
9777
|
+
targetX,
|
|
9778
|
+
targetY,
|
|
9779
|
+
targetZ,
|
|
9780
|
+
width,
|
|
9781
|
+
// defaults to target width
|
|
9782
|
+
height
|
|
9783
|
+
// defaults to target height
|
|
9784
|
+
} = options || {};
|
|
9785
|
+
const {
|
|
9786
|
+
framebuffer,
|
|
9787
|
+
deleteFramebuffer
|
|
9788
|
+
} = getFramebuffer2(source);
|
|
9789
|
+
assert2(framebuffer);
|
|
9790
|
+
const webglFramebuffer = framebuffer;
|
|
9791
|
+
const {
|
|
9792
|
+
device,
|
|
9793
|
+
handle
|
|
9794
|
+
} = webglFramebuffer;
|
|
9795
|
+
const isSubCopy = typeof targetX !== "undefined" || typeof targetY !== "undefined" || typeof targetZ !== "undefined";
|
|
9796
|
+
targetX = targetX || 0;
|
|
9797
|
+
targetY = targetY || 0;
|
|
9798
|
+
targetZ = targetZ || 0;
|
|
9799
|
+
const prevHandle2 = device.gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
|
|
9800
|
+
assert2(target);
|
|
9801
|
+
let texture = null;
|
|
9802
|
+
let textureTarget;
|
|
9803
|
+
if (target instanceof Texture) {
|
|
9804
|
+
texture = target;
|
|
9805
|
+
width = Number.isFinite(width) ? width : texture.width;
|
|
9806
|
+
height = Number.isFinite(height) ? height : texture.height;
|
|
9807
|
+
texture.bind(0);
|
|
9808
|
+
textureTarget = texture.target;
|
|
9809
|
+
} else {
|
|
9810
|
+
textureTarget = target;
|
|
9811
|
+
}
|
|
9812
|
+
if (!isSubCopy) {
|
|
9813
|
+
device.gl.copyTexImage2D(
|
|
9814
|
+
textureTarget,
|
|
9815
|
+
targetMipmaplevel,
|
|
9816
|
+
targetInternalFormat,
|
|
9817
|
+
sourceX,
|
|
9818
|
+
sourceY,
|
|
9819
|
+
width,
|
|
9820
|
+
height,
|
|
9821
|
+
0
|
|
9822
|
+
/* border must be 0 */
|
|
9823
|
+
);
|
|
9824
|
+
} else {
|
|
9825
|
+
switch (textureTarget) {
|
|
9826
|
+
case GL.TEXTURE_2D:
|
|
9827
|
+
case GL.TEXTURE_CUBE_MAP:
|
|
9828
|
+
device.gl.copyTexSubImage2D(textureTarget, targetMipmaplevel, targetX, targetY, sourceX, sourceY, width, height);
|
|
9829
|
+
break;
|
|
9830
|
+
case GL.TEXTURE_2D_ARRAY:
|
|
9831
|
+
case GL.TEXTURE_3D:
|
|
9832
|
+
device.assertWebGL2();
|
|
9833
|
+
device.gl2.copyTexSubImage3D(textureTarget, targetMipmaplevel, targetX, targetY, targetZ, sourceX, sourceY, width, height);
|
|
9834
|
+
break;
|
|
9835
|
+
default:
|
|
9836
|
+
}
|
|
9837
|
+
}
|
|
9838
|
+
if (texture) {
|
|
9839
|
+
texture.unbind();
|
|
9840
|
+
}
|
|
9841
|
+
gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle2 || null);
|
|
9842
|
+
if (deleteFramebuffer) {
|
|
9843
|
+
framebuffer.destroy();
|
|
9844
|
+
}
|
|
9845
|
+
return texture;
|
|
9846
|
+
}
|
|
9762
9847
|
function getFramebuffer2(source) {
|
|
9763
9848
|
if (!(source instanceof Framebuffer)) {
|
|
9764
9849
|
return {
|