forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfloat.js
More file actions
38 lines (36 loc) · 918 Bytes
/
float.js
File metadata and controls
38 lines (36 loc) · 918 Bytes
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
const { utils } = require('../../../utils');
const { GLTexture } = require('./index');
class GLTextureFloat extends GLTexture {
get textureType() {
return this.context.FLOAT;
}
constructor(settings) {
super(settings);
this.type = 'ArrayTexture(1)';
}
renderRawOutput() {
const gl = this.context;
const size = this.size;
gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer());
gl.framebufferTexture2D(
gl.FRAMEBUFFER,
gl.COLOR_ATTACHMENT0,
gl.TEXTURE_2D,
this.texture,
0
);
const result = new Float32Array(size[0] * size[1] * 4);
gl.readPixels(0, 0, size[0], size[1], gl.RGBA, gl.FLOAT, result);
return result;
}
renderValues() {
if (this._deleted) return null;
return this.renderRawOutput();
}
toArray() {
return utils.erectFloat(this.renderValues(), this.output[0]);
}
}
module.exports = {
GLTextureFloat
};