11// Closure capture for the ast function, prevent collision with existing AST functions
22var functionNode_webgl = ( function ( ) {
33
4- var gpu , jsFunctionString ;
4+ var gpu , opt , jsFunctionString ;
55
66 function isIdentifierKernelParam ( paramName , ast , funcParam ) {
77 return funcParam . paramNames . indexOf ( paramName ) != - 1 ;
@@ -31,8 +31,9 @@ var functionNode_webgl = (function() {
3131 /// Returns:
3232 /// the converted webGL function string
3333 ///
34- function functionNode_webgl ( inNode ) {
34+ function functionNode_webgl ( inNode , _opt ) {
3535 gpu = inNode . gpu ;
36+ opt = _opt ;
3637 jsFunctionString = inNode . jsFunctionString ;
3738 inNode . webglFunctionString_array = ast_generic ( inNode . getJS_AST ( ) , [ ] , inNode ) ;
3839 inNode . webglFunctionString = webgl_regex_optimize (
@@ -344,15 +345,26 @@ var functionNode_webgl = (function() {
344345 }
345346
346347 if ( forNode . test && forNode . test . type == "BinaryExpression" ) {
347- if ( forNode . test . right . type != "Literal" ) {
348- retArr . push ( "{\n" ) ;
349- retArr . push ( "float " ) ;
348+ if ( forNode . test . right . type == "Identifier"
349+ && forNode . test . operator == "<" ) {
350+
351+ console . log ( opt . loopMaxIterations ) ;
352+ if ( opt . loopMaxIterations === undefined ) {
353+ console . warn ( "Warning: loopMaxIterations is not set! Using default of 100 which may result in unintended behavior." ) ;
354+ console . warn ( "Set loopMaxIterations or use a for loop of fixed length to silence this message." ) ;
355+ }
356+
357+ retArr . push ( "for (float " ) ;
350358 ast_generic ( forNode . init , retArr , funcParam ) ;
351- retArr . push ( ";\n" ) ;
352- retArr . push ( "for (float i=0.0; i<LOOP_MAX; i++, " ) ;
359+ retArr . push ( ";" ) ;
360+ ast_generic ( forNode . test . left , retArr , funcParam ) ;
361+ retArr . push ( forNode . test . operator ) ;
362+ retArr . push ( "LOOP_MAX" ) ;
363+ retArr . push ( ";" ) ;
353364 ast_generic ( forNode . update , retArr , funcParam ) ;
354- retArr . push ( ") {\n " ) ;
365+ retArr . push ( ")" ) ;
355366
367+ retArr . push ( "{\n" ) ;
356368 retArr . push ( "if (" ) ;
357369 ast_generic ( forNode . test . left , retArr , funcParam ) ;
358370 retArr . push ( forNode . test . operator ) ;
@@ -363,8 +375,6 @@ var functionNode_webgl = (function() {
363375 }
364376 retArr . push ( "} else {\n" ) ;
365377 retArr . push ( "break;\n" ) ;
366- retArr . push ( "}\n" ) ;
367-
368378 retArr . push ( "}\n" ) ;
369379 retArr . push ( "}\n" ) ;
370380
0 commit comments