@shaderfrog/core 1.3.0 → 1.3.2
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/package.json +10 -7
- package/cjs/engine.js +0 -218
- package/cjs/graph/base-node.js +0 -13
- package/cjs/graph/code-nodes.js +0 -23
- package/cjs/graph/context.js +0 -253
- package/cjs/graph/data-nodes.js +0 -146
- package/cjs/graph/edge.js +0 -12
- package/cjs/graph/evaluate.js +0 -32
- package/cjs/graph/graph-node.js +0 -143
- package/cjs/graph/graph-types.js +0 -25
- package/cjs/graph/graph.js +0 -533
- package/cjs/graph/graph.test.js +0 -173
- package/cjs/graph/index.js +0 -27
- package/cjs/graph/parsers.js +0 -219
- package/cjs/graph/shader-sections.js +0 -268
- package/cjs/index.js +0 -19
- package/cjs/package.json +0 -1
- package/cjs/plugins/babylon/bablyengine.js +0 -597
- package/cjs/plugins/babylon/importers.js +0 -66
- package/cjs/plugins/babylon/index.js +0 -5
- package/cjs/plugins/playcanvas/importers.js +0 -30
- package/cjs/plugins/playcanvas/index.js +0 -5
- package/cjs/plugins/playcanvas/playengine.js +0 -549
- package/cjs/plugins/three/importers.js +0 -17
- package/cjs/plugins/three/index.js +0 -6
- package/cjs/plugins/three/threngine.js +0 -619
- package/cjs/strategy/assignemntTo.js +0 -31
- package/cjs/strategy/declarationOf.js +0 -28
- package/cjs/strategy/hardCode.js +0 -28
- package/cjs/strategy/index.js +0 -25
- package/cjs/strategy/inject.js +0 -127
- package/cjs/strategy/namedAttribute.js +0 -53
- package/cjs/strategy/strategy.js +0 -35
- package/cjs/strategy/stratgies.test.js +0 -192
- package/cjs/strategy/texture2D.js +0 -88
- package/cjs/strategy/uniform.js +0 -195
- package/cjs/strategy/variable.js +0 -85
- package/cjs/util/ast.js +0 -351
- package/cjs/util/ensure.js +0 -11
- package/cjs/util/id.js +0 -6
- package/esm/engine.d.ts +0 -69
- package/esm/graph/base-node.d.ts +0 -36
- package/esm/graph/code-nodes.d.ts +0 -44
- package/esm/graph/context.d.ts +0 -37
- package/esm/graph/data-nodes.d.ts +0 -83
- package/esm/graph/edge.d.ts +0 -13
- package/esm/graph/evaluate.d.ts +0 -9
- package/esm/graph/graph-node.d.ts +0 -8
- package/esm/graph/graph-types.d.ts +0 -38
- package/esm/graph/graph.d.ts +0 -89
- package/esm/graph/graph.test.d.ts +0 -1
- package/esm/graph/index.d.ts +0 -11
- package/esm/graph/parsers.d.ts +0 -39
- package/esm/graph/shader-sections.d.ts +0 -47
- package/esm/index.d.ts +0 -3
- package/esm/package.json +0 -1
- package/esm/plugins/babylon/bablyengine.d.ts +0 -28
- package/esm/plugins/babylon/importers.d.ts +0 -3
- package/esm/plugins/babylon/index.d.ts +0 -2
- package/esm/plugins/playcanvas/importers.d.ts +0 -3
- package/esm/plugins/playcanvas/index.d.ts +0 -2
- package/esm/plugins/playcanvas/playengine.d.ts +0 -39
- package/esm/plugins/three/importers.d.ts +0 -3
- package/esm/plugins/three/index.d.ts +0 -2
- package/esm/plugins/three/threngine.d.ts +0 -34
- package/esm/strategy/assignemntTo.d.ts +0 -9
- package/esm/strategy/declarationOf.d.ts +0 -9
- package/esm/strategy/hardCode.d.ts +0 -15
- package/esm/strategy/index.d.ts +0 -9
- package/esm/strategy/inject.d.ts +0 -15
- package/esm/strategy/namedAttribute.d.ts +0 -9
- package/esm/strategy/strategy.d.ts +0 -28
- package/esm/strategy/stratgies.test.d.ts +0 -1
- package/esm/strategy/texture2D.d.ts +0 -6
- package/esm/strategy/uniform.d.ts +0 -6
- package/esm/strategy/variable.d.ts +0 -6
- package/esm/util/ast.d.ts +0 -30
- package/esm/util/ensure.d.ts +0 -1
- package/esm/util/id.d.ts +0 -1
- /package/{cjs/engine.d.ts → engine.d.ts} +0 -0
- /package/{esm/engine.js → engine.js} +0 -0
- /package/{cjs/graph → graph}/base-node.d.ts +0 -0
- /package/{esm/graph → graph}/base-node.js +0 -0
- /package/{cjs/graph → graph}/code-nodes.d.ts +0 -0
- /package/{esm/graph → graph}/code-nodes.js +0 -0
- /package/{cjs/graph → graph}/context.d.ts +0 -0
- /package/{esm/graph → graph}/context.js +0 -0
- /package/{cjs/graph → graph}/data-nodes.d.ts +0 -0
- /package/{esm/graph → graph}/data-nodes.js +0 -0
- /package/{cjs/graph → graph}/edge.d.ts +0 -0
- /package/{esm/graph → graph}/edge.js +0 -0
- /package/{cjs/graph → graph}/evaluate.d.ts +0 -0
- /package/{esm/graph → graph}/evaluate.js +0 -0
- /package/{cjs/graph → graph}/graph-node.d.ts +0 -0
- /package/{esm/graph → graph}/graph-node.js +0 -0
- /package/{cjs/graph → graph}/graph-types.d.ts +0 -0
- /package/{esm/graph → graph}/graph-types.js +0 -0
- /package/{cjs/graph → graph}/graph.d.ts +0 -0
- /package/{esm/graph → graph}/graph.js +0 -0
- /package/{cjs/graph → graph}/graph.test.d.ts +0 -0
- /package/{esm/graph → graph}/graph.test.js +0 -0
- /package/{cjs/graph → graph}/index.d.ts +0 -0
- /package/{esm/graph → graph}/index.js +0 -0
- /package/{cjs/graph → graph}/parsers.d.ts +0 -0
- /package/{esm/graph → graph}/parsers.js +0 -0
- /package/{cjs/graph → graph}/shader-sections.d.ts +0 -0
- /package/{esm/graph → graph}/shader-sections.js +0 -0
- /package/{cjs/index.d.ts → index.d.ts} +0 -0
- /package/{esm/index.js → index.js} +0 -0
- /package/{cjs/plugins → plugins}/babylon/bablyengine.d.ts +0 -0
- /package/{esm/plugins → plugins}/babylon/bablyengine.js +0 -0
- /package/{cjs/plugins → plugins}/babylon/importers.d.ts +0 -0
- /package/{esm/plugins → plugins}/babylon/importers.js +0 -0
- /package/{cjs/plugins → plugins}/babylon/index.d.ts +0 -0
- /package/{esm/plugins → plugins}/babylon/index.js +0 -0
- /package/{cjs/plugins → plugins}/playcanvas/importers.d.ts +0 -0
- /package/{esm/plugins → plugins}/playcanvas/importers.js +0 -0
- /package/{cjs/plugins → plugins}/playcanvas/index.d.ts +0 -0
- /package/{esm/plugins → plugins}/playcanvas/index.js +0 -0
- /package/{cjs/plugins → plugins}/playcanvas/playengine.d.ts +0 -0
- /package/{esm/plugins → plugins}/playcanvas/playengine.js +0 -0
- /package/{cjs/plugins → plugins}/three/importers.d.ts +0 -0
- /package/{esm/plugins → plugins}/three/importers.js +0 -0
- /package/{cjs/plugins → plugins}/three/index.d.ts +0 -0
- /package/{esm/plugins → plugins}/three/index.js +0 -0
- /package/{cjs/plugins → plugins}/three/threngine.d.ts +0 -0
- /package/{esm/plugins → plugins}/three/threngine.js +0 -0
- /package/{cjs/strategy → strategy}/assignemntTo.d.ts +0 -0
- /package/{esm/strategy → strategy}/assignemntTo.js +0 -0
- /package/{cjs/strategy → strategy}/declarationOf.d.ts +0 -0
- /package/{esm/strategy → strategy}/declarationOf.js +0 -0
- /package/{cjs/strategy → strategy}/hardCode.d.ts +0 -0
- /package/{esm/strategy → strategy}/hardCode.js +0 -0
- /package/{cjs/strategy → strategy}/index.d.ts +0 -0
- /package/{esm/strategy → strategy}/index.js +0 -0
- /package/{cjs/strategy → strategy}/inject.d.ts +0 -0
- /package/{esm/strategy → strategy}/inject.js +0 -0
- /package/{cjs/strategy → strategy}/namedAttribute.d.ts +0 -0
- /package/{esm/strategy → strategy}/namedAttribute.js +0 -0
- /package/{cjs/strategy → strategy}/strategy.d.ts +0 -0
- /package/{esm/strategy → strategy}/strategy.js +0 -0
- /package/{cjs/strategy → strategy}/stratgies.test.d.ts +0 -0
- /package/{esm/strategy → strategy}/stratgies.test.js +0 -0
- /package/{cjs/strategy → strategy}/texture2D.d.ts +0 -0
- /package/{esm/strategy → strategy}/texture2D.js +0 -0
- /package/{cjs/strategy → strategy}/uniform.d.ts +0 -0
- /package/{esm/strategy → strategy}/uniform.js +0 -0
- /package/{cjs/strategy → strategy}/variable.d.ts +0 -0
- /package/{esm/strategy → strategy}/variable.js +0 -0
- /package/{cjs/util → util}/ast.d.ts +0 -0
- /package/{esm/util → util}/ast.js +0 -0
- /package/{cjs/util → util}/ensure.d.ts +0 -0
- /package/{esm/util → util}/ensure.js +0 -0
- /package/{cjs/util → util}/id.d.ts +0 -0
- /package/{esm/util → util}/id.js +0 -0
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
-
if (ar || !(i in from)) {
|
|
32
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
-
ar[i] = from[i];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.findShaderSections = exports.shaderSectionsToProgram = exports.mergeShaderSections = exports.dedupeUniforms = exports.dedupeQualifiedStatements = exports.highestPrecisions = exports.dedupeVersions = exports.higherPrecision = exports.emptyShaderSections = void 0;
|
|
40
|
-
var glsl_parser_1 = require("@shaderfrog/glsl-parser");
|
|
41
|
-
var ast_1 = require("../util/ast");
|
|
42
|
-
var emptyShaderSections = function () { return ({
|
|
43
|
-
precision: [],
|
|
44
|
-
preprocessor: [],
|
|
45
|
-
version: [],
|
|
46
|
-
structs: [],
|
|
47
|
-
program: [],
|
|
48
|
-
inStatements: [],
|
|
49
|
-
outStatements: [],
|
|
50
|
-
uniforms: [],
|
|
51
|
-
}); };
|
|
52
|
-
exports.emptyShaderSections = emptyShaderSections;
|
|
53
|
-
var Precision;
|
|
54
|
-
(function (Precision) {
|
|
55
|
-
Precision[Precision["highp"] = 2] = "highp";
|
|
56
|
-
Precision[Precision["mediump"] = 1] = "mediump";
|
|
57
|
-
Precision[Precision["lowp"] = 0] = "lowp";
|
|
58
|
-
})(Precision || (Precision = {}));
|
|
59
|
-
var higherPrecision = function (p1, p2) {
|
|
60
|
-
return Precision[p1] > Precision[p2] ? p1 : p2;
|
|
61
|
-
};
|
|
62
|
-
exports.higherPrecision = higherPrecision;
|
|
63
|
-
var dedupeVersions = function (nodes) { return nodes[0]; };
|
|
64
|
-
exports.dedupeVersions = dedupeVersions;
|
|
65
|
-
var highestPrecisions = function (nodes) {
|
|
66
|
-
return Object.entries(nodes.reduce(function (precisions, stmt) {
|
|
67
|
-
var _a;
|
|
68
|
-
return (__assign(__assign({}, precisions), (_a = {}, _a[stmt.declaration.specifier.specifier.token] = (0, exports.higherPrecision)(precisions[stmt.declaration.specifier.specifier.token], stmt.declaration.qualifier.token), _a)));
|
|
69
|
-
}, {})).map(function (_a) {
|
|
70
|
-
var _b = __read(_a, 2), typeName = _b[0], precision = _b[1];
|
|
71
|
-
return (0, ast_1.makeStatement)("precision ".concat(precision, " ").concat(typeName));
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
exports.highestPrecisions = highestPrecisions;
|
|
75
|
-
var dedupeQualifiedStatements = function (statements, qualifier) {
|
|
76
|
-
return Object.entries(statements.reduce(function (stmts, stmt) {
|
|
77
|
-
var _a;
|
|
78
|
-
return (__assign(__assign({}, stmts), (_a = {}, _a[stmt.declaration.specified_type.specifier.specifier.token] = __assign(__assign({}, (stmts[stmt.declaration.specified_type.specifier.specifier.token] || {})), stmt.declaration.declarations.reduce(function (types, decl) {
|
|
79
|
-
var _a;
|
|
80
|
-
return (__assign(__assign({}, types), (_a = {}, _a[decl.identifier.identifier] = true, _a)));
|
|
81
|
-
}, {})), _a)));
|
|
82
|
-
}, {})).map(function (_a) {
|
|
83
|
-
var _b = __read(_a, 2), type = _b[0], varNames = _b[1];
|
|
84
|
-
return (0, ast_1.makeStatement)("".concat(qualifier, " ").concat(type, " ").concat(Object.keys(varNames).join(', ')));
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
exports.dedupeQualifiedStatements = dedupeQualifiedStatements;
|
|
88
|
-
/**
|
|
89
|
-
* Merge uniforms together into lists of identifiers under the same type.
|
|
90
|
-
* There's special case handling for mixing of uniforms with "interface blocks"
|
|
91
|
-
* and those without when merging to make sure the interface block definition is
|
|
92
|
-
* preserved. Check out the tests for more.
|
|
93
|
-
*
|
|
94
|
-
* This function consumes uniforms as found by findShaderSections, so the
|
|
95
|
-
* definitions must line up
|
|
96
|
-
*/
|
|
97
|
-
var dedupeUniforms = function (statements) {
|
|
98
|
-
var groupedByTypeName = Object.entries(statements.reduce(function (stmts, stmt) {
|
|
99
|
-
var _a, _b, _c;
|
|
100
|
-
var _d;
|
|
101
|
-
var decl = stmt.declaration;
|
|
102
|
-
// This is the standard case, a uniform like "uniform vec2 x"
|
|
103
|
-
if ('specified_type' in decl) {
|
|
104
|
-
var specified_type = decl.specified_type;
|
|
105
|
-
var specifier = specified_type.specifier.specifier;
|
|
106
|
-
// Token is for "vec2", "identifier" is for custom names like struct
|
|
107
|
-
var type_1 = 'token' in specifier
|
|
108
|
-
? specifier.token
|
|
109
|
-
: 'identifier' in specifier
|
|
110
|
-
? specifier.identifier
|
|
111
|
-
: undefined;
|
|
112
|
-
if (!type_1) {
|
|
113
|
-
console.error('Unknown statement: ', stmt);
|
|
114
|
-
throw new Error("Unknown specifier: ".concat(specifier.type));
|
|
115
|
-
}
|
|
116
|
-
// Groups uniforms into their return type, and for each type, collapses
|
|
117
|
-
// uniform names into an object where the keys determine uniqueness
|
|
118
|
-
// "vec2": { x: x[1] }
|
|
119
|
-
var grouped = decl.declarations.reduce(function (types, decl) {
|
|
120
|
-
var _a;
|
|
121
|
-
var _b, _c, _d;
|
|
122
|
-
var identifier = decl.identifier;
|
|
123
|
-
var quantifier = '';
|
|
124
|
-
if (decl.quantifier) {
|
|
125
|
-
if (!('token' in decl.quantifier[0].expression)) {
|
|
126
|
-
console.error('Unknown expression in quantifier: ', decl);
|
|
127
|
-
throw new Error("Unknown expression in quantifier: ".concat((0, glsl_parser_1.generate)(decl)));
|
|
128
|
-
}
|
|
129
|
-
quantifier = "[".concat(decl.quantifier[0].expression.token, "]");
|
|
130
|
-
}
|
|
131
|
-
return __assign(__assign({}, types), (_a = {}, _a[identifier.identifier] = ((_c = (_b = stmts[type_1]) === null || _b === void 0 ? void 0 : _b[identifier.identifier]) === null || _c === void 0 ? void 0 : _c.hasInterface)
|
|
132
|
-
? (_d = stmts[type_1]) === null || _d === void 0 ? void 0 : _d[identifier.identifier]
|
|
133
|
-
: {
|
|
134
|
-
hasInterface: false,
|
|
135
|
-
generated: identifier.identifier + quantifier,
|
|
136
|
-
}, _a));
|
|
137
|
-
}, {});
|
|
138
|
-
return __assign(__assign({}, stmts), (_a = {}, _a[type_1] = __assign(__assign({}, (stmts[type_1] || {})), grouped), _a));
|
|
139
|
-
// This is the less common case, a uniform like "uniform Light { vec3 position; } name"
|
|
140
|
-
}
|
|
141
|
-
else if ('interface_type' in decl) {
|
|
142
|
-
var interface_type = decl.interface_type, identifier = decl.identifier;
|
|
143
|
-
// If this is an interface block only, like uniform Scene { mat4 view; };
|
|
144
|
-
// then group the interface block declaration under ''
|
|
145
|
-
var interfaceDeclaredUniform = ((_d = identifier === null || identifier === void 0 ? void 0 : identifier.identifier) === null || _d === void 0 ? void 0 : _d.identifier) || '';
|
|
146
|
-
var node = {
|
|
147
|
-
type: 'interface_declarator',
|
|
148
|
-
lp: decl.lp,
|
|
149
|
-
declarations: decl.declarations,
|
|
150
|
-
qualifiers: [],
|
|
151
|
-
// This is non-nullable, to produce "X" in "uniform X { ... } varName"
|
|
152
|
-
// But it appears "X" is in declarations above
|
|
153
|
-
interface_type: {
|
|
154
|
-
type: 'identifier',
|
|
155
|
-
identifier: '',
|
|
156
|
-
whitespace: '',
|
|
157
|
-
},
|
|
158
|
-
rp: decl.rp,
|
|
159
|
-
};
|
|
160
|
-
return __assign(__assign({}, stmts), (_b = {}, _b[interface_type.identifier] = (_c = {},
|
|
161
|
-
_c[interfaceDeclaredUniform] = {
|
|
162
|
-
generated: "".concat((0, glsl_parser_1.generate)(node)).concat(interfaceDeclaredUniform),
|
|
163
|
-
hasInterface: true,
|
|
164
|
-
},
|
|
165
|
-
_c), _b));
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
console.error('Unknown uniform AST', { stmt: stmt, code: (0, glsl_parser_1.generate)(stmt) });
|
|
169
|
-
throw new Error('Unknown uniform AST encountered when merging uniforms');
|
|
170
|
-
}
|
|
171
|
-
}, {}));
|
|
172
|
-
return groupedByTypeName.map(function (_a) {
|
|
173
|
-
var _b = __read(_a, 2), type = _b[0], variables = _b[1];
|
|
174
|
-
return (0, ast_1.makeStatement)("uniform ".concat(type, " ").concat(Object.values(variables)
|
|
175
|
-
.map(function (v) { return v.generated; })
|
|
176
|
-
.join(', ')));
|
|
177
|
-
});
|
|
178
|
-
};
|
|
179
|
-
exports.dedupeUniforms = dedupeUniforms;
|
|
180
|
-
var mergeShaderSections = function (s1, s2) {
|
|
181
|
-
return {
|
|
182
|
-
version: __spreadArray(__spreadArray([], __read(s1.version), false), __read(s2.version), false),
|
|
183
|
-
precision: __spreadArray(__spreadArray([], __read(s1.precision), false), __read(s2.precision), false),
|
|
184
|
-
preprocessor: __spreadArray(__spreadArray([], __read(s1.preprocessor), false), __read(s2.preprocessor), false),
|
|
185
|
-
inStatements: __spreadArray(__spreadArray([], __read(s1.inStatements), false), __read(s2.inStatements), false),
|
|
186
|
-
outStatements: __spreadArray(__spreadArray([], __read(s1.outStatements), false), __read(s2.outStatements), false),
|
|
187
|
-
structs: __spreadArray(__spreadArray([], __read(s1.structs), false), __read(s2.structs), false),
|
|
188
|
-
uniforms: __spreadArray(__spreadArray([], __read(s1.uniforms), false), __read(s2.uniforms), false),
|
|
189
|
-
program: __spreadArray(__spreadArray([], __read(s1.program), false), __read(s2.program), false),
|
|
190
|
-
};
|
|
191
|
-
};
|
|
192
|
-
exports.mergeShaderSections = mergeShaderSections;
|
|
193
|
-
var shaderSectionsToProgram = function (sections, mergeOptions) { return ({
|
|
194
|
-
type: 'program',
|
|
195
|
-
scopes: [],
|
|
196
|
-
program: __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read((mergeOptions.includeVersion ? [(0, exports.dedupeVersions)(sections.version)] : [])), false), __read((mergeOptions.includePrecisions
|
|
197
|
-
? (0, exports.highestPrecisions)(sections.precision)
|
|
198
|
-
: [])), false), __read(sections.preprocessor), false), __read(sections.structs), false), __read((0, exports.dedupeQualifiedStatements)(sections.inStatements, 'in')), false), __read((0, exports.dedupeQualifiedStatements)(sections.outStatements, 'out')), false), __read((0, exports.dedupeUniforms)(sections.uniforms)), false), __read(sections.program), false),
|
|
199
|
-
}); };
|
|
200
|
-
exports.shaderSectionsToProgram = shaderSectionsToProgram;
|
|
201
|
-
/**
|
|
202
|
-
* Group an AST into logical sections. The output of this funciton is consumed
|
|
203
|
-
* by the dedupe methods, namely dedupeUniforms, so the data shapes are coupled
|
|
204
|
-
*/
|
|
205
|
-
var findShaderSections = function (ast) {
|
|
206
|
-
var initialValue = {
|
|
207
|
-
precision: [],
|
|
208
|
-
preprocessor: [],
|
|
209
|
-
version: [],
|
|
210
|
-
structs: [],
|
|
211
|
-
inStatements: [],
|
|
212
|
-
outStatements: [],
|
|
213
|
-
uniforms: [],
|
|
214
|
-
program: [],
|
|
215
|
-
};
|
|
216
|
-
return ast.program.reduce(function (sections, node) {
|
|
217
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
218
|
-
if (node.type === 'preprocessor' && node.line.startsWith('#version')) {
|
|
219
|
-
return __assign(__assign({}, sections), { version: sections.version.concat(node) });
|
|
220
|
-
}
|
|
221
|
-
else if (node.type === 'declaration_statement' &&
|
|
222
|
-
node.declaration.type === 'precision') {
|
|
223
|
-
return __assign(__assign({}, sections), { precision: sections.precision.concat(node) });
|
|
224
|
-
}
|
|
225
|
-
else if (node.type === 'preprocessor') {
|
|
226
|
-
return __assign(__assign({}, sections), { preprocessor: sections.preprocessor.concat(node) });
|
|
227
|
-
}
|
|
228
|
-
else if (node.type === 'declaration_statement' &&
|
|
229
|
-
node.declaration.type === 'declarator_list' &&
|
|
230
|
-
((_d = (_c = (_b = (_a = node.declaration) === null || _a === void 0 ? void 0 : _a.specified_type) === null || _b === void 0 ? void 0 : _b.specifier) === null || _c === void 0 ? void 0 : _c.specifier) === null || _d === void 0 ? void 0 : _d.type) === 'struct') {
|
|
231
|
-
return __assign(__assign({}, sections), { structs: sections.structs.concat(node) });
|
|
232
|
-
// This definition of a uniform lines up with the processing we do in
|
|
233
|
-
// dedupeUniforms
|
|
234
|
-
}
|
|
235
|
-
else if (node.type === 'declaration_statement' &&
|
|
236
|
-
// Ignore lines like "layout(std140,column_major) uniform;"
|
|
237
|
-
!('qualifiers' in node.declaration &&
|
|
238
|
-
((_f = (_e = node.declaration) === null || _e === void 0 ? void 0 : _e.qualifiers) === null || _f === void 0 ? void 0 : _f.find(function (q) { return 'layout' in q; }))) &&
|
|
239
|
-
// One of these checks is for a uniform with an interface block, and the
|
|
240
|
-
// other is for vanilla uniforms. I don't remember which is which
|
|
241
|
-
(('specified_type' in node.declaration &&
|
|
242
|
-
'qualifiers' in node.declaration.specified_type &&
|
|
243
|
-
((_g = node.declaration.specified_type.qualifiers) === null || _g === void 0 ? void 0 : _g.find(function (n) { return 'token' in n && n.token === 'uniform'; }))) ||
|
|
244
|
-
('qualifiers' in node.declaration &&
|
|
245
|
-
((_j = (_h = node.declaration) === null || _h === void 0 ? void 0 : _h.qualifiers) === null || _j === void 0 ? void 0 : _j.find(function (n) { return 'token' in n && n.token === 'uniform'; }))))) {
|
|
246
|
-
return __assign(__assign({}, sections), { uniforms: sections.uniforms.concat(node) });
|
|
247
|
-
}
|
|
248
|
-
else if (node.type === 'declaration_statement' &&
|
|
249
|
-
'specified_type' in node.declaration &&
|
|
250
|
-
((_m = (_l = (_k = node.declaration) === null || _k === void 0 ? void 0 : _k.specified_type) === null || _l === void 0 ? void 0 : _l.qualifiers) === null || _m === void 0 ? void 0 : _m.find(function (n) { return 'token' in n && n.token === 'in'; }))) {
|
|
251
|
-
if ((0, glsl_parser_1.generate)(node).includes('main_Fireball')) {
|
|
252
|
-
console.log('findShaderSections\n', (0, glsl_parser_1.generate)(ast));
|
|
253
|
-
console.log("Tracking inStatement \"".concat((0, glsl_parser_1.generate)(node), "\""), node);
|
|
254
|
-
debugger;
|
|
255
|
-
}
|
|
256
|
-
return __assign(__assign({}, sections), { inStatements: sections.inStatements.concat(node) });
|
|
257
|
-
}
|
|
258
|
-
else if (node.type === 'declaration_statement' &&
|
|
259
|
-
'specified_type' in node.declaration &&
|
|
260
|
-
((_q = (_p = (_o = node.declaration) === null || _o === void 0 ? void 0 : _o.specified_type) === null || _p === void 0 ? void 0 : _p.qualifiers) === null || _q === void 0 ? void 0 : _q.find(function (n) { return 'token' in n && n.token === 'out'; }))) {
|
|
261
|
-
return __assign(__assign({}, sections), { outStatements: sections.outStatements.concat(node) });
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
return __assign(__assign({}, sections), { program: sections.program.concat(node) });
|
|
265
|
-
}
|
|
266
|
-
}, initialValue);
|
|
267
|
-
};
|
|
268
|
-
exports.findShaderSections = findShaderSections;
|
package/cjs/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./graph"), exports);
|
|
18
|
-
__exportStar(require("./strategy"), exports);
|
|
19
|
-
__exportStar(require("./engine"), exports);
|
package/cjs/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type": "commonjs"}
|