Skip to content

Commit

Permalink
Move usage of Number.isInteger to utilities and cleanup some number…
Browse files Browse the repository at this point in the history
… checking

Tests pass same as before
  • Loading branch information
robertleeplummerjr committed Jun 8, 2018
1 parent 26e14d9 commit cfd3c77
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
36 changes: 16 additions & 20 deletions src/backend/web-gl/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,8 @@ module.exports = class WebGLKernel extends KernelBase {
this.setUniform1i(`user_${name}`, this.argumentsLength);
break;
}
case 'Number':
case 'Integer':
case 'Float':
{
this.setUniform1f(`user_${name}`, value);
break;
Expand Down Expand Up @@ -998,9 +999,9 @@ module.exports = class WebGLKernel extends KernelBase {
`highp vec2 user_${ paramName }Size = vec2(${ paramSize[0] }.0, ${ paramSize[1] }.0)`,
`highp vec3 user_${ paramName }Dim = vec3(${ paramDim[0] }.0, ${ paramDim[1]}.0, ${ paramDim[2] }.0)`
);
} else if (paramType === 'Number' && Number.isInteger(param)) {
} else if (paramType === 'Integer') {
result.push(`highp float user_${ paramName } = ${ param }.0`);
} else if (paramType === 'Number') {
} else if (paramType === 'Float') {
result.push(`highp float user_${ paramName } = ${ param }`);
}
} else {
Expand All @@ -1010,7 +1011,7 @@ module.exports = class WebGLKernel extends KernelBase {
`uniform highp vec2 user_${ paramName }Size`,
`uniform highp vec3 user_${ paramName }Dim`
);
} else if (paramType === 'Number') {
} else if (paramType === 'Integer' || paramType === 'Float') {
result.push(`uniform highp float user_${ paramName }`);
} else {
throw new Error(`Param type ${paramType} not supported in WebGL, only WebGL2`);
Expand All @@ -1031,12 +1032,17 @@ module.exports = class WebGLKernel extends KernelBase {
if (this.constants) {
for (let name in this.constants) {
if (!this.constants.hasOwnProperty(name)) continue;
let value = parseFloat(this.constants[name]);

if (Number.isInteger(value)) {
result.push('const float constants_' + name + ' = ' + parseInt(value) + '.0');
} else {
result.push('const float constants_' + name + ' = ' + parseFloat(value));
let value = this.constants[name];
let type = utils.getArgumentType(value);
switch (type) {
case 'Integer':
result.push('const float constants_' + name + ' = ' + parseInt(value) + '.0');
break;
case 'Float':
result.push('const float constants_' + name + ' = ' + parseFloat(value));
break;
default:
throw new Error(`Unsupported constant ${ name } type ${ type }`);
}
}
}
Expand All @@ -1063,16 +1069,6 @@ module.exports = class WebGLKernel extends KernelBase {
`highp float ${ names[i] } = 0.0`
);
}

/* this is v2 prep
result.push('highp float kernelResult = 0.0');
result.push('layout(location = 0) out highp float fradData0 = 0.0');
for (let i = 0; i < names.length; i++) {
result.push(
`highp float ${ names[i] } = 0.0`,
`layout(location = ${ i + 1 }) out highp float fragData${ i + 1 } = 0.0`
);
}*/
} else {
result.push('highp float kernelResult = 0.0');
}
Expand Down
9 changes: 5 additions & 4 deletions src/backend/web-gl2/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ module.exports = class WebGL2Kernel extends WebGLKernel {
this.setUniform1i(`user_${name}`, this.argumentsLength);
break;
}
case 'Number':
case 'Integer':
case 'Float':
{
this.setUniform1f(`user_${name}`, value);
break;
Expand Down Expand Up @@ -506,9 +507,9 @@ module.exports = class WebGL2Kernel extends WebGLKernel {
`highp vec2 user_${ paramName }Size = vec2(${ paramSize[0] }.0, ${ paramSize[1] }.0)`,
`highp vec3 user_${ paramName }Dim = vec3(${ paramDim[0] }.0, ${ paramDim[1]}.0, ${ paramDim[2] }.0)`
);
} else if (paramType === 'Number' && Number.isInteger(param)) {
} else if (paramType === 'Integer') {
result.push(`highp float user_${ paramName } = ${ param }.0`);
} else if (paramType === 'Number') {
} else if (paramType === 'Float') {
result.push(`highp float user_${ paramName } = ${ param }`);
}
} else {
Expand All @@ -524,7 +525,7 @@ module.exports = class WebGL2Kernel extends WebGLKernel {
`uniform highp vec2 user_${ paramName }Size`,
`uniform highp vec3 user_${ paramName }Dim`
);
} else if (paramType === 'Number') {
} else if (paramType === 'Integer' || paramType === 'Float') {
result.push(`uniform highp float user_${ paramName }`);
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class Utils extends UtilsCore {
*
* @param {Object} arg - The argument object to evaluate type
*
* @returns {String} Argument type Array/Number/Texture/Unknown
* @returns {String} Argument type Array/Number/Float/Texture/Unknown
*
*/
static getArgumentType(arg) {
Expand All @@ -281,7 +281,10 @@ class Utils extends UtilsCore {
}
return 'Array';
} else if (typeof arg === 'number') {
return 'Number';
if (Number.isInteger(arg)) {
return 'Integer';
}
return 'Float';
} else if (arg instanceof Texture) {
return 'Texture';
} else if (arg instanceof Input) {
Expand Down

0 comments on commit cfd3c77

Please sign in to comment.