Skip to content

Commit

Permalink
Use JS string templates in src/library_glemu.js. NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Feb 5, 2024
1 parent 50d2d32 commit 6b99922
Showing 1 changed file with 11 additions and 40 deletions.
51 changes: 11 additions & 40 deletions src/library_glemu.js
Original file line number Diff line number Diff line change
Expand Up @@ -1075,14 +1075,14 @@ var LibraryGLEmulation = {
func = "textureCube";
break;
default:
return abort_sanity("Unknown texType: " + ptrToString(texType));
return abort_sanity(`Unknown texType: ${ptrToString(texType)}`);
}

var texCoordExpr = TEX_COORD_VARYING_PREFIX + texUnitID;
if (TEX_MATRIX_UNIFORM_PREFIX != null) {
texCoordExpr = "(" + TEX_MATRIX_UNIFORM_PREFIX + texUnitID + " * " + texCoordExpr + ")";
texCoordExpr = `(${TEX_MATRIX_UNIFORM_PREFIX}${texUnitID} * ${texCoordExpr})`;
}
return func + "(" + TEX_UNIT_UNIFORM_PREFIX + texUnitID + ", " + texCoordExpr + ".xy)";
return `${func}($[TEX_UNIT_UNIFORM_PREFIX}${texUnitID}, ${texCoordExpr}.xy)`;
}

function getTypeFromCombineOp(op) {
Expand Down Expand Up @@ -1499,58 +1499,29 @@ var LibraryGLEmulation = {
var lines = null;
switch (combiner) {
case GL_REPLACE: {
var line = [
outputType + " " + outputVar,
" = ",
src0Expr,
";",
];
lines = [line.join("")];
lines = [`${outputType} ${outputVar} = ${src0Expr};`]
break;
}
case GL_MODULATE: {
var line = [
outputType + " " + outputVar + " = ",
src0Expr + " * " + src1Expr,
";",
];
lines = [line.join("")];
lines = [`${outputType} ${outputVar} = ${src0Expr} * ${src1Expr};`];
break;
}
case GL_ADD: {
var line = [
outputType + " " + outputVar + " = ",
src0Expr + " + " + src1Expr,
";",
];
lines = [line.join("")];
lines = [`${outputType} ${outputVar} = ${src0Expr} + ${src1Expr};`]
break;
}
case GL_SUBTRACT: {
var line = [
outputType + " " + outputVar + " = ",
src0Expr + " - " + src1Expr,
";",
];
lines = [line.join("")];
lines = [`${outputType} ${outputVar} = ${src0Expr} - ${src1Expr};`]
break;
}
case GL_INTERPOLATE: {
var prefix = TEXENVJIT_NAMESPACE_PREFIX + 'env' + texUnitID + "_";
var prefix = `${TEXENVJIT_NAMESPACE_PREFIX}env${texUnitID}_`;
var arg2Var = prefix + "colorSrc2";
var arg2Line = getTypeFromCombineOp(this.colorOp[2]) + " " + arg2Var + " = " + src2Expr + ";";
var arg2Type = getTypeFromCombineOp(this.colorOp[2]);

var line = [
outputType + " " + outputVar,
" = ",
src0Expr + " * " + arg2Var,
" + ",
src1Expr + " * (1.0 - " + arg2Var + ")",
";",
];
lines = [
arg2Line,
line.join(""),
`${arg2Type} ${arg2Var} = ${src2Expr};`,
`${outputType} ${outputVar} = ${src0Expr} * ${arg2Var} + ${src1Expr} * (1.0 - ${arg2Var});`,
];
break;
}
Expand Down

0 comments on commit 6b99922

Please sign in to comment.