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
46 lines (41 loc) · 1.01 KB
/
texture.js
File metadata and controls
46 lines (41 loc) · 1.01 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
/**
* @desc WebGl Texture implementation in JS
* @param {Object} texture
* @param {Array} size
* @param {Object|Array} dimensions
* @param {Array} output
* @param {Object} context
* @param {String} [type]
*/
class Texture {
constructor(texture, size, dimensions, output, context, type = 'NumberTexture') {
this.texture = texture;
this.size = size;
this.dimensions = dimensions;
this.output = output;
this.context = context;
this.kernel = null;
this.type = type;
}
/**
* @desc Converts the Texture into a JavaScript Array.
* @param {GPU} 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);
}
/**
* @desc Deletes the Texture
*/
delete() {
return this.context.deleteTexture(this.texture);
}
}
module.exports = {
Texture
};