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,25 @@ 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+ if ( opt . loopMaxIterations === undefined ) {
352+ console . warn ( "Warning: loopMaxIterations is not set! Using default of 100 which may result in unintended behavior." ) ;
353+ console . warn ( "Set loopMaxIterations or use a for loop of fixed length to silence this message." ) ;
354+ }
355+
356+ retArr . push ( "for (float " ) ;
350357 ast_generic ( forNode . init , retArr , funcParam ) ;
351- retArr . push ( ";\n" ) ;
352- retArr . push ( "for (float i=0.0; i<LOOP_MAX; i++, " ) ;
358+ retArr . push ( ";" ) ;
359+ ast_generic ( forNode . test . left , retArr , funcParam ) ;
360+ retArr . push ( forNode . test . operator ) ;
361+ retArr . push ( "LOOP_MAX" ) ;
362+ retArr . push ( ";" ) ;
353363 ast_generic ( forNode . update , retArr , funcParam ) ;
354- retArr . push ( ") {\n " ) ;
364+ retArr . push ( ")" ) ;
355365
366+ retArr . push ( "{\n" ) ;
356367 retArr . push ( "if (" ) ;
357368 ast_generic ( forNode . test . left , retArr , funcParam ) ;
358369 retArr . push ( forNode . test . operator ) ;
@@ -363,8 +374,6 @@ var functionNode_webgl = (function() {
363374 }
364375 retArr . push ( "} else {\n" ) ;
365376 retArr . push ( "break;\n" ) ;
366- retArr . push ( "}\n" ) ;
367-
368377 retArr . push ( "}\n" ) ;
369378 retArr . push ( "}\n" ) ;
370379
0 commit comments