MCPcopy
hub / github.com/CesiumGS/cesium / glslToJavaScript

Function glslToJavaScript

scripts/build.js:509–651  ·  view source on GitHub ↗
(minify, minifyStateFilePath, workspace)

Source from the content-addressed store, hash-verified

507 * @param {Workspace} workspace
508 */
509export async function glslToJavaScript(minify, minifyStateFilePath, workspace) {
510 await writeFile(minifyStateFilePath, minify.toString());
511 const minifyStateFileLastModified = existsSync(minifyStateFilePath)
512 ? statSync(minifyStateFilePath).mtime.getTime()
513 : 0;
514
515 // collect all currently existing JS files into a set, later we will remove the ones
516 // we still are using from the set, then delete any files remaining in the set.
517 /** @type {Record<string, boolean>} */
518 const leftOverJsFiles = {};
519
520 const files = await globby([
521 `packages/${workspace}/Source/Shaders/**/*.js`,
522 `packages/${workspace}/Source/ThirdParty/Shaders/*.js`,
523 ]);
524 files.forEach(function (file) {
525 leftOverJsFiles[path.normalize(file)] = true;
526 });
527
528 /** @type {string[]} */
529 const builtinFunctions = [];
530 /** @type {string[]} */
531 const builtinConstants = [];
532 /** @type {string[]} */
533 const builtinStructs = [];
534
535 const glslFiles = await globby(shaderFiles);
536 await Promise.all(
537 glslFiles.map(async function (glslFile) {
538 glslFile = path.normalize(glslFile);
539 const baseName = path.basename(glslFile, ".glsl");
540 const jsFile = `${path.join(path.dirname(glslFile), baseName)}.js`;
541
542 // identify built in functions, structs, and constants
543 const baseDir = path.join(
544 `packages/${workspace}/`,
545 "Source",
546 "Shaders",
547 "Builtin",
548 );
549 if (
550 glslFile.indexOf(path.normalize(path.join(baseDir, "Functions"))) === 0
551 ) {
552 builtinFunctions.push(baseName);
553 } else if (
554 glslFile.indexOf(path.normalize(path.join(baseDir, "Constants"))) === 0
555 ) {
556 builtinConstants.push(baseName);
557 } else if (
558 glslFile.indexOf(path.normalize(path.join(baseDir, "Structs"))) === 0
559 ) {
560 builtinStructs.push(baseName);
561 }
562
563 delete leftOverJsFiles[jsFile];
564
565 const jsFileExists = existsSync(jsFile);
566 const jsFileModified = jsFileExists

Callers 4

gulpfile.jsFile · 0.90
server.jsFile · 0.90
buildEngineFunction · 0.85

Calls 4

generateBuiltinContentsFunction · 0.85
mapMethod · 0.80
toStringMethod · 0.45
normalizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…