mirror of
https://github.com/gpujs/gpu.js.git
synced 2026-01-25 16:08:02 +00:00
fix: Upgrade remaining non-javascript like types
To be referenced in same way. Simplify FunctionNode. Update documentation to be more straightforward. Remove code no longer needed from WebGL2 FunctionNode.
This commit is contained in:
parent
2599966e7c
commit
d765de4cd0
71
README.md
71
README.md
@ -167,6 +167,72 @@ const myFunc = gpu.createKernel(function() {
|
||||
myFunc();
|
||||
// Result: [0, 1, 2, 3, ... 99]
|
||||
```
|
||||
|
||||
### Declaring variables
|
||||
|
||||
GPU.js makes variable declaration inside kernel functions easy. Variable types supported are:
|
||||
Numbers
|
||||
Array(2)
|
||||
Array(3)
|
||||
Array(4)
|
||||
|
||||
Numbers example:
|
||||
```js
|
||||
const myFunc = gpu.createKernel(function() {
|
||||
const i = 1;
|
||||
const j = 0.89;
|
||||
return i + j;
|
||||
}).setOutput([100]);
|
||||
```
|
||||
|
||||
Array(2) examples:
|
||||
Using declaration
|
||||
```js
|
||||
const myFunc = gpu.createKernel(function() {
|
||||
const array2 = [0.08, 2];
|
||||
return array2;
|
||||
}).setOutput([100]);
|
||||
```
|
||||
|
||||
Directly returned
|
||||
```js
|
||||
const myFunc = gpu.createKernel(function() {
|
||||
return [0.08, 2];
|
||||
}).setOutput([100]);
|
||||
```
|
||||
|
||||
Array(3) example:
|
||||
Using declaration
|
||||
```js
|
||||
const myFunc = gpu.createKernel(function() {
|
||||
const array2 = [0.08, 2, 0.1];
|
||||
return array2;
|
||||
}).setOutput([100]);
|
||||
```
|
||||
|
||||
Directly returned
|
||||
```js
|
||||
const myFunc = gpu.createKernel(function() {
|
||||
return [0.08, 2, 0.1];
|
||||
}).setOutput([100]);
|
||||
```
|
||||
|
||||
Array(4) example:
|
||||
Using declaration
|
||||
```js
|
||||
const myFunc = gpu.createKernel(function() {
|
||||
const array2 = [0.08, 2, 0.1, 3];
|
||||
return array2;
|
||||
}).setOutput([100]);
|
||||
```
|
||||
|
||||
Directly returned
|
||||
```js
|
||||
const myFunc = gpu.createKernel(function() {
|
||||
return [0.08, 2, 0.1, 3];
|
||||
}).setOutput([100]);
|
||||
```
|
||||
|
||||
## Accepting Input
|
||||
### Supported Input Types
|
||||
* Numbers
|
||||
@ -368,15 +434,16 @@ To strongly type a function you may use options. Options take an optional hash
|
||||
`returnType`: optional, defaults to float, the value you'd like to return from the function
|
||||
`paramTypes`: optional, defaults to float for each param, a hash of param names with values of the return types
|
||||
|
||||
Types: that may be used for `returnType` or for each property of `paramTypes`:
|
||||
Types: that may be used for `returnType` or for each property of `paramTypes`:
|
||||
'Array'
|
||||
'Array(2)'
|
||||
'Array(3)'
|
||||
'Array(4)'
|
||||
'Integer'
|
||||
'HTMLImage'
|
||||
'HTMLImageArray'
|
||||
'Number'
|
||||
'NumberTexture'
|
||||
'ArrayTexture(4)'
|
||||
|
||||
Example:
|
||||
```js
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
* GPU Accelerated JavaScript
|
||||
*
|
||||
* @version 1.10.0
|
||||
* @date Sun Oct 28 2018 13:54:33 GMT-0400 (EDT)
|
||||
* @date Tue Oct 30 2018 07:33:44 GMT-0600 (MDT)
|
||||
*
|
||||
* @license MIT
|
||||
* The MIT License
|
||||
|
||||
2
bin/gpu-core.min.js
vendored
2
bin/gpu-core.min.js
vendored
@ -5,7 +5,7 @@
|
||||
* GPU Accelerated JavaScript
|
||||
*
|
||||
* @version 1.10.0
|
||||
* @date Sun Oct 28 2018 13:54:33 GMT-0400 (EDT)
|
||||
* @date Tue Oct 30 2018 07:33:44 GMT-0600 (MDT)
|
||||
*
|
||||
* @license MIT
|
||||
* The MIT License
|
||||
|
||||
161
bin/gpu.js
161
bin/gpu.js
@ -5,7 +5,7 @@
|
||||
* GPU Accelerated JavaScript
|
||||
*
|
||||
* @version 1.10.0
|
||||
* @date Sun Oct 28 2018 13:54:33 GMT-0400 (EDT)
|
||||
* @date Tue Oct 30 2018 07:33:45 GMT-0600 (MDT)
|
||||
*
|
||||
* @license MIT
|
||||
* The MIT License
|
||||
@ -877,7 +877,7 @@ module.exports = function (_KernelBase) {
|
||||
var argType = utils.getArgumentType(arguments[0]);
|
||||
if (argType === 'Array') {
|
||||
this.output = utils.getDimensions(argType);
|
||||
} else if (argType === 'Texture' || argType === 'TextureVec4') {
|
||||
} else if (argType === 'NumberTexture' || argType === 'ArrayTexture(4)') {
|
||||
this.output = arguments[0].output;
|
||||
} else {
|
||||
throw 'Auto dimensions not supported for input type: ' + argType;
|
||||
@ -2043,6 +2043,7 @@ module.exports = function () {
|
||||
this.paramSizes = [];
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
var arg = args[i];
|
||||
|
||||
this.paramTypes.push(utils.getArgumentType(arg));
|
||||
this.paramSizes.push(arg.constructor === Input ? arg.size : null);
|
||||
}
|
||||
@ -2910,34 +2911,22 @@ module.exports = function (_FunctionNodeBase) {
|
||||
if (init.object.object.type === 'Identifier') {
|
||||
var _type2 = this.getParamType(init.object.object.name);
|
||||
declarationType = typeLookupMap[_type2];
|
||||
if (!declarationType) {
|
||||
throw new Error('unknown lookup type ' + typeLookupMap);
|
||||
}
|
||||
debugger;
|
||||
} else if (init.object.object.object && init.object.object.object.type === 'Identifier') {
|
||||
var _type3 = this.getParamType(init.object.object.object.name);
|
||||
declarationType = typeLookupMap[_type3];
|
||||
if (!declarationType) {
|
||||
throw new Error('unknown lookup type ' + typeLookupMap);
|
||||
}
|
||||
debugger;
|
||||
} else if (init.object.object.object.object) {
|
||||
if (init.object.object.object.object.type === 'ThisExpression' && init.object.object.object.property.name === 'constants') {
|
||||
var _type4 = this.getConstantType(init.object.object.property.name);
|
||||
declarationType = typeLookupMap[_type4];
|
||||
if (!declarationType) {
|
||||
throw new Error('unknown lookup type ' + typeLookupMap);
|
||||
}
|
||||
debugger;
|
||||
} else if (init.object.object.object.object.object.type === 'ThisExpression' && init.object.object.object.object.property.name === 'constants') {
|
||||
var _type5 = this.getConstantType(init.object.object.object.property.name);
|
||||
declarationType = typeLookupMap[_type5];
|
||||
if (!declarationType) {
|
||||
throw new Error('unknown lookup type ' + typeLookupMap);
|
||||
}
|
||||
debugger;
|
||||
}
|
||||
}
|
||||
else if (init.object.object.object && init.object.object.object.type === 'Identifier') {
|
||||
var _type3 = this.getParamType(init.object.object.object.name);
|
||||
declarationType = typeLookupMap[_type3];
|
||||
}
|
||||
else if (init.object.object.object.object && init.object.object.object.object.type === 'ThisExpression' && init.object.object.object.property.name === 'constants') {
|
||||
var _type4 = this.getConstantType(init.object.object.property.name);
|
||||
declarationType = typeLookupMap[_type4];
|
||||
}
|
||||
else if (init.object.object.object.object.object && init.object.object.object.object.object.type === 'ThisExpression' && init.object.object.object.object.property.name === 'constants') {
|
||||
var _type5 = this.getConstantType(init.object.object.object.property.name);
|
||||
declarationType = typeLookupMap[_type5];
|
||||
}
|
||||
}
|
||||
if (!declarationType) {
|
||||
throw new Error('unknown lookup type ' + typeLookupMap);
|
||||
}
|
||||
} else {
|
||||
if (init.name && this.declarations[init.name]) {
|
||||
@ -3085,7 +3074,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
|
||||
if (this.paramNames) {
|
||||
var idx = this.paramNames.indexOf(reqName);
|
||||
if (idx >= 0 && this.paramTypes[idx] === 'float') {
|
||||
if (idx >= 0 && this.paramTypes[idx] === 'Number') {
|
||||
assumeNotTexture = true;
|
||||
}
|
||||
}
|
||||
@ -3148,7 +3137,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
retArr.push(')');
|
||||
break;
|
||||
case 'TextureVec4':
|
||||
case 'ArrayTexture(4)':
|
||||
case 'HTMLImage':
|
||||
retArr.push('getImage2D(');
|
||||
this.astGeneric(mNode.object, retArr);
|
||||
@ -3397,41 +3386,30 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}(FunctionNodeBase);
|
||||
|
||||
var typeMap = {
|
||||
'TextureVec4': 'sampler2D',
|
||||
'Texture': 'sampler2D',
|
||||
'Input': 'sampler2D',
|
||||
'Array': 'sampler2D',
|
||||
'Array(2)': 'vec2',
|
||||
'Array(3)': 'vec3',
|
||||
'Array(4)': 'vec4',
|
||||
'Array2D': 'sampler2D',
|
||||
'Array3D': 'sampler2D',
|
||||
'Float': 'float',
|
||||
'Input': 'sampler2D',
|
||||
'Integer': 'float',
|
||||
'Number': 'float',
|
||||
'Integer': 'float'
|
||||
'NumberTexture': 'sampler2D',
|
||||
'ArrayTexture(4)': 'sampler2D'
|
||||
};
|
||||
|
||||
var typeLookupMap = {
|
||||
'Array': 'Number',
|
||||
'Array2D': 'Number',
|
||||
'Array3D': 'Number',
|
||||
'HTMLImage': 'Array(4)',
|
||||
'HTMLImageArray': 'Array(4)',
|
||||
'TextureVec4': 'Array(4)',
|
||||
'Array': 'Number'
|
||||
'NumberTexture': 'Number',
|
||||
'ArrayTexture(4)': 'Array(4)'
|
||||
};
|
||||
|
||||
function isIdentifierKernelParam(paramName, ast, funcParam) {
|
||||
return funcParam.paramNames.indexOf(paramName) !== -1;
|
||||
}
|
||||
|
||||
function ensureIndentifierType(paramName, expectedType, ast, funcParam) {
|
||||
var start = ast.loc.start;
|
||||
|
||||
if (!isIdentifierKernelParam(paramName) && expectedType !== 'float') {
|
||||
throw new Error('Error unexpected identifier ' + paramName + ' on line ' + start.line);
|
||||
} else {
|
||||
var actualType = funcParam.paramTypes[funcParam.paramNames.indexOf(paramName)];
|
||||
if (actualType !== expectedType) {
|
||||
throw new Error('Error unexpected identifier ' + paramName + ' on line ' + start.line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function webGlRegexOptimize(inStr) {
|
||||
return inStr.replace(DECODE32_ENCODE32, '((').replace(ENCODE32_DECODE32, '((');
|
||||
}
|
||||
@ -3568,7 +3546,7 @@ module.exports = function (_KernelBase) {
|
||||
var argType = utils.getArgumentType(arguments[0]);
|
||||
if (argType === 'Array') {
|
||||
this.output = utils.getDimensions(argType);
|
||||
} else if (argType === 'Texture' || argType === 'TextureVec4') {
|
||||
} else if (argType === 'NumberTexture' || argType === 'ArrayTexture(4)') {
|
||||
this.output = arguments[0].output;
|
||||
} else {
|
||||
throw new Error('Auto output not supported for input type: ' + argType);
|
||||
@ -3756,7 +3734,7 @@ module.exports = function (_KernelBase) {
|
||||
this._setupOutputTexture();
|
||||
}
|
||||
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
||||
return new Texture(this.outputTexture, texSize, this.threadDim, this.output, this._webGl, 'vec4');
|
||||
return new Texture(this.outputTexture, texSize, this.threadDim, this.output, this._webGl, 'ArrayTexture(4)');
|
||||
}
|
||||
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
@ -4052,10 +4030,15 @@ module.exports = function (_KernelBase) {
|
||||
var gl = this._webGl;
|
||||
var argumentTexture = this.getArgumentTexture(name);
|
||||
if (value instanceof Texture) {
|
||||
type = 'Texture';
|
||||
type = value.type;
|
||||
}
|
||||
switch (type) {
|
||||
case 'Array':
|
||||
case 'Array(2)':
|
||||
case 'Array(3)':
|
||||
case 'Array(4)':
|
||||
case 'Array2D':
|
||||
case 'Array3D':
|
||||
{
|
||||
var dim = utils.getDimensions(value, true);
|
||||
var size = utils.dimToTexSize({
|
||||
@ -4093,6 +4076,7 @@ module.exports = function (_KernelBase) {
|
||||
}
|
||||
case 'Integer':
|
||||
case 'Float':
|
||||
case 'Number':
|
||||
{
|
||||
this.setUniform1f('user_' + name, value);
|
||||
break;
|
||||
@ -4156,7 +4140,8 @@ module.exports = function (_KernelBase) {
|
||||
this.setUniform1i('user_' + name, this.argumentsLength);
|
||||
break;
|
||||
}
|
||||
case 'Texture':
|
||||
case 'ArrayTexture(4)':
|
||||
case 'NumberTexture':
|
||||
{
|
||||
var inputTexture = value;
|
||||
var _dim3 = inputTexture.dimensions;
|
||||
@ -4184,7 +4169,7 @@ module.exports = function (_KernelBase) {
|
||||
var gl = this._webGl;
|
||||
var argumentTexture = this.getArgumentTexture(name);
|
||||
if (value instanceof Texture) {
|
||||
type = 'Texture';
|
||||
type = value.type;
|
||||
}
|
||||
switch (type) {
|
||||
case 'Array':
|
||||
@ -4282,7 +4267,8 @@ module.exports = function (_KernelBase) {
|
||||
this.setUniform1i('constants_' + name, this.constantsLength);
|
||||
break;
|
||||
}
|
||||
case 'Texture':
|
||||
case 'ArrayTexture(4)':
|
||||
case 'NumberTexture':
|
||||
{
|
||||
var inputTexture = value;
|
||||
var _dim6 = inputTexture.dimensions;
|
||||
@ -4447,7 +4433,7 @@ module.exports = function (_KernelBase) {
|
||||
var paramName = paramNames[i];
|
||||
var paramType = paramTypes[i];
|
||||
if (this.hardcodeConstants) {
|
||||
if (paramType === 'Array' || paramType === 'Texture' || paramType === 'TextureVec4') {
|
||||
if (paramType === 'Array' || paramType === 'NumberTexture' || paramType === 'ArrayTexture(4)') {
|
||||
var paramDim = utils.getDimensions(param, true);
|
||||
var paramSize = utils.dimToTexSize({
|
||||
floatTextures: this.floatTextures,
|
||||
@ -4461,7 +4447,7 @@ module.exports = function (_KernelBase) {
|
||||
result.push('float user_' + paramName + ' = ' + param);
|
||||
}
|
||||
} else {
|
||||
if (paramType === 'Array' || paramType === 'Texture' || paramType === 'TextureVec4' || paramType === 'Input' || paramType === 'HTMLImage') {
|
||||
if (paramType === 'Array' || paramType === 'NumberTexture' || paramType === 'ArrayTexture(4)' || paramType === 'Input' || paramType === 'HTMLImage') {
|
||||
result.push('uniform sampler2D user_' + paramName, 'uniform ivec2 user_' + paramName + 'Size', 'uniform ivec3 user_' + paramName + 'Dim');
|
||||
if (paramType !== 'HTMLImage') {
|
||||
result.push('uniform int user_' + paramName + 'BitRatio');
|
||||
@ -4496,7 +4482,8 @@ module.exports = function (_KernelBase) {
|
||||
case 'Array':
|
||||
case 'Input':
|
||||
case 'HTMLImage':
|
||||
case 'Texture':
|
||||
case 'NumberTexture':
|
||||
case 'ArrayTexture(4)':
|
||||
result.push('uniform sampler2D constants_' + name, 'uniform ivec2 constants_' + name + 'Size', 'uniform ivec3 constants_' + name + 'Dim', 'uniform int constants_' + name + 'BitRatio');
|
||||
break;
|
||||
default:
|
||||
@ -4857,9 +4844,6 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var WebGLFunctionNode = require('../web-gl/function-node');
|
||||
|
||||
var constantsPrefix = 'this.constants.';
|
||||
|
||||
var DECODE32_ENCODE32 = /decode32\(\s+encode32\(/g;
|
||||
var ENCODE32_DECODE32 = /encode32\(\s+decode32\(/g;
|
||||
|
||||
@ -4941,20 +4925,6 @@ module.exports = function (_WebGLFunctionNode) {
|
||||
return WebGL2FunctionNode;
|
||||
}(WebGLFunctionNode);
|
||||
|
||||
var typeMap = {
|
||||
'TextureVec4': 'sampler2D',
|
||||
'Texture': 'sampler2D',
|
||||
'Input': 'sampler2D',
|
||||
'Array': 'sampler2D',
|
||||
'Array(2)': 'vec2',
|
||||
'Array(3)': 'vec3',
|
||||
'Array(4)': 'vec4',
|
||||
'Number': 'float',
|
||||
'Integer': 'float',
|
||||
'HTMLImage': 'vec4',
|
||||
'HTMLImageArray': 'vec4'
|
||||
};
|
||||
|
||||
function webGlRegexOptimize(inStr) {
|
||||
return inStr.replace(DECODE32_ENCODE32, '((').replace(ENCODE32_DECODE32, '((');
|
||||
}
|
||||
@ -5018,7 +4988,7 @@ module.exports = function (_WebGLKernel) {
|
||||
var argType = utils.getArgumentType(arguments[0]);
|
||||
if (argType === 'Array') {
|
||||
this.output = utils.getDimensions(argType);
|
||||
} else if (argType === 'Texture' || argType === 'TextureVec4') {
|
||||
} else if (argType === 'NumberTexture' || argType === 'ArrayTexture(4)') {
|
||||
this.output = arguments[0].output;
|
||||
} else {
|
||||
throw new Error('Auto output not supported for input type: ' + argType);
|
||||
@ -5085,7 +5055,7 @@ module.exports = function (_WebGLKernel) {
|
||||
this._setupOutputTexture();
|
||||
}
|
||||
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
||||
return new Texture(this.outputTexture, texSize, this.threadDim, this.output, this._webGl, 'vec4');
|
||||
return new Texture(this.outputTexture, texSize, this.threadDim, this.output, this._webGl, 'ArrayTexture(4)');
|
||||
}
|
||||
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
@ -5196,7 +5166,7 @@ module.exports = function (_WebGLKernel) {
|
||||
var gl = this._webGl;
|
||||
var argumentTexture = this.getArgumentTexture(name);
|
||||
if (value instanceof Texture) {
|
||||
type = 'Texture';
|
||||
type = value.type;
|
||||
}
|
||||
switch (type) {
|
||||
case 'Array':
|
||||
@ -5237,6 +5207,7 @@ module.exports = function (_WebGLKernel) {
|
||||
}
|
||||
case 'Integer':
|
||||
case 'Float':
|
||||
case 'Number':
|
||||
{
|
||||
this.setUniform1f('user_' + name, value);
|
||||
break;
|
||||
@ -5331,7 +5302,8 @@ module.exports = function (_WebGLKernel) {
|
||||
this.setUniform1i('user_' + name, this.argumentsLength);
|
||||
break;
|
||||
}
|
||||
case 'Texture':
|
||||
case 'ArrayTexture(4)':
|
||||
case 'NumberTexture':
|
||||
{
|
||||
var inputTexture = value;
|
||||
var _dim4 = inputTexture.dimensions;
|
||||
@ -5372,8 +5344,8 @@ module.exports = function (_WebGLKernel) {
|
||||
case 'Array':
|
||||
case 'Input':
|
||||
case 'HTMLImage':
|
||||
case 'TextureVec4':
|
||||
case 'Texture':
|
||||
case 'ArrayTexture(4)':
|
||||
case 'NumberTexture':
|
||||
result.push('uniform highp sampler2D constants_' + name, 'uniform highp ivec2 constants_' + name + 'Size', 'uniform highp ivec3 constants_' + name + 'Dim', 'uniform highp int constants_' + name + 'BitRatio');
|
||||
break;
|
||||
case 'HTMLImageArray':
|
||||
@ -5395,7 +5367,7 @@ module.exports = function (_WebGLKernel) {
|
||||
var gl = this._webGl;
|
||||
var argumentTexture = this.getArgumentTexture(name);
|
||||
if (value instanceof Texture) {
|
||||
type = 'Texture';
|
||||
type = value.type;
|
||||
}
|
||||
switch (type) {
|
||||
case 'Array':
|
||||
@ -5524,7 +5496,8 @@ module.exports = function (_WebGLKernel) {
|
||||
this.setUniform1i('constants_' + name, this.constantsLength);
|
||||
break;
|
||||
}
|
||||
case 'Texture':
|
||||
case 'ArrayTexture(4)':
|
||||
case 'NumberTexture':
|
||||
{
|
||||
var inputTexture = value;
|
||||
var _dim8 = inputTexture.dimensions;
|
||||
@ -5587,7 +5560,7 @@ module.exports = function (_WebGLKernel) {
|
||||
var paramName = paramNames[i];
|
||||
var paramType = paramTypes[i];
|
||||
if (this.hardcodeConstants) {
|
||||
if (paramType === 'Array' || paramType === 'Texture' || paramType === 'TextureVec4') {
|
||||
if (paramType === 'Array' || paramType === 'NumberTexture' || paramType === 'ArrayTexture(4)') {
|
||||
var paramDim = utils.getDimensions(param, true);
|
||||
var paramSize = utils.dimToTexSize({
|
||||
floatTextures: this.floatTextures,
|
||||
@ -5605,7 +5578,7 @@ module.exports = function (_WebGLKernel) {
|
||||
result.push('highp float user_' + paramName + ' = ' + param);
|
||||
}
|
||||
} else {
|
||||
if (paramType === 'Array' || paramType === 'Texture' || paramType === 'TextureVec4' || paramType === 'Input' || paramType === 'HTMLImage') {
|
||||
if (paramType === 'Array' || paramType === 'NumberTexture' || paramType === 'ArrayTexture(4)' || paramType === 'Input' || paramType === 'HTMLImage') {
|
||||
result.push('uniform highp sampler2D user_' + paramName, 'uniform highp ivec2 user_' + paramName + 'Size', 'uniform highp ivec3 user_' + paramName + 'Dim');
|
||||
if (paramType !== 'HTMLImage') {
|
||||
result.push('uniform highp int user_' + paramName + 'BitRatio');
|
||||
@ -6241,7 +6214,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
||||
module.exports = function () {
|
||||
|
||||
function Texture(texture, size, dimensions, output, webGl) {
|
||||
var type = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'float';
|
||||
var type = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'NumberTexture';
|
||||
|
||||
_classCallCheck(this, Texture);
|
||||
|
||||
@ -6637,11 +6610,7 @@ var Utils = function (_UtilsCore) {
|
||||
}
|
||||
return 'Float';
|
||||
} else if (arg instanceof Texture) {
|
||||
if (arg.type === 'vec4') {
|
||||
return 'TextureVec4';
|
||||
} else {
|
||||
return 'Texture';
|
||||
}
|
||||
return arg.type;
|
||||
} else if (arg instanceof Input) {
|
||||
return 'Input';
|
||||
} else if (arg.nodeName === 'IMG') {
|
||||
|
||||
18
bin/gpu.min.js
vendored
18
bin/gpu.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/backend/cpu/kernel.js
vendored
2
dist/backend/cpu/kernel.js
vendored
@ -77,7 +77,7 @@ module.exports = function (_KernelBase) {
|
||||
var argType = utils.getArgumentType(arguments[0]);
|
||||
if (argType === 'Array') {
|
||||
this.output = utils.getDimensions(argType);
|
||||
} else if (argType === 'Texture' || argType === 'TextureVec4') {
|
||||
} else if (argType === 'NumberTexture' || argType === 'ArrayTexture(4)') {
|
||||
this.output = arguments[0].output;
|
||||
} else {
|
||||
throw 'Auto dimensions not supported for input type: ' + argType;
|
||||
|
||||
1
dist/backend/kernel-base.js
vendored
1
dist/backend/kernel-base.js
vendored
@ -107,6 +107,7 @@ module.exports = function () {
|
||||
this.paramSizes = [];
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
var arg = args[i];
|
||||
|
||||
this.paramTypes.push(utils.getArgumentType(arg));
|
||||
this.paramSizes.push(arg.constructor === Input ? arg.size : null);
|
||||
}
|
||||
|
||||
85
dist/backend/web-gl/function-node.js
vendored
85
dist/backend/web-gl/function-node.js
vendored
@ -689,37 +689,29 @@ module.exports = function (_FunctionNodeBase) {
|
||||
if (init) {
|
||||
if (init.object) {
|
||||
if (init.object.type === 'MemberExpression' && init.object.object) {
|
||||
// param[]
|
||||
if (init.object.object.type === 'Identifier') {
|
||||
var _type2 = this.getParamType(init.object.object.name);
|
||||
declarationType = typeLookupMap[_type2];
|
||||
if (!declarationType) {
|
||||
throw new Error('unknown lookup type ' + typeLookupMap);
|
||||
}
|
||||
debugger;
|
||||
} else if (init.object.object.object && init.object.object.object.type === 'Identifier') {
|
||||
var _type3 = this.getParamType(init.object.object.object.name);
|
||||
declarationType = typeLookupMap[_type3];
|
||||
if (!declarationType) {
|
||||
throw new Error('unknown lookup type ' + typeLookupMap);
|
||||
}
|
||||
debugger;
|
||||
} else if (init.object.object.object.object) {
|
||||
if (init.object.object.object.object.type === 'ThisExpression' && init.object.object.object.property.name === 'constants') {
|
||||
var _type4 = this.getConstantType(init.object.object.property.name);
|
||||
declarationType = typeLookupMap[_type4];
|
||||
if (!declarationType) {
|
||||
throw new Error('unknown lookup type ' + typeLookupMap);
|
||||
}
|
||||
debugger;
|
||||
} else if (init.object.object.object.object.object.type === 'ThisExpression' && init.object.object.object.object.property.name === 'constants') {
|
||||
var _type5 = this.getConstantType(init.object.object.object.property.name);
|
||||
declarationType = typeLookupMap[_type5];
|
||||
if (!declarationType) {
|
||||
throw new Error('unknown lookup type ' + typeLookupMap);
|
||||
}
|
||||
debugger;
|
||||
}
|
||||
}
|
||||
// param[][]
|
||||
else if (init.object.object.object && init.object.object.object.type === 'Identifier') {
|
||||
var _type3 = this.getParamType(init.object.object.object.name);
|
||||
declarationType = typeLookupMap[_type3];
|
||||
}
|
||||
// this.constants.param[]
|
||||
else if (init.object.object.object.object && init.object.object.object.object.type === 'ThisExpression' && init.object.object.object.property.name === 'constants') {
|
||||
var _type4 = this.getConstantType(init.object.object.property.name);
|
||||
declarationType = typeLookupMap[_type4];
|
||||
}
|
||||
// this.constants.param[][]
|
||||
else if (init.object.object.object.object.object && init.object.object.object.object.object.type === 'ThisExpression' && init.object.object.object.object.property.name === 'constants') {
|
||||
var _type5 = this.getConstantType(init.object.object.object.property.name);
|
||||
declarationType = typeLookupMap[_type5];
|
||||
}
|
||||
}
|
||||
if (!declarationType) {
|
||||
throw new Error('unknown lookup type ' + typeLookupMap);
|
||||
}
|
||||
} else {
|
||||
if (init.name && this.declarations[init.name]) {
|
||||
@ -978,7 +970,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
// Possibly an array request - handle it as such
|
||||
if (this.paramNames) {
|
||||
var idx = this.paramNames.indexOf(reqName);
|
||||
if (idx >= 0 && this.paramTypes[idx] === 'float') {
|
||||
if (idx >= 0 && this.paramTypes[idx] === 'Number') {
|
||||
assumeNotTexture = true;
|
||||
}
|
||||
}
|
||||
@ -1045,7 +1037,7 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}
|
||||
retArr.push(')');
|
||||
break;
|
||||
case 'TextureVec4':
|
||||
case 'ArrayTexture(4)':
|
||||
case 'HTMLImage':
|
||||
// Get from image
|
||||
retArr.push('getImage2D(');
|
||||
@ -1351,41 +1343,30 @@ module.exports = function (_FunctionNodeBase) {
|
||||
}(FunctionNodeBase);
|
||||
|
||||
var typeMap = {
|
||||
'TextureVec4': 'sampler2D',
|
||||
'Texture': 'sampler2D',
|
||||
'Input': 'sampler2D',
|
||||
'Array': 'sampler2D',
|
||||
'Array(2)': 'vec2',
|
||||
'Array(3)': 'vec3',
|
||||
'Array(4)': 'vec4',
|
||||
'Array2D': 'sampler2D',
|
||||
'Array3D': 'sampler2D',
|
||||
'Float': 'float',
|
||||
'Input': 'sampler2D',
|
||||
'Integer': 'float',
|
||||
'Number': 'float',
|
||||
'Integer': 'float'
|
||||
'NumberTexture': 'sampler2D',
|
||||
'ArrayTexture(4)': 'sampler2D'
|
||||
};
|
||||
|
||||
var typeLookupMap = {
|
||||
'Array': 'Number',
|
||||
'Array2D': 'Number',
|
||||
'Array3D': 'Number',
|
||||
'HTMLImage': 'Array(4)',
|
||||
'HTMLImageArray': 'Array(4)',
|
||||
'TextureVec4': 'Array(4)',
|
||||
'Array': 'Number'
|
||||
'NumberTexture': 'Number',
|
||||
'ArrayTexture(4)': 'Array(4)'
|
||||
};
|
||||
|
||||
function isIdentifierKernelParam(paramName, ast, funcParam) {
|
||||
return funcParam.paramNames.indexOf(paramName) !== -1;
|
||||
}
|
||||
|
||||
function ensureIndentifierType(paramName, expectedType, ast, funcParam) {
|
||||
var start = ast.loc.start;
|
||||
|
||||
if (!isIdentifierKernelParam(paramName) && expectedType !== 'float') {
|
||||
throw new Error('Error unexpected identifier ' + paramName + ' on line ' + start.line);
|
||||
} else {
|
||||
var actualType = funcParam.paramTypes[funcParam.paramNames.indexOf(paramName)];
|
||||
if (actualType !== expectedType) {
|
||||
throw new Error('Error unexpected identifier ' + paramName + ' on line ' + start.line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @function
|
||||
|
||||
27
dist/backend/web-gl/kernel.js
vendored
27
dist/backend/web-gl/kernel.js
vendored
@ -141,7 +141,7 @@ module.exports = function (_KernelBase) {
|
||||
var argType = utils.getArgumentType(arguments[0]);
|
||||
if (argType === 'Array') {
|
||||
this.output = utils.getDimensions(argType);
|
||||
} else if (argType === 'Texture' || argType === 'TextureVec4') {
|
||||
} else if (argType === 'NumberTexture' || argType === 'ArrayTexture(4)') {
|
||||
this.output = arguments[0].output;
|
||||
} else {
|
||||
throw new Error('Auto output not supported for input type: ' + argType);
|
||||
@ -351,7 +351,7 @@ module.exports = function (_KernelBase) {
|
||||
this._setupOutputTexture();
|
||||
}
|
||||
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
||||
return new Texture(this.outputTexture, texSize, this.threadDim, this.output, this._webGl, 'vec4');
|
||||
return new Texture(this.outputTexture, texSize, this.threadDim, this.output, this._webGl, 'ArrayTexture(4)');
|
||||
}
|
||||
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
@ -757,10 +757,15 @@ module.exports = function (_KernelBase) {
|
||||
var gl = this._webGl;
|
||||
var argumentTexture = this.getArgumentTexture(name);
|
||||
if (value instanceof Texture) {
|
||||
type = 'Texture';
|
||||
type = value.type;
|
||||
}
|
||||
switch (type) {
|
||||
case 'Array':
|
||||
case 'Array(2)':
|
||||
case 'Array(3)':
|
||||
case 'Array(4)':
|
||||
case 'Array2D':
|
||||
case 'Array3D':
|
||||
{
|
||||
var dim = utils.getDimensions(value, true);
|
||||
var size = utils.dimToTexSize({
|
||||
@ -798,6 +803,7 @@ module.exports = function (_KernelBase) {
|
||||
}
|
||||
case 'Integer':
|
||||
case 'Float':
|
||||
case 'Number':
|
||||
{
|
||||
this.setUniform1f('user_' + name, value);
|
||||
break;
|
||||
@ -862,7 +868,8 @@ module.exports = function (_KernelBase) {
|
||||
this.setUniform1i('user_' + name, this.argumentsLength);
|
||||
break;
|
||||
}
|
||||
case 'Texture':
|
||||
case 'ArrayTexture(4)':
|
||||
case 'NumberTexture':
|
||||
{
|
||||
var inputTexture = value;
|
||||
var _dim3 = inputTexture.dimensions;
|
||||
@ -903,7 +910,7 @@ module.exports = function (_KernelBase) {
|
||||
var gl = this._webGl;
|
||||
var argumentTexture = this.getArgumentTexture(name);
|
||||
if (value instanceof Texture) {
|
||||
type = 'Texture';
|
||||
type = value.type;
|
||||
}
|
||||
switch (type) {
|
||||
case 'Array':
|
||||
@ -1002,7 +1009,8 @@ module.exports = function (_KernelBase) {
|
||||
this.setUniform1i('constants_' + name, this.constantsLength);
|
||||
break;
|
||||
}
|
||||
case 'Texture':
|
||||
case 'ArrayTexture(4)':
|
||||
case 'NumberTexture':
|
||||
{
|
||||
var inputTexture = value;
|
||||
var _dim6 = inputTexture.dimensions;
|
||||
@ -1298,7 +1306,7 @@ module.exports = function (_KernelBase) {
|
||||
var paramName = paramNames[i];
|
||||
var paramType = paramTypes[i];
|
||||
if (this.hardcodeConstants) {
|
||||
if (paramType === 'Array' || paramType === 'Texture' || paramType === 'TextureVec4') {
|
||||
if (paramType === 'Array' || paramType === 'NumberTexture' || paramType === 'ArrayTexture(4)') {
|
||||
var paramDim = utils.getDimensions(param, true);
|
||||
var paramSize = utils.dimToTexSize({
|
||||
floatTextures: this.floatTextures,
|
||||
@ -1312,7 +1320,7 @@ module.exports = function (_KernelBase) {
|
||||
result.push('float user_' + paramName + ' = ' + param);
|
||||
}
|
||||
} else {
|
||||
if (paramType === 'Array' || paramType === 'Texture' || paramType === 'TextureVec4' || paramType === 'Input' || paramType === 'HTMLImage') {
|
||||
if (paramType === 'Array' || paramType === 'NumberTexture' || paramType === 'ArrayTexture(4)' || paramType === 'Input' || paramType === 'HTMLImage') {
|
||||
result.push('uniform sampler2D user_' + paramName, 'uniform ivec2 user_' + paramName + 'Size', 'uniform ivec3 user_' + paramName + 'Dim');
|
||||
if (paramType !== 'HTMLImage') {
|
||||
result.push('uniform int user_' + paramName + 'BitRatio');
|
||||
@ -1353,7 +1361,8 @@ module.exports = function (_KernelBase) {
|
||||
case 'Array':
|
||||
case 'Input':
|
||||
case 'HTMLImage':
|
||||
case 'Texture':
|
||||
case 'NumberTexture':
|
||||
case 'ArrayTexture(4)':
|
||||
result.push('uniform sampler2D constants_' + name, 'uniform ivec2 constants_' + name + 'Size', 'uniform ivec3 constants_' + name + 'Dim', 'uniform int constants_' + name + 'BitRatio');
|
||||
break;
|
||||
default:
|
||||
|
||||
19
dist/backend/web-gl2/function-node.js
vendored
19
dist/backend/web-gl2/function-node.js
vendored
@ -9,11 +9,6 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var WebGLFunctionNode = require('../web-gl/function-node');
|
||||
|
||||
// Closure capture for the ast function, prevent collision with existing AST functions
|
||||
// The prefixes to use
|
||||
var constantsPrefix = 'this.constants.';
|
||||
|
||||
var DECODE32_ENCODE32 = /decode32\(\s+encode32\(/g;
|
||||
var ENCODE32_DECODE32 = /encode32\(\s+decode32\(/g;
|
||||
|
||||
@ -118,20 +113,6 @@ module.exports = function (_WebGLFunctionNode) {
|
||||
return WebGL2FunctionNode;
|
||||
}(WebGLFunctionNode);
|
||||
|
||||
var typeMap = {
|
||||
'TextureVec4': 'sampler2D',
|
||||
'Texture': 'sampler2D',
|
||||
'Input': 'sampler2D',
|
||||
'Array': 'sampler2D',
|
||||
'Array(2)': 'vec2',
|
||||
'Array(3)': 'vec3',
|
||||
'Array(4)': 'vec4',
|
||||
'Number': 'float',
|
||||
'Integer': 'float',
|
||||
'HTMLImage': 'vec4',
|
||||
'HTMLImageArray': 'vec4'
|
||||
};
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @function
|
||||
|
||||
23
dist/backend/web-gl2/kernel.js
vendored
23
dist/backend/web-gl2/kernel.js
vendored
@ -67,7 +67,7 @@ module.exports = function (_WebGLKernel) {
|
||||
var argType = utils.getArgumentType(arguments[0]);
|
||||
if (argType === 'Array') {
|
||||
this.output = utils.getDimensions(argType);
|
||||
} else if (argType === 'Texture' || argType === 'TextureVec4') {
|
||||
} else if (argType === 'NumberTexture' || argType === 'ArrayTexture(4)') {
|
||||
this.output = arguments[0].output;
|
||||
} else {
|
||||
throw new Error('Auto output not supported for input type: ' + argType);
|
||||
@ -147,7 +147,7 @@ module.exports = function (_WebGLKernel) {
|
||||
this._setupOutputTexture();
|
||||
}
|
||||
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
||||
return new Texture(this.outputTexture, texSize, this.threadDim, this.output, this._webGl, 'vec4');
|
||||
return new Texture(this.outputTexture, texSize, this.threadDim, this.output, this._webGl, 'ArrayTexture(4)');
|
||||
}
|
||||
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
@ -296,7 +296,7 @@ module.exports = function (_WebGLKernel) {
|
||||
var gl = this._webGl;
|
||||
var argumentTexture = this.getArgumentTexture(name);
|
||||
if (value instanceof Texture) {
|
||||
type = 'Texture';
|
||||
type = value.type;
|
||||
}
|
||||
switch (type) {
|
||||
case 'Array':
|
||||
@ -337,6 +337,7 @@ module.exports = function (_WebGLKernel) {
|
||||
}
|
||||
case 'Integer':
|
||||
case 'Float':
|
||||
case 'Number':
|
||||
{
|
||||
this.setUniform1f('user_' + name, value);
|
||||
break;
|
||||
@ -433,7 +434,8 @@ module.exports = function (_WebGLKernel) {
|
||||
this.setUniform1i('user_' + name, this.argumentsLength);
|
||||
break;
|
||||
}
|
||||
case 'Texture':
|
||||
case 'ArrayTexture(4)':
|
||||
case 'NumberTexture':
|
||||
{
|
||||
var inputTexture = value;
|
||||
var _dim4 = inputTexture.dimensions;
|
||||
@ -480,8 +482,8 @@ module.exports = function (_WebGLKernel) {
|
||||
case 'Array':
|
||||
case 'Input':
|
||||
case 'HTMLImage':
|
||||
case 'TextureVec4':
|
||||
case 'Texture':
|
||||
case 'ArrayTexture(4)':
|
||||
case 'NumberTexture':
|
||||
result.push('uniform highp sampler2D constants_' + name, 'uniform highp ivec2 constants_' + name + 'Size', 'uniform highp ivec3 constants_' + name + 'Dim', 'uniform highp int constants_' + name + 'BitRatio');
|
||||
break;
|
||||
case 'HTMLImageArray':
|
||||
@ -516,7 +518,7 @@ module.exports = function (_WebGLKernel) {
|
||||
var gl = this._webGl;
|
||||
var argumentTexture = this.getArgumentTexture(name);
|
||||
if (value instanceof Texture) {
|
||||
type = 'Texture';
|
||||
type = value.type;
|
||||
}
|
||||
switch (type) {
|
||||
case 'Array':
|
||||
@ -647,7 +649,8 @@ module.exports = function (_WebGLKernel) {
|
||||
this.setUniform1i('constants_' + name, this.constantsLength);
|
||||
break;
|
||||
}
|
||||
case 'Texture':
|
||||
case 'ArrayTexture(4)':
|
||||
case 'NumberTexture':
|
||||
{
|
||||
var inputTexture = value;
|
||||
var _dim8 = inputTexture.dimensions;
|
||||
@ -749,7 +752,7 @@ module.exports = function (_WebGLKernel) {
|
||||
var paramName = paramNames[i];
|
||||
var paramType = paramTypes[i];
|
||||
if (this.hardcodeConstants) {
|
||||
if (paramType === 'Array' || paramType === 'Texture' || paramType === 'TextureVec4') {
|
||||
if (paramType === 'Array' || paramType === 'NumberTexture' || paramType === 'ArrayTexture(4)') {
|
||||
var paramDim = utils.getDimensions(param, true);
|
||||
var paramSize = utils.dimToTexSize({
|
||||
floatTextures: this.floatTextures,
|
||||
@ -767,7 +770,7 @@ module.exports = function (_WebGLKernel) {
|
||||
result.push('highp float user_' + paramName + ' = ' + param);
|
||||
}
|
||||
} else {
|
||||
if (paramType === 'Array' || paramType === 'Texture' || paramType === 'TextureVec4' || paramType === 'Input' || paramType === 'HTMLImage') {
|
||||
if (paramType === 'Array' || paramType === 'NumberTexture' || paramType === 'ArrayTexture(4)' || paramType === 'Input' || paramType === 'HTMLImage') {
|
||||
result.push('uniform highp sampler2D user_' + paramName, 'uniform highp ivec2 user_' + paramName + 'Size', 'uniform highp ivec3 user_' + paramName + 'Dim');
|
||||
if (paramType !== 'HTMLImage') {
|
||||
result.push('uniform highp int user_' + paramName + 'BitRatio');
|
||||
|
||||
2
dist/core/texture.js
vendored
2
dist/core/texture.js
vendored
@ -17,7 +17,7 @@ module.exports = function () {
|
||||
* @param {String} [type]
|
||||
*/
|
||||
function Texture(texture, size, dimensions, output, webGl) {
|
||||
var type = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'float';
|
||||
var type = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'NumberTexture';
|
||||
|
||||
_classCallCheck(this, Texture);
|
||||
|
||||
|
||||
6
dist/core/utils.js
vendored
6
dist/core/utils.js
vendored
@ -339,11 +339,7 @@ var Utils = function (_UtilsCore) {
|
||||
}
|
||||
return 'Float';
|
||||
} else if (arg instanceof Texture) {
|
||||
if (arg.type === 'vec4') {
|
||||
return 'TextureVec4';
|
||||
} else {
|
||||
return 'Texture';
|
||||
}
|
||||
return arg.type;
|
||||
} else if (arg instanceof Input) {
|
||||
return 'Input';
|
||||
} else if (arg.nodeName === 'IMG') {
|
||||
|
||||
@ -60,7 +60,7 @@ module.exports = class CPUKernel extends KernelBase {
|
||||
const argType = utils.getArgumentType(arguments[0]);
|
||||
if (argType === 'Array') {
|
||||
this.output = utils.getDimensions(argType);
|
||||
} else if (argType === 'Texture' || argType === 'TextureVec4') {
|
||||
} else if (argType === 'NumberTexture' || argType === 'ArrayTexture(4)') {
|
||||
this.output = arguments[0].output;
|
||||
} else {
|
||||
throw 'Auto dimensions not supported for input type: ' + argType;
|
||||
|
||||
@ -96,6 +96,7 @@ module.exports = class KernelBase {
|
||||
this.paramSizes = [];
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const arg = args[i];
|
||||
|
||||
this.paramTypes.push(utils.getArgumentType(arg));
|
||||
this.paramSizes.push(arg.constructor === Input ? arg.size : null);
|
||||
}
|
||||
|
||||
@ -653,48 +653,40 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
init.object.type === 'MemberExpression' &&
|
||||
init.object.object
|
||||
) {
|
||||
// param[]
|
||||
if (init.object.object.type === 'Identifier') {
|
||||
const type = this.getParamType(init.object.object.name);
|
||||
declarationType = typeLookupMap[type];
|
||||
if (!declarationType) {
|
||||
throw new Error(`unknown lookup type ${ typeLookupMap }`);
|
||||
}
|
||||
debugger;
|
||||
} else if (
|
||||
}
|
||||
// param[][]
|
||||
else if (
|
||||
init.object.object.object &&
|
||||
init.object.object.object.type === 'Identifier'
|
||||
) {
|
||||
const type = this.getParamType(init.object.object.object.name);
|
||||
declarationType = typeLookupMap[type];
|
||||
if (!declarationType) {
|
||||
throw new Error(`unknown lookup type ${ typeLookupMap }`);
|
||||
}
|
||||
debugger;
|
||||
} else if (
|
||||
init.object.object.object.object
|
||||
) {
|
||||
if (
|
||||
init.object.object.object.object.type === 'ThisExpression' &&
|
||||
init.object.object.object.property.name === 'constants'
|
||||
) {
|
||||
const type = this.getConstantType(init.object.object.property.name);
|
||||
declarationType = typeLookupMap[type];
|
||||
if (!declarationType) {
|
||||
throw new Error(`unknown lookup type ${ typeLookupMap }`);
|
||||
}
|
||||
debugger;
|
||||
} else if (
|
||||
init.object.object.object.object.object.type === 'ThisExpression' &&
|
||||
init.object.object.object.object.property.name === 'constants'
|
||||
) {
|
||||
const type = this.getConstantType(init.object.object.object.property.name);
|
||||
declarationType = typeLookupMap[type];
|
||||
if (!declarationType) {
|
||||
throw new Error(`unknown lookup type ${ typeLookupMap }`);
|
||||
}
|
||||
debugger;
|
||||
}
|
||||
}
|
||||
// this.constants.param[]
|
||||
else if (
|
||||
init.object.object.object.object &&
|
||||
init.object.object.object.object.type === 'ThisExpression' &&
|
||||
init.object.object.object.property.name === 'constants'
|
||||
) {
|
||||
const type = this.getConstantType(init.object.object.property.name);
|
||||
declarationType = typeLookupMap[type];
|
||||
}
|
||||
// this.constants.param[][]
|
||||
else if (
|
||||
init.object.object.object.object.object &&
|
||||
init.object.object.object.object.object.type === 'ThisExpression' &&
|
||||
init.object.object.object.object.property.name === 'constants'
|
||||
) {
|
||||
const type = this.getConstantType(init.object.object.object.property.name);
|
||||
declarationType = typeLookupMap[type];
|
||||
}
|
||||
}
|
||||
if (!declarationType) {
|
||||
throw new Error(`unknown lookup type ${ typeLookupMap }`);
|
||||
}
|
||||
} else {
|
||||
if (init.name && this.declarations[init.name]) {
|
||||
@ -933,7 +925,7 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
// Possibly an array request - handle it as such
|
||||
if (this.paramNames) {
|
||||
const idx = this.paramNames.indexOf(reqName);
|
||||
if (idx >= 0 && this.paramTypes[idx] === 'float') {
|
||||
if (idx >= 0 && this.paramTypes[idx] === 'Number') {
|
||||
assumeNotTexture = true;
|
||||
}
|
||||
}
|
||||
@ -1005,7 +997,7 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
}
|
||||
retArr.push(')');
|
||||
break;
|
||||
case 'TextureVec4':
|
||||
case 'ArrayTexture(4)':
|
||||
case 'HTMLImage':
|
||||
// Get from image
|
||||
retArr.push('getImage2D(');
|
||||
@ -1303,41 +1295,30 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
|
||||
};
|
||||
|
||||
const typeMap = {
|
||||
'TextureVec4': 'sampler2D',
|
||||
'Texture': 'sampler2D',
|
||||
'Input': 'sampler2D',
|
||||
'Array': 'sampler2D',
|
||||
'Array(2)': 'vec2',
|
||||
'Array(3)': 'vec3',
|
||||
'Array(4)': 'vec4',
|
||||
'Array2D': 'sampler2D',
|
||||
'Array3D': 'sampler2D',
|
||||
'Float': 'float',
|
||||
'Input': 'sampler2D',
|
||||
'Integer': 'float',
|
||||
'Number': 'float',
|
||||
'Integer': 'float'
|
||||
'NumberTexture': 'sampler2D',
|
||||
'ArrayTexture(4)': 'sampler2D'
|
||||
};
|
||||
|
||||
const typeLookupMap = {
|
||||
'Array': 'Number',
|
||||
'Array2D': 'Number',
|
||||
'Array3D': 'Number',
|
||||
'HTMLImage': 'Array(4)',
|
||||
'HTMLImageArray': 'Array(4)',
|
||||
'TextureVec4': 'Array(4)',
|
||||
'Array': 'Number'
|
||||
'NumberTexture': 'Number',
|
||||
'ArrayTexture(4)': 'Array(4)',
|
||||
};
|
||||
|
||||
function isIdentifierKernelParam(paramName, ast, funcParam) {
|
||||
return funcParam.paramNames.indexOf(paramName) !== -1;
|
||||
}
|
||||
|
||||
function ensureIndentifierType(paramName, expectedType, ast, funcParam) {
|
||||
const start = ast.loc.start;
|
||||
|
||||
if (!isIdentifierKernelParam(paramName) && expectedType !== 'float') {
|
||||
throw new Error('Error unexpected identifier ' + paramName + ' on line ' + start.line);
|
||||
} else {
|
||||
const actualType = funcParam.paramTypes[funcParam.paramNames.indexOf(paramName)];
|
||||
if (actualType !== expectedType) {
|
||||
throw new Error('Error unexpected identifier ' + paramName + ' on line ' + start.line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @function
|
||||
|
||||
@ -113,7 +113,7 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
const argType = utils.getArgumentType(arguments[0]);
|
||||
if (argType === 'Array') {
|
||||
this.output = utils.getDimensions(argType);
|
||||
} else if (argType === 'Texture' || argType === 'TextureVec4') {
|
||||
} else if (argType === 'NumberTexture' || argType === 'ArrayTexture(4)') {
|
||||
this.output = arguments[0].output;
|
||||
} else {
|
||||
throw new Error('Auto output not supported for input type: ' + argType);
|
||||
@ -328,7 +328,7 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
this._setupOutputTexture();
|
||||
}
|
||||
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
||||
return new Texture(this.outputTexture, texSize, this.threadDim, this.output, this._webGl, 'vec4');
|
||||
return new Texture(this.outputTexture, texSize, this.threadDim, this.output, this._webGl, 'ArrayTexture(4)');
|
||||
}
|
||||
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
@ -714,10 +714,15 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
const gl = this._webGl;
|
||||
const argumentTexture = this.getArgumentTexture(name);
|
||||
if (value instanceof Texture) {
|
||||
type = 'Texture';
|
||||
type = value.type;
|
||||
}
|
||||
switch (type) {
|
||||
case 'Array':
|
||||
case 'Array(2)':
|
||||
case 'Array(3)':
|
||||
case 'Array(4)':
|
||||
case 'Array2D':
|
||||
case 'Array3D':
|
||||
{
|
||||
const dim = utils.getDimensions(value, true);
|
||||
const size = utils.dimToTexSize({
|
||||
@ -756,6 +761,7 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
}
|
||||
case 'Integer':
|
||||
case 'Float':
|
||||
case 'Number':
|
||||
{
|
||||
this.setUniform1f(`user_${name}`, value);
|
||||
break;
|
||||
@ -826,7 +832,8 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
this.setUniform1i(`user_${name}`, this.argumentsLength);
|
||||
break;
|
||||
}
|
||||
case 'Texture':
|
||||
case 'ArrayTexture(4)':
|
||||
case 'NumberTexture':
|
||||
{
|
||||
const inputTexture = value;
|
||||
const dim = inputTexture.dimensions;
|
||||
@ -864,7 +871,7 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
const gl = this._webGl;
|
||||
const argumentTexture = this.getArgumentTexture(name);
|
||||
if (value instanceof Texture) {
|
||||
type = 'Texture';
|
||||
type = value.type;
|
||||
}
|
||||
switch (type) {
|
||||
case 'Array':
|
||||
@ -969,7 +976,8 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
this.setUniform1i(`constants_${name}`, this.constantsLength);
|
||||
break;
|
||||
}
|
||||
case 'Texture':
|
||||
case 'ArrayTexture(4)':
|
||||
case 'NumberTexture':
|
||||
{
|
||||
const inputTexture = value;
|
||||
const dim = inputTexture.dimensions;
|
||||
@ -1272,7 +1280,7 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
const paramName = paramNames[i];
|
||||
const paramType = paramTypes[i];
|
||||
if (this.hardcodeConstants) {
|
||||
if (paramType === 'Array' || paramType === 'Texture' || paramType === 'TextureVec4') {
|
||||
if (paramType === 'Array' || paramType === 'NumberTexture' || paramType === 'ArrayTexture(4)') {
|
||||
const paramDim = utils.getDimensions(param, true);
|
||||
const paramSize = utils.dimToTexSize({
|
||||
floatTextures: this.floatTextures,
|
||||
@ -1291,7 +1299,7 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
result.push(`float user_${ paramName } = ${ param }`);
|
||||
}
|
||||
} else {
|
||||
if (paramType === 'Array' || paramType === 'Texture' || paramType === 'TextureVec4' || paramType === 'Input' || paramType === 'HTMLImage') {
|
||||
if (paramType === 'Array' || paramType === 'NumberTexture' || paramType === 'ArrayTexture(4)' || paramType === 'Input' || paramType === 'HTMLImage') {
|
||||
result.push(
|
||||
`uniform sampler2D user_${ paramName }`,
|
||||
`uniform ivec2 user_${ paramName }Size`,
|
||||
@ -1335,7 +1343,8 @@ module.exports = class WebGLKernel extends KernelBase {
|
||||
case 'Array':
|
||||
case 'Input':
|
||||
case 'HTMLImage':
|
||||
case 'Texture':
|
||||
case 'NumberTexture':
|
||||
case 'ArrayTexture(4)':
|
||||
result.push(
|
||||
`uniform sampler2D constants_${ name }`,
|
||||
`uniform ivec2 constants_${ name }Size`,
|
||||
|
||||
@ -1,11 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const WebGLFunctionNode = require('../web-gl/function-node');
|
||||
|
||||
// Closure capture for the ast function, prevent collision with existing AST functions
|
||||
// The prefixes to use
|
||||
const constantsPrefix = 'this.constants.';
|
||||
|
||||
const DECODE32_ENCODE32 = /decode32\(\s+encode32\(/g;
|
||||
const ENCODE32_DECODE32 = /encode32\(\s+decode32\(/g;
|
||||
|
||||
@ -99,20 +94,6 @@ module.exports = class WebGL2FunctionNode extends WebGLFunctionNode {
|
||||
}
|
||||
};
|
||||
|
||||
const typeMap = {
|
||||
'TextureVec4': 'sampler2D',
|
||||
'Texture': 'sampler2D',
|
||||
'Input': 'sampler2D',
|
||||
'Array': 'sampler2D',
|
||||
'Array(2)': 'vec2',
|
||||
'Array(3)': 'vec3',
|
||||
'Array(4)': 'vec4',
|
||||
'Number': 'float',
|
||||
'Integer': 'float',
|
||||
'HTMLImage': 'vec4',
|
||||
'HTMLImageArray': 'vec4'
|
||||
};
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @function
|
||||
|
||||
@ -52,7 +52,7 @@ module.exports = class WebGL2Kernel extends WebGLKernel {
|
||||
const argType = utils.getArgumentType(arguments[0]);
|
||||
if (argType === 'Array') {
|
||||
this.output = utils.getDimensions(argType);
|
||||
} else if (argType === 'Texture' || argType === 'TextureVec4') {
|
||||
} else if (argType === 'NumberTexture' || argType === 'ArrayTexture(4)') {
|
||||
this.output = arguments[0].output;
|
||||
} else {
|
||||
throw new Error('Auto output not supported for input type: ' + argType);
|
||||
@ -129,7 +129,7 @@ module.exports = class WebGL2Kernel extends WebGLKernel {
|
||||
this._setupOutputTexture();
|
||||
}
|
||||
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
||||
return new Texture(this.outputTexture, texSize, this.threadDim, this.output, this._webGl, 'vec4');
|
||||
return new Texture(this.outputTexture, texSize, this.threadDim, this.output, this._webGl, 'ArrayTexture(4)');
|
||||
}
|
||||
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
@ -269,7 +269,7 @@ module.exports = class WebGL2Kernel extends WebGLKernel {
|
||||
const gl = this._webGl;
|
||||
const argumentTexture = this.getArgumentTexture(name);
|
||||
if (value instanceof Texture) {
|
||||
type = 'Texture';
|
||||
type = value.type;
|
||||
}
|
||||
switch (type) {
|
||||
case 'Array':
|
||||
@ -311,6 +311,7 @@ module.exports = class WebGL2Kernel extends WebGLKernel {
|
||||
}
|
||||
case 'Integer':
|
||||
case 'Float':
|
||||
case 'Number':
|
||||
{
|
||||
this.setUniform1f(`user_${name}`, value);
|
||||
break;
|
||||
@ -435,7 +436,8 @@ module.exports = class WebGL2Kernel extends WebGLKernel {
|
||||
this.setUniform1i(`user_${name}`, this.argumentsLength);
|
||||
break;
|
||||
}
|
||||
case 'Texture':
|
||||
case 'ArrayTexture(4)':
|
||||
case 'NumberTexture':
|
||||
{
|
||||
const inputTexture = value;
|
||||
const dim = inputTexture.dimensions;
|
||||
@ -479,8 +481,8 @@ module.exports = class WebGL2Kernel extends WebGLKernel {
|
||||
case 'Array':
|
||||
case 'Input':
|
||||
case 'HTMLImage':
|
||||
case 'TextureVec4':
|
||||
case 'Texture':
|
||||
case 'ArrayTexture(4)':
|
||||
case 'NumberTexture':
|
||||
result.push(
|
||||
`uniform highp sampler2D constants_${ name }`,
|
||||
`uniform highp ivec2 constants_${ name }Size`,
|
||||
@ -522,7 +524,7 @@ module.exports = class WebGL2Kernel extends WebGLKernel {
|
||||
const gl = this._webGl;
|
||||
const argumentTexture = this.getArgumentTexture(name);
|
||||
if (value instanceof Texture) {
|
||||
type = 'Texture';
|
||||
type = value.type;
|
||||
}
|
||||
switch (type) {
|
||||
case 'Array':
|
||||
@ -682,7 +684,8 @@ module.exports = class WebGL2Kernel extends WebGLKernel {
|
||||
this.setUniform1i(`constants_${name}`, this.constantsLength);
|
||||
break;
|
||||
}
|
||||
case 'Texture':
|
||||
case 'ArrayTexture(4)':
|
||||
case 'NumberTexture':
|
||||
{
|
||||
const inputTexture = value;
|
||||
const dim = inputTexture.dimensions;
|
||||
@ -772,7 +775,7 @@ module.exports = class WebGL2Kernel extends WebGLKernel {
|
||||
const paramName = paramNames[i];
|
||||
const paramType = paramTypes[i];
|
||||
if (this.hardcodeConstants) {
|
||||
if (paramType === 'Array' || paramType === 'Texture' || paramType === 'TextureVec4') {
|
||||
if (paramType === 'Array' || paramType === 'NumberTexture' || paramType === 'ArrayTexture(4)') {
|
||||
const paramDim = utils.getDimensions(param, true);
|
||||
const paramSize = utils.dimToTexSize({
|
||||
floatTextures: this.floatTextures,
|
||||
@ -795,7 +798,7 @@ module.exports = class WebGL2Kernel extends WebGLKernel {
|
||||
result.push(`highp float user_${ paramName } = ${ param }`);
|
||||
}
|
||||
} else {
|
||||
if (paramType === 'Array' || paramType === 'Texture' || paramType === 'TextureVec4' || paramType === 'Input' || paramType === 'HTMLImage') {
|
||||
if (paramType === 'Array' || paramType === 'NumberTexture' || paramType === 'ArrayTexture(4)' || paramType === 'Input' || paramType === 'HTMLImage') {
|
||||
result.push(
|
||||
`uniform highp sampler2D user_${ paramName }`,
|
||||
`uniform highp ivec2 user_${ paramName }Size`,
|
||||
|
||||
@ -12,7 +12,7 @@ module.exports = class Texture {
|
||||
* @param {Object} webGl
|
||||
* @param {String} [type]
|
||||
*/
|
||||
constructor(texture, size, dimensions, output, webGl, type = 'float') {
|
||||
constructor(texture, size, dimensions, output, webGl, type = 'NumberTexture') {
|
||||
this.texture = texture;
|
||||
this.size = size;
|
||||
this.dimensions = dimensions;
|
||||
|
||||
@ -292,11 +292,7 @@ class Utils extends UtilsCore {
|
||||
}
|
||||
return 'Float';
|
||||
} else if (arg instanceof Texture) {
|
||||
if (arg.type === 'vec4') {
|
||||
return 'TextureVec4';
|
||||
} else {
|
||||
return 'Texture';
|
||||
}
|
||||
return arg.type;
|
||||
} else if (arg instanceof Input) {
|
||||
return 'Input';
|
||||
} else if (arg.nodeName === 'IMG') {
|
||||
|
||||
@ -12,8 +12,7 @@
|
||||
this.color(pixel[0], pixel[1], pixel[2], pixel[3]);
|
||||
}, {
|
||||
graphical: true,
|
||||
output : [image.width, image.height],
|
||||
debug: true
|
||||
output : [image.width, image.height]
|
||||
});
|
||||
imageKernel(image);
|
||||
assert.equal(true, true, 'does not throw');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user