@Override public void delete(IRenderingEngine re) { if (fboId != -1) { re.deleteFramebuffer(fboId); fboId = -1; } if (depthRenderBufferId != -1) { re.deleteRenderbuffer(depthRenderBufferId); depthRenderBufferId = -1; } super.delete(re); }
@Override public void bind(IRenderingEngine re, boolean forDrawing) { if (forDrawing) { // We are copying the texture back to the main frame buffer, // bind the texture, not the FBO. re.bindFramebuffer(IRenderingEngine.RE_FRAMEBUFFER, 0); super.bind(re, forDrawing); } else { if (fboId == -1) { // Create the FBO and associate it to the texture fboId = re.genFramebuffer(); re.bindFramebuffer(IRenderingEngine.RE_FRAMEBUFFER, fboId); // Create a render buffer for the depth buffer depthRenderBufferId = re.genRenderbuffer(); re.bindRenderbuffer(depthRenderBufferId); re.setRenderbufferStorage( IRenderingEngine.RE_DEPTH_COMPONENT, getTexImageWidth(), getTexImageHeight()); // Create the texture super.bind(re, forDrawing); // Attach the texture to the FBO re.setFramebufferTexture( IRenderingEngine.RE_FRAMEBUFFER, IRenderingEngine.RE_COLOR_ATTACHMENT0, textureId, 0); // Attach the depth buffer to the FBO re.setFramebufferRenderbuffer( IRenderingEngine.RE_FRAMEBUFFER, IRenderingEngine.RE_DEPTH_ATTACHMENT, depthRenderBufferId); } else { // Bind the FBO re.bindFramebuffer(IRenderingEngine.RE_FRAMEBUFFER, fboId); } } }