@luma.gl/webgl 9.1.0-alpha.15 → 9.1.0-alpha.16
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/converters/device-parameters.d.ts +3 -3
- package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-texture-utils.d.ts +24 -22
- package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-texture-utils.js +6 -224
- package/dist/adapter/resources/webgl-command-buffer.js +15 -15
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +24 -11
- package/dist/adapter/resources/webgl-shader.d.ts +1 -0
- package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-shader.js +6 -4
- package/dist/adapter/webgl-adapter.d.ts.map +1 -1
- package/dist/adapter/webgl-adapter.js +4 -10
- package/dist/adapter/webgl-device.d.ts +1 -2
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +33 -14
- package/dist/context/debug/spector-types.js +1 -1
- package/dist/context/debug/spector.d.ts +5 -5
- package/dist/context/debug/spector.d.ts.map +1 -1
- package/dist/context/debug/spector.js +6 -6
- package/dist/context/debug/webgl-developer-tools.d.ts +1 -3
- package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +4 -19
- package/dist/context/helpers/create-browser-context.d.ts +6 -22
- package/dist/context/helpers/create-browser-context.d.ts.map +1 -1
- package/dist/context/helpers/create-browser-context.js +26 -32
- package/dist/dist.dev.js +147 -135
- package/dist/dist.min.js +2 -2
- package/dist/index.cjs +129 -123
- package/dist/index.cjs.map +3 -3
- package/package.json +3 -3
- package/src/adapter/converters/device-parameters.ts +3 -3
- package/src/adapter/helpers/webgl-texture-utils.ts +33 -30
- package/src/adapter/resources/webgl-command-buffer.ts +16 -16
- package/src/adapter/resources/webgl-render-pipeline.ts +26 -11
- package/src/adapter/resources/webgl-shader.ts +7 -5
- package/src/adapter/webgl-adapter.ts +4 -12
- package/src/adapter/webgl-device.ts +67 -40
- package/src/context/debug/spector-types.ts +1 -1
- package/src/context/debug/spector.ts +11 -11
- package/src/context/debug/webgl-developer-tools.ts +5 -31
- package/src/context/helpers/create-browser-context.ts +39 -64
package/dist/dist.dev.js
CHANGED
|
@@ -14,9 +14,9 @@ var __exports__ = (() => {
|
|
|
14
14
|
var __commonJS = (cb, mod) => function __require() {
|
|
15
15
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
16
16
|
};
|
|
17
|
-
var __export = (
|
|
17
|
+
var __export = (target2, all) => {
|
|
18
18
|
for (var name in all)
|
|
19
|
-
__defProp(
|
|
19
|
+
__defProp(target2, name, { get: all[name], enumerable: true });
|
|
20
20
|
};
|
|
21
21
|
var __copyProps = (to, from, except, desc) => {
|
|
22
22
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -26,13 +26,13 @@ var __exports__ = (() => {
|
|
|
26
26
|
}
|
|
27
27
|
return to;
|
|
28
28
|
};
|
|
29
|
-
var __reExport = (
|
|
30
|
-
var __toESM = (mod, isNodeMode,
|
|
29
|
+
var __reExport = (target2, mod, secondTarget) => (__copyProps(target2, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
30
|
+
var __toESM = (mod, isNodeMode, target2) => (target2 = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
31
31
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
32
32
|
// file that has been converted to a CommonJS file using a Babel-
|
|
33
33
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
34
34
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
35
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(
|
|
35
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target2, "default", { value: mod, enumerable: true }) : target2,
|
|
36
36
|
mod
|
|
37
37
|
));
|
|
38
38
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
@@ -815,8 +815,8 @@ var __exports__ = (() => {
|
|
|
815
815
|
var hint = (gl, value, key) => gl.hint(key, value);
|
|
816
816
|
var pixelStorei = (gl, value, key) => gl.pixelStorei(key, value);
|
|
817
817
|
var bindFramebuffer = (gl, value, key) => {
|
|
818
|
-
const
|
|
819
|
-
return gl.bindFramebuffer(
|
|
818
|
+
const target2 = key === 36006 /* FRAMEBUFFER_BINDING */ ? 36009 /* DRAW_FRAMEBUFFER */ : 36008 /* READ_FRAMEBUFFER */;
|
|
819
|
+
return gl.bindFramebuffer(target2, value);
|
|
820
820
|
};
|
|
821
821
|
var bindBuffer = (gl, value, key) => {
|
|
822
822
|
const bindingMap = {
|
|
@@ -1049,17 +1049,17 @@ var __exports__ = (() => {
|
|
|
1049
1049
|
useProgram: (update, value) => update({
|
|
1050
1050
|
[35725 /* CURRENT_PROGRAM */]: value
|
|
1051
1051
|
}),
|
|
1052
|
-
bindRenderbuffer: (update,
|
|
1052
|
+
bindRenderbuffer: (update, target2, value) => update({
|
|
1053
1053
|
[36007 /* RENDERBUFFER_BINDING */]: value
|
|
1054
1054
|
}),
|
|
1055
|
-
bindTransformFeedback: (update,
|
|
1055
|
+
bindTransformFeedback: (update, target2, value) => update({
|
|
1056
1056
|
[36389 /* TRANSFORM_FEEDBACK_BINDING */]: value
|
|
1057
1057
|
}),
|
|
1058
1058
|
bindVertexArray: (update, value) => update({
|
|
1059
1059
|
[34229 /* VERTEX_ARRAY_BINDING */]: value
|
|
1060
1060
|
}),
|
|
1061
|
-
bindFramebuffer: (update,
|
|
1062
|
-
switch (
|
|
1061
|
+
bindFramebuffer: (update, target2, framebuffer) => {
|
|
1062
|
+
switch (target2) {
|
|
1063
1063
|
case 36160 /* FRAMEBUFFER */:
|
|
1064
1064
|
return update({
|
|
1065
1065
|
[36006 /* DRAW_FRAMEBUFFER_BINDING */]: framebuffer,
|
|
@@ -1073,14 +1073,14 @@ var __exports__ = (() => {
|
|
|
1073
1073
|
return null;
|
|
1074
1074
|
}
|
|
1075
1075
|
},
|
|
1076
|
-
bindBuffer: (update,
|
|
1076
|
+
bindBuffer: (update, target2, buffer) => {
|
|
1077
1077
|
const pname = {
|
|
1078
1078
|
[34962 /* ARRAY_BUFFER */]: [34964 /* ARRAY_BUFFER_BINDING */],
|
|
1079
1079
|
[36662 /* COPY_READ_BUFFER */]: [36662 /* COPY_READ_BUFFER_BINDING */],
|
|
1080
1080
|
[36663 /* COPY_WRITE_BUFFER */]: [36663 /* COPY_WRITE_BUFFER_BINDING */],
|
|
1081
1081
|
[35051 /* PIXEL_PACK_BUFFER */]: [35053 /* PIXEL_PACK_BUFFER_BINDING */],
|
|
1082
1082
|
[35052 /* PIXEL_UNPACK_BUFFER */]: [35055 /* PIXEL_UNPACK_BUFFER_BINDING */]
|
|
1083
|
-
}[
|
|
1083
|
+
}[target2];
|
|
1084
1084
|
if (pname) {
|
|
1085
1085
|
return update({ [pname]: buffer });
|
|
1086
1086
|
}
|
|
@@ -1434,37 +1434,31 @@ var __exports__ = (() => {
|
|
|
1434
1434
|
}
|
|
1435
1435
|
|
|
1436
1436
|
// src/context/helpers/create-browser-context.ts
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
};
|
|
1445
|
-
function createBrowserContext(canvas, props) {
|
|
1446
|
-
props = { ...DEFAULT_CONTEXT_PROPS, ...props };
|
|
1447
|
-
let errorMessage = null;
|
|
1448
|
-
const onCreateError = (error) => errorMessage = error.statusMessage || errorMessage;
|
|
1449
|
-
canvas.addEventListener("webglcontextcreationerror", onCreateError, false);
|
|
1437
|
+
function createBrowserContext(canvas, props, webglContextAttributes) {
|
|
1438
|
+
const errorMessage = null;
|
|
1439
|
+
const webglProps = {
|
|
1440
|
+
preserveDrawingBuffer: true,
|
|
1441
|
+
// failIfMajorPerformanceCaveat: true,
|
|
1442
|
+
...webglContextAttributes
|
|
1443
|
+
};
|
|
1450
1444
|
let gl = null;
|
|
1451
|
-
gl ||= canvas.getContext("webgl2",
|
|
1452
|
-
|
|
1445
|
+
gl ||= canvas.getContext("webgl2", webglProps);
|
|
1446
|
+
if (!gl && !webglContextAttributes.failIfMajorPerformanceCaveat) {
|
|
1447
|
+
webglProps.failIfMajorPerformanceCaveat = false;
|
|
1448
|
+
gl = canvas.getContext("webgl", webglProps);
|
|
1449
|
+
gl.luma ||= {};
|
|
1450
|
+
gl.luma.softwareRenderer = true;
|
|
1451
|
+
}
|
|
1453
1452
|
if (!gl) {
|
|
1454
1453
|
throw new Error(`Failed to create WebGL context: ${errorMessage || "Unknown error"}`);
|
|
1455
1454
|
}
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
"webglcontextrestored",
|
|
1464
|
-
(event) => onContextRestored(event),
|
|
1465
|
-
false
|
|
1466
|
-
);
|
|
1467
|
-
}
|
|
1455
|
+
const { onContextLost, onContextRestored } = props;
|
|
1456
|
+
canvas.addEventListener("webglcontextlost", (event) => onContextLost(event), false);
|
|
1457
|
+
canvas.addEventListener(
|
|
1458
|
+
"webglcontextrestored",
|
|
1459
|
+
(event) => onContextRestored(event),
|
|
1460
|
+
false
|
|
1461
|
+
);
|
|
1468
1462
|
return gl;
|
|
1469
1463
|
}
|
|
1470
1464
|
|
|
@@ -2341,17 +2335,17 @@ var __exports__ = (() => {
|
|
|
2341
2335
|
var spector = null;
|
|
2342
2336
|
var initialized = false;
|
|
2343
2337
|
var DEFAULT_SPECTOR_PROPS = {
|
|
2344
|
-
|
|
2338
|
+
debugSpectorJS: import_core6.log.get("debug-spectorjs"),
|
|
2345
2339
|
// https://github.com/BabylonJS/Spector.js#basic-usage
|
|
2346
2340
|
// https://forum.babylonjs.com/t/spectorcdn-is-temporarily-off/48241
|
|
2347
2341
|
// spectorUrl: 'https://spectorcdn.babylonjs.com/spector.bundle.js';
|
|
2348
|
-
|
|
2342
|
+
debugSpectorJSUrl: "https://cdn.jsdelivr.net/npm/spectorjs@0.9.30/dist/spector.bundle.js",
|
|
2349
2343
|
gl: void 0
|
|
2350
2344
|
};
|
|
2351
2345
|
async function loadSpectorJS(props) {
|
|
2352
2346
|
if (!globalThis.SPECTOR) {
|
|
2353
2347
|
try {
|
|
2354
|
-
await loadScript(props.
|
|
2348
|
+
await loadScript(props.debugSpectorJSUrl || DEFAULT_SPECTOR_PROPS.debugSpectorJSUrl);
|
|
2355
2349
|
} catch (error) {
|
|
2356
2350
|
import_core6.log.warn(String(error));
|
|
2357
2351
|
}
|
|
@@ -2359,13 +2353,13 @@ var __exports__ = (() => {
|
|
|
2359
2353
|
}
|
|
2360
2354
|
function initializeSpectorJS(props) {
|
|
2361
2355
|
props = { ...DEFAULT_SPECTOR_PROPS, ...props };
|
|
2362
|
-
if (!props.
|
|
2356
|
+
if (!props.debugSpectorJS) {
|
|
2363
2357
|
return null;
|
|
2364
2358
|
}
|
|
2365
2359
|
if (!spector && globalThis.SPECTOR && !globalThis.luma?.spector) {
|
|
2366
2360
|
import_core6.log.probe(LOG_LEVEL, "SPECTOR found and initialized. Start with `luma.spector.displayUI()`")();
|
|
2367
|
-
const { Spector } = globalThis.SPECTOR;
|
|
2368
|
-
spector = new
|
|
2361
|
+
const { Spector: SpectorJS } = globalThis.SPECTOR;
|
|
2362
|
+
spector = new SpectorJS();
|
|
2369
2363
|
if (globalThis.luma) {
|
|
2370
2364
|
globalThis.luma.spector = spector;
|
|
2371
2365
|
}
|
|
@@ -2468,7 +2462,7 @@ var __exports__ = (() => {
|
|
|
2468
2462
|
}
|
|
2469
2463
|
}
|
|
2470
2464
|
function makeDebugContext(gl, props = {}) {
|
|
2471
|
-
return props.
|
|
2465
|
+
return props.debugWebGL ? getDebugContext(gl, props) : getRealContext(gl);
|
|
2472
2466
|
}
|
|
2473
2467
|
function getRealContext(gl) {
|
|
2474
2468
|
const data = getWebGLContextData(gl);
|
|
@@ -2517,9 +2511,6 @@ var __exports__ = (() => {
|
|
|
2517
2511
|
const message2 = `${errorMessage} in gl.${functionName}(${functionArgs})`;
|
|
2518
2512
|
import_core7.log.error(message2)();
|
|
2519
2513
|
debugger;
|
|
2520
|
-
if (props.throwOnError) {
|
|
2521
|
-
throw new Error(message2);
|
|
2522
|
-
}
|
|
2523
2514
|
}
|
|
2524
2515
|
function onValidateGLFunc(props, functionName, functionArgs) {
|
|
2525
2516
|
let functionString = "";
|
|
@@ -2527,24 +2518,10 @@ var __exports__ = (() => {
|
|
|
2527
2518
|
functionString = getFunctionString(functionName, functionArgs);
|
|
2528
2519
|
import_core7.log.log(1, functionString)();
|
|
2529
2520
|
}
|
|
2530
|
-
if (props.break && props.break.length > 0) {
|
|
2531
|
-
functionString = functionString || getFunctionString(functionName, functionArgs);
|
|
2532
|
-
const isBreakpoint = props.break.every(
|
|
2533
|
-
(breakOn) => functionString.indexOf(breakOn) !== -1
|
|
2534
|
-
);
|
|
2535
|
-
if (isBreakpoint) {
|
|
2536
|
-
debugger;
|
|
2537
|
-
}
|
|
2538
|
-
}
|
|
2539
2521
|
for (const arg of functionArgs) {
|
|
2540
2522
|
if (arg === void 0) {
|
|
2541
2523
|
functionString = functionString || getFunctionString(functionName, functionArgs);
|
|
2542
|
-
|
|
2543
|
-
throw new Error(`Undefined argument: ${functionString}`);
|
|
2544
|
-
} else {
|
|
2545
|
-
import_core7.log.error(`Undefined argument: ${functionString}`)();
|
|
2546
|
-
debugger;
|
|
2547
|
-
}
|
|
2524
|
+
debugger;
|
|
2548
2525
|
}
|
|
2549
2526
|
}
|
|
2550
2527
|
}
|
|
@@ -2754,13 +2731,16 @@ var __exports__ = (() => {
|
|
|
2754
2731
|
this.destroyed = true;
|
|
2755
2732
|
}
|
|
2756
2733
|
}
|
|
2734
|
+
get asyncCompilationStatus() {
|
|
2735
|
+
return this._waitForCompilationComplete().then(() => this.compilationStatus);
|
|
2736
|
+
}
|
|
2757
2737
|
async getCompilationInfo() {
|
|
2758
2738
|
await this._waitForCompilationComplete();
|
|
2759
2739
|
return this.getCompilationInfoSync();
|
|
2760
2740
|
}
|
|
2761
2741
|
getCompilationInfoSync() {
|
|
2762
|
-
const
|
|
2763
|
-
return
|
|
2742
|
+
const shaderLog = this.device.gl.getShaderInfoLog(this.handle);
|
|
2743
|
+
return shaderLog ? parseShaderCompilerLog(shaderLog) : [];
|
|
2764
2744
|
}
|
|
2765
2745
|
getTranslatedSource() {
|
|
2766
2746
|
const extensions = this.device.getExtension("WEBGL_debug_shaders");
|
|
@@ -2770,9 +2750,8 @@ var __exports__ = (() => {
|
|
|
2770
2750
|
// PRIVATE METHODS
|
|
2771
2751
|
/** Compile a shader and get compilation status */
|
|
2772
2752
|
async _compile(source) {
|
|
2773
|
-
|
|
2774
|
-
${
|
|
2775
|
-
source = addGLSLVersion(source);
|
|
2753
|
+
source = source.startsWith("#version ") ? source : `#version 300 es
|
|
2754
|
+
${source}`;
|
|
2776
2755
|
const { gl } = this.device;
|
|
2777
2756
|
gl.shaderSource(this.handle, source);
|
|
2778
2757
|
gl.compileShader(this.handle);
|
|
@@ -3423,7 +3402,7 @@ ${source2}`;
|
|
|
3423
3402
|
// TODO - support gl.readBuffer
|
|
3424
3403
|
} = options || {};
|
|
3425
3404
|
let {
|
|
3426
|
-
target = null,
|
|
3405
|
+
target: target2 = null,
|
|
3427
3406
|
// following parameters are auto deduced if not provided
|
|
3428
3407
|
sourceWidth,
|
|
3429
3408
|
sourceHeight,
|
|
@@ -3439,19 +3418,19 @@ ${source2}`;
|
|
|
3439
3418
|
sourceDepth = framebuffer.colorAttachments[attachment]?.texture?.depth || 1;
|
|
3440
3419
|
sourceFormat ||= framebuffer.colorAttachments[attachment]?.texture?.glFormat || 6408 /* RGBA */;
|
|
3441
3420
|
sourceType ||= framebuffer.colorAttachments[attachment]?.texture?.glType || 5121 /* UNSIGNED_BYTE */;
|
|
3442
|
-
|
|
3443
|
-
sourceType = sourceType || getGLTypeFromTypedArray(
|
|
3421
|
+
target2 = getPixelArray(target2, sourceType, sourceFormat, sourceWidth, sourceHeight, sourceDepth);
|
|
3422
|
+
sourceType = sourceType || getGLTypeFromTypedArray(target2);
|
|
3444
3423
|
const prevHandle = gl.bindFramebuffer(36160 /* FRAMEBUFFER */, handle);
|
|
3445
|
-
gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType,
|
|
3424
|
+
gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target2);
|
|
3446
3425
|
gl.bindFramebuffer(36160 /* FRAMEBUFFER */, prevHandle || null);
|
|
3447
3426
|
if (deleteFramebuffer) {
|
|
3448
3427
|
framebuffer.destroy();
|
|
3449
3428
|
}
|
|
3450
|
-
return
|
|
3429
|
+
return target2;
|
|
3451
3430
|
}
|
|
3452
3431
|
function readPixelsToBuffer(source, options) {
|
|
3453
3432
|
const {
|
|
3454
|
-
target,
|
|
3433
|
+
target: target2,
|
|
3455
3434
|
sourceX = 0,
|
|
3456
3435
|
sourceY = 0,
|
|
3457
3436
|
sourceFormat = 6408 /* RGBA */,
|
|
@@ -3463,7 +3442,7 @@ ${source2}`;
|
|
|
3463
3442
|
sourceHeight = sourceHeight || framebuffer.height;
|
|
3464
3443
|
const webglFramebuffer = framebuffer;
|
|
3465
3444
|
sourceType = sourceType || 5121 /* UNSIGNED_BYTE */;
|
|
3466
|
-
let webglBufferTarget =
|
|
3445
|
+
let webglBufferTarget = target2;
|
|
3467
3446
|
if (!webglBufferTarget) {
|
|
3468
3447
|
const components = glFormatToComponents(sourceFormat);
|
|
3469
3448
|
const byteCount = glTypeToBytes(sourceType);
|
|
@@ -3472,11 +3451,11 @@ ${source2}`;
|
|
|
3472
3451
|
}
|
|
3473
3452
|
const commandEncoder = source.device.createCommandEncoder();
|
|
3474
3453
|
commandEncoder.copyTextureToBuffer({
|
|
3475
|
-
source,
|
|
3454
|
+
sourceTexture: source,
|
|
3476
3455
|
width: sourceWidth,
|
|
3477
3456
|
height: sourceHeight,
|
|
3478
3457
|
origin: [sourceX, sourceY],
|
|
3479
|
-
|
|
3458
|
+
destinationBuffer: webglBufferTarget,
|
|
3480
3459
|
byteOffset: targetByteOffset
|
|
3481
3460
|
});
|
|
3482
3461
|
commandEncoder.destroy();
|
|
@@ -4634,9 +4613,9 @@ ${source2}`;
|
|
|
4634
4613
|
*/
|
|
4635
4614
|
setBindings(bindings, options) {
|
|
4636
4615
|
for (const [name, value] of Object.entries(bindings)) {
|
|
4637
|
-
const binding = this.shaderLayout.bindings.find((
|
|
4616
|
+
const binding = this.shaderLayout.bindings.find((binding_) => binding_.name === name) || this.shaderLayout.bindings.find((binding_) => binding_.name === `${name}Uniforms`);
|
|
4638
4617
|
if (!binding) {
|
|
4639
|
-
const validBindings = this.shaderLayout.bindings.map((
|
|
4618
|
+
const validBindings = this.shaderLayout.bindings.map((binding_) => `"${binding_.name}"`).join(", ");
|
|
4640
4619
|
if (!options?.disableWarnings) {
|
|
4641
4620
|
import_core16.log.warn(
|
|
4642
4621
|
`No binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`,
|
|
@@ -4772,20 +4751,33 @@ ${source2}`;
|
|
|
4772
4751
|
this._reportLinkStatus(status);
|
|
4773
4752
|
}
|
|
4774
4753
|
/** Report link status. First, check for shader compilation failures if linking fails */
|
|
4775
|
-
_reportLinkStatus(status) {
|
|
4754
|
+
async _reportLinkStatus(status) {
|
|
4776
4755
|
switch (status) {
|
|
4777
4756
|
case "success":
|
|
4778
4757
|
return;
|
|
4779
4758
|
default:
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4759
|
+
switch (this.vs.compilationStatus) {
|
|
4760
|
+
case "error":
|
|
4761
|
+
this.vs.debugShader();
|
|
4762
|
+
throw new Error(`Error during compilation of shader ${this.vs.id}`);
|
|
4763
|
+
case "pending":
|
|
4764
|
+
this.vs.asyncCompilationStatus.then(() => this.vs.debugShader());
|
|
4765
|
+
break;
|
|
4766
|
+
case "success":
|
|
4767
|
+
break;
|
|
4783
4768
|
}
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4769
|
+
switch (this.fs?.compilationStatus) {
|
|
4770
|
+
case "error":
|
|
4771
|
+
this.fs.debugShader();
|
|
4772
|
+
throw new Error(`Error during compilation of shader ${this.fs.id}`);
|
|
4773
|
+
case "pending":
|
|
4774
|
+
this.fs.asyncCompilationStatus.then(() => this.fs.debugShader());
|
|
4775
|
+
break;
|
|
4776
|
+
case "success":
|
|
4777
|
+
break;
|
|
4787
4778
|
}
|
|
4788
|
-
|
|
4779
|
+
const linkErrorLog = this.device.gl.getProgramInfoLog(this.handle);
|
|
4780
|
+
throw new Error(`Error during ${status}: ${linkErrorLog}`);
|
|
4789
4781
|
}
|
|
4790
4782
|
}
|
|
4791
4783
|
/**
|
|
@@ -4976,8 +4968,8 @@ ${source2}`;
|
|
|
4976
4968
|
}
|
|
4977
4969
|
};
|
|
4978
4970
|
function _copyBufferToBuffer(device, options) {
|
|
4979
|
-
const source = options.
|
|
4980
|
-
const destination = options.
|
|
4971
|
+
const source = options.sourceBuffer;
|
|
4972
|
+
const destination = options.destinationBuffer;
|
|
4981
4973
|
device.gl.bindBuffer(36662 /* COPY_READ_BUFFER */, source.handle);
|
|
4982
4974
|
device.gl.bindBuffer(36663 /* COPY_WRITE_BUFFER */, destination.handle);
|
|
4983
4975
|
device.gl.copyBufferSubData(
|
|
@@ -4996,20 +4988,20 @@ ${source2}`;
|
|
|
4996
4988
|
function _copyTextureToBuffer(device, options) {
|
|
4997
4989
|
const {
|
|
4998
4990
|
/** Texture to copy to/from. */
|
|
4999
|
-
|
|
4991
|
+
sourceTexture,
|
|
5000
4992
|
/** Mip-map level of the texture to copy to/from. (Default 0) */
|
|
5001
4993
|
mipLevel = 0,
|
|
5002
4994
|
/** Defines which aspects of the texture to copy to/from. */
|
|
5003
4995
|
aspect = "all",
|
|
5004
4996
|
/** Width to copy */
|
|
5005
|
-
width = options.
|
|
4997
|
+
width = options.sourceTexture.width,
|
|
5006
4998
|
/** Height to copy */
|
|
5007
|
-
height = options.
|
|
4999
|
+
height = options.sourceTexture.height,
|
|
5008
5000
|
depthOrArrayLayers = 0,
|
|
5009
5001
|
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
|
|
5010
5002
|
origin = [0, 0],
|
|
5011
5003
|
/** Destination buffer */
|
|
5012
|
-
|
|
5004
|
+
destinationBuffer,
|
|
5013
5005
|
/** Offset, in bytes, from the beginning of the buffer to the start of the image data (default 0) */
|
|
5014
5006
|
byteOffset = 0,
|
|
5015
5007
|
/**
|
|
@@ -5025,15 +5017,15 @@ ${source2}`;
|
|
|
5025
5017
|
rowsPerImage
|
|
5026
5018
|
} = options;
|
|
5027
5019
|
if (aspect !== "all") {
|
|
5028
|
-
throw new Error("not supported");
|
|
5020
|
+
throw new Error("aspect not supported in WebGL");
|
|
5029
5021
|
}
|
|
5030
5022
|
if (mipLevel !== 0 || depthOrArrayLayers !== 0 || bytesPerRow || rowsPerImage) {
|
|
5031
5023
|
throw new Error("not implemented");
|
|
5032
5024
|
}
|
|
5033
|
-
const { framebuffer, destroyFramebuffer } = getFramebuffer2(
|
|
5025
|
+
const { framebuffer, destroyFramebuffer } = getFramebuffer2(sourceTexture);
|
|
5034
5026
|
let prevHandle;
|
|
5035
5027
|
try {
|
|
5036
|
-
const webglBuffer =
|
|
5028
|
+
const webglBuffer = destinationBuffer;
|
|
5037
5029
|
const sourceWidth = width || framebuffer.width;
|
|
5038
5030
|
const sourceHeight = height || framebuffer.height;
|
|
5039
5031
|
const sourceParams = getTextureFormatWebGL(
|
|
@@ -5065,7 +5057,7 @@ ${source2}`;
|
|
|
5065
5057
|
function _copyTextureToTexture(device, options) {
|
|
5066
5058
|
const {
|
|
5067
5059
|
/** Texture to copy to/from. */
|
|
5068
|
-
|
|
5060
|
+
sourceTexture,
|
|
5069
5061
|
/** Mip-map level of the texture to copy to (Default 0) */
|
|
5070
5062
|
destinationMipLevel = 0,
|
|
5071
5063
|
/** Defines which aspects of the texture to copy to/from. */
|
|
@@ -5075,7 +5067,7 @@ ${source2}`;
|
|
|
5075
5067
|
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to. */
|
|
5076
5068
|
destinationOrigin = [0, 0],
|
|
5077
5069
|
/** Texture to copy to/from. */
|
|
5078
|
-
|
|
5070
|
+
destinationTexture
|
|
5079
5071
|
/** Mip-map level of the texture to copy to/from. (Default 0) */
|
|
5080
5072
|
// destinationMipLevel = options.mipLevel,
|
|
5081
5073
|
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
|
|
@@ -5084,11 +5076,11 @@ ${source2}`;
|
|
|
5084
5076
|
// destinationAspect = options.aspect,
|
|
5085
5077
|
} = options;
|
|
5086
5078
|
let {
|
|
5087
|
-
width = options.
|
|
5088
|
-
height = options.
|
|
5079
|
+
width = options.destinationTexture.width,
|
|
5080
|
+
height = options.destinationTexture.height
|
|
5089
5081
|
// depthOrArrayLayers = 0
|
|
5090
5082
|
} = options;
|
|
5091
|
-
const { framebuffer, destroyFramebuffer } = getFramebuffer2(
|
|
5083
|
+
const { framebuffer, destroyFramebuffer } = getFramebuffer2(sourceTexture);
|
|
5092
5084
|
const [sourceX, sourceY] = origin;
|
|
5093
5085
|
const [destinationX, destinationY, destinationZ] = destinationOrigin;
|
|
5094
5086
|
const prevHandle = device.gl.bindFramebuffer(
|
|
@@ -5097,8 +5089,8 @@ ${source2}`;
|
|
|
5097
5089
|
);
|
|
5098
5090
|
let texture = null;
|
|
5099
5091
|
let textureTarget;
|
|
5100
|
-
if (
|
|
5101
|
-
texture =
|
|
5092
|
+
if (destinationTexture instanceof WEBGLTexture) {
|
|
5093
|
+
texture = destinationTexture;
|
|
5102
5094
|
width = Number.isFinite(width) ? width : texture.width;
|
|
5103
5095
|
height = Number.isFinite(height) ? height : texture.height;
|
|
5104
5096
|
texture.bind(0);
|
|
@@ -5202,19 +5194,19 @@ ${source2}`;
|
|
|
5202
5194
|
|
|
5203
5195
|
// src/utils/fill-array.ts
|
|
5204
5196
|
function fillArray(options) {
|
|
5205
|
-
const { target, source, start = 0, count = 1 } = options;
|
|
5197
|
+
const { target: target2, source, start = 0, count = 1 } = options;
|
|
5206
5198
|
const length = source.length;
|
|
5207
5199
|
const total = count * length;
|
|
5208
5200
|
let copied = 0;
|
|
5209
5201
|
for (let i = start; copied < length; copied++) {
|
|
5210
|
-
|
|
5202
|
+
target2[i++] = source[copied];
|
|
5211
5203
|
}
|
|
5212
5204
|
while (copied < total) {
|
|
5213
5205
|
if (copied < total - copied) {
|
|
5214
|
-
|
|
5206
|
+
target2.copyWithin(start + copied, start, start + copied);
|
|
5215
5207
|
copied *= 2;
|
|
5216
5208
|
} else {
|
|
5217
|
-
|
|
5209
|
+
target2.copyWithin(start + copied, start, start + total - copied);
|
|
5218
5210
|
copied = total;
|
|
5219
5211
|
}
|
|
5220
5212
|
}
|
|
@@ -5631,11 +5623,11 @@ ${source2}`;
|
|
|
5631
5623
|
* outstanding queries representing disjoint `begin()`/`end()` intervals.
|
|
5632
5624
|
* It is not possible to interleave or overlap `begin` and `end` calls.
|
|
5633
5625
|
*/
|
|
5634
|
-
_begin(
|
|
5626
|
+
_begin(target2) {
|
|
5635
5627
|
if (this._queryPending) {
|
|
5636
5628
|
return;
|
|
5637
5629
|
}
|
|
5638
|
-
this.target =
|
|
5630
|
+
this.target = target2;
|
|
5639
5631
|
this.device.gl.beginQuery(this.target, this.handle);
|
|
5640
5632
|
return;
|
|
5641
5633
|
}
|
|
@@ -5768,33 +5760,57 @@ ${source2}`;
|
|
|
5768
5760
|
//
|
|
5769
5761
|
constructor(props) {
|
|
5770
5762
|
super({ ...props, id: props.id || uid("webgl-device") });
|
|
5771
|
-
|
|
5763
|
+
if (!props.createCanvasContext) {
|
|
5764
|
+
throw new Error("WebGLDevice requires props.createCanvasContext to be set");
|
|
5765
|
+
}
|
|
5766
|
+
const canvasContextProps = props.createCanvasContext === true ? {} : props.createCanvasContext;
|
|
5767
|
+
let device = canvasContextProps.canvas?.gl?.device;
|
|
5772
5768
|
if (device) {
|
|
5773
5769
|
throw new Error(`WebGL context already attached to device ${device.id}`);
|
|
5774
5770
|
}
|
|
5775
|
-
|
|
5776
|
-
this.canvasContext = new WebGLCanvasContext(this, { ...props, canvas });
|
|
5771
|
+
this.canvasContext = new WebGLCanvasContext(this, canvasContextProps);
|
|
5777
5772
|
this.lost = new Promise((resolve) => {
|
|
5778
5773
|
this._resolveContextLost = resolve;
|
|
5779
5774
|
});
|
|
5780
|
-
|
|
5781
|
-
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
}
|
|
5787
|
-
|
|
5788
|
-
|
|
5775
|
+
const webglContextAttributes = { ...props.webgl };
|
|
5776
|
+
if (canvasContextProps.alphaMode === "premultiplied") {
|
|
5777
|
+
webglContextAttributes.premultipliedAlpha = true;
|
|
5778
|
+
}
|
|
5779
|
+
if (props.powerPreference !== void 0) {
|
|
5780
|
+
webglContextAttributes.powerPreference = props.powerPreference;
|
|
5781
|
+
}
|
|
5782
|
+
const gl = createBrowserContext(
|
|
5783
|
+
this.canvasContext.canvas,
|
|
5784
|
+
{
|
|
5785
|
+
onContextLost: (event) => this._resolveContextLost?.({
|
|
5786
|
+
reason: "destroyed",
|
|
5787
|
+
message: "Entered sleep mode, or too many apps or browser tabs are using the GPU."
|
|
5788
|
+
}),
|
|
5789
|
+
// eslint-disable-next-line no-console
|
|
5790
|
+
onContextRestored: (event) => console.log("WebGL context restored")
|
|
5791
|
+
},
|
|
5792
|
+
webglContextAttributes
|
|
5793
|
+
);
|
|
5794
|
+
if (!gl) {
|
|
5789
5795
|
throw new Error("WebGL context creation failed");
|
|
5790
5796
|
}
|
|
5797
|
+
device = gl.device;
|
|
5798
|
+
if (device) {
|
|
5799
|
+
throw new Error(`WebGL context already attached to device ${device.id}`);
|
|
5800
|
+
}
|
|
5801
|
+
this.handle = gl;
|
|
5802
|
+
this.gl = gl;
|
|
5791
5803
|
this.spectorJS = initializeSpectorJS({ ...this.props, gl: this.handle });
|
|
5792
5804
|
this.gl.device = this;
|
|
5793
5805
|
this.gl._version = 2;
|
|
5794
5806
|
this.info = getDeviceInfo(this.gl, this._extensions);
|
|
5795
5807
|
this.limits = new WebGLDeviceLimits(this.gl);
|
|
5796
|
-
this.features = new WebGLDeviceFeatures(
|
|
5797
|
-
|
|
5808
|
+
this.features = new WebGLDeviceFeatures(
|
|
5809
|
+
this.gl,
|
|
5810
|
+
this._extensions,
|
|
5811
|
+
this.props._disabledFeatures
|
|
5812
|
+
);
|
|
5813
|
+
if (this.props._initializeFeatures) {
|
|
5798
5814
|
this.features.initializeFeatures();
|
|
5799
5815
|
}
|
|
5800
5816
|
this.canvasContext.resize();
|
|
@@ -5802,8 +5818,8 @@ ${source2}`;
|
|
|
5802
5818
|
log: (...args) => import_core23.log.log(1, ...args)()
|
|
5803
5819
|
});
|
|
5804
5820
|
glState.trackState(this.gl, { copyState: false });
|
|
5805
|
-
if (props.
|
|
5806
|
-
this.gl = makeDebugContext(this.gl, { ...props
|
|
5821
|
+
if (props.debugWebGL) {
|
|
5822
|
+
this.gl = makeDebugContext(this.gl, { ...props });
|
|
5807
5823
|
this.debug = true;
|
|
5808
5824
|
import_core23.log.level = Math.max(import_core23.log.level, 1);
|
|
5809
5825
|
import_core23.log.warn("WebGL debug mode activated. Performance reduced.")();
|
|
@@ -5832,7 +5848,7 @@ ${source2}`;
|
|
|
5832
5848
|
throw new Error("WebGL only supports a single canvas");
|
|
5833
5849
|
}
|
|
5834
5850
|
createBuffer(props) {
|
|
5835
|
-
const newProps = this.
|
|
5851
|
+
const newProps = this._normalizeBufferProps(props);
|
|
5836
5852
|
return new WEBGLBuffer(this, newProps);
|
|
5837
5853
|
}
|
|
5838
5854
|
createTexture(props) {
|
|
@@ -6176,27 +6192,23 @@ ${source2}`;
|
|
|
6176
6192
|
if (!isWebGL(gl)) {
|
|
6177
6193
|
throw new Error("Invalid WebGL2RenderingContext");
|
|
6178
6194
|
}
|
|
6179
|
-
return new WebGLDevice({ gl });
|
|
6195
|
+
return new WebGLDevice({ _handle: gl });
|
|
6180
6196
|
}
|
|
6181
6197
|
async create(props = {}) {
|
|
6182
6198
|
import_core24.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created")();
|
|
6183
6199
|
const promises = [];
|
|
6184
|
-
if (props.
|
|
6200
|
+
if (props.debugWebGL) {
|
|
6185
6201
|
promises.push(loadWebGLDeveloperTools());
|
|
6186
6202
|
}
|
|
6187
|
-
if (props.
|
|
6203
|
+
if (props.debugSpectorJS) {
|
|
6188
6204
|
promises.push(loadSpectorJS(props));
|
|
6189
6205
|
}
|
|
6190
|
-
if (typeof props.canvas === "string") {
|
|
6191
|
-
promises.push(import_core24.CanvasContext.pageLoaded);
|
|
6192
|
-
}
|
|
6193
6206
|
const results = await Promise.allSettled(promises);
|
|
6194
6207
|
for (const result of results) {
|
|
6195
6208
|
if (result.status === "rejected") {
|
|
6196
6209
|
import_core24.log.error(`Failed to initialize debug libraries ${result.reason}`)();
|
|
6197
6210
|
}
|
|
6198
6211
|
}
|
|
6199
|
-
import_core24.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
|
|
6200
6212
|
const device = new WebGLDevice(props);
|
|
6201
6213
|
const message2 = `Created ${device.type}${device.debug ? " debug" : ""} context: ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
|
|
6202
6214
|
import_core24.log.probe(LOG_LEVEL2, message2)();
|