Skip to content

Commit 3b39ade

Browse files
fix: Move framebuffer for raw values to kernel
1 parent 5397186 commit 3b39ade

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

src/backend/gl/texture/index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,17 @@ class GLTexture extends Texture {
9494
if (this.texture._refs) return;
9595
}
9696
this.context.deleteTexture(this.texture);
97-
if (this.texture._refs === 0 && this._framebuffer) {
98-
this.context.deleteFramebuffer(this._framebuffer);
99-
this._framebuffer = null;
100-
}
97+
// TODO: Remove me
98+
// if (this.texture._refs === 0 && this._framebuffer) {
99+
// this.context.deleteFramebuffer(this._framebuffer);
100+
// this._framebuffer = null;
101+
// }
101102
}
102103

103104
framebuffer() {
104105
if (!this._framebuffer) {
105-
this._framebuffer = this.context.createFramebuffer();
106+
this._framebuffer = this.kernel.getRawValueFramebuffer(this.size[0], this.size[1]);
106107
}
107-
this._framebuffer.width = this.size[0];
108-
this._framebuffer.height = this.size[1];
109108
return this._framebuffer;
110109
}
111110
}
@@ -123,4 +122,4 @@ function selectTexture(gl, texture) {
123122
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
124123
}
125124

126-
module.exports = { GLTexture };
125+
module.exports = { GLTexture };

src/backend/gl/texture/unsigned.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ class GLTextureUnsigned extends GLTexture {
1111
}
1212
renderRawOutput() {
1313
const { context: gl } = this;
14-
const framebuffer = gl.createFramebuffer();
15-
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
14+
gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer());
1615
gl.framebufferTexture2D(
1716
gl.FRAMEBUFFER,
1817
gl.COLOR_ATTACHMENT0,
@@ -35,4 +34,4 @@ class GLTextureUnsigned extends GLTexture {
3534

3635
module.exports = {
3736
GLTextureUnsigned
38-
};
37+
};

src/backend/web-gl/kernel.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ class WebGLKernel extends GLKernel {
529529
this.framebuffer = gl.createFramebuffer();
530530
this.framebuffer.width = texSize[0];
531531
this.framebuffer.height = texSize[1];
532+
this.rawValueFramebuffers = {};
532533

533534
const vertices = new Float32Array([-1, -1,
534535
1, -1, -1, 1,
@@ -1131,6 +1132,19 @@ float integerCorrectionModulo(float number, float divisor) {
11311132
return result.join('');
11321133
}
11331134

1135+
getRawValueFramebuffer(width, height) {
1136+
if (!this.rawValueFramebuffers[width]) {
1137+
this.rawValueFramebuffers[width] = {};
1138+
}
1139+
if (!this.rawValueFramebuffers[width][height]) {
1140+
const framebuffer = this.context.createFramebuffer();
1141+
framebuffer.width = width;
1142+
framebuffer.height = height;
1143+
this.rawValueFramebuffers[width][height] = framebuffer;
1144+
}
1145+
return this.rawValueFramebuffers[width][height];
1146+
}
1147+
11341148
getKernelResultDeclaration() {
11351149
switch (this.returnType) {
11361150
case 'Array(2)':
@@ -1491,6 +1505,13 @@ float integerCorrectionModulo(float number, float divisor) {
14911505
if (this.framebuffer) {
14921506
this.context.deleteFramebuffer(this.framebuffer);
14931507
}
1508+
for (const width in this.rawValueFramebuffers) {
1509+
for (const height in this.rawValueFramebuffers[width]) {
1510+
this.context.deleteFramebuffer(this.rawValueFramebuffers[width][height]);
1511+
delete this.rawValueFramebuffers[width][height];
1512+
}
1513+
delete this.rawValueFramebuffers[width];
1514+
}
14941515
if (this.vertShader) {
14951516
this.context.deleteShader(this.vertShader);
14961517
}
@@ -1576,4 +1597,4 @@ float integerCorrectionModulo(float number, float divisor) {
15761597

15771598
module.exports = {
15781599
WebGLKernel
1579-
};
1600+
};

0 commit comments

Comments
 (0)