-
Notifications
You must be signed in to change notification settings - Fork 664
/
Copy pathnumber-texture.js
59 lines (51 loc) · 1.71 KB
/
number-texture.js
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
const { utils } = require('../../../utils');
const { WebGLKernelArray } = require('./array');
class WebGLKernelValueNumberTexture extends WebGLKernelArray {
constructor(value, settings) {
super(value, settings);
const [width, height] = value.size;
this.checkSize(width, height);
const { size: textureSize, dimensions } = value;
this.bitRatio = this.getBitRatio(value);
this.dimensions = dimensions;
this.textureSize = textureSize;
this.uploadValue = value.texture;
this.forceUploadEachRun = true;
}
setup() {
this.setupTexture();
}
getStringValueHandler() {
return `const uploadValue_${this.name} = ${this.varName}.texture;\n`;
}
getSource() {
return utils.linesToString([
`uniform sampler2D ${this.id}`,
`ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`,
`ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`,
]);
}
/**
*
* @param {GLTexture} inputTexture
*/
updateValue(inputTexture) {
if (inputTexture.constructor !== this.initialValueConstructor) {
this.onUpdateValueMismatch(inputTexture.constructor);
return;
}
if (this.checkContext && inputTexture.context !== this.context) {
throw new Error(`Value ${this.name} (${this.type}) must be from same context`);
}
const { kernel, context: gl } = this;
if (kernel.pipeline) {
kernel.updateTextureArgumentRefs(this, inputTexture);
}
gl.activeTexture(this.contextHandle);
gl.bindTexture(gl.TEXTURE_2D, this.uploadValue = inputTexture.texture);
this.kernel.setUniform1i(this.id, this.index);
}
}
module.exports = {
WebGLKernelValueNumberTexture
};