Skip to content

Commit 7dab659

Browse files
committed
Merge branch 'master' of github.com:gpujs/gpu.js
2 parents 2bee76d + a3851aa commit 7dab659

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/backend/functionNode_webgl.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,32 @@ var functionNode_webgl = (function() {
3535
gpu = inNode.gpu;
3636
jsFunctionString = inNode.jsFunctionString;
3737
inNode.webglFunctionString_array = ast_generic( inNode.getJS_AST(), [], inNode );
38-
inNode.webglFunctionString = inNode.webglFunctionString_array.join("").trim();
38+
inNode.webglFunctionString = webgl_regex_optimize(
39+
inNode.webglFunctionString_array.join("").trim()
40+
);
3941
return inNode.webglFunctionString;
4042
}
4143

44+
var DECODE32_ENCODE32 = /decode32\(\s+encode32\(/g;
45+
var ENCODE32_DECODE32 = /encode32\(\s+decode32\(/g;
46+
47+
///
48+
/// Function: webgl_regex_optimize
49+
///
50+
/// [INTERNAL] Takes the near final webgl function string, and do regex search and replacments.
51+
/// For voodoo optimize out the following
52+
///
53+
/// - decode32(encode32(
54+
/// - encode32(decode32(
55+
///
56+
function webgl_regex_optimize( inStr ) {
57+
return inStr
58+
.replace(DECODE32_ENCODE32, "((")
59+
.replace(ENCODE32_DECODE32, "((")
60+
;
61+
}
62+
63+
4264
/// the AST error, with its location. To throw
4365
///
4466
/// @TODO: add location support fpr the AST error

0 commit comments

Comments
 (0)