mirror of
https://github.com/gpujs/gpu.js.git
synced 2026-02-01 16:57:35 +00:00
Merge pull request #108 from abhisheksoni27/develop
Internal Documentation: Convert to JSDoc
This commit is contained in:
commit
ba0083731f
@ -2,9 +2,9 @@ const FunctionBuilderBase = require('../function-builder-base');
|
||||
const CPUFunctionNode = require('./function-node');
|
||||
|
||||
/**
|
||||
* Class: CPUFunctionBuilder
|
||||
* @class CPUFunctionBuilder
|
||||
*
|
||||
* Extends: FunctionBuilderBase
|
||||
* @extends FunctionBuilderBase
|
||||
*
|
||||
* Builds functions to execute on CPU from JavaScript function Strings
|
||||
*
|
||||
@ -18,15 +18,13 @@ module.exports = class CPUFunctionBuilder extends FunctionBuilderBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getPrototypeString
|
||||
* @name getPrototypeString
|
||||
*
|
||||
* Return the JS Function String optimized for cpu.
|
||||
*
|
||||
* Parameters:
|
||||
* functionName - {String} Function name to trace from. If null, it returns the WHOLE builder stack
|
||||
* @param functionName {String} Function name to trace from. If null, it returns the WHOLE builder stack
|
||||
*
|
||||
* Returns:
|
||||
* {String} Function String
|
||||
* @returns {String} Function String
|
||||
*
|
||||
*/
|
||||
getPrototypeString() {
|
||||
@ -44,14 +42,13 @@ module.exports = class CPUFunctionBuilder extends FunctionBuilderBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: addSubKernel
|
||||
* @name addSubKernel
|
||||
*
|
||||
* Add a new sub-kernel to the current kernel instance
|
||||
*
|
||||
* Parameters:
|
||||
* jsFunction - {Function} Sub-kernel function (JavaScript)
|
||||
* paramNames - {Array} Parameters of the sub-kernel
|
||||
* returnType - {Array} Return type of the subKernel
|
||||
* @param jsFunction {Function} Sub-kernel function (JavaScript)
|
||||
* @param paramNames {Array} Parameters of the sub-kernel
|
||||
* @param returnType {Array} Return type of the subKernel
|
||||
*
|
||||
*/
|
||||
addSubKernel(jsFunction, paramTypes, returnType) {
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
const BaseFunctionNode = require('../function-node-base');
|
||||
|
||||
/**
|
||||
* Class: CPUFunctionNode
|
||||
* @class CPUFunctionNode
|
||||
*
|
||||
* [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()
|
||||
@ -28,12 +28,11 @@ module.exports = class CPUFunctionNode extends BaseFunctionNode {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getFunctionPrototypeString
|
||||
* @name getFunctionPrototypeString
|
||||
*
|
||||
* Returns the converted webgl shader function equivalent of the JS function
|
||||
*
|
||||
* Returns:
|
||||
* {String} webgl function string, result is cached under this.getFunctionPrototypeString
|
||||
* @returns {String} webgl function string, result is cached under this.getFunctionPrototypeString
|
||||
*
|
||||
*/
|
||||
getFunctionPrototypeString(options) {
|
||||
|
||||
@ -3,28 +3,26 @@ const utils = require('../../core/utils');
|
||||
const kernelString = require('./kernel-string');
|
||||
|
||||
/**
|
||||
* Class: CPUKernel
|
||||
* @class CPUKernel
|
||||
*
|
||||
* Kernel Implementation for CPU.
|
||||
*
|
||||
* Extends:
|
||||
* KernelBase
|
||||
* @extends KernelBase
|
||||
*
|
||||
* Parameters:
|
||||
* thread - {Object} The thread dimensions, x, y and z
|
||||
* runDimensions - {Object} The canvas dimensions
|
||||
* functionBuilder - {Object} Function Builder instance bound to this Kernel
|
||||
* run - {Function} Method to run the kernel
|
||||
* @param thread {Object} The thread dimensions, x, y and z
|
||||
* @param runDimensions {Object} The canvas dimensions
|
||||
* @param functionBuilder {Object} Function Builder instance bound to this Kernel
|
||||
* @param run {Function} Method to run the kernel
|
||||
*
|
||||
*/
|
||||
module.exports = class CPUKernel extends KernelBase {
|
||||
|
||||
//
|
||||
// [Constructor]
|
||||
// @constructor
|
||||
//
|
||||
|
||||
/**
|
||||
* Function: CPUKernel
|
||||
* @name CPUKernel
|
||||
*
|
||||
* Instantiates properties to the CPU Kernel.
|
||||
*
|
||||
@ -58,7 +56,7 @@ module.exports = class CPUKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: validateOptions
|
||||
* @name validateOptions
|
||||
*
|
||||
* Validate options related to CPU Kernel, such as
|
||||
* dimensions size, and auto dimension support.
|
||||
@ -82,7 +80,7 @@ module.exports = class CPUKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: build
|
||||
* @name build
|
||||
*
|
||||
* Builds the Kernel, by generating the kernel
|
||||
* string using thread dimensions, and arguments
|
||||
@ -162,7 +160,7 @@ module.exports = class CPUKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getKernelString
|
||||
* @name getKernelString
|
||||
*
|
||||
* Generates kernel string for this kernel program.
|
||||
*
|
||||
@ -170,8 +168,7 @@ module.exports = class CPUKernel extends KernelBase {
|
||||
* This string can be saved by calling the `toString` method
|
||||
* and then can be reused later.
|
||||
*
|
||||
* Returns:
|
||||
* result {String}
|
||||
* @returns result {String}
|
||||
*
|
||||
*/
|
||||
getKernelString() {
|
||||
@ -277,7 +274,7 @@ module.exports = class CPUKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: toString
|
||||
* @name toString
|
||||
*
|
||||
* Returns the *pre-compiled* Kernel as a JS Object String, that can be reused.
|
||||
*
|
||||
@ -287,13 +284,12 @@ module.exports = class CPUKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: precompileKernelObj
|
||||
* @name precompileKernelObj
|
||||
*
|
||||
* Precompile the kernel into a single object,
|
||||
* that can be used for building the execution kernel subsequently.
|
||||
*
|
||||
* Parameters:
|
||||
* argTypes - {Array} Array of argument types
|
||||
* @param argTypes {Array} Array of argument types
|
||||
*
|
||||
* Return:
|
||||
* Compiled kernel {Object}
|
||||
@ -310,7 +306,7 @@ module.exports = class CPUKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: compileKernel
|
||||
* @name compileKernel
|
||||
*
|
||||
* Takes a previously precompiled kernel object,
|
||||
* and complete compilation into a full kernel
|
||||
|
||||
@ -4,9 +4,9 @@ const CPUKernel = require('./kernel');
|
||||
const CPUFunctionBuilder = require('./function-builder');
|
||||
|
||||
/**
|
||||
* Class: CPURunner
|
||||
* @class CPURunner
|
||||
*
|
||||
* Extends: RunnerBase
|
||||
* @extends RunnerBase
|
||||
*
|
||||
* Instantiates a Runner instance for the kernel.
|
||||
*
|
||||
@ -18,10 +18,9 @@ module.exports = class CPURunner extends RunnerBase {
|
||||
//
|
||||
|
||||
/**
|
||||
* Function: CPURunner
|
||||
* @name CPURunner
|
||||
*
|
||||
* Parameters:
|
||||
* settings - {Object} Settings to instantiate properties in RunnerBase, with given values
|
||||
* @param settings {Object} Settings to instantiate properties in RunnerBase, with given values
|
||||
*
|
||||
*/
|
||||
constructor(settings) {
|
||||
@ -31,12 +30,11 @@ module.exports = class CPURunner extends RunnerBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getMode()
|
||||
* @name getMode()
|
||||
*
|
||||
* Return the current mode in which gpu.js is executing.
|
||||
*
|
||||
* Returns:
|
||||
* {String} The current mode; "cpu".
|
||||
* @returns {String} The current mode; "cpu".
|
||||
*
|
||||
*/
|
||||
getMode() {
|
||||
|
||||
@ -1,22 +1,21 @@
|
||||
/**
|
||||
* Class: FunctionBuilderBase
|
||||
* @class FunctionBuilderBase
|
||||
*
|
||||
* [INTERNAL] A collection of functionNodes.
|
||||
*
|
||||
* This handles all the raw state, converted state, etc. Of a single function.
|
||||
*
|
||||
* Properties:
|
||||
* nodeMap - {Object} Object map, where nodeMap[function] = new FunctionNode;
|
||||
* gpu - {Object} The current gpu instance bound to this builder
|
||||
* rootKernel - {Object} The root kernel object, contains the paramNames, dimensions etc.
|
||||
* @param nodeMap {Object} Object map, where nodeMap[function] = new FunctionNode;
|
||||
* @param gpu {Object} The current gpu instance bound to this builder
|
||||
* @param rootKernel {Object} The root kernel object, contains the paramNames, dimensions etc.
|
||||
*
|
||||
*/
|
||||
module.exports = class FunctionBuilderBase {
|
||||
|
||||
/**
|
||||
* Function: FunctionBuilderBase
|
||||
* @name FunctionBuilderBase
|
||||
*
|
||||
* [Constructor] Blank constructor, which initializes the properties
|
||||
* @constructor Blank constructor, which initializes the properties
|
||||
*
|
||||
*/
|
||||
constructor(gpu) {
|
||||
@ -26,16 +25,15 @@ module.exports = class FunctionBuilderBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: addFunction
|
||||
* @name addFunction
|
||||
*
|
||||
* Instantiates a FunctionNode, and add it to the nodeMap
|
||||
*
|
||||
* 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} JS Function to do conversion
|
||||
* paramTypes - {[String,...]|{variableName: Type,...}} Parameter type array, assumes all parameters are 'float' if null
|
||||
* returnType - {String} The return type, assumes 'float' if null
|
||||
* @param gpu {GPU} The GPU instance
|
||||
* @param functionName {String} Function name to assume, if its null, it attempts to extract from the function
|
||||
* @param jsFunction {JS Function} JS Function to do conversion
|
||||
* @param paramTypes {[String,...]|{variableName: Type,...}} Parameter type array, assumes all parameters are 'float' if null
|
||||
* @param returnType {String} The return type, assumes 'float' if null
|
||||
*
|
||||
*/
|
||||
addFunction(functionName, jsFunction, paramTypes, returnType) {
|
||||
@ -43,12 +41,11 @@ module.exports = class FunctionBuilderBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: addFunctionNode
|
||||
* @name addFunctionNode
|
||||
*
|
||||
* Add the funciton node directly
|
||||
*
|
||||
* Parameters:
|
||||
* inNode - {functionNode} functionNode to add
|
||||
* @param inNode {functionNode} functionNode to add
|
||||
*
|
||||
*/
|
||||
addFunctionNode(inNode) {
|
||||
@ -59,19 +56,17 @@ module.exports = class FunctionBuilderBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: traceFunctionCalls
|
||||
* @name traceFunctionCalls
|
||||
*
|
||||
* Trace all the depending functions being called, from a single function
|
||||
*
|
||||
* This allow for 'unneeded' functions to be automatically optimized out.
|
||||
* Note that the 0-index, is the starting function trace.
|
||||
*
|
||||
* Parameters:
|
||||
* functionName - {String} Function name to trace from, default to 'kernel'
|
||||
* retList - {[String,...]} Returning list of function names that is traced. Including itself.
|
||||
* @param functionName {String} Function name to trace from, default to 'kernel'
|
||||
* @param retList {[String,...]} Returning list of function names that is traced. Including itself.
|
||||
*
|
||||
* Returns:
|
||||
* {[String,...]} Returning list of function names that is traced. Including itself.
|
||||
* @returns {[String,...]} Returning list of function names that is traced. Including itself.
|
||||
*/
|
||||
traceFunctionCalls(functionName, retList, parent) {
|
||||
functionName = functionName || 'kernel';
|
||||
@ -110,7 +105,7 @@ module.exports = class FunctionBuilderBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: polyfillStandardFunctions
|
||||
* @name polyfillStandardFunctions
|
||||
*
|
||||
* Polyfill in the missing Math functions (round)
|
||||
*
|
||||
|
||||
@ -2,25 +2,24 @@ const utils = require('../core/utils');
|
||||
const parser = require('../core/parser').parser;
|
||||
|
||||
/**
|
||||
* Class: FunctionNodeBase
|
||||
* @class FunctionNodeBase
|
||||
*
|
||||
* [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
|
||||
* paramTypes - {[String,...]} Shader land parameters 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
|
||||
* @param functionName {String} Name of the function
|
||||
* @param jsFunction {JS Function} The JS Function the node represents
|
||||
* @param jsFunctionString {String} jsFunction.toString()
|
||||
* @param paramNames {[String,...]} Parameter names of the function
|
||||
* @param paramTypes {[String,...]} Shader land parameters type assumption
|
||||
* @param isRootKernel {Boolean} Special indicator, for kernel function
|
||||
* @param webglFunctionString {String} webgl converted function string
|
||||
* @param openglFunctionString {String} opengl converted function string
|
||||
* @param calledFunctions {[String,...]} List of all the functions called
|
||||
* @param initVariables {[String,...]} List of variables initialized in the function
|
||||
* @param readVariables {[String,...]} List of variables read operations occur
|
||||
* @param writeVariables {[String,...]} List of variables write operations occur
|
||||
*
|
||||
*/
|
||||
module.exports = class BaseFunctionNode {
|
||||
@ -30,16 +29,15 @@ module.exports = class BaseFunctionNode {
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Function: FunctionNodeBase
|
||||
* @name FunctionNodeBase
|
||||
*
|
||||
* [Constructor] Builds the function with the given JS function, and argument type array.
|
||||
* @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
|
||||
* paramTypes - {[String,...]|{variableName: Type}} Parameter type array, assumes all parameters are 'float' if null
|
||||
* returnType - {String} The return type, assumes 'float' if null
|
||||
* @param gpu {GPU} The GPU instance
|
||||
* @param functionName {String} Function name to assume, if its null, it attempts to extract from the function
|
||||
* @param jsFunction {JS Function / String} JS Function to do conversion
|
||||
* @param paramTypes {[String,...]|{variableName: Type}} Parameter type array, assumes all parameters are 'float' if null
|
||||
* @param returnType {String} The return type, assumes 'float' if null
|
||||
*
|
||||
*/
|
||||
constructor(functionName, jsFunction, options, paramTypes, returnType) {
|
||||
@ -168,13 +166,12 @@ module.exports = class BaseFunctionNode {
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Function: getJSFunction
|
||||
* @name getJSFunction
|
||||
*
|
||||
* Gets and return the stored JS Function.
|
||||
* Note: that this internally eval the function, if only the string was provided on construction
|
||||
*
|
||||
* Returns:
|
||||
* {JS Function} The function object
|
||||
* @returns {JS Function} The function object
|
||||
*
|
||||
*/
|
||||
getJsFunction() {
|
||||
@ -191,17 +188,15 @@ module.exports = class BaseFunctionNode {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getJS_AST
|
||||
* @name getJS_AST
|
||||
*
|
||||
* Parses the class function JS, and returns its Abstract Syntax Tree object.
|
||||
*
|
||||
* This is used internally to convert to shader code
|
||||
*
|
||||
* Parameters:
|
||||
* inParser - {JISON Parser} Parser to use, assumes in scope 'parser' if null
|
||||
* @param inParser {JISON Parser} Parser to use, assumes in scope 'parser' if null
|
||||
*
|
||||
* Returns:
|
||||
* {AST Object} The function AST Object, note that result is cached under this.jsFunctionAST;
|
||||
* @returns {AST Object} The function AST Object, note that result is cached under this.jsFunctionAST;
|
||||
*
|
||||
*/
|
||||
getJsAST(inParser) {
|
||||
@ -228,12 +223,11 @@ module.exports = class BaseFunctionNode {
|
||||
|
||||
|
||||
/**
|
||||
* Function: getFunctionString
|
||||
* @name getFunctionString
|
||||
*
|
||||
* Returns the converted webgl shader function equivalent of the JS function
|
||||
*
|
||||
* Returns:
|
||||
* {String} webgl function string, result is cached under this.webGlFunctionString
|
||||
* @returns {String} webgl function string, result is cached under this.webGlFunctionString
|
||||
*
|
||||
*/
|
||||
getFunctionString() {
|
||||
@ -242,12 +236,11 @@ module.exports = class BaseFunctionNode {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: setFunctionString
|
||||
* @name setFunctionString
|
||||
*
|
||||
* Set the functionString value, overwriting it
|
||||
*
|
||||
* Parameters:
|
||||
* functionString - {String} Shader code string, representing the function
|
||||
* @param functionString {String} Shader code string, representing the function
|
||||
*
|
||||
*/
|
||||
setFunctionString(functionString) {
|
||||
@ -255,15 +248,13 @@ module.exports = class BaseFunctionNode {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getParamType
|
||||
* @name getParamType
|
||||
*
|
||||
* Return the type of parameter sent to subKernel/Kernel.
|
||||
*
|
||||
* Parameters:
|
||||
* paramName - {String} Name of the parameter
|
||||
* @param paramName {String} Name of the parameter
|
||||
*
|
||||
* Returns:
|
||||
* {String} Type of the parameter
|
||||
* @returns {String} Type of the parameter
|
||||
*
|
||||
*/
|
||||
getParamType(paramName) {
|
||||
@ -282,16 +273,14 @@ module.exports = class BaseFunctionNode {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getUserParamName
|
||||
* @name getUserParamName
|
||||
*
|
||||
* Return the name of the *user parameter*(subKernel parameter) corresponding
|
||||
* to the parameter supplied to the kernel
|
||||
*
|
||||
* Parameters:
|
||||
* paramName - {String} Name of the parameter
|
||||
* @param paramName {String} Name of the parameter
|
||||
*
|
||||
* Returns:
|
||||
* {String} Name of the parameter
|
||||
* @returns {String} Name of the parameter
|
||||
*
|
||||
*/
|
||||
getUserParamName(paramName) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const utils = require('../core/utils');
|
||||
|
||||
/**
|
||||
* Class: BaseKernel
|
||||
* @class BaseKernel
|
||||
*
|
||||
* Implements the base class for Kernels, and is used as a
|
||||
* parent class for all Kernel implementations.
|
||||
@ -9,25 +9,24 @@ const utils = require('../core/utils');
|
||||
* This contains the basic methods needed by all Kernel implementations,
|
||||
* like setDimensions, addSubKernel, etc.
|
||||
*
|
||||
* Properties:
|
||||
* paramNames - {Array} Name of the parameters of the kernel function
|
||||
* fnString - {String} Kernel function as a String
|
||||
* dimensions - {Array} Dimensions of the kernel function, this.thread.x, etc.
|
||||
* debug - {Boolean} Toggle debug mode
|
||||
* graphical - {String} Toggle graphical mode
|
||||
* loopMaxIterations - {Number} Maximum number of loop iterations
|
||||
* constants - {Object} Global constants
|
||||
* subKernels - {Array} Sub kernels bound to this kernel instance
|
||||
* subKernelProperties - {Object} Sub kernels bound to this kernel instance as key/value pairs
|
||||
* subKernelOutputVariableNames - {Array} Names of the variables outputted by the subkerls
|
||||
* @param paramNames {Array} Name of the parameters of the kernel function
|
||||
* @param fnString {String} Kernel function as a String
|
||||
* @param dimensions {Array} Dimensions of the kernel function, this.thread.x, etc.
|
||||
* @param debug {Boolean} Toggle debug mode
|
||||
* @param graphical {String} Toggle graphical mode
|
||||
* @param loopMaxIterations {Number} Maximum number of loop iterations
|
||||
* @param constants {Object} Global constants
|
||||
* @param subKernels {Array} Sub kernels bound to this kernel instance
|
||||
* @param subKernelProperties {Object} Sub kernels bound to this kernel instance as key/value pairs
|
||||
* @param subKernelOutputVariableNames {Array} Names of the variables outputted by the subkerls
|
||||
*
|
||||
*/
|
||||
module.exports = class BaseKernel {
|
||||
|
||||
/**
|
||||
* Function: BaseKernel
|
||||
* @name BaseKernel
|
||||
*
|
||||
* [Constructor] Blank constructor, which initializes the properties
|
||||
* @constructor Blank constructor, which initializes the properties
|
||||
*
|
||||
*/
|
||||
constructor(fnString, settings) {
|
||||
@ -76,12 +75,11 @@ module.exports = class BaseKernel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: setDimensions
|
||||
* @name setDimensions
|
||||
*
|
||||
* Set dimensions of the kernel function
|
||||
*
|
||||
* Parameters:
|
||||
* dimensions - {Array} The dimensions array set the dimensions to
|
||||
* @param dimensions {Array} The dimensions array set the dimensions to
|
||||
*
|
||||
*/
|
||||
setDimensions(dimensions) {
|
||||
@ -90,12 +88,11 @@ module.exports = class BaseKernel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: setDebug
|
||||
* @name setDebug
|
||||
*
|
||||
* Toggle debug mode
|
||||
*
|
||||
* Parameters:
|
||||
* flag - {Boolean} true to enable debug
|
||||
* @param flag {Boolean} true to enable debug
|
||||
*
|
||||
*/
|
||||
setDebug(flag) {
|
||||
@ -104,12 +101,11 @@ module.exports = class BaseKernel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: setGraphical
|
||||
* @name setGraphical
|
||||
*
|
||||
* Toggle graphical output mode
|
||||
*
|
||||
* Parameters:
|
||||
* flag - {Boolean} true to enable graphical output
|
||||
* @param flag {Boolean} true to enable graphical output
|
||||
*
|
||||
*/
|
||||
setGraphical(flag) {
|
||||
@ -118,12 +114,11 @@ module.exports = class BaseKernel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: setLoopMaxIterations
|
||||
* @name setLoopMaxIterations
|
||||
*
|
||||
* Set the maximum number of loop iterations
|
||||
*
|
||||
* Parameters:
|
||||
* max - {Number} iterations count
|
||||
* @param max {Number} iterations count
|
||||
*
|
||||
*/
|
||||
setLoopMaxIterations(max) {
|
||||
@ -132,7 +127,7 @@ module.exports = class BaseKernel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: setConstants
|
||||
* @name setConstants
|
||||
*
|
||||
*/
|
||||
setConstants(constants) {
|
||||
@ -157,12 +152,11 @@ module.exports = class BaseKernel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: setFloatTextures
|
||||
* @name setFloatTextures
|
||||
*
|
||||
* Toggle texture output mode
|
||||
*
|
||||
* Parameters:
|
||||
* flag - {Boolean} true to enable floatTextures
|
||||
* @param flag {Boolean} true to enable floatTextures
|
||||
*
|
||||
*/
|
||||
setFloatTextures(flag) {
|
||||
@ -171,12 +165,11 @@ module.exports = class BaseKernel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: setFloatOutput
|
||||
* @name setFloatOutput
|
||||
*
|
||||
* Toggle output mode
|
||||
*
|
||||
* Parameters:
|
||||
* flag - {Boolean} true to enable float
|
||||
* @param flag {Boolean} true to enable float
|
||||
*
|
||||
*/
|
||||
setFloatOutput(flag) {
|
||||
@ -190,12 +183,11 @@ module.exports = class BaseKernel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: setCanvas
|
||||
* @name setCanvas
|
||||
*
|
||||
* Bind the canvas to kernel
|
||||
*
|
||||
* Parameters:
|
||||
* canvas - {Canvas} Canvas to bind
|
||||
* @param canvas {Canvas} Canvas to bind
|
||||
*
|
||||
*/
|
||||
setCanvas(canvas) {
|
||||
@ -204,12 +196,11 @@ module.exports = class BaseKernel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: setCanvas
|
||||
* @name setCanvas
|
||||
*
|
||||
* Bind the webGL instance to kernel
|
||||
*
|
||||
* Parameters:
|
||||
* webGL - {Canvas} webGL instance to bind
|
||||
* @param webGL {Canvas} webGL instance to bind
|
||||
*
|
||||
*/
|
||||
setWebGl(webGl) {
|
||||
@ -223,7 +214,7 @@ module.exports = class BaseKernel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getCanvas()
|
||||
* @name getCanvas()
|
||||
*
|
||||
* Returns the current canvas instance bound to the kernel
|
||||
*
|
||||
@ -233,7 +224,7 @@ module.exports = class BaseKernel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getWebGl()
|
||||
* @name getWebGl()
|
||||
*
|
||||
* Returns the current webGl instance bound to the kernel
|
||||
*
|
||||
@ -276,8 +267,7 @@ module.exports = class BaseKernel {
|
||||
* Add a sub kernel to the root kernel instance.
|
||||
* This is what `createKernels` uses.
|
||||
*
|
||||
* Parameters:
|
||||
* fnString - {String} function (as a String) of the subKernel to add
|
||||
* @param fnString {String} function (as a String) of the subKernel to add
|
||||
*
|
||||
*/
|
||||
addSubKernel(fnString) {
|
||||
@ -295,9 +285,8 @@ module.exports = class BaseKernel {
|
||||
* Add a sub kernel to the root kernel instance, indexed by a property name
|
||||
* This is what `createKernels` uses.
|
||||
*
|
||||
* Parameters:
|
||||
* property - {String} property key for the subKernel
|
||||
* fnString - {String} function (as a String) of the subKernel to add
|
||||
* @param property {String} property key for the subKernel
|
||||
* @param fnString {String} function (as a String) of the subKernel to add
|
||||
*
|
||||
*/
|
||||
addSubKernelProperty(property, fnString) {
|
||||
|
||||
@ -2,7 +2,7 @@ const utils = require('../core/utils');
|
||||
const kernelRunShortcut = require('./kernel-run-shortcut');
|
||||
|
||||
/**
|
||||
* Class: BaseRunner
|
||||
* @class BaseRunner
|
||||
*
|
||||
* Represents the 'private/protected' namespace of the GPU class
|
||||
*
|
||||
@ -14,24 +14,23 @@ const kernelRunShortcut = require('./kernel-run-shortcut');
|
||||
* File isolation is currently the best way to go
|
||||
*
|
||||
*
|
||||
* Properties:
|
||||
* settings - {Object} Settings object used to set Dimensions, etc.
|
||||
* kernel - {String} Current kernel instance
|
||||
* canvas - {Object} Canvas instance attached to the kernel
|
||||
* webGl - {Object} WebGl instance attached to the kernel
|
||||
* fn - {Function} Kernel function to run
|
||||
* functionBuilder - {Object} FunctionBuilder instance
|
||||
* fnString - {String} Kernel function (as a String)
|
||||
* endianness - {String} endian information like Little-endian, Big-endian.
|
||||
* @param settings {Object} Settings object used to set Dimensions, etc.
|
||||
* @param kernel {String} Current kernel instance
|
||||
* @param canvas {Object} Canvas instance attached to the kernel
|
||||
* @param webGl {Object} WebGl instance attached to the kernel
|
||||
* @param fn {Function} Kernel function to run
|
||||
* @param functionBuilder {Object} FunctionBuilder instance
|
||||
* @param fnString {String} Kernel function (as a String)
|
||||
* @param endianness {String} endian information like Little-endian, Big-endian.
|
||||
*
|
||||
*/
|
||||
|
||||
module.exports = class BaseRunner {
|
||||
|
||||
/**
|
||||
* Function: BaseRunner
|
||||
* @name BaseRunner
|
||||
*
|
||||
* [Constructor] Blank constructor, which initializes the properties related to runner
|
||||
* @constructor Blank constructor, which initializes the properties related to runner
|
||||
*
|
||||
*/
|
||||
constructor(functionBuilder, settings) {
|
||||
@ -47,12 +46,11 @@ module.exports = class BaseRunner {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: textureToArray
|
||||
* @name textureToArray
|
||||
*
|
||||
* Converts the provided Texture instance to a JavaScript Array
|
||||
*
|
||||
* Parameters:
|
||||
* texture - {Object}
|
||||
* @param texture {Object}
|
||||
*
|
||||
*/
|
||||
textureToArray(texture) {
|
||||
@ -64,12 +62,11 @@ module.exports = class BaseRunner {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: deleteTexture
|
||||
* @name deleteTexture
|
||||
*
|
||||
* Deletes the provided Texture instance
|
||||
*
|
||||
* Parameters:
|
||||
* texture - {Object}
|
||||
* @param texture {Object}
|
||||
*/
|
||||
deleteTexture(texture) {
|
||||
this.webGl.deleteTexture(texture.texture);
|
||||
|
||||
@ -3,9 +3,9 @@ const WebGLFunctionNode = require('./function-node');
|
||||
const utils = require('../../core/utils');
|
||||
|
||||
/**
|
||||
* Class: WebGLFunctionBuilder
|
||||
* @class WebGLFunctionBuilder
|
||||
*
|
||||
* Extends: FunctionBuilderBase
|
||||
* @extends FunctionBuilderBase
|
||||
*
|
||||
* Builds webGl functions (shaders) from JavaScript function Strings
|
||||
*
|
||||
@ -19,13 +19,11 @@ module.exports = class WebGLFunctionBuilder extends FunctionBuilderBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getStringFromFunctionNames
|
||||
* @name getStringFromFunctionNames
|
||||
*
|
||||
* Parameters:
|
||||
* functionList - {[String,...]} List of function to build the webgl string.
|
||||
* @param functionList {[String,...]} List of function to build the webgl string.
|
||||
*
|
||||
* Returns:
|
||||
* {String} The full webgl string, of all the various functions. Trace optimized if functionName given
|
||||
* @returns {String} The full webgl string, of all the various functions. Trace optimized if functionName given
|
||||
*
|
||||
*/
|
||||
getStringFromFunctionNames(functionList) {
|
||||
@ -40,15 +38,14 @@ module.exports = class WebGLFunctionBuilder extends FunctionBuilderBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getPrototypeStringFromFunctionNames
|
||||
* @name getPrototypeStringFromFunctionNames
|
||||
*
|
||||
* Return webgl String of all functions converted to webgl shader form
|
||||
* Parameters:
|
||||
* functionList - {[String,...]} List of function names to build the webgl string.
|
||||
* opt - {Object} Settings object passed to functionNode. See functionNode for more details.
|
||||
*
|
||||
* Returns:
|
||||
* {String} Prototype String of all functions converted to webgl shader form
|
||||
* @param functionList {[String,...]} List of function names to build the webgl string.
|
||||
* @param opt {Object} Settings object passed to functionNode. See functionNode for more details.
|
||||
*
|
||||
* @returns {String} Prototype String of all functions converted to webgl shader form
|
||||
*
|
||||
*/
|
||||
getPrototypeStringFromFunctionNames(functionList, opt) {
|
||||
@ -63,13 +60,11 @@ module.exports = class WebGLFunctionBuilder extends FunctionBuilderBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getString
|
||||
* @name getString
|
||||
*
|
||||
* Parameters:
|
||||
* functionName - {String} Function name to trace from. If null, it returns the WHOLE builder stack
|
||||
* @param functionName {String} Function name to trace from. If null, it returns the WHOLE builder stack
|
||||
*
|
||||
* Returns:
|
||||
* {String} The full webgl string, of all the various functions. Trace optimized if functionName given
|
||||
* @returns {String} The full webgl string, of all the various functions. Trace optimized if functionName given
|
||||
*
|
||||
*/
|
||||
getString(functionName, opt) {
|
||||
@ -84,15 +79,13 @@ module.exports = class WebGLFunctionBuilder extends FunctionBuilderBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getPrototypeString
|
||||
* @name getPrototypeString
|
||||
*
|
||||
* Return the webgl string for a function converted to glsl (webgl shaders)
|
||||
*
|
||||
* Parameters:
|
||||
* functionName - {String} Function name to trace from. If null, it returns the WHOLE builder stack
|
||||
* @param functionName {String} Function name to trace from. If null, it returns the WHOLE builder stack
|
||||
*
|
||||
* Returns:
|
||||
* {String} The full webgl string, of all the various functions. Trace optimized if functionName given
|
||||
* @returns {String} The full webgl string, of all the various functions. Trace optimized if functionName given
|
||||
*
|
||||
*/
|
||||
getPrototypeString(functionName) {
|
||||
@ -104,19 +97,17 @@ module.exports = class WebGLFunctionBuilder extends FunctionBuilderBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: addKernel
|
||||
* @name addKernel
|
||||
*
|
||||
* Add a new kernel to this instance
|
||||
*
|
||||
* Parameters:
|
||||
* fnString - {String} Kernel function as a String
|
||||
* options - {Object} Settings object to set constants, debug mode, etc.
|
||||
* paramNames - {Array} Parameters of the kernel
|
||||
* paramTypes - {Array} Types of the parameters
|
||||
* @param fnString {String} Kernel function as a String
|
||||
* @param options {Object} Settings object to set constants, debug mode, etc.
|
||||
* @param paramNames {Array} Parameters of the kernel
|
||||
* @param paramTypes {Array} Types of the parameters
|
||||
*
|
||||
*
|
||||
* Returns:
|
||||
* {Object} The inserted kernel as a Kernel Node
|
||||
* @returns {Object} The inserted kernel as a Kernel Node
|
||||
*
|
||||
*/
|
||||
addKernel(fnString, options, paramNames, paramTypes) {
|
||||
@ -130,18 +121,16 @@ module.exports = class WebGLFunctionBuilder extends FunctionBuilderBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: addSubKernel
|
||||
* @name addSubKernel
|
||||
*
|
||||
* Add a new sub-kernel to the current kernel instance
|
||||
*
|
||||
* Parameters:
|
||||
* jsFunction - {Function} Sub-kernel function (JavaScript)
|
||||
* options - {Object} Settings object to set constants, debug mode, etc.
|
||||
* paramNames - {Array} Parameters of the sub-kernel
|
||||
* returnType - {Array} Return type of the subKernel
|
||||
* @param jsFunction {Function} Sub-kernel function (JavaScript)
|
||||
* @param options {Object} Settings object to set constants, debug mode, etc.
|
||||
* @param paramNames {Array} Parameters of the sub-kernel
|
||||
* @param returnType {Array} Return type of the subKernel
|
||||
*
|
||||
* Returns:
|
||||
* {Object} The inserted sub-kernel as a Kernel Node
|
||||
* @returns {Object} The inserted sub-kernel as a Kernel Node
|
||||
*
|
||||
*/
|
||||
addSubKernel(jsFunction, options, paramTypes, returnType) {
|
||||
|
||||
@ -10,18 +10,16 @@ const DECODE32_ENCODE32 = /decode32\(\s+encode32\(/g;
|
||||
const ENCODE32_DECODE32 = /encode32\(\s+decode32\(/g;
|
||||
|
||||
/**
|
||||
* Class: WebGLFunctionNode
|
||||
* @class WebGLFunctionNode
|
||||
*
|
||||
* [INTERNAL] Takes in a function node, and does all the AST voodoo required to generate its respective webGL code.
|
||||
*
|
||||
* Extends:
|
||||
* FunctionNodeBase
|
||||
* @extends FunctionNodeBase
|
||||
*
|
||||
* Parameter:
|
||||
* inNode - {functionNode} The function node object
|
||||
*
|
||||
* Returns:
|
||||
* the converted webGL function string
|
||||
* @returns the converted webGL function string
|
||||
*
|
||||
*/
|
||||
module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
@ -46,17 +44,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astGeneric
|
||||
* @name astGeneric
|
||||
*
|
||||
* Parses the abstract syntax tree for generically to its respective function
|
||||
*
|
||||
* Parameters:
|
||||
* ast - the AST object to parse
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
* *
|
||||
* @param ast - the AST object to parse
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the prased openclgl string array
|
||||
* @returns {String} the prased openclgl string array
|
||||
*/
|
||||
astGeneric(ast, retArr, funcParam) {
|
||||
if (ast === null) {
|
||||
@ -127,16 +124,15 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astFunctionDeclaration
|
||||
* @name astFunctionDeclaration
|
||||
*
|
||||
* Parses the abstract syntax tree for to its *named function declaration*
|
||||
*
|
||||
* ast - the AST object to parse
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
* @param ast the AST object to parse
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
astFunctionDeclaration(ast, retArr, funcParam) {
|
||||
if (this.addFunction) {
|
||||
@ -146,17 +142,15 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astFunctionPrototype
|
||||
* @name astFunctionPrototype
|
||||
*
|
||||
* Parses the abstract syntax tree for to its *named function prototype*
|
||||
*
|
||||
* Parameters:
|
||||
* ast - the AST object to parse
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
* @param ast the AST object to parse
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
static astFunctionPrototype(ast, retArr, funcParam) {
|
||||
// Setup function return type and name
|
||||
@ -187,17 +181,15 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astFunctionExpression
|
||||
* @name astFunctionExpression
|
||||
*
|
||||
* Parses the abstract syntax tree for to its *named function*
|
||||
*
|
||||
* Parameters:
|
||||
* ast - the AST object to parse
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
* @param ast the AST object to parse
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
astFunctionExpression(ast, retArr, funcParam) {
|
||||
|
||||
@ -250,17 +242,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astReturnStatement
|
||||
* @name astReturnStatement
|
||||
*
|
||||
* Parses the abstract syntax tree for to *return* statement
|
||||
*
|
||||
* Parameters:
|
||||
* ast - the AST object to parse
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
|
||||
* @param ast the AST object to parse
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
astReturnStatement(ast, retArr, funcParam) {
|
||||
if (funcParam.isRootKernel) {
|
||||
@ -288,17 +279,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astLiteral
|
||||
* @name astLiteral
|
||||
*
|
||||
* Parses the abstract syntax tree for *literal value*
|
||||
*
|
||||
* Parameters:
|
||||
* ast - the AST object to parse
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
|
||||
* @param ast the AST object to parse
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
astLiteral(ast, retArr, funcParam) {
|
||||
|
||||
@ -322,17 +312,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astBinaryExpression
|
||||
* @name astBinaryExpression
|
||||
*
|
||||
* Parses the abstract syntax tree for *binary* expression
|
||||
*
|
||||
* Parameters:
|
||||
* ast - the AST object to parse
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
|
||||
* @param ast the AST object to parse
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
astBinaryExpression(ast, retArr, funcParam) {
|
||||
retArr.push('(');
|
||||
@ -363,17 +352,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astIdentifierExpression
|
||||
* @name astIdentifierExpression
|
||||
*
|
||||
* Parses the abstract syntax tree for *identifier* expression
|
||||
*
|
||||
* Parameters:
|
||||
* idtNode - An ast Node
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
|
||||
* @param idtNode An ast Node
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
astIdentifierExpression(idtNode, retArr, funcParam) {
|
||||
if (idtNode.type !== 'Identifier') {
|
||||
@ -419,17 +407,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astForStatement
|
||||
* @name astForStatement
|
||||
*
|
||||
* Parses the abstract syntax tree forfor *for-loop* expression
|
||||
*
|
||||
* Parameters:
|
||||
|
||||
*
|
||||
* forNode - An ast Node
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
* @param forNode An ast Node
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the prased openclgl string
|
||||
*/
|
||||
astForStatement(forNode, retArr, funcParam) {
|
||||
@ -505,17 +492,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astWhileStatement
|
||||
* @name astWhileStatement
|
||||
*
|
||||
* Parses the abstract syntax tree for *while* loop
|
||||
*
|
||||
* Parameters:
|
||||
|
||||
*
|
||||
* whileNode - An ast Node
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
* @param whileNode An ast Node
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the parsed openclgl string
|
||||
*/
|
||||
astWhileStatement(whileNode, retArr, funcParam) {
|
||||
@ -540,17 +526,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astAssignmentExpression
|
||||
* @name astAssignmentExpression
|
||||
*
|
||||
* Parses the abstract syntax tree for *Assignment* Expression
|
||||
*
|
||||
* Parameters:
|
||||
* assNode - An ast Node
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
|
||||
* @param assNode An ast Node
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
astAssignmentExpression(assNode, retArr, funcParam) {
|
||||
if (assNode.operator === '%=') {
|
||||
@ -570,17 +555,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astEmptyStatement
|
||||
* @name astEmptyStatement
|
||||
*
|
||||
* Parses the abstract syntax tree for an *Empty* Statement
|
||||
*
|
||||
* Parameters:
|
||||
* eNode - An ast Node
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
|
||||
* @param eNode An ast Node
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
astEmptyStatement(eNode, retArr, funcParam) {
|
||||
//retArr.push(';\n');
|
||||
@ -588,17 +572,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astBlockStatement
|
||||
* @name astBlockStatement
|
||||
*
|
||||
* Parses the abstract syntax tree for *Block* statement
|
||||
*
|
||||
* Parameters:
|
||||
* bnode the AST object to parse
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
|
||||
* @param bnode the AST object to parse
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
astBlockStatement(bNode, retArr, funcParam) {
|
||||
retArr.push('{\n');
|
||||
@ -610,17 +593,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astExpressionStatement
|
||||
* @name astExpressionStatement
|
||||
*
|
||||
* Parses the abstract syntax tree for *generic expression* statement
|
||||
*
|
||||
* Parameters:
|
||||
* esNode - An ast Node
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
|
||||
* @param esNode An ast Node
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
astExpressionStatement(esNode, retArr, funcParam) {
|
||||
this.astGeneric(esNode.expression, retArr, funcParam);
|
||||
@ -629,17 +611,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astVariableDeclaration
|
||||
* @name astVariableDeclaration
|
||||
*
|
||||
* Parses the abstract syntax tree for *Variable Declaration*
|
||||
*
|
||||
* Parameters:
|
||||
* vardecNode - An ast Node
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
|
||||
* @param vardecNode An ast Node
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
astVariableDeclaration(vardecNode, retArr, funcParam) {
|
||||
retArr.push('float ');
|
||||
@ -654,17 +635,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astVariableDeclarator
|
||||
* @name astVariableDeclarator
|
||||
*
|
||||
* Parses the abstract syntax tree for *Variable Declarator*
|
||||
*
|
||||
* Parameters:
|
||||
* ivardecNode - An ast Node
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
|
||||
* @param ivardecNode An ast Node
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
astVariableDeclarator(ivardecNode, retArr, funcParam) {
|
||||
this.astGeneric(ivardecNode.id, retArr, funcParam);
|
||||
@ -676,17 +656,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astIfStatement
|
||||
* @name astIfStatement
|
||||
*
|
||||
* Parses the abstract syntax tree for *If* Statement
|
||||
*
|
||||
* Parameters:
|
||||
* ifNode - An ast Node
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
|
||||
* @param ifNode An ast Node
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
astIfStatement(ifNode, retArr, funcParam) {
|
||||
retArr.push('if (');
|
||||
@ -715,17 +694,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astBreakStatement
|
||||
* @name astBreakStatement
|
||||
*
|
||||
* Parses the abstract syntax tree for *Break* Statement
|
||||
*
|
||||
* Parameters:
|
||||
* brNode - An ast Node
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
|
||||
* @param brNode An ast Node
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
astBreakStatement(brNode, retArr, funcParam) {
|
||||
retArr.push('break;\n');
|
||||
@ -733,17 +711,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astContinueStatement
|
||||
* @name astContinueStatement
|
||||
*
|
||||
* Parses the abstract syntax tree for *Continue* Statement
|
||||
*
|
||||
* Parameters:
|
||||
* crNode - An ast Node
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
|
||||
* @param crNode An ast Node
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
astContinueStatement(crNode, retArr, funcParam) {
|
||||
retArr.push('continue;\n');
|
||||
@ -751,17 +728,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astLogicalExpression
|
||||
* @name astLogicalExpression
|
||||
*
|
||||
* Parses the abstract syntax tree for *Logical* Expression
|
||||
*
|
||||
* Parameters:
|
||||
* logNode - An ast Node
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
|
||||
* @param logNode An ast Node
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
astLogicalExpression(logNode, retArr, funcParam) {
|
||||
retArr.push('(');
|
||||
@ -773,17 +749,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astUpdateExpression
|
||||
* @name astUpdateExpression
|
||||
*
|
||||
* Parses the abstract syntax tree for *Update* Expression
|
||||
*
|
||||
* Parameters:
|
||||
* uNode - An ast Node
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
|
||||
* @param uNode An ast Node
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
astUpdateExpression(uNode, retArr, funcParam) {
|
||||
if (uNode.prefix) {
|
||||
@ -798,17 +773,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astUnaryExpression
|
||||
* @name astUnaryExpression
|
||||
*
|
||||
* Parses the abstract syntax tree for *Unary* Expression
|
||||
*
|
||||
* Parameters:
|
||||
* uNode - An ast Node
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
|
||||
* @param uNode An ast Node
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
astUnaryExpression(uNode, retArr, funcParam) {
|
||||
if (uNode.prefix) {
|
||||
@ -823,17 +797,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astThisExpression
|
||||
* @name astThisExpression
|
||||
*
|
||||
* Parses the abstract syntax tree for *This* expression
|
||||
*
|
||||
* Parameters:
|
||||
* tNode - An ast Node
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
|
||||
* @param tNode An ast Node
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
astThisExpression(tNode, retArr, funcParam) {
|
||||
retArr.push('this');
|
||||
@ -841,17 +814,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astMemberExpression
|
||||
* @name astMemberExpression
|
||||
*
|
||||
* Parses the abstract syntax tree for *Member* Expression
|
||||
*
|
||||
* Parameters:
|
||||
* mNode - An ast Node
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
|
||||
* @param mNode An ast Node
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
astMemberExpression(mNode, retArr, funcParam) {
|
||||
if (mNode.computed) {
|
||||
@ -946,11 +918,11 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
*
|
||||
* Parses the abstract syntax tree for binary expression.
|
||||
*
|
||||
* Parameters:
|
||||
* ast the AST object to parse
|
||||
* funcParam
|
||||
* Returns:
|
||||
* {String} the function namespace call, unrolled
|
||||
|
||||
* @param ast the AST object to parse
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* @returns {String} the function namespace call, unrolled
|
||||
*/
|
||||
astMemberExpressionUnroll(ast, funcParam) {
|
||||
if (ast.type === 'Identifier') {
|
||||
@ -977,18 +949,16 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astCallExpression
|
||||
* @name astCallExpression
|
||||
*
|
||||
* Parses the abstract syntax tree for *call* expression
|
||||
*
|
||||
* Parameters:
|
||||
*
|
||||
* ast - the AST object to parse
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
* @param ast the AST object to parse
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the appended retArr
|
||||
* @returns {Array} the append retArr
|
||||
*/
|
||||
astCallExpression(ast, retArr, funcParam) {
|
||||
if (ast.callee) {
|
||||
@ -1060,16 +1030,15 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astArrayExpression
|
||||
* @name astArrayExpression
|
||||
*
|
||||
* Parses the abstract syntax tree for *Array* Expression
|
||||
*
|
||||
* Parameters:
|
||||
* ast - the AST object to parse
|
||||
* retArr - return array string
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
|
||||
* @param ast the AST object to parse
|
||||
* @param retArr return array string
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*
|
||||
* Returns:
|
||||
* the append retArr
|
||||
*/
|
||||
astArrayExpression(arrNode, retArr, funcParam) {
|
||||
@ -1095,12 +1064,11 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getFunctionPrototypeString
|
||||
* @name getFunctionPrototypeString
|
||||
*
|
||||
* Returns the converted webgl shader function equivalent of the JS function
|
||||
*
|
||||
* Returns:
|
||||
* {String} webgl function string, result is cached under this.getFunctionPrototypeString
|
||||
* @returns {String} webgl function string, result is cached under this.getFunctionPrototypeString
|
||||
*
|
||||
*/
|
||||
getFunctionPrototypeString() {
|
||||
@ -1133,7 +1101,7 @@ function ensureIndentifierType(paramName, expectedType, ast, funcParam) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: webgl_regex_optimize
|
||||
* @name webgl_regex_optimize
|
||||
*
|
||||
* [INTERNAL] Takes the near final webgl function string, and do regex search and replacments.
|
||||
* For voodoo optimize out the following
|
||||
@ -1141,8 +1109,7 @@ function ensureIndentifierType(paramName, expectedType, ast, funcParam) {
|
||||
* - decode32(encode32(
|
||||
* - encode32(decode32(
|
||||
*
|
||||
* Parameters:
|
||||
* inStr - {String} The webGl function String
|
||||
* @param inStr - {String} The webGl function String
|
||||
*
|
||||
*/
|
||||
function webGlRegexOptimize(inStr) {
|
||||
@ -1152,16 +1119,16 @@ function webGlRegexOptimize(inStr) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: astErrorOutput
|
||||
* @name astErrorOutput
|
||||
*
|
||||
* To throw the AST error, with its location.
|
||||
*
|
||||
* @TODO: add location support fpr the AST error
|
||||
*
|
||||
* Parameters:
|
||||
* error - the error message output
|
||||
* ast - the AST object where the error is
|
||||
* funcParam - FunctionNode, that tracks compilation state
|
||||
|
||||
* @param error the error message output
|
||||
* @param ast the AST object where the error is
|
||||
* @param funcParam FunctionNode, that tracks compilation state
|
||||
*/
|
||||
function astErrorOutput(error, ast, funcParam) {
|
||||
console.error(error, ast, funcParam);
|
||||
|
||||
@ -7,39 +7,37 @@ const vertShaderString = require('./shader-vert');
|
||||
const kernelString = require('./kernel-string');
|
||||
|
||||
/**
|
||||
* Class: WebGLKernel
|
||||
* @class WebGLKernel
|
||||
*
|
||||
* Kernel Implementation for WebGL.
|
||||
* This builds the shaders and runs them on the GPU,
|
||||
* the outputs the result back as float(enabled by default) and Texture.
|
||||
*
|
||||
* Extends:
|
||||
* KernelBase
|
||||
* @extends KernelBase
|
||||
*
|
||||
* Parameters:
|
||||
* textureCache - {Object} webGl Texture cache
|
||||
* threadDim - {Object} The thread dimensions, x, y and z
|
||||
* programUniformLocationCache - {Object} Location of program variables in memory
|
||||
* framebuffer - {Object} Webgl frameBuffer
|
||||
* buffer - {Object} WebGL buffer
|
||||
* program - {Object} The webGl Program
|
||||
* functionBuilder - {Object} Function Builder instance bound to this Kernel
|
||||
* outputToTexture - {Boolean} Set output type to Texture, instead of float
|
||||
* endianness - {String} Endian information like Little-endian, Big-endian.
|
||||
* paramTypes - {Array} Types of parameters sent to the Kernel
|
||||
* argumentsLength - {Number} Number of parameters sent to the Kernel
|
||||
* compiledFragShaderString - {String} Compiled fragment shader string
|
||||
* compiledVertShaderString - {String} Compiled Vertical shader string
|
||||
* @param textureCache - {Object} webGl Texture cache
|
||||
* @param threadDim - {Object} The thread dimensions, x, y and z
|
||||
* @param programUniformLocationCache - {Object} Location of program variables in memory
|
||||
* @param framebuffer - {Object} Webgl frameBuffer
|
||||
* @param buffer - {Object} WebGL buffer
|
||||
* @param program - {Object} The webGl Program
|
||||
* @param functionBuilder - {Object} Function Builder instance bound to this Kernel
|
||||
* @param outputToTexture - {Boolean} Set output type to Texture, instead of float
|
||||
* @param endianness - {String} Endian information like Little-endian, Big-endian.
|
||||
* @param paramTypes - {Array} Types of parameters sent to the Kernel
|
||||
* @param argumentsLength - {Number} Number of parameters sent to the Kernel
|
||||
* @param compiledFragShaderString - {String} Compiled fragment shader string
|
||||
* @param compiledVertShaderString - {String} Compiled Vertical shader string
|
||||
*
|
||||
*/
|
||||
module.exports = class WebGLKernel extends KernelBase {
|
||||
|
||||
//
|
||||
// [Constructor]
|
||||
// @constructor
|
||||
//
|
||||
|
||||
/**
|
||||
* Function: WebGLKernel
|
||||
* @name WebGLKernel
|
||||
*
|
||||
* Instantiates properties to the WebGl Kernel.
|
||||
*
|
||||
@ -67,7 +65,7 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: validateOptions
|
||||
* @name validateOptions
|
||||
*
|
||||
* Validate options related to Kernel, such as
|
||||
* floatOutputs and Textures, texSize, dimensions,
|
||||
@ -122,7 +120,7 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: build
|
||||
* @name build
|
||||
*
|
||||
* Builds the Kernel, by compiling Fragment and Vertical Shaders,
|
||||
* and instantiates the program.
|
||||
@ -184,14 +182,13 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: run
|
||||
* @name run
|
||||
*
|
||||
* Run the kernel program, and send the output to renderOutput
|
||||
*
|
||||
* This method calls a helper method *renderOutput* to return the result.
|
||||
*
|
||||
* Returns:
|
||||
* Result {Object} The final output of the program, as float, and as Textures for reuse.
|
||||
* @returns Result {Object} The final output of the program, as float, and as Textures for reuse.
|
||||
*
|
||||
*
|
||||
*/
|
||||
@ -319,7 +316,7 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: renderOutput
|
||||
* @name renderOutput
|
||||
*
|
||||
*
|
||||
* Helper function to return webGl function's output.
|
||||
@ -328,11 +325,9 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
*
|
||||
* *Note*: This should not be called directly.
|
||||
*
|
||||
* Parameters:
|
||||
* outputTexture Output Texture returned by webGl program
|
||||
* @param outputTexture Output Texture returned by webGl program
|
||||
*
|
||||
* Returns:
|
||||
* result {Object|Array}
|
||||
* @returns result {Object|Array}
|
||||
*
|
||||
*
|
||||
*/
|
||||
@ -370,12 +365,12 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getOutputTexture
|
||||
* @name getOutputTexture
|
||||
*
|
||||
* This uses *getTextureCache* to get the Texture Cache of the Output
|
||||
*
|
||||
* Returns:
|
||||
* Ouptut Texture Cache
|
||||
|
||||
* @returns {Object} Ouptut Texture Cache
|
||||
*
|
||||
*/
|
||||
getOutputTexture() {
|
||||
@ -383,14 +378,12 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getArgumentTexture
|
||||
* @name getArgumentTexture
|
||||
*
|
||||
* This uses *getTextureCache** to get the Texture Cache of the argument supplied
|
||||
*
|
||||
* Parameters:
|
||||
* name {String} Name of the argument
|
||||
* @param name {String} Name of the argument
|
||||
*
|
||||
* Returns:
|
||||
* Texture cache for the supplied argument
|
||||
*
|
||||
*/
|
||||
@ -399,15 +392,14 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getSubKernelTexture
|
||||
* @name getSubKernelTexture
|
||||
*
|
||||
* This uses *getTextureCache* to get the Texture Cache of the sub-kernel
|
||||
*
|
||||
* Parameters:
|
||||
* name {String} Name of the subKernel
|
||||
|
||||
* @param name {String} Name of the subKernel
|
||||
*
|
||||
* Returns:
|
||||
* Texture cache for the subKernel
|
||||
* @returns {Object} Texture cache for the subKernel
|
||||
*
|
||||
*/
|
||||
getSubKernelTexture(name) {
|
||||
@ -415,15 +407,14 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getTextureCache
|
||||
* @name getTextureCache
|
||||
*
|
||||
* Returns the Texture Cache of the supplied parameter (can be kernel, sub-kernel or argument)
|
||||
*
|
||||
* Parameters:
|
||||
* name {String} Name of the subkernel, argument, or kernel.
|
||||
|
||||
* @param name {String} Name of the subkernel, argument, or kernel.
|
||||
*
|
||||
* Returns:
|
||||
* Texture cache
|
||||
* @returns {Object} Texture cache
|
||||
*
|
||||
*/
|
||||
getTextureCache(name) {
|
||||
@ -438,13 +429,12 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: setupParams
|
||||
* @name setupParams
|
||||
*
|
||||
* Setup the parameter types for the parameters
|
||||
* supplied to the Kernel function
|
||||
*
|
||||
* Parameters:
|
||||
* args {Array} The actual parameters sent to the Kernel
|
||||
* @param args {Array} The actual parameters sent to the Kernel
|
||||
*
|
||||
*/
|
||||
setupParams(args) {
|
||||
@ -457,7 +447,7 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getUniformLocation
|
||||
* @name getUniformLocation
|
||||
*
|
||||
* Return WebGlUniformLocation for various variables
|
||||
* related to webGl program, such as user-defiend variables,
|
||||
@ -474,16 +464,15 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: _getFragShaderArtifactMap
|
||||
* @name _getFragShaderArtifactMap
|
||||
*
|
||||
* Generate Shader artifacts for the kernel program.
|
||||
* The final object contains HEADER, KERNEL, MAIN_RESULT, and others.
|
||||
*
|
||||
* Parameters:
|
||||
* args {Array} The actual parameters sent to the Kernel
|
||||
* @param args {Array} The actual parameters sent to the Kernel
|
||||
*
|
||||
* Returns:
|
||||
* {Object} An object containing the Shader Artifacts(CONSTANTS, HEADER, KERNEL, etc.)
|
||||
|
||||
* @returns {Object} An object containing the Shader Artifacts(CONSTANTS, HEADER, KERNEL, etc.)
|
||||
*
|
||||
*/
|
||||
_getFragShaderArtifactMap(args) {
|
||||
@ -505,15 +494,14 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: _addArgument
|
||||
* @name _addArgument
|
||||
*
|
||||
* Adds kernel parameters to the Argument Texture,
|
||||
* binding it to the webGl instance, etc.
|
||||
*
|
||||
* Parameters:
|
||||
* value {Array|Texture|Number} The actual argument supplied to the kernel
|
||||
* type {String} Type of the argument
|
||||
* name {String} Name of the argument
|
||||
* @param value {Array|Texture|Number} The actual argument supplied to the kernel
|
||||
* @param type {String} Type of the argument
|
||||
* @param name {String} Name of the argument
|
||||
*
|
||||
*/
|
||||
_addArgument(value, type, name) {
|
||||
@ -598,13 +586,12 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: _getHeaderString
|
||||
* @name _getHeaderString
|
||||
*
|
||||
* Get the header string for the program.
|
||||
* This returns an empty string if no sub-kernels are defined.
|
||||
*
|
||||
* Returns:
|
||||
* result {String}
|
||||
* @returns result {String}
|
||||
*
|
||||
*/
|
||||
_getHeaderString() {
|
||||
@ -617,12 +604,11 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: _getLoopMaxString
|
||||
* @name _getLoopMaxString
|
||||
*
|
||||
* Get the maximum loop size String.
|
||||
*
|
||||
* Returns:
|
||||
* result {String}
|
||||
* @returns result {String}
|
||||
*
|
||||
*/
|
||||
_getLoopMaxString() {
|
||||
@ -634,14 +620,13 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: _getConstantsString
|
||||
* @name _getConstantsString
|
||||
*
|
||||
* Generate transpiled glsl Strings for constant parameters sent to a kernel
|
||||
*
|
||||
* They can be defined by *hardcodeConstants*
|
||||
*
|
||||
* Returns:
|
||||
* result {String}
|
||||
* @returns result {String}
|
||||
*
|
||||
*/
|
||||
_getConstantsString() {
|
||||
@ -664,12 +649,11 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: _getTextureCoordinate
|
||||
* @name _getTextureCoordinate
|
||||
*
|
||||
* Get texture coordinate string for the program
|
||||
*
|
||||
* Returns:
|
||||
* result {String}
|
||||
* @returns result {String}
|
||||
*
|
||||
*/
|
||||
_getTextureCoordinate() {
|
||||
@ -682,12 +666,11 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: _getDecode32EndiannessString
|
||||
* @name _getDecode32EndiannessString
|
||||
*
|
||||
* Get Decode32 endianness string for little-endian and big-endian
|
||||
*
|
||||
* Returns:
|
||||
* result {String}
|
||||
* @returns result {String}
|
||||
*
|
||||
*/
|
||||
_getDecode32EndiannessString() {
|
||||
@ -699,12 +682,11 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: _getEncode32EndiannessString
|
||||
* @name _getEncode32EndiannessString
|
||||
*
|
||||
* Get Encode32 endianness string for little-endian and big-endian
|
||||
*
|
||||
* Returns:
|
||||
* result {String}
|
||||
* @returns result {String}
|
||||
*
|
||||
*/
|
||||
_getEncode32EndiannessString() {
|
||||
@ -716,7 +698,7 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: _getGetWraparoundString
|
||||
* @name _getGetWraparoundString
|
||||
*
|
||||
*/
|
||||
_getGetWraparoundString() {
|
||||
@ -728,7 +710,7 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: _getGetTextureChannelString
|
||||
* @name _getGetTextureChannelString
|
||||
*
|
||||
*/
|
||||
_getGetTextureChannelString() {
|
||||
@ -741,7 +723,7 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: _getGetTextureIndexString
|
||||
* @name _getGetTextureIndexString
|
||||
*
|
||||
* Get generic texture index string, if floatTextures flag is true.
|
||||
*
|
||||
@ -757,7 +739,7 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: _getGetResultString
|
||||
* @name _getGetResultString
|
||||
*
|
||||
*/
|
||||
_getGetResultString() {
|
||||
@ -771,15 +753,14 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: _getMainParamsString
|
||||
* @name _getMainParamsString
|
||||
*
|
||||
* Generate transpiled glsl Strings for user-defined parameters sent to a kernel
|
||||
*
|
||||
* Parameters:
|
||||
* args {Array} The actual parameters sent to the Kernel
|
||||
|
||||
* @param args {Array} The actual parameters sent to the Kernel
|
||||
*
|
||||
* Returns:
|
||||
* result {String}
|
||||
* @returns result {String}
|
||||
*
|
||||
*/
|
||||
_getMainParamsString(args) {
|
||||
@ -824,10 +805,7 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: _getMainConstantsString
|
||||
*
|
||||
* Returns:
|
||||
* Texture cache
|
||||
* @name _getMainConstantsString
|
||||
*
|
||||
*/
|
||||
_getMainConstantsString() {
|
||||
@ -848,12 +826,11 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: _getKernelString
|
||||
* @name _getKernelString
|
||||
*
|
||||
* Get Kernel program string (in *glsl*) for a kernel.
|
||||
*
|
||||
* Returns:
|
||||
* result {String}
|
||||
* @returns result {String}
|
||||
*
|
||||
*/
|
||||
_getKernelString() {
|
||||
@ -884,12 +861,11 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: _getMainResultString
|
||||
* @name _getMainResultString
|
||||
*
|
||||
* Get main result string with checks for floatOutput, graphical, subKernelsOutputs, etc.
|
||||
*
|
||||
* Returns:
|
||||
* result {String}
|
||||
* @returns result {String}
|
||||
*
|
||||
*/
|
||||
_getMainResultString() {
|
||||
@ -948,13 +924,11 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: _linesToString
|
||||
* @name _linesToString
|
||||
*
|
||||
* Parameters:
|
||||
* lines {Array} An Array of strings
|
||||
* @param lines {Array} An Array of strings
|
||||
*
|
||||
* Returns:
|
||||
* Single combined String, seperated by *\n*
|
||||
* @returns {String} Single combined String, seperated by *\n*
|
||||
*
|
||||
*/
|
||||
_linesToString(lines) {
|
||||
@ -966,14 +940,10 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: _replaceArtifacts
|
||||
* @name _replaceArtifacts
|
||||
*
|
||||
* Parameters:
|
||||
* src {String} Name of the subkernel, argument, or kernel.
|
||||
* map {String} Name of the subkernel, argument, or kernel.
|
||||
*
|
||||
* Returns:
|
||||
* Texture cache
|
||||
* @param src {String} Shader string
|
||||
* @param map {Array} Variables/Constants associated with shader
|
||||
*
|
||||
*/
|
||||
_replaceArtifacts(src, map) {
|
||||
@ -986,7 +956,7 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: _addKernels
|
||||
* @name _addKernels
|
||||
*
|
||||
* Adds all the sub-kernels supplied with this Kernel instance.
|
||||
*
|
||||
@ -1041,17 +1011,15 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: _getFragShaderString
|
||||
* @name _getFragShaderString
|
||||
*
|
||||
* Get the fragment shader String.
|
||||
* If the String hasn't been compiled yet,
|
||||
* then this method compiles it as well
|
||||
*
|
||||
* Parameters:
|
||||
* args {Array} The actual parameters sent to the Kernel
|
||||
* @param args {Array} The actual parameters sent to the Kernel
|
||||
*
|
||||
* Returns:
|
||||
* {String} Fragment Shader string
|
||||
* @returns {String} Fragment Shader string
|
||||
*
|
||||
*/
|
||||
_getFragShaderString(args) {
|
||||
@ -1062,15 +1030,13 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: _getVertShaderString
|
||||
* @name _getVertShaderString
|
||||
*
|
||||
* Get the vertical shader String
|
||||
*
|
||||
* Parameters:
|
||||
* args {Array} The actual parameters sent to the Kernel
|
||||
* @param args {Array} The actual parameters sent to the Kernel
|
||||
*
|
||||
* Returns:
|
||||
* {String} Vertical Shader string
|
||||
* @returns {String} Vertical Shader string
|
||||
*
|
||||
*/
|
||||
_getVertShaderString(args) {
|
||||
@ -1082,7 +1048,7 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: toString
|
||||
* @name toString
|
||||
*
|
||||
* Returns the *pre-compiled* Kernel as a JS Object String, that can be reused.
|
||||
*
|
||||
|
||||
@ -4,12 +4,11 @@ const utils = require('../../core/utils');
|
||||
const WebGLFunctionBuilder = require('./function-builder');
|
||||
|
||||
/**
|
||||
* Class: WebGLRunner
|
||||
* @class WebGLRunner
|
||||
*
|
||||
* Instantiates a Runner instance for the kernel.
|
||||
*
|
||||
* Extends:
|
||||
* RunnerBase
|
||||
* @extends RunnerBase
|
||||
*
|
||||
*/
|
||||
module.exports = class WebGLRunner extends RunnerBase {
|
||||
@ -19,10 +18,9 @@ module.exports = class WebGLRunner extends RunnerBase {
|
||||
//
|
||||
|
||||
/**
|
||||
* Function: WebGLRunner
|
||||
* @name WebGLRunner
|
||||
*
|
||||
* Parameters:
|
||||
* settings - {Object} Settings to instantiate properties in RunnerBase, with given values
|
||||
* @param settings {Object} Settings to instantiate properties in RunnerBase, with given values
|
||||
*
|
||||
*/
|
||||
constructor(settings) {
|
||||
@ -32,12 +30,11 @@ module.exports = class WebGLRunner extends RunnerBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getMode()
|
||||
* @name getMode()
|
||||
*
|
||||
* Return the current mode in which gpu.js is executing.
|
||||
*
|
||||
* Returns:
|
||||
* {String} The current mode; "cpu".
|
||||
* @returns {String} The current mode; "cpu".
|
||||
*
|
||||
*/
|
||||
getMode() {
|
||||
|
||||
@ -2,7 +2,7 @@ const WebGLKernel = require('./kernel');
|
||||
const utils = require('../../core/utils');
|
||||
|
||||
/**
|
||||
* Class: WebGLValidatorKernel
|
||||
* @class WebGLValidatorKernel
|
||||
*
|
||||
* Helper class for WebGLKernel to validate texture size and dimensions.
|
||||
*
|
||||
@ -10,7 +10,7 @@ const utils = require('../../core/utils');
|
||||
module.exports = class WebGLValidatorKernel extends WebGLKernel {
|
||||
|
||||
/**
|
||||
* Function: validateOptions
|
||||
* @name validateOptions
|
||||
*
|
||||
*/
|
||||
validateOptions() {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const UtilsCore = require("./utils-core");
|
||||
|
||||
/**
|
||||
* Class: GPUCore
|
||||
* @class GPUCore
|
||||
*
|
||||
* This is a minimalistic version of GPU.js used
|
||||
* To run precompiled GPU.JS code
|
||||
@ -12,7 +12,7 @@ const UtilsCore = require("./utils-core");
|
||||
module.exports = class GPUCore {
|
||||
|
||||
/**
|
||||
* Function: validateKernelObj
|
||||
* @name validateKernelObj
|
||||
*
|
||||
* Validates the KernelObj to comply with the defined format
|
||||
* Note that this does only a limited sanity check, and does not
|
||||
@ -20,11 +20,9 @@ module.exports = class GPUCore {
|
||||
*
|
||||
* For the kernel object format see : <kernelObj-format>
|
||||
*
|
||||
* Parameters:
|
||||
* kernelObj - <Object>/<String> KernelObj used to validate
|
||||
* @param kernelObj {Object|String} KernelObj used to validate
|
||||
*
|
||||
* Returns:
|
||||
* <Object> The validated kernel object, converted from JSON if needed
|
||||
* @returns {Object} The validated kernel object, converted from JSON if needed
|
||||
*
|
||||
*/
|
||||
static validateKernelObj(kernelObj) {
|
||||
@ -59,7 +57,7 @@ module.exports = class GPUCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: loadKernelObj
|
||||
* @name loadKernelObj
|
||||
*
|
||||
* Loads the precompilled kernel object. For GPUCore this is the ONLY way to create the kernel.
|
||||
* To generate the kernelObj use <Kernel.exportKernelObj>
|
||||
@ -70,12 +68,10 @@ module.exports = class GPUCore {
|
||||
* <GPUCore.validateKernelObj>,
|
||||
* <Kernel.exportKernelObj>
|
||||
*
|
||||
* Parameters:
|
||||
* kernelObj - <Object> The precompilled kernel object
|
||||
* inOpt - <Object> [Optional] the option overrides to use
|
||||
* @param kernelObj {Object} The precompilled kernel object
|
||||
* @param inOpt {Object} [Optional] the option overrides to use
|
||||
*
|
||||
* Returns:
|
||||
* <Function> The kernel function
|
||||
* @returns {Function} The kernel function
|
||||
*
|
||||
*/
|
||||
static loadKernelObj(kernelObj, inOpt) {
|
||||
|
||||
@ -5,7 +5,7 @@ const WebGLValidatorKernel = require('../backend/web-gl/validator-kernel');
|
||||
const GPUCore = require("./gpu-core");
|
||||
|
||||
/**
|
||||
* Class: GPU
|
||||
* @class GPU
|
||||
*
|
||||
* Initialises the GPU.js library class which manages the WebGL context for the created functions.
|
||||
*
|
||||
@ -49,7 +49,7 @@ class GPU extends GPUCore {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Function: createKernel
|
||||
* @name createKernel
|
||||
*
|
||||
* This creates a callable function object to call the kernel function with the argument parameter set
|
||||
*
|
||||
@ -65,12 +65,10 @@ class GPU extends GPUCore {
|
||||
* | | | + 'cpu' : Forces JS fallback mode only |
|
||||
* |---------------|---------------|---------------------------------------------------------------------------|
|
||||
*
|
||||
* Parameters:
|
||||
* inputFunction {JS Function} The calling to perform the conversion
|
||||
* settings {Object} The parameter configuration object (see above)
|
||||
* @param inputFunction {JS Function} The calling to perform the conversion
|
||||
* @param settings {Object} The parameter configuration object (see above)
|
||||
*
|
||||
* Returns:
|
||||
* {Function} callable function to run
|
||||
* @returns {Function} callable function to run
|
||||
*
|
||||
*/
|
||||
createKernel(fn, settings) {
|
||||
@ -101,15 +99,14 @@ class GPU extends GPUCore {
|
||||
|
||||
/**
|
||||
*
|
||||
* Function: createKernels
|
||||
* @name createKernels
|
||||
*
|
||||
* Create a super kernel which executes sub kernels
|
||||
* and saves their output to be used with the next sub kernel.
|
||||
* This can be useful if we want to save the output on one kernel,
|
||||
* and then use it as an input to another kernel. *Machine Learning*
|
||||
*
|
||||
* Example:
|
||||
* (start code)
|
||||
* @example
|
||||
* const megaKernel = gpu.createKernels({
|
||||
* addResult: function add(a, b) {
|
||||
* return a[this.thread.x] + b[this.thread.x];
|
||||
@ -122,17 +119,14 @@ class GPU extends GPUCore {
|
||||
* });
|
||||
*
|
||||
* megaKernel(a, b, c);
|
||||
* (end code)
|
||||
*
|
||||
* *Note:* You can also define subKernels as an array of functions.
|
||||
* Note: You can also define subKernels as an array of functions.
|
||||
* > [add, multiply]
|
||||
*
|
||||
* Parameters:
|
||||
* subKernels - {Object|Array} Sub kernels for this kernel
|
||||
* rootKernel - {Function} Root kernel
|
||||
* @param subKernels {Object|Array} Sub kernels for this kernel
|
||||
* @param rootKernel {Function} Root kernel
|
||||
*
|
||||
* Returns:
|
||||
* {Function} callable kernel function
|
||||
* @returns {Function} callable kernel function
|
||||
*
|
||||
*/
|
||||
createKernels() {
|
||||
@ -167,7 +161,7 @@ class GPU extends GPUCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: combineKernels
|
||||
* @name combineKernels
|
||||
*
|
||||
* Combine different kernels into one super Kernel,
|
||||
* useful to perform multiple operations inside one
|
||||
@ -177,17 +171,15 @@ class GPU extends GPUCore {
|
||||
* The number of kernel functions sent to this method can be variable.
|
||||
* You can send in one, two, etc.
|
||||
*
|
||||
* Example:
|
||||
* > combineKernels(add, multiply, function(a,b,c){
|
||||
* > return add(multiply(a,b), c)
|
||||
* > })
|
||||
* @example
|
||||
* combineKernels(add, multiply, function(a,b,c){
|
||||
* return add(multiply(a,b), c)
|
||||
* })
|
||||
*
|
||||
* Parameters:
|
||||
* subKernels - {Function} Kernel function(s) to combine.
|
||||
* rootKernel - {Function} Root kernel to combine kernels into
|
||||
* @param subKernels {Function} Kernel function(s) to combine.
|
||||
* @param rootKernel {Function} Root kernel to combine kernels into
|
||||
*
|
||||
* Returns:
|
||||
* {Function} callable kernel function
|
||||
* @returns {Function} callable kernel function
|
||||
*
|
||||
*/
|
||||
combineKernels() {
|
||||
@ -237,17 +229,15 @@ class GPU extends GPUCore {
|
||||
|
||||
|
||||
/**
|
||||
* Function: addFunction
|
||||
* @name addFunction
|
||||
*
|
||||
* Adds additional functions, that the kernel may call.
|
||||
*
|
||||
* Parameters:
|
||||
* fn - {Function|String} JS Function to do conversion
|
||||
* paramTypes - {[String,...]|{variableName: Type,...}} Parameter type array, assumes all parameters are 'float' if null
|
||||
* returnType - {String} The return type, assumes 'float' if null
|
||||
* @param fn {Function|String} JS Function to do conversion
|
||||
* @param paramTypes {[String,...]|{variableName: Type,...}} Parameter type array, assumes all parameters are 'float' if null
|
||||
* @param returnType {String} The return type, assumes 'float' if null
|
||||
*
|
||||
* Returns:
|
||||
* {GPU} returns itself
|
||||
* @returns {GPU} returns itself
|
||||
*
|
||||
*/
|
||||
addFunction(fn, paramTypes, returnType) {
|
||||
@ -256,12 +246,11 @@ class GPU extends GPUCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getMode()
|
||||
* @name getMode()
|
||||
*
|
||||
* Return the current mode in which gpu.js is executing.
|
||||
*
|
||||
* Returns:
|
||||
* {String} The current mode, "cpu", "webgl", etc.
|
||||
* @returns {String} The current mode, "cpu", "webgl", etc.
|
||||
*
|
||||
*/
|
||||
getMode() {
|
||||
@ -269,14 +258,13 @@ class GPU extends GPUCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: get isWebGlSupported()
|
||||
* @name get isWebGlSupported()
|
||||
*
|
||||
* Return TRUE, if browser supports WebGl AND Canvas
|
||||
*
|
||||
* Note: This function can also be called directly `GPU.isWebGlSupported()`
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} TRUE if browser supports webGl
|
||||
* @returns {Boolean} TRUE if browser supports webGl
|
||||
*
|
||||
*/
|
||||
isWebGlSupported() {
|
||||
@ -284,12 +272,11 @@ class GPU extends GPUCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getCanvas()
|
||||
* @name getCanvas()
|
||||
*
|
||||
* Return the canvas object bound to this gpu instance.
|
||||
*
|
||||
* Returns:
|
||||
* {Object} Canvas object if present
|
||||
* @returns {Object} Canvas object if present
|
||||
*
|
||||
*/
|
||||
getCanvas() {
|
||||
@ -297,12 +284,11 @@ class GPU extends GPUCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getWebGl()
|
||||
* @name getWebGl()
|
||||
*
|
||||
* Return the webGl object bound to this gpu instance.
|
||||
*
|
||||
* Returns:
|
||||
* {Object} WebGl object if present
|
||||
* @returns {Object} WebGl object if present
|
||||
*
|
||||
*/
|
||||
getWebGl() {
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
let gpu = null;
|
||||
|
||||
/**
|
||||
* Class: Texture
|
||||
*
|
||||
* @class Texture
|
||||
*
|
||||
*/
|
||||
module.exports = class Texture {
|
||||
@ -14,7 +13,7 @@ module.exports = class Texture {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: toArray
|
||||
* @name toArray
|
||||
*
|
||||
* Converts the Texture into a JavaScript Array.
|
||||
*
|
||||
@ -32,7 +31,7 @@ module.exports = class Texture {
|
||||
return copy(this.texture);
|
||||
}
|
||||
/**
|
||||
* Function: delete
|
||||
* @name delete
|
||||
*
|
||||
* Deletes the Texture.
|
||||
*
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Class: UtilsCore
|
||||
* @class UtilsCore
|
||||
*
|
||||
* Reduced subset of Utils, used exclusively in gpu-core.js
|
||||
*
|
||||
@ -18,17 +18,15 @@ class UtilsCore {
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Function: isCanvas
|
||||
* @name isCanvas
|
||||
*
|
||||
* Return TRUE, on a valid DOM canvas object
|
||||
*
|
||||
* Note: This does just a VERY simply sanity check. And may give false positives.
|
||||
*
|
||||
* Parameters:
|
||||
* canvasObj - {Canvas DOM object} Object to validate
|
||||
* @param canvasObj {Canvas DOM object} Object to validate
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} TRUE if the object is a DOM canvas
|
||||
* @returns {Boolean} TRUE if the object is a DOM canvas
|
||||
*
|
||||
*/
|
||||
static isCanvas(canvasObj) {
|
||||
@ -41,12 +39,11 @@ class UtilsCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: isCanvasSupported
|
||||
* @name isCanvasSupported
|
||||
*
|
||||
* Return TRUE, if browser supports canvas
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} TRUE if browser supports canvas
|
||||
* @returns {Boolean} TRUE if browser supports canvas
|
||||
*
|
||||
*/
|
||||
static isCanvasSupported() {
|
||||
@ -54,13 +51,12 @@ class UtilsCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: initCanvas
|
||||
* @name initCanvas
|
||||
*
|
||||
* Initiate and returns a canvas, for usage in init_webgl.
|
||||
* Returns only if canvas is supported by browser.
|
||||
*
|
||||
* Returns:
|
||||
* {Canvas DOM object} Canvas dom object if supported by browser, else null
|
||||
* @returns {Canvas DOM object} Canvas dom object if supported by browser, else null
|
||||
*
|
||||
*/
|
||||
static initCanvas() {
|
||||
@ -87,17 +83,16 @@ class UtilsCore {
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Function: isWebGl
|
||||
* @name isWebGl
|
||||
*
|
||||
* Return TRUE, on a valid webGl context object
|
||||
*
|
||||
* Note: This does just a VERY simply sanity check. And may give false positives.
|
||||
*
|
||||
* Parameters:
|
||||
* webGlObj - {webGl context} Object to validate
|
||||
* @param webGlObj {webGl context} Object to validate
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} TRUE if the object is a webgl context object
|
||||
|
||||
* @returns {Boolean} TRUE if the object is a webgl context object
|
||||
*
|
||||
*/
|
||||
static isWebGl(webGlObj) {
|
||||
@ -117,12 +112,12 @@ class UtilsCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: isWebGlSupported
|
||||
* @name isWebGlSupported
|
||||
*
|
||||
* Return TRUE, if browser supports webgl
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} TRUE if browser supports webgl
|
||||
|
||||
* @returns {Boolean} TRUE if browser supports webgl
|
||||
*
|
||||
*/
|
||||
static isWebGlSupported() {
|
||||
@ -143,16 +138,15 @@ class UtilsCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: initWebGl
|
||||
* @name initWebGl
|
||||
*
|
||||
* Initiate and returns a webGl, from a canvas object
|
||||
* Returns only if webGl is supported by browser.
|
||||
*
|
||||
* Parameters:
|
||||
* canvasObj - {Canvas DOM object} Object to validate
|
||||
* @param canvasObj {Canvas DOM object} Object to validate
|
||||
*
|
||||
* Returns:
|
||||
* {Canvas DOM object} Canvas dom object if supported by browser, else null
|
||||
|
||||
* @returns {Canvas DOM object} Canvas dom object if supported by browser, else null
|
||||
*
|
||||
*/
|
||||
static initWebGl(canvasObj) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Class: Utils
|
||||
* @class Utils
|
||||
*
|
||||
* Various utility functions / snippets of code that GPU.JS uses internally.\
|
||||
* This covers various snippets of code that is not entirely gpu.js specific (ie. may find uses elsewhere)
|
||||
@ -39,12 +39,11 @@ class Utils extends UtilsCore {
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Function: systemEndianness
|
||||
* @name systemEndianness
|
||||
*
|
||||
* Gets the system endianness, and cache it
|
||||
*
|
||||
* Returns:
|
||||
* {String} 'LE' or 'BE' depending on system architecture
|
||||
* @returns {String} 'LE' or 'BE' depending on system architecture
|
||||
*
|
||||
* Credit: https://gist.github.com/TooTallNate/4750953
|
||||
*/
|
||||
@ -59,15 +58,13 @@ class Utils extends UtilsCore {
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Function: isFunction
|
||||
* @name isFunction
|
||||
*
|
||||
* Return TRUE, on a JS function
|
||||
*
|
||||
* Parameters:
|
||||
* funcObj - {JS Function} Object to validate if its a function
|
||||
* @param funcObj {JS Function} Object to validate if its a function
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} TRUE if the object is a JS function
|
||||
* @returns {Boolean} TRUE if the object is a JS function
|
||||
*
|
||||
*/
|
||||
static isFunction(funcObj) {
|
||||
@ -75,17 +72,16 @@ class Utils extends UtilsCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: isFunctionString
|
||||
* @name isFunctionString
|
||||
*
|
||||
* Return TRUE, on a valid JS function string
|
||||
*
|
||||
* Note: This does just a VERY simply sanity check. And may give false positives.
|
||||
*
|
||||
* Parameters:
|
||||
* funcStr - {String} String of JS function to validate
|
||||
* @param funcStr {String} String of JS function to validate
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} TRUE if the string passes basic validation
|
||||
|
||||
* @returns {Boolean} TRUE if the string passes basic validation
|
||||
*
|
||||
*/
|
||||
static isFunctionString(funcStr) {
|
||||
@ -98,15 +94,14 @@ class Utils extends UtilsCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getFunctionName_fromString
|
||||
* @name getFunctionName_fromString
|
||||
*
|
||||
* Return the function name from a JS function string
|
||||
*
|
||||
* Parameters:
|
||||
* funcStr - {String} String of JS function to validate
|
||||
* @param funcStr {String} String of JS function to validate
|
||||
*
|
||||
* Returns:
|
||||
* {String} Function name string (if found)
|
||||
|
||||
* @returns {String} Function name string (if found)
|
||||
*
|
||||
*/
|
||||
static getFunctionNameFromString(funcStr) {
|
||||
@ -118,14 +113,13 @@ class Utils extends UtilsCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getParamNames_fromString
|
||||
* @name getParamNames_fromString
|
||||
*
|
||||
* Return list of parameter names extracted from the JS function string
|
||||
*
|
||||
* Parameters:
|
||||
* funcStr - {String} String of JS function to validate
|
||||
* @param funcStr {String} String of JS function to validate
|
||||
*
|
||||
* Returns:
|
||||
|
||||
* {[String, ...]} Array representing all the parameter names
|
||||
*
|
||||
*/
|
||||
@ -144,15 +138,14 @@ class Utils extends UtilsCore {
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Function: clone
|
||||
* @name clone
|
||||
*
|
||||
* Returns a clone
|
||||
*
|
||||
* Parameters:
|
||||
* obj - {Object} Object to clone
|
||||
* @param obj {Object} Object to clone
|
||||
*
|
||||
* Returns:
|
||||
* {Object} Cloned object
|
||||
|
||||
* @returns {Object} Cloned object
|
||||
*
|
||||
*/
|
||||
static clone(obj) {
|
||||
@ -172,15 +165,13 @@ class Utils extends UtilsCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: newPromise
|
||||
* @name newPromise
|
||||
*
|
||||
* Returns a `new Promise` object based on the underlying implmentation
|
||||
*
|
||||
* Parameters:
|
||||
* executor - {function(resolve,reject)} Promise builder function
|
||||
* @param executor {function(resolve,reject)} Promise builder function
|
||||
*
|
||||
* Returns:
|
||||
* {Promise} Promise object
|
||||
* @returns {Promise} Promise object
|
||||
*
|
||||
*/
|
||||
static newPromise(executor) {
|
||||
@ -192,16 +183,14 @@ class Utils extends UtilsCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: functionBinder
|
||||
* @name functionBinder
|
||||
*
|
||||
* Limited implementation of Function.bind, with fallback
|
||||
*
|
||||
* Parameters:
|
||||
* inFunc - {JS Function} to setup bind on
|
||||
* thisObj - {Object} The this parameter to assume inside the binded function
|
||||
* @param inFunc {JS Function} to setup bind on
|
||||
* @param thisObj {Object} The this parameter to assume inside the binded function
|
||||
*
|
||||
* Returns:
|
||||
* {JS Function} The binded function
|
||||
* @returns {JS Function} The binded function
|
||||
*
|
||||
*/
|
||||
static functionBinder(inFunc, thisObj) {
|
||||
@ -216,15 +205,13 @@ class Utils extends UtilsCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: isArray
|
||||
* @name isArray
|
||||
*
|
||||
* Checks if is an array or Array-like object
|
||||
*
|
||||
* Parameters:
|
||||
* arg - {Object} The argument object to check if is array
|
||||
* @param arg {Object} The argument object to check if is array
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} true if is array or Array-like object
|
||||
* @returns {Boolean} true if is array or Array-like object
|
||||
*
|
||||
*/
|
||||
static isArray(arr) {
|
||||
@ -233,15 +220,13 @@ class Utils extends UtilsCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getArgumentType
|
||||
* @name getArgumentType
|
||||
*
|
||||
* Evaluate the argument type, to apply respective logic for it
|
||||
*
|
||||
* Parameters:
|
||||
* arg - {Object} The argument object to evaluate type
|
||||
* @param arg {Object} The argument object to evaluate type
|
||||
*
|
||||
* Returns:
|
||||
* {String} Argument type Array/Number/Texture/Unknown
|
||||
* @returns {String} Argument type Array/Number/Texture/Unknown
|
||||
*
|
||||
*/
|
||||
static getArgumentType(arg) {
|
||||
@ -257,15 +242,13 @@ class Utils extends UtilsCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: isFloatReadPixelsSupported
|
||||
* @name isFloatReadPixelsSupported
|
||||
*
|
||||
* Checks if the browser supports readPixels with float type
|
||||
*
|
||||
* Parameters:
|
||||
* gpu - {gpu.js object} the gpu object
|
||||
* @param gpu {gpu.js object} the gpu object
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} true if browser supports
|
||||
* @returns {Boolean} true if browser supports
|
||||
*
|
||||
*/
|
||||
static isFloatReadPixelsSupported() {
|
||||
@ -306,13 +289,12 @@ class Utils extends UtilsCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: getDimensions
|
||||
* @name getDimensions
|
||||
*
|
||||
* Return the dimension of an array.
|
||||
*
|
||||
* Parameters:
|
||||
* x - {Array} The array
|
||||
* pad - {Number} To include padding in the dimension calculation [Optional]
|
||||
* @param x {Array} The array
|
||||
* @param pad {Number} To include padding in the dimension calculation [Optional]
|
||||
*
|
||||
*
|
||||
*
|
||||
@ -345,15 +327,14 @@ class Utils extends UtilsCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: pad
|
||||
* @name pad
|
||||
*
|
||||
* Pad an array AND its elements with leading and ending zeros
|
||||
* Parameters:
|
||||
* arr - {Array} the array to pad zeros to
|
||||
* padding - {Number} amount of padding
|
||||
*
|
||||
* Returns:
|
||||
* {Array} Array with leading and ending zeros, and all the elements padded by zeros.
|
||||
* @param arr {Array} the array to pad zeros to
|
||||
* @param padding {Number} amount of padding
|
||||
*
|
||||
* @returns {Array} Array with leading and ending zeros, and all the elements padded by zeros.
|
||||
*
|
||||
*/
|
||||
static pad(arr, padding) {
|
||||
@ -375,15 +356,13 @@ class Utils extends UtilsCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: flatten
|
||||
* @name flatten
|
||||
*
|
||||
* Converts a nested array into a one-dimensional array
|
||||
*
|
||||
* Parameters:
|
||||
* _arr - {Array} the nested array to flatten
|
||||
* @param _arr {Array} the nested array to flatten
|
||||
*
|
||||
* Returns:
|
||||
* {Array} 1D Array
|
||||
* @returns {Array} 1D Array
|
||||
*
|
||||
*/
|
||||
static flatten(_arr) {
|
||||
@ -409,17 +388,16 @@ class Utils extends UtilsCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: splitArray
|
||||
* @name splitArray
|
||||
*
|
||||
* Splits an array into smaller arrays.
|
||||
* Number of elements in one small chunk is given by `part`
|
||||
*
|
||||
* Parameters:
|
||||
* array - {Array} The array to split into chunks
|
||||
* part - {Array} elements in one chunk
|
||||
* @param array {Array} The array to split into chunks
|
||||
* @param part {Array} elements in one chunk
|
||||
*
|
||||
* Returns:
|
||||
* {Array} An array of smaller chunks
|
||||
|
||||
* @returns {Array} An array of smaller chunks
|
||||
*
|
||||
*/
|
||||
static splitArray(array, part) {
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: Object
|
||||
* @class Object
|
||||
* Native javascript object, while this can mean anything in JS. You probably should not be using a string/numeric/array type here.
|
||||
*
|
||||
* See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||
@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: String
|
||||
* @class String
|
||||
* Native javascript String.
|
||||
*
|
||||
* See: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||
@ -23,7 +23,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: Boolean
|
||||
* @class Boolean
|
||||
* Native javascript Boolean, basically TRUE or FALSE.
|
||||
*
|
||||
* See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||
@ -31,7 +31,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: Function
|
||||
* @class Function
|
||||
* Native javascript Function object, that is executable, hopefully without exceptions.
|
||||
*
|
||||
* See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function
|
||||
@ -39,7 +39,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: Number
|
||||
* @class Number
|
||||
* Native javascript Number object.
|
||||
*
|
||||
* See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||
@ -47,7 +47,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: Int
|
||||
* @class Int
|
||||
* Native javascript Number. But this time you probably shold limit it to a whole number.
|
||||
*
|
||||
* See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* File: kernel-obj-format
|
||||
*
|
||||
* Class: KernelObjFormat
|
||||
* @class KernelObjFormat
|
||||
*
|
||||
* The kernelObj is a standard JS object that matches the following format.
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user