From 3b39adef85bd2b7ade79ce2a62f68fb6f0bed693 Mon Sep 17 00:00:00 2001 From: Robert Plummer Date: Tue, 11 Aug 2020 08:37:30 -0400 Subject: [PATCH] fix: Move framebuffer for raw values to kernel --- src/backend/gl/texture/index.js | 15 +++++++-------- src/backend/gl/texture/unsigned.js | 5 ++--- src/backend/web-gl/kernel.js | 23 ++++++++++++++++++++++- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/backend/gl/texture/index.js b/src/backend/gl/texture/index.js index 70667e87..66aa685c 100644 --- a/src/backend/gl/texture/index.js +++ b/src/backend/gl/texture/index.js @@ -94,18 +94,17 @@ class GLTexture extends Texture { if (this.texture._refs) return; } this.context.deleteTexture(this.texture); - if (this.texture._refs === 0 && this._framebuffer) { - this.context.deleteFramebuffer(this._framebuffer); - this._framebuffer = null; - } + // TODO: Remove me + // if (this.texture._refs === 0 && this._framebuffer) { + // this.context.deleteFramebuffer(this._framebuffer); + // this._framebuffer = null; + // } } framebuffer() { if (!this._framebuffer) { - this._framebuffer = this.context.createFramebuffer(); + this._framebuffer = this.kernel.getRawValueFramebuffer(this.size[0], this.size[1]); } - this._framebuffer.width = this.size[0]; - this._framebuffer.height = this.size[1]; return this._framebuffer; } } @@ -123,4 +122,4 @@ function selectTexture(gl, texture) { gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); } -module.exports = { GLTexture }; \ No newline at end of file +module.exports = { GLTexture }; diff --git a/src/backend/gl/texture/unsigned.js b/src/backend/gl/texture/unsigned.js index 7e70c27c..2d1c9246 100644 --- a/src/backend/gl/texture/unsigned.js +++ b/src/backend/gl/texture/unsigned.js @@ -11,8 +11,7 @@ class GLTextureUnsigned extends GLTexture { } renderRawOutput() { const { context: gl } = this; - const framebuffer = gl.createFramebuffer(); - gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); + gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer()); gl.framebufferTexture2D( gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, @@ -35,4 +34,4 @@ class GLTextureUnsigned extends GLTexture { module.exports = { GLTextureUnsigned -}; \ No newline at end of file +}; diff --git a/src/backend/web-gl/kernel.js b/src/backend/web-gl/kernel.js index 0f9dc043..11f64397 100644 --- a/src/backend/web-gl/kernel.js +++ b/src/backend/web-gl/kernel.js @@ -529,6 +529,7 @@ class WebGLKernel extends GLKernel { this.framebuffer = gl.createFramebuffer(); this.framebuffer.width = texSize[0]; this.framebuffer.height = texSize[1]; + this.rawValueFramebuffers = {}; const vertices = new Float32Array([-1, -1, 1, -1, -1, 1, @@ -1131,6 +1132,19 @@ float integerCorrectionModulo(float number, float divisor) { return result.join(''); } + getRawValueFramebuffer(width, height) { + if (!this.rawValueFramebuffers[width]) { + this.rawValueFramebuffers[width] = {}; + } + if (!this.rawValueFramebuffers[width][height]) { + const framebuffer = this.context.createFramebuffer(); + framebuffer.width = width; + framebuffer.height = height; + this.rawValueFramebuffers[width][height] = framebuffer; + } + return this.rawValueFramebuffers[width][height]; + } + getKernelResultDeclaration() { switch (this.returnType) { case 'Array(2)': @@ -1491,6 +1505,13 @@ float integerCorrectionModulo(float number, float divisor) { if (this.framebuffer) { this.context.deleteFramebuffer(this.framebuffer); } + for (const width in this.rawValueFramebuffers) { + for (const height in this.rawValueFramebuffers[width]) { + this.context.deleteFramebuffer(this.rawValueFramebuffers[width][height]); + delete this.rawValueFramebuffers[width][height]; + } + delete this.rawValueFramebuffers[width]; + } if (this.vertShader) { this.context.deleteShader(this.vertShader); } @@ -1576,4 +1597,4 @@ float integerCorrectionModulo(float number, float divisor) { module.exports = { WebGLKernel -}; \ No newline at end of file +};