@luma.gl/webgl 9.0.0-alpha.50 → 9.0.0-alpha.51
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/resources/webgl-shader.d.ts +2 -1
- package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-shader.js +11 -23
- package/dist/adapter/resources/webgl-shader.js.map +1 -1
- package/dist/dist.dev.js +159 -90
- package/dist/index.cjs +13 -45
- package/dist.min.js +43 -40
- package/package.json +5 -5
- package/src/adapter/resources/.webgl-render-pipeline.ts.swp +0 -0
- package/src/adapter/resources/webgl-shader.ts +26 -23
- package/dist/adapter/helpers/get-shader-info.d.ts +0 -9
- package/dist/adapter/helpers/get-shader-info.d.ts.map +0 -1
- package/dist/adapter/helpers/get-shader-info.js +0 -25
- package/dist/adapter/helpers/get-shader-info.js.map +0 -1
- package/src/adapter/helpers/get-shader-info.ts +0 -41
|
@@ -8,7 +8,8 @@ export declare class WEBGLShader extends Shader {
|
|
|
8
8
|
readonly handle: WebGLShader;
|
|
9
9
|
constructor(device: WebGLDevice, props: ShaderProps);
|
|
10
10
|
destroy(): void;
|
|
11
|
-
|
|
11
|
+
getCompilationInfo(): Promise<readonly CompilerMessage[]>;
|
|
12
|
+
getCompilationInfoSync(): readonly CompilerMessage[];
|
|
12
13
|
_compile(source: string): void;
|
|
13
14
|
}
|
|
14
15
|
//# sourceMappingURL=webgl-shader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgl-shader.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgl-shader.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"webgl-shader.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgl-shader.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,MAAM,EAAE,WAAW,EAAE,eAAe,EAAC,MAAM,eAAe,CAAC;AAGnE,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAE5C;;GAEG;AACH,qBAAa,WAAY,SAAQ,MAAM;IACrC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;gBAEjB,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW;IAgB1C,OAAO,IAAI,IAAI;IAST,kBAAkB,IAAI,OAAO,CAAC,SAAS,eAAe,EAAE,CAAC;IAI/D,sBAAsB;IAO/B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;CAqB/B"}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getShaderInfo } from "../helpers/get-shader-info.js";
|
|
1
|
+
import { Shader } from '@luma.gl/core';
|
|
3
2
|
import { parseShaderCompilerLog } from "../helpers/parse-shader-compiler-log.js";
|
|
4
3
|
export class WEBGLShader extends Shader {
|
|
5
4
|
constructor(device, props) {
|
|
6
|
-
super(device,
|
|
7
|
-
id: getShaderIdFromProps(props),
|
|
8
|
-
...props
|
|
9
|
-
});
|
|
5
|
+
super(device, props);
|
|
10
6
|
this.device = void 0;
|
|
11
7
|
this.handle = void 0;
|
|
12
8
|
this.device = device;
|
|
@@ -29,9 +25,12 @@ export class WEBGLShader extends Shader {
|
|
|
29
25
|
this.destroyed = true;
|
|
30
26
|
}
|
|
31
27
|
}
|
|
32
|
-
async
|
|
28
|
+
async getCompilationInfo() {
|
|
29
|
+
return this.getCompilationInfoSync();
|
|
30
|
+
}
|
|
31
|
+
getCompilationInfoSync() {
|
|
33
32
|
const log = this.device.gl.getShaderInfoLog(this.handle);
|
|
34
|
-
return
|
|
33
|
+
return parseShaderCompilerLog(log);
|
|
35
34
|
}
|
|
36
35
|
_compile(source) {
|
|
37
36
|
const addGLSLVersion = source => source.startsWith('#version ') ? source : `#version 100\n${source}`;
|
|
@@ -41,22 +40,11 @@ export class WEBGLShader extends Shader {
|
|
|
41
40
|
} = this.device;
|
|
42
41
|
gl.shaderSource(this.handle, source);
|
|
43
42
|
gl.compileShader(this.handle);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const messages = parsedLog.filter(message => message.type === 'error');
|
|
49
|
-
const formattedLog = formatCompilerLog(messages, source, {
|
|
50
|
-
showSourceCode: true
|
|
51
|
-
});
|
|
52
|
-
const shaderName = getShaderInfo(source).name;
|
|
53
|
-
const shaderDescription = `${this.stage} shader ${shaderName}`;
|
|
54
|
-
log.error(`GLSL compilation errors in ${shaderDescription}\n${formattedLog}`)();
|
|
55
|
-
throw new Error(`GLSL compilation errors in ${shaderName}`);
|
|
43
|
+
this.compilationStatus = gl.getShaderParameter(this.handle, 35713) ? 'success' : 'error';
|
|
44
|
+
this.debugShader();
|
|
45
|
+
if (this.compilationStatus === 'error') {
|
|
46
|
+
throw new Error(`GLSL compilation errors in ${this.props.stage} shader ${this.props.id}`);
|
|
56
47
|
}
|
|
57
48
|
}
|
|
58
49
|
}
|
|
59
|
-
function getShaderIdFromProps(props) {
|
|
60
|
-
return getShaderInfo(props.source).name || props.id || uid(`unnamed ${props.stage}-shader`);
|
|
61
|
-
}
|
|
62
50
|
//# sourceMappingURL=webgl-shader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgl-shader.js","names":["
|
|
1
|
+
{"version":3,"file":"webgl-shader.js","names":["Shader","parseShaderCompilerLog","WEBGLShader","constructor","device","props","handle","stage","gl","createShader","Error","_compile","source","destroy","removeStats","deleteShader","destroyed","getCompilationInfo","getCompilationInfoSync","log","getShaderInfoLog","addGLSLVersion","startsWith","shaderSource","compileShader","compilationStatus","getShaderParameter","debugShader","id"],"sources":["../../../src/adapter/resources/webgl-shader.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {Shader, ShaderProps, CompilerMessage} from '@luma.gl/core';\nimport {GL} from '@luma.gl/constants';\nimport {parseShaderCompilerLog} from '../helpers/parse-shader-compiler-log';\nimport {WebGLDevice} from '../webgl-device';\n\n/**\n * An immutable compiled shader program that execute portions of the GPU Pipeline\n */\nexport class WEBGLShader extends Shader {\n readonly device: WebGLDevice;\n readonly handle: WebGLShader;\n\n constructor(device: WebGLDevice, props: ShaderProps) {\n super(device, props);\n this.device = device;\n switch (this.props.stage) {\n case 'vertex':\n this.handle = this.props.handle || this.device.gl.createShader(GL.VERTEX_SHADER);\n break;\n case 'fragment':\n this.handle = this.props.handle || this.device.gl.createShader(GL.FRAGMENT_SHADER);\n break;\n default:\n throw new Error(this.props.stage);\n }\n this._compile(this.source);\n }\n\n override destroy(): void {\n if (this.handle) {\n this.removeStats();\n this.device.gl.deleteShader(this.handle);\n // this.handle = null;\n this.destroyed = true;\n }\n }\n\n override async getCompilationInfo(): Promise<readonly CompilerMessage[]> {\n return this.getCompilationInfoSync();\n }\n\n override getCompilationInfoSync() {\n const log = this.device.gl.getShaderInfoLog(this.handle);\n return parseShaderCompilerLog(log);\n }\n\n // PRIVATE METHODS\n\n _compile(source: string): void {\n const addGLSLVersion = (source: string) =>\n source.startsWith('#version ') ? source : `#version 100\\n${source}`;\n source = addGLSLVersion(source);\n\n const {gl} = this.device;\n gl.shaderSource(this.handle, source);\n gl.compileShader(this.handle);\n\n // TODO - For performance reasons, avoid checking shader compilation errors on production?\n // TODO - Load log even when no error reported, to catch warnings?\n // https://gamedev.stackexchange.com/questions/30429/how-to-detect-glsl-warnings\n this.compilationStatus = gl.getShaderParameter(this.handle, GL.COMPILE_STATUS) ? 'success' : 'error';\n\n // The `Shader` base class will determine if debug window should be opened based on props\n this.debugShader();\n\n if (this.compilationStatus === 'error') {\n throw new Error(`GLSL compilation errors in ${this.props.stage} shader ${this.props.id}`);\n }\n }\n}\n\n// TODO - Original code from luma.gl v8 - keep until new debug functionality has matured\n// if (!compilationSuccess) {\n// const parsedLog = shaderLog ? parseShaderCompilerLog(shaderLog) : [];\n// const messages = parsedLog.filter(message => message.type === 'error');\n// const formattedLog = formatCompilerLog(messages, source, {showSourceCode: 'all', html: true});\n// const shaderDescription = `${this.stage} shader ${shaderName}`;\n// log.error(`GLSL compilation errors in ${shaderDescription}\\n${formattedLog}`)();\n// displayShaderLog(parsedLog, source, shaderName);\n// }\n\n"],"mappings":"AAGA,SAAQA,MAAM,QAAqC,eAAe;AAAC,SAE3DC,sBAAsB;AAM9B,OAAO,MAAMC,WAAW,SAASF,MAAM,CAAC;EAItCG,WAAWA,CAACC,MAAmB,EAAEC,KAAkB,EAAE;IACnD,KAAK,CAACD,MAAM,EAAEC,KAAK,CAAC;IAAC,KAJdD,MAAM;IAAA,KACNE,MAAM;IAIb,IAAI,CAACF,MAAM,GAAGA,MAAM;IACpB,QAAQ,IAAI,CAACC,KAAK,CAACE,KAAK;MACtB,KAAK,QAAQ;QACX,IAAI,CAACD,MAAM,GAAG,IAAI,CAACD,KAAK,CAACC,MAAM,IAAI,IAAI,CAACF,MAAM,CAACI,EAAE,CAACC,YAAY,MAAiB,CAAC;QAChF;MACF,KAAK,UAAU;QACb,IAAI,CAACH,MAAM,GAAG,IAAI,CAACD,KAAK,CAACC,MAAM,IAAI,IAAI,CAACF,MAAM,CAACI,EAAE,CAACC,YAAY,MAAmB,CAAC;QAClF;MACF;QACE,MAAM,IAAIC,KAAK,CAAC,IAAI,CAACL,KAAK,CAACE,KAAK,CAAC;IACrC;IACA,IAAI,CAACI,QAAQ,CAAC,IAAI,CAACC,MAAM,CAAC;EAC5B;EAESC,OAAOA,CAAA,EAAS;IACvB,IAAI,IAAI,CAACP,MAAM,EAAE;MACf,IAAI,CAACQ,WAAW,CAAC,CAAC;MAClB,IAAI,CAACV,MAAM,CAACI,EAAE,CAACO,YAAY,CAAC,IAAI,CAACT,MAAM,CAAC;MAExC,IAAI,CAACU,SAAS,GAAG,IAAI;IACvB;EACF;EAEA,MAAeC,kBAAkBA,CAAA,EAAwC;IACvE,OAAO,IAAI,CAACC,sBAAsB,CAAC,CAAC;EACtC;EAESA,sBAAsBA,CAAA,EAAG;IAChC,MAAMC,GAAG,GAAG,IAAI,CAACf,MAAM,CAACI,EAAE,CAACY,gBAAgB,CAAC,IAAI,CAACd,MAAM,CAAC;IACxD,OAAOL,sBAAsB,CAACkB,GAAG,CAAC;EACpC;EAIAR,QAAQA,CAACC,MAAc,EAAQ;IAC7B,MAAMS,cAAc,GAAIT,MAAc,IACpCA,MAAM,CAACU,UAAU,CAAC,WAAW,CAAC,GAAGV,MAAM,GAAI,iBAAgBA,MAAO,EAAC;IACrEA,MAAM,GAAGS,cAAc,CAACT,MAAM,CAAC;IAE/B,MAAM;MAACJ;IAAE,CAAC,GAAG,IAAI,CAACJ,MAAM;IACxBI,EAAE,CAACe,YAAY,CAAC,IAAI,CAACjB,MAAM,EAAEM,MAAM,CAAC;IACpCJ,EAAE,CAACgB,aAAa,CAAC,IAAI,CAAClB,MAAM,CAAC;IAK7B,IAAI,CAACmB,iBAAiB,GAAGjB,EAAE,CAACkB,kBAAkB,CAAC,IAAI,CAACpB,MAAM,OAAmB,CAAC,GAAG,SAAS,GAAG,OAAO;IAGpG,IAAI,CAACqB,WAAW,CAAC,CAAC;IAElB,IAAI,IAAI,CAACF,iBAAiB,KAAK,OAAO,EAAE;MACtC,MAAM,IAAIf,KAAK,CAAE,8BAA6B,IAAI,CAACL,KAAK,CAACE,KAAM,WAAU,IAAI,CAACF,KAAK,CAACuB,EAAG,EAAC,CAAC;IAC3F;EACF;AACF"}
|
package/dist/dist.dev.js
CHANGED
|
@@ -1433,26 +1433,172 @@ var __exports__ = (() => {
|
|
|
1433
1433
|
__publicField(Texture, "STORAGE_BINDING", 8);
|
|
1434
1434
|
__publicField(Texture, "RENDER_ATTACHMENT", 16);
|
|
1435
1435
|
|
|
1436
|
+
// ../core/src/lib/compiler-log/format-compiler-log.ts
|
|
1437
|
+
function formatCompilerLog(shaderLog, source, options) {
|
|
1438
|
+
let formattedLog = "";
|
|
1439
|
+
const lines = source.split(/\r?\n/);
|
|
1440
|
+
const log3 = shaderLog.slice().sort((a, b) => a.lineNum - b.lineNum);
|
|
1441
|
+
switch (options?.showSourceCode || "no") {
|
|
1442
|
+
case "all":
|
|
1443
|
+
let currentMessage = 0;
|
|
1444
|
+
for (let lineNum = 1; lineNum <= lines.length; lineNum++) {
|
|
1445
|
+
formattedLog += getNumberedLine(lines[lineNum - 1], lineNum, options);
|
|
1446
|
+
while (log3.length > currentMessage && log3[currentMessage].lineNum === lineNum) {
|
|
1447
|
+
const message2 = log3[currentMessage++];
|
|
1448
|
+
formattedLog += formatCompilerMessage(message2, lines, message2.lineNum, {
|
|
1449
|
+
...options,
|
|
1450
|
+
inlineSource: false
|
|
1451
|
+
});
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
return formattedLog;
|
|
1455
|
+
case "issues":
|
|
1456
|
+
case "no":
|
|
1457
|
+
for (const message2 of shaderLog) {
|
|
1458
|
+
formattedLog += formatCompilerMessage(message2, lines, message2.lineNum, {
|
|
1459
|
+
inlineSource: options?.showSourceCode !== "no"
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1462
|
+
return formattedLog;
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
function formatCompilerMessage(message2, lines, lineNum, options) {
|
|
1466
|
+
if (options?.inlineSource) {
|
|
1467
|
+
const numberedLines = getNumberedLines(lines, lineNum);
|
|
1468
|
+
const positionIndicator = message2.linePos > 0 ? `${" ".repeat(message2.linePos + 5)}^^^
|
|
1469
|
+
` : "";
|
|
1470
|
+
return `
|
|
1471
|
+
${numberedLines}${positionIndicator}${message2.type.toUpperCase()}: ${message2.message}
|
|
1472
|
+
|
|
1473
|
+
`;
|
|
1474
|
+
}
|
|
1475
|
+
return options?.html ? `<div class='luma-compiler-log-error' style="color:red;"><b> ${message2.type.toUpperCase()}: ${message2.message}</b></div>` : `${message2.type.toUpperCase()}: ${message2.message}`;
|
|
1476
|
+
}
|
|
1477
|
+
function getNumberedLines(lines, lineNum, options) {
|
|
1478
|
+
let numberedLines = "";
|
|
1479
|
+
for (let lineIndex = lineNum - 2; lineIndex <= lineNum; lineIndex++) {
|
|
1480
|
+
const sourceLine = lines[lineIndex - 1];
|
|
1481
|
+
if (sourceLine !== void 0) {
|
|
1482
|
+
numberedLines += getNumberedLine(sourceLine, lineNum, options);
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
return numberedLines;
|
|
1486
|
+
}
|
|
1487
|
+
function getNumberedLine(line, lineNum, options) {
|
|
1488
|
+
return `${padLeft(String(lineNum), 4)}: ${line}${options?.html ? "<br/>" : "\n"}`;
|
|
1489
|
+
}
|
|
1490
|
+
function padLeft(string, paddedLength) {
|
|
1491
|
+
let result = "";
|
|
1492
|
+
for (let i = string.length; i < paddedLength; ++i) {
|
|
1493
|
+
result += " ";
|
|
1494
|
+
}
|
|
1495
|
+
return result + string;
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
// ../core/src/lib/compiler-log/get-shader-info.ts
|
|
1499
|
+
function getShaderInfo(source, defaultName) {
|
|
1500
|
+
return {
|
|
1501
|
+
name: getShaderName(source, defaultName),
|
|
1502
|
+
language: "glsl",
|
|
1503
|
+
version: getShaderVersion(source)
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1506
|
+
function getShaderName(shader, defaultName = "unnamed") {
|
|
1507
|
+
const SHADER_NAME_REGEXP = /#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/;
|
|
1508
|
+
const match = SHADER_NAME_REGEXP.exec(shader);
|
|
1509
|
+
return match ? match[1] : defaultName;
|
|
1510
|
+
}
|
|
1511
|
+
function getShaderVersion(source) {
|
|
1512
|
+
let version = 100;
|
|
1513
|
+
const words = source.match(/[^\s]+/g);
|
|
1514
|
+
if (words && words.length >= 2 && words[0] === "#version") {
|
|
1515
|
+
const v = parseInt(words[1], 10);
|
|
1516
|
+
if (Number.isFinite(v)) {
|
|
1517
|
+
version = v;
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
return version;
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1436
1523
|
// ../core/src/adapter/resources/shader.ts
|
|
1437
1524
|
var _Shader = class extends Resource {
|
|
1438
1525
|
get [Symbol.toStringTag]() {
|
|
1439
1526
|
return "Shader";
|
|
1440
1527
|
}
|
|
1528
|
+
compilationStatus = "pending";
|
|
1441
1529
|
constructor(device, props) {
|
|
1442
|
-
super(device,
|
|
1530
|
+
super(device, {
|
|
1531
|
+
id: getShaderIdFromProps(props),
|
|
1532
|
+
...props
|
|
1533
|
+
}, _Shader.defaultProps);
|
|
1443
1534
|
this.stage = this.props.stage;
|
|
1444
1535
|
this.source = this.props.source;
|
|
1445
1536
|
}
|
|
1537
|
+
getCompilationInfoSync() {
|
|
1538
|
+
return null;
|
|
1539
|
+
}
|
|
1540
|
+
async debugShader() {
|
|
1541
|
+
switch (this.props.debug) {
|
|
1542
|
+
case "never":
|
|
1543
|
+
return;
|
|
1544
|
+
case "errors":
|
|
1545
|
+
if (this.compilationStatus === "success") {
|
|
1546
|
+
return;
|
|
1547
|
+
}
|
|
1548
|
+
break;
|
|
1549
|
+
case "warnings":
|
|
1550
|
+
case "always":
|
|
1551
|
+
break;
|
|
1552
|
+
}
|
|
1553
|
+
const messages = await this.getCompilationInfo();
|
|
1554
|
+
if (this.props.debug === "warnings" && messages?.length === 0) {
|
|
1555
|
+
return;
|
|
1556
|
+
}
|
|
1557
|
+
this._displayShaderLog(messages);
|
|
1558
|
+
}
|
|
1559
|
+
_displayShaderLog(messages) {
|
|
1560
|
+
if (typeof document === "undefined" || !document?.createElement) {
|
|
1561
|
+
return;
|
|
1562
|
+
}
|
|
1563
|
+
const shaderName = getShaderInfo(this.source).name;
|
|
1564
|
+
const shaderTitle = `${this.stage} ${shaderName}`;
|
|
1565
|
+
const htmlLog = formatCompilerLog(messages, this.source, {
|
|
1566
|
+
showSourceCode: "all",
|
|
1567
|
+
html: true
|
|
1568
|
+
});
|
|
1569
|
+
const button = document.createElement("Button");
|
|
1570
|
+
button.innerHTML = `
|
|
1571
|
+
<h1>Shader Compilation Error in ${shaderTitle}</h1><br /><br />
|
|
1572
|
+
<code style="user-select:text;"><pre>
|
|
1573
|
+
${htmlLog}
|
|
1574
|
+
</pre></code>`;
|
|
1575
|
+
button.style.top = "10px";
|
|
1576
|
+
button.style.left = "10px";
|
|
1577
|
+
button.style.position = "absolute";
|
|
1578
|
+
button.style.zIndex = "9999";
|
|
1579
|
+
button.style.width = "100%";
|
|
1580
|
+
button.style.textAlign = "left";
|
|
1581
|
+
document.body.appendChild(button);
|
|
1582
|
+
document.getElementsByClassName("luma-compiler-log-error")[0]?.scrollIntoView();
|
|
1583
|
+
button.onclick = () => {
|
|
1584
|
+
const dataURI = `data:text/plain,${encodeURIComponent(this.source)}`;
|
|
1585
|
+
navigator.clipboard.writeText(dataURI);
|
|
1586
|
+
};
|
|
1587
|
+
}
|
|
1446
1588
|
};
|
|
1447
1589
|
var Shader = _Shader;
|
|
1448
1590
|
__publicField(Shader, "defaultProps", {
|
|
1449
1591
|
...Resource.defaultProps,
|
|
1592
|
+
language: "auto",
|
|
1450
1593
|
stage: "vertex",
|
|
1451
1594
|
source: "",
|
|
1452
1595
|
sourceMap: null,
|
|
1453
|
-
|
|
1454
|
-
|
|
1596
|
+
entryPoint: "main",
|
|
1597
|
+
debug: "errors"
|
|
1455
1598
|
});
|
|
1599
|
+
function getShaderIdFromProps(props) {
|
|
1600
|
+
return getShaderInfo(props.source).name || props.id || uid(`unnamed ${props.stage}-shader`);
|
|
1601
|
+
}
|
|
1456
1602
|
|
|
1457
1603
|
// ../core/src/adapter/resources/sampler.ts
|
|
1458
1604
|
var _Sampler = class extends Resource {
|
|
@@ -2098,46 +2244,6 @@ var __exports__ = (() => {
|
|
|
2098
2244
|
};
|
|
2099
2245
|
}
|
|
2100
2246
|
|
|
2101
|
-
// ../core/src/lib/compiler-log/format-compiler-log.ts
|
|
2102
|
-
function formatCompilerLog(shaderLog, source, options) {
|
|
2103
|
-
const lines = source.split(/\r?\n/);
|
|
2104
|
-
let formattedLog = "";
|
|
2105
|
-
for (const message2 of shaderLog) {
|
|
2106
|
-
formattedLog += formatCompilerMessage(message2, lines, message2.lineNum, options);
|
|
2107
|
-
}
|
|
2108
|
-
return formattedLog;
|
|
2109
|
-
}
|
|
2110
|
-
function formatCompilerMessage(message2, lines, lineNum, options) {
|
|
2111
|
-
if (options?.showSourceCode) {
|
|
2112
|
-
const positionIndicator = message2.linePos > 0 ? `${" ".repeat(message2.linePos + 5)}^^^
|
|
2113
|
-
` : "";
|
|
2114
|
-
const numberedLines = getNumberedLines(lines, lineNum);
|
|
2115
|
-
return `${numberedLines}${positionIndicator}${message2.type.toUpperCase()}: ${message2.message}
|
|
2116
|
-
|
|
2117
|
-
`;
|
|
2118
|
-
}
|
|
2119
|
-
return `${message2.type.toUpperCase()}: ${message2.message}
|
|
2120
|
-
`;
|
|
2121
|
-
}
|
|
2122
|
-
function getNumberedLines(lines, lineNum) {
|
|
2123
|
-
let numberedLines = "";
|
|
2124
|
-
for (let line = lineNum - 2; line <= lineNum; line++) {
|
|
2125
|
-
const sourceLine = lines[line];
|
|
2126
|
-
if (sourceLine !== void 0) {
|
|
2127
|
-
numberedLines += `${padLeft(String(line), 4)}: ${sourceLine}
|
|
2128
|
-
`;
|
|
2129
|
-
}
|
|
2130
|
-
}
|
|
2131
|
-
return numberedLines;
|
|
2132
|
-
}
|
|
2133
|
-
function padLeft(string, paddedLength) {
|
|
2134
|
-
let result = "";
|
|
2135
|
-
for (let i = string.length; i < paddedLength; ++i) {
|
|
2136
|
-
result += " ";
|
|
2137
|
-
}
|
|
2138
|
-
return result + string;
|
|
2139
|
-
}
|
|
2140
|
-
|
|
2141
2247
|
// ../core/src/lib/utils/cast.ts
|
|
2142
2248
|
function cast(value) {
|
|
2143
2249
|
return value;
|
|
@@ -6406,31 +6512,6 @@ void main(void) {}`;
|
|
|
6406
6512
|
}
|
|
6407
6513
|
}
|
|
6408
6514
|
|
|
6409
|
-
// src/adapter/helpers/get-shader-info.ts
|
|
6410
|
-
function getShaderInfo(source, defaultName) {
|
|
6411
|
-
return {
|
|
6412
|
-
name: getShaderName(source, defaultName),
|
|
6413
|
-
language: "glsl",
|
|
6414
|
-
version: getShaderVersion(source)
|
|
6415
|
-
};
|
|
6416
|
-
}
|
|
6417
|
-
function getShaderName(shader, defaultName = "unnamed") {
|
|
6418
|
-
const SHADER_NAME_REGEXP = /#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/;
|
|
6419
|
-
const match = SHADER_NAME_REGEXP.exec(shader);
|
|
6420
|
-
return match ? match[1] : defaultName;
|
|
6421
|
-
}
|
|
6422
|
-
function getShaderVersion(source) {
|
|
6423
|
-
let version = 100;
|
|
6424
|
-
const words = source.match(/[^\s]+/g);
|
|
6425
|
-
if (words && words.length >= 2 && words[0] === "#version") {
|
|
6426
|
-
const v = parseInt(words[1], 10);
|
|
6427
|
-
if (Number.isFinite(v)) {
|
|
6428
|
-
version = v;
|
|
6429
|
-
}
|
|
6430
|
-
}
|
|
6431
|
-
return version;
|
|
6432
|
-
}
|
|
6433
|
-
|
|
6434
6515
|
// src/adapter/helpers/parse-shader-compiler-log.ts
|
|
6435
6516
|
function parseShaderCompilerLog(errLog) {
|
|
6436
6517
|
const lines = errLog.split(/\r?\n/);
|
|
@@ -6477,10 +6558,7 @@ void main(void) {}`;
|
|
|
6477
6558
|
// src/adapter/resources/webgl-shader.ts
|
|
6478
6559
|
var WEBGLShader = class extends Shader {
|
|
6479
6560
|
constructor(device, props) {
|
|
6480
|
-
super(device,
|
|
6481
|
-
id: getShaderIdFromProps(props),
|
|
6482
|
-
...props
|
|
6483
|
-
});
|
|
6561
|
+
super(device, props);
|
|
6484
6562
|
this.device = device;
|
|
6485
6563
|
switch (this.props.stage) {
|
|
6486
6564
|
case "vertex":
|
|
@@ -6501,9 +6579,12 @@ void main(void) {}`;
|
|
|
6501
6579
|
this.destroyed = true;
|
|
6502
6580
|
}
|
|
6503
6581
|
}
|
|
6504
|
-
async
|
|
6582
|
+
async getCompilationInfo() {
|
|
6583
|
+
return this.getCompilationInfoSync();
|
|
6584
|
+
}
|
|
6585
|
+
getCompilationInfoSync() {
|
|
6505
6586
|
const log3 = this.device.gl.getShaderInfoLog(this.handle);
|
|
6506
|
-
return
|
|
6587
|
+
return parseShaderCompilerLog(log3);
|
|
6507
6588
|
}
|
|
6508
6589
|
_compile(source) {
|
|
6509
6590
|
const addGLSLVersion = (source2) => source2.startsWith("#version ") ? source2 : `#version 100
|
|
@@ -6514,25 +6595,13 @@ ${source2}`;
|
|
|
6514
6595
|
} = this.device;
|
|
6515
6596
|
gl.shaderSource(this.handle, source);
|
|
6516
6597
|
gl.compileShader(this.handle);
|
|
6517
|
-
|
|
6518
|
-
|
|
6519
|
-
|
|
6520
|
-
|
|
6521
|
-
const messages = parsedLog.filter((message2) => message2.type === "error");
|
|
6522
|
-
const formattedLog = formatCompilerLog(messages, source, {
|
|
6523
|
-
showSourceCode: true
|
|
6524
|
-
});
|
|
6525
|
-
const shaderName = getShaderInfo(source).name;
|
|
6526
|
-
const shaderDescription = `${this.stage} shader ${shaderName}`;
|
|
6527
|
-
log.error(`GLSL compilation errors in ${shaderDescription}
|
|
6528
|
-
${formattedLog}`)();
|
|
6529
|
-
throw new Error(`GLSL compilation errors in ${shaderName}`);
|
|
6598
|
+
this.compilationStatus = gl.getShaderParameter(this.handle, 35713) ? "success" : "error";
|
|
6599
|
+
this.debugShader();
|
|
6600
|
+
if (this.compilationStatus === "error") {
|
|
6601
|
+
throw new Error(`GLSL compilation errors in ${this.props.stage} shader ${this.props.id}`);
|
|
6530
6602
|
}
|
|
6531
6603
|
}
|
|
6532
6604
|
};
|
|
6533
|
-
function getShaderIdFromProps(props) {
|
|
6534
|
-
return getShaderInfo(props.source).name || props.id || uid(`unnamed ${props.stage}-shader`);
|
|
6535
|
-
}
|
|
6536
6605
|
|
|
6537
6606
|
// src/adapter/resources/webgl-render-pass.ts
|
|
6538
6607
|
var GL_DEPTH_BUFFER_BIT = 256;
|
package/dist/index.cjs
CHANGED
|
@@ -1331,13 +1331,13 @@ var GLState = class {
|
|
|
1331
1331
|
constructor(gl, {
|
|
1332
1332
|
copyState = false,
|
|
1333
1333
|
// Copy cache from params (slow) or initialize from WebGL defaults (fast)
|
|
1334
|
-
log:
|
|
1334
|
+
log: log9 = () => {
|
|
1335
1335
|
}
|
|
1336
1336
|
// Logging function, called when gl parameter change calls are actually issued
|
|
1337
1337
|
} = {}) {
|
|
1338
1338
|
this.gl = gl;
|
|
1339
1339
|
this.cache = copyState ? getGLParameters(gl) : Object.assign({}, GL_PARAMETER_DEFAULTS);
|
|
1340
|
-
this.log =
|
|
1340
|
+
this.log = log9;
|
|
1341
1341
|
this._updateCache = this._updateCache.bind(this);
|
|
1342
1342
|
Object.seal(this);
|
|
1343
1343
|
}
|
|
@@ -4155,31 +4155,6 @@ function onValidateGLFunc(props, functionName, functionArgs) {
|
|
|
4155
4155
|
var import_core18 = require("@luma.gl/core");
|
|
4156
4156
|
var import_constants16 = require("@luma.gl/constants");
|
|
4157
4157
|
|
|
4158
|
-
// src/adapter/helpers/get-shader-info.ts
|
|
4159
|
-
function getShaderInfo(source, defaultName) {
|
|
4160
|
-
return {
|
|
4161
|
-
name: getShaderName(source, defaultName),
|
|
4162
|
-
language: "glsl",
|
|
4163
|
-
version: getShaderVersion(source)
|
|
4164
|
-
};
|
|
4165
|
-
}
|
|
4166
|
-
function getShaderName(shader, defaultName = "unnamed") {
|
|
4167
|
-
const SHADER_NAME_REGEXP = /#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/;
|
|
4168
|
-
const match = SHADER_NAME_REGEXP.exec(shader);
|
|
4169
|
-
return match ? match[1] : defaultName;
|
|
4170
|
-
}
|
|
4171
|
-
function getShaderVersion(source) {
|
|
4172
|
-
let version = 100;
|
|
4173
|
-
const words = source.match(/[^\s]+/g);
|
|
4174
|
-
if (words && words.length >= 2 && words[0] === "#version") {
|
|
4175
|
-
const v = parseInt(words[1], 10);
|
|
4176
|
-
if (Number.isFinite(v)) {
|
|
4177
|
-
version = v;
|
|
4178
|
-
}
|
|
4179
|
-
}
|
|
4180
|
-
return version;
|
|
4181
|
-
}
|
|
4182
|
-
|
|
4183
4158
|
// src/adapter/helpers/parse-shader-compiler-log.ts
|
|
4184
4159
|
function parseShaderCompilerLog(errLog) {
|
|
4185
4160
|
const lines = errLog.split(/\r?\n/);
|
|
@@ -4229,7 +4204,7 @@ var WEBGLShader = class extends import_core18.Shader {
|
|
|
4229
4204
|
device;
|
|
4230
4205
|
handle;
|
|
4231
4206
|
constructor(device, props) {
|
|
4232
|
-
super(device,
|
|
4207
|
+
super(device, props);
|
|
4233
4208
|
this.device = device;
|
|
4234
4209
|
switch (this.props.stage) {
|
|
4235
4210
|
case "vertex":
|
|
@@ -4250,9 +4225,12 @@ var WEBGLShader = class extends import_core18.Shader {
|
|
|
4250
4225
|
this.destroyed = true;
|
|
4251
4226
|
}
|
|
4252
4227
|
}
|
|
4253
|
-
async
|
|
4254
|
-
|
|
4255
|
-
|
|
4228
|
+
async getCompilationInfo() {
|
|
4229
|
+
return this.getCompilationInfoSync();
|
|
4230
|
+
}
|
|
4231
|
+
getCompilationInfoSync() {
|
|
4232
|
+
const log9 = this.device.gl.getShaderInfoLog(this.handle);
|
|
4233
|
+
return parseShaderCompilerLog(log9);
|
|
4256
4234
|
}
|
|
4257
4235
|
// PRIVATE METHODS
|
|
4258
4236
|
_compile(source) {
|
|
@@ -4262,23 +4240,13 @@ ${source2}`;
|
|
|
4262
4240
|
const { gl } = this.device;
|
|
4263
4241
|
gl.shaderSource(this.handle, source);
|
|
4264
4242
|
gl.compileShader(this.handle);
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
const messages = parsedLog.filter((message2) => message2.type === "error");
|
|
4270
|
-
const formattedLog = (0, import_core18.formatCompilerLog)(messages, source, { showSourceCode: true });
|
|
4271
|
-
const shaderName = getShaderInfo(source).name;
|
|
4272
|
-
const shaderDescription = `${this.stage} shader ${shaderName}`;
|
|
4273
|
-
import_core18.log.error(`GLSL compilation errors in ${shaderDescription}
|
|
4274
|
-
${formattedLog}`)();
|
|
4275
|
-
throw new Error(`GLSL compilation errors in ${shaderName}`);
|
|
4243
|
+
this.compilationStatus = gl.getShaderParameter(this.handle, import_constants16.GL.COMPILE_STATUS) ? "success" : "error";
|
|
4244
|
+
this.debugShader();
|
|
4245
|
+
if (this.compilationStatus === "error") {
|
|
4246
|
+
throw new Error(`GLSL compilation errors in ${this.props.stage} shader ${this.props.id}`);
|
|
4276
4247
|
}
|
|
4277
4248
|
}
|
|
4278
4249
|
};
|
|
4279
|
-
function getShaderIdFromProps(props) {
|
|
4280
|
-
return getShaderInfo(props.source).name || props.id || (0, import_core18.uid)(`unnamed ${props.stage}-shader`);
|
|
4281
|
-
}
|
|
4282
4250
|
|
|
4283
4251
|
// src/adapter/resources/webgl-render-pass.ts
|
|
4284
4252
|
var import_core19 = require("@luma.gl/core");
|