mirror of
https://github.com/gpujs/gpu.js.git
synced 2026-01-18 16:04:10 +00:00
fix: Move framebuffer for raw values to kernel
This commit is contained in:
parent
5397186a7a
commit
3b39adef85
@ -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 };
|
||||
module.exports = { GLTexture };
|
||||
|
||||
@ -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
|
||||
};
|
||||
};
|
||||
|
||||
@ -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
|
||||
};
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user