@@ -109,7 +109,11 @@ var functionNode_webgl = (function() {
109109 function ast_FunctionExpression ( ast , retArr , funcParam ) {
110110
111111 // Setup function return type and name
112- retArr . push ( funcParam . returnType ) ;
112+ if ( funcParam . isRootKernal ) {
113+ retArr . push ( "vec4" ) ;
114+ } else {
115+ retArr . push ( funcParam . returnType ) ;
116+ }
113117 retArr . push ( " " ) ;
114118 retArr . push ( funcParam . functionName ) ;
115119 retArr . push ( "(" ) ;
@@ -243,6 +247,8 @@ var functionNode_webgl = (function() {
243247 retArr . push ( 'uOutputDim.y' ) ;
244248 } else if ( idtNode . name == "gpu_dimensionsZ" ) {
245249 retArr . push ( 'uOutputDim.z' ) ;
250+ } else if ( funcParam . isRootKernal ) {
251+ retArr . push ( "user_" + idtNode . name ) ;
246252 } else {
247253 retArr . push ( idtNode . name ) ;
248254 }
@@ -415,9 +421,26 @@ var functionNode_webgl = (function() {
415421 ast_generic ( mNode . property , retArr , funcParam ) ;
416422 retArr . push ( ")" ) ;
417423 } else {
418- ast_generic ( mNode . object , retArr , funcParam ) ;
419- retArr . push ( "." ) ;
420- ast_generic ( mNode . property , retArr , funcParam ) ;
424+
425+ // Unroll the member expression
426+ var unrolled = ast_MemberExpression_unroll ( mNode ) ;
427+ var unrolled_lc = unrolled . toLowerCase ( )
428+
429+ if ( unrolled_lc == "this.thread.x" ) {
430+ retArr . push ( 'threadId.x' ) ;
431+ } else if ( unrolled_lc == "this.thread.y" ) {
432+ retArr . push ( 'threadId.y' ) ;
433+ } else if ( unrolled_lc == "this.thread.z" ) {
434+ retArr . push ( 'threadId.z' ) ;
435+ } else if ( unrolled_lc == "this.dimensions.x" ) {
436+ retArr . push ( 'uOutputDim.x' ) ;
437+ } else if ( unrolled_lc == "this.dimensions.y" ) {
438+ retArr . push ( 'uOutputDim.y' ) ;
439+ } else if ( unrolled_lc == "this.dimensions.z" ) {
440+ retArr . push ( 'uOutputDim.z' ) ;
441+ } else {
442+ retArr . push ( unrolled ) ;
443+ }
421444 }
422445 return retArr ;
423446 }
@@ -439,17 +462,19 @@ var functionNode_webgl = (function() {
439462 /// @param ast the AST object to parse
440463 ///
441464 /// @returns {String } the function namespace call, unrolled
442- function ast_CallExpression_unroll ( ast , funcParam ) {
465+ function ast_MemberExpression_unroll ( ast , funcParam ) {
443466 if ( ast . type == "Identifier" ) {
444467 return ast . name ;
445- }
468+ } else if ( ast . type == "ThisExpression" ) {
469+ return "this" ;
470+ }
446471
447472 if ( ast . type == "MemberExpression" ) {
448473 if ( ast . object && ast . property ) {
449474 return (
450- ast_CallExpression_unroll ( ast . object , funcParam ) +
475+ ast_MemberExpression_unroll ( ast . object , funcParam ) +
451476 "." +
452- ast_CallExpression_unroll ( ast . property , funcParam )
477+ ast_MemberExpression_unroll ( ast . property , funcParam )
453478 ) ;
454479 }
455480 }
@@ -474,7 +499,7 @@ var functionNode_webgl = (function() {
474499 function ast_CallExpression ( ast , retArr , funcParam ) {
475500 if ( ast . callee ) {
476501 // Get the full function call, unrolled
477- var funcName = ast_CallExpression_unroll ( ast . callee ) ;
502+ var funcName = ast_MemberExpression_unroll ( ast . callee ) ;
478503
479504 // Its a math operator, remove the prefix
480505 if ( funcName . indexOf ( jsMathPrefix ) === 0 ) {
0 commit comments