forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexture.js
More file actions
55 lines (48 loc) · 1.04 KB
/
texture.js
File metadata and controls
55 lines (48 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';
let gpu = null;
module.exports = class Texture {
/**
* @desc WebGl Texture implementation in JS
* @constructor Texture
* @param {Object} texture
* @param {Array} size
* @param {Array} output
* @param {Object} webGl
*/
constructor(texture, size, output, webGl) {
this.texture = texture;
this.size = size;
this.output = output;
this.webGl = webGl;
this.kernel = null;
}
/**
* @name toArray
* @function
* @memberOf Texture#
*
* @desc Converts the Texture into a JavaScript Array.
*
* @param {Object} The `gpu` Object
*
*/
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#
*
*
*/
delete() {
return this.webGl.deleteTexture(this.texture);
}
};