mirror of
https://github.com/gpujs/gpu.js.git
synced 2026-01-25 16:08:02 +00:00
To be referenced in same way. Simplify FunctionNode. Update documentation to be more straightforward. Remove code no longer needed from WebGL2 FunctionNode.
75 lines
2.1 KiB
JavaScript
75 lines
2.1 KiB
JavaScript
'use strict';
|
|
|
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
module.exports = function () {
|
|
|
|
/**
|
|
* @desc WebGl Texture implementation in JS
|
|
* @constructor Texture
|
|
* @param {Object} texture
|
|
* @param {Array} size
|
|
* @param dimensions
|
|
* @param {Array} output
|
|
* @param {Object} webGl
|
|
* @param {String} [type]
|
|
*/
|
|
function Texture(texture, size, dimensions, output, webGl) {
|
|
var type = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'NumberTexture';
|
|
|
|
_classCallCheck(this, Texture);
|
|
|
|
this.texture = texture;
|
|
this.size = size;
|
|
this.dimensions = dimensions;
|
|
this.output = output;
|
|
this.webGl = webGl;
|
|
this.kernel = null;
|
|
this.type = type;
|
|
}
|
|
|
|
/**
|
|
* @name toArray
|
|
* @function
|
|
* @memberOf Texture#
|
|
*
|
|
* @desc Converts the Texture into a JavaScript Array.
|
|
*
|
|
* @param {Object} The `gpu` Object
|
|
*
|
|
*/
|
|
|
|
|
|
_createClass(Texture, [{
|
|
key: 'toArray',
|
|
value: function toArray(gpu) {
|
|
if (!gpu) throw new Error('You need to pass the GPU object for toArray to work.');
|
|
if (this.kernel) return this.kernel(this);
|
|
|
|
this.kernel = gpu.createKernel(function (x) {
|
|
return x[this.thread.z][this.thread.y][this.thread.x];
|
|
}).setOutput(this.output);
|
|
|
|
return this.kernel(this);
|
|
}
|
|
|
|
/**
|
|
* @name delete
|
|
* @desc Deletes the Texture.
|
|
* @function
|
|
* @memberOf Texture#
|
|
*
|
|
*
|
|
*/
|
|
|
|
}, {
|
|
key: 'delete',
|
|
value: function _delete() {
|
|
return this.webGl.deleteTexture(this.texture);
|
|
}
|
|
}]);
|
|
|
|
return Texture;
|
|
}(); |