diff --git a/src/renderer/webgl/WebGLRenderer.js b/src/renderer/webgl/WebGLRenderer.js index 59e9c0878..2ffda2d3f 100644 --- a/src/renderer/webgl/WebGLRenderer.js +++ b/src/renderer/webgl/WebGLRenderer.js @@ -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; },