MCPcopy Index your code
hub / github.com/microsoft/SandDance / injectShader

Function injectShader

docs/app/js/sanddance-app.js:68574–68623  ·  view source on GitHub ↗
(source, type, inject, injectStandardStubs)

Source from the content-addressed store, hash-verified

68572var REGEX_END_OF_MAIN = /}\n?[^{}]*$/;
68573var fragments = [];
68574function injectShader(source, type, inject, injectStandardStubs) {
68575 var isVertex = type === (0, _constants.VERTEX_SHADER);
68576 var _loop = function _loop(key) {
68577 var fragmentData = inject[key];
68578 fragmentData.sort(function(a, b) {
68579 return a.order - b.order;
68580 });
68581 fragments.length = fragmentData.length;
68582 for(var i = 0, len = fragmentData.length; i < len; ++i)fragments[i] = fragmentData[i].injection;
68583 var fragmentString = "".concat(fragments.join("\n"), "\n");
68584 switch(key){
68585 case "vs:#decl":
68586 if (isVertex) source = source.replace(DECLARATION_INJECT_MARKER, fragmentString);
68587 break;
68588 case "vs:#main-start":
68589 if (isVertex) source = source.replace(REGEX_START_OF_MAIN, function(match) {
68590 return match + fragmentString;
68591 });
68592 break;
68593 case "vs:#main-end":
68594 if (isVertex) source = source.replace(REGEX_END_OF_MAIN, function(match) {
68595 return fragmentString + match;
68596 });
68597 break;
68598 case "fs:#decl":
68599 if (!isVertex) source = source.replace(DECLARATION_INJECT_MARKER, fragmentString);
68600 break;
68601 case "fs:#main-start":
68602 if (!isVertex) source = source.replace(REGEX_START_OF_MAIN, function(match) {
68603 return match + fragmentString;
68604 });
68605 break;
68606 case "fs:#main-end":
68607 if (!isVertex) source = source.replace(REGEX_END_OF_MAIN, function(match) {
68608 return fragmentString + match;
68609 });
68610 break;
68611 default:
68612 source = source.replace(key, function(match) {
68613 return match + fragmentString;
68614 });
68615 }
68616 };
68617 for(var key1 in inject)_loop(key1);
68618 source = source.replace(DECLARATION_INJECT_MARKER, "");
68619 if (injectStandardStubs) source = source.replace(/\}\s*$/, function(match) {
68620 return match + MODULE_INJECTORS[type];
68621 });
68622 return source;
68623}
68624exports.default = injectShader;
68625function combineInjects(injects) {
68626 var result = {};

Callers

nothing calls this directly

Calls 2

replaceMethod · 0.80
_loopFunction · 0.70

Tested by

no test coverage detected