GPUUtils

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)

Note that all moethods in this class is “static” by nature `GPUUtils.functionName()`

Summary
GPUUtilsVarious utility functions / snippets of code that GPU.JS uses internally.\ This covers various snippets of code that is not entirely gpu.js specific (ie.
Functions
systemEndiannessGets the system endianness, and cache it
isFunctionReturn TRUE, on a JS function
isFunctionStringReturn TRUE, on a valid JS function string
getFunctionName_fromStringReturn the function name from a JS function string
getParamNames_fromStringReturn list of parameter names extracted from the JS function string
cloneReturns a clone
newPromiseReturns a `new Promise` object based on the underlying implmentation
functionBinderLimited implmentation of Function.bind, with fallback
getArgumentTypeEvaluate the argument type, to apply respective logic for it
isCanvasReturn TRUE, on a valid DOM canvas object
browserSupport_canvasReturn TRUE, if browser supports canvas
init_canvasInitiate and returns a canvas, for usage in init_webgl.
isWebglReturn TRUE, on a valid webgl context object
browserSupport_webglReturn TRUE, if browser supports webgl
init_webglInitiate and returns a webgl, from a canvas object Returns only if webgl is supported by browser.

Functions

systemEndianness

function systemEndianness()

Gets the system endianness, and cache it

Returns

{String} “LE” or “BE” depending on system architecture

Credit: https://gist.github.com/TooTallNate/4750953

isFunction

function isFunction(funcObj)

Return TRUE, on a JS function

Parameters

funcObj{JS Function} Object to validate if its a function

Returns

{Boolean} TRUE if the object is a JS function

isFunctionString

function isFunctionString(funcStr)

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

Returns

{Boolean} TRUE if the string passes basic validation

getFunctionName_fromString

function getFunctionName_fromString(funcStr)

Return the function name from a JS function string

Parameters

funcStr{String} String of JS function to validate

Returns

{String} Function name string (if found)

getParamNames_fromString

function getParamNames_fromString(func)

Return list of parameter names extracted from the JS function string

Parameters

funcStr{String} String of JS function to validate

Returns

{[String, ...]} Array representing all the parameter names

clone

function clone(obj)

Returns a clone

Parameters

obj{Object} Object to clone

Returns

{Object} Cloned object

newPromise

function newPromise(executor)

Returns a `new Promise` object based on the underlying implmentation

Parameters

executor{function(resolve,reject)} Promise builder function

Returns

{Promise} Promise object

functionBinder

function functionBinder(inFunc,
thisObj)

Limited implmentation of Function.bind, with fallback

Parameters

inFunc{JS Function} to setup bind on
thisObj{Object} The this parameter to assume inside the binded function

Returns

{JS Function} The binded function

getArgumentType

function getArgumentType(arg)

Evaluate the argument type, to apply respective logic for it

Parameters

arg{Object} The argument object to evaluate type

Returns

{String} Argument type Array/Number/Texture/Unknown

isCanvas

function isCanvas(canvasObj)

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

Returns

{Boolean} TRUE if the object is a DOM canvas

browserSupport_canvas

function browserSupport_canvas()

Return TRUE, if browser supports canvas

Returns

{Boolean} TRUE if browser supports canvas

init_canvas

function init_canvas()

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

isWebgl

function isWebgl(webglObj)

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

Returns

{Boolean} TRUE if the object is a webgl context object

browserSupport_webgl

function browserSupport_webgl()

Return TRUE, if browser supports webgl

Returns

{Boolean} TRUE if browser supports webgl

init_webgl

function init_webgl(canvasObj)

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

Returns

{Canvas DOM object} Canvas dom object if supported by browser, else null

function systemEndianness()
Gets the system endianness, and cache it
function isFunction(funcObj)
Return TRUE, on a JS function
function isFunctionString(funcStr)
Return TRUE, on a valid JS function string
function getFunctionName_fromString(funcStr)
Return the function name from a JS function string
function getParamNames_fromString(func)
Return list of parameter names extracted from the JS function string
function clone(obj)
Returns a clone
function newPromise(executor)
Returns a `new Promise` object based on the underlying implmentation
function functionBinder(inFunc,
thisObj)
Limited implmentation of Function.bind, with fallback
function getArgumentType(arg)
Evaluate the argument type, to apply respective logic for it
function isCanvas(canvasObj)
Return TRUE, on a valid DOM canvas object
function browserSupport_canvas()
Return TRUE, if browser supports canvas
function init_canvas()
Initiate and returns a canvas, for usage in init_webgl.
function isWebgl(webglObj)
Return TRUE, on a valid webgl context object
function browserSupport_webgl()
Return TRUE, if browser supports webgl
function init_webgl(canvasObj)
Initiate and returns a webgl, from a canvas object Returns only if webgl is supported by browser.
Close