/// /// Class: functionNode /// /// [INTERNAL] Represents a single function, inside JS, webGL, or openGL. /// /// This handles all the raw state, converted state, etc. Of a single function. /// /// Properties: /// functionName - {String} Name of the function /// jsFunction - {JS Function} The JS Function the node represents /// jsFunctionString - {String} jsFunction.toString() /// paramNames - {[String,...]} Parameter names of the function /// paramType - {[String,...]} Shader land parameter type assumption /// isRootKernel - {Boolean} Special indicator, for kernel function /// webglFunctionString - {String} webgl converted function string /// openglFunctionString - {String} opengl converted function string /// calledFunctions - {[String,...]} List of all the functions called /// initVariables - {[String,...]} List of variables initialized in the function /// readVariables - {[String,...]} List of variables read operations occur /// writeVariables - {[String,...]} List of variables write operations occur /// var functionNode = (function() { // // Constructor //---------------------------------------------------------------------------------------------------- /// /// Function: functionNode /// /// [Constructor] Builds the function with the given JS function, and argument type array. /// /// Parameters: /// gpu - {GPU} The GPU instance /// functionName - {String} Function name to assume, if its null, it attempts to extract from the function /// jsFunction - {JS Function / String} JS Function to do conversion /// paramTypeArray - {[String,...]} Parameter type array, assumes all parameters are "float" if null /// returnType - {String} The return type, assumes "float" if null /// function functionNode( gpu, functionName, jsFunction, paramTypeArray, returnType ) { this.gpu = gpu; // // Internal vars setup // this.calledFunctions = []; this.initVariables = []; this.readVariables = []; this.writeVariables = []; // // Missing jsFunction object exception // if( jsFunction == null ) { throw "jsFunction, parameter is null"; } // // Setup jsFunction and its string property + validate them // this.jsFunctionString = jsFunction.toString(); if( !gpu_utils.isFunctionString(this.jsFunctionString) ) { console.error("jsFunction, to string conversion check falied: not a function?", this.jsFunctionString); throw "jsFunction, to string conversion check falied: not a function?"; } if( !gpu_utils.isFunction(jsFunction) ) { //throw "jsFunction, is not a valid JS Function"; this.jsFunction = null; } else { this.jsFunction = jsFunction; } // // Setup the function name property // this.functionName = functionName || (jsFunction && jsFunction.name) || gpu_utils.getFunctionName_fromString(this.jsFunctionString); if( !(this.functionName) ) { throw "jsFunction, missing name argument or value"; } // // Extract parameter name, and its argument types // this.paramNames = gpu_utils.getParamNames_fromString(this.jsFunctionString); if( paramTypeArray != null ) { if( paramTypeArray.length != this.paramNames.length ) { throw "Invalid argument type array length, against function length -> ("+ paramTypeArray.length+","+ this.paramNames.length+ ")"; } this.paramType = paramTypeArray; } else { this.paramType = []; for(var a=0; a