MCPcopy Create free account
hub / github.com/microsoft/SandDance / updateForTextures

Function updateForTextures

docs/tests/v2/es6/js/sanddance.js:29687–29749  ·  view source on GitHub ↗
(_ref)

Source from the content-addressed store, hash-verified

29685// for texture target, get varying type and inject position instruction
29686
29687function updateForTextures(_ref) {
29688 var vs = _ref.vs,
29689 sourceTextureMap = _ref.sourceTextureMap,
29690 targetTextureVarying = _ref.targetTextureVarying,
29691 targetTexture = _ref.targetTexture;
29692 var texAttributeNames = Object.keys(sourceTextureMap);
29693 var sourceCount = texAttributeNames.length;
29694 var targetTextureType = null;
29695 var samplerTextureMap = {};
29696 var updatedVs = vs;
29697 var finalInject = {};
29698
29699 if (sourceCount > 0 || targetTextureVarying) {
29700 var vsLines = updatedVs.split('\n');
29701 var updateVsLines = vsLines.slice();
29702 vsLines.forEach(function (line, index, lines) {
29703 // TODO add early exit
29704 if (sourceCount > 0) {
29705 var updated = processAttributeDefinition(line, sourceTextureMap);
29706
29707 if (updated) {
29708 var updatedLine = updated.updatedLine,
29709 inject = updated.inject;
29710 updateVsLines[index] = updatedLine; // sampleInstructions.push(sampleInstruction);
29711
29712 finalInject = (0, _src.combineInjects)([finalInject, inject]);
29713 Object.assign(samplerTextureMap, updated.samplerTextureMap);
29714 sourceCount--;
29715 }
29716 }
29717
29718 if (targetTextureVarying && !targetTextureType) {
29719 targetTextureType = getVaryingType(line, targetTextureVarying);
29720 }
29721 });
29722
29723 if (targetTextureVarying) {
29724 (0, _assert.default)(targetTexture);
29725 var sizeName = "".concat(SIZE_UNIFORM_PREFIX).concat(targetTextureVarying);
29726 var uniformDeclaration = "uniform vec2 ".concat(sizeName, ";\n");
29727 var posInstructions = " vec2 ".concat(VS_POS_VARIABLE, " = transform_getPos(").concat(sizeName, ");\n gl_Position = vec4(").concat(VS_POS_VARIABLE, ", 0, 1.);\n");
29728 var inject = {
29729 'vs:#decl': uniformDeclaration,
29730 'vs:#main-start': posInstructions
29731 };
29732 finalInject = (0, _src.combineInjects)([finalInject, inject]);
29733 }
29734
29735 updatedVs = updateVsLines.join('\n');
29736 }
29737
29738 return {
29739 // updated vertex shader (commented texture attribute definition)
29740 vs: updatedVs,
29741 // type (float, vec2, vec3 of vec4) target texture varying
29742 targetTextureType: targetTextureType,
29743 // required vertex and fragment shader injects
29744 inject: finalInject,

Callers

nothing calls this directly

Calls 3

getVaryingTypeFunction · 0.70
forEachMethod · 0.45

Tested by

no test coverage detected