Array Remove and unbind before deleting the framebuffer

This commit is contained in:
Richard Davey 2023-10-12 15:22:23 +01:00
parent 2d364f08c4
commit 1935119141

View file

@ -2291,43 +2291,45 @@ var WebGLRenderer = new Class({
*/
deleteFramebuffer: function (framebuffer)
{
if (framebuffer)
if (!framebuffer)
{
var gl = this.gl;
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
// Check for a color attachment and remove it
var colorAttachment = gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
if (colorAttachment !== null)
{
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, null, 0);
// TODO: Check if this texture is used elsewhere. If not, delete it:
// gl.deleteTexture(colorAttachment);
}
// Check for a depth-stencil attachment and delete it
var depthStencilAttachment = gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
if (depthStencilAttachment !== null)
{
gl.deleteRenderbuffer(depthStencilAttachment);
}
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
gl.deleteFramebuffer(framebuffer);
ArrayRemove(this.fboStack, framebuffer);
if (this.currentFramebuffer === framebuffer)
{
this.currentFramebuffer = null;
}
return this;
}
var gl = this.gl;
if (this.currentFramebuffer === framebuffer)
{
this.currentFramebuffer = null;
}
ArrayRemove(this.fboStack, framebuffer);
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
// Check for a color attachment and remove it
var colorAttachment = gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
if (colorAttachment !== null)
{
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, null, 0);
// TODO: Check if this texture is used elsewhere. If not, delete it:
// gl.deleteTexture(colorAttachment);
}
// Check for a depth-stencil attachment and delete it
var depthStencilAttachment = gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
if (depthStencilAttachment !== null)
{
gl.deleteRenderbuffer(depthStencilAttachment);
}
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
gl.deleteFramebuffer(framebuffer);
return this;
},