forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner-base.js
More file actions
80 lines (69 loc) · 2.08 KB
/
runner-base.js
File metadata and controls
80 lines (69 loc) · 2.08 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const utils = require('../utils');
const kernelRunShortcut = require('./kernel-run-shortcut');
///
/// Class: Base
///
/// Represents the 'private/protected' namespace of the GPU class
///
/// *base.js* internal functions namespace
/// *gpu.js* PUBLIC function namespace
///
/// I know @private makes more sense, but since the documentation engine state is undetirmined.
/// (See https://github.com/gpujs/gpu.js/issues/19 regarding documentation engine issue)
/// File isolation is currently the best way to go
///
module.exports = class BaseRunner {
constructor(functionBuilder, settings) {
settings = settings || {};
this.kernel = settings.kernel;
this.canvas = settings.canvas;
this.webGl = settings.webGl;
this.fn = null;
this.functionBuilder = functionBuilder;
this.fnString = null;
this.endianness = utils.systemEndianness;
this.functionBuilder.polyfillStandardFunctions();
}
textureToArray(texture) {
const copy = this.createKernel(function(x) {
return x[this.thread.z][this.thread.y][this.thread.x];
});
return copy(texture);
}
deleteTexture(texture) {
this.webGl.deleteTexture(texture.texture);
}
///
/// Get and returns the ASYNCHRONOUS executor, of a class and kernel
/// This returns a Promise object from an argument set.
///
/// Note that there is no current implementation.
///
buildPromiseKernel() {
throw new Error('not yet implemented');
}
get mode() {
throw new Error('"mode" not implemented on BaseRunner');
}
///
/// Get and returns the Synchronous executor, of a class and kernel
/// Which returns the result directly after passing the arguments.
///
buildKernel(fn, settings) {
settings = Object.assign({}, settings || {});
const fnString = fn.toString();
if (!utils.isFunctionString(fnString)) {
throw 'Unable to get body of kernel function';
}
if (!settings.functionBuilder) {
settings.functionBuilder = this.functionBuilder;
}
if (!settings.canvas) {
settings.canvas = this.canvas;
}
if (!settings.webGl) {
settings.webGl = this.webGl;
}
return kernelRunShortcut(new this.Kernel(fnString, settings));
}
};