deallocateRenderTarget method

void deallocateRenderTarget(
  1. RenderTarget renderTarget
)

Implementation

void deallocateRenderTarget(RenderTarget renderTarget) {
  final texture = renderTarget.texture;

  final renderTargetProperties = properties.get(renderTarget);
  final textureProperties = properties.get(texture);

  if (textureProperties["__webglTexture"] != null) {
    gl.deleteTexture(textureProperties["__webglTexture"]);
    info.memory["textures"] = info.memory["textures"]! - 1;
  }

  if (renderTarget.depthTexture != null) {
    renderTarget.depthTexture!.dispose();
  }

  if (renderTarget.isWebGLCubeRenderTarget) {
    for (int i = 0; i < 6; i++) {
      gl.deleteFramebuffer(renderTargetProperties["__webglFramebuffer"][i]);
      if (renderTargetProperties["__webglDepthbuffer"] != null) {
        gl.deleteRenderbuffer(renderTargetProperties["__webglDepthbuffer"][i]);
      }
    }
  } else {
    gl.deleteFramebuffer(renderTargetProperties["__webglFramebuffer"]);
    if (renderTargetProperties["__webglDepthbuffer"] != null) {
      gl.deleteRenderbuffer(renderTargetProperties["__webglDepthbuffer"]);
    }
    if (renderTargetProperties["__webglMultisampledFramebuffer"] != null) {
      gl.deleteFramebuffer(renderTargetProperties["__webglMultisampledFramebuffer"]);
    }
    if (renderTargetProperties["__webglColorRenderbuffer"] != null) {
      gl.deleteRenderbuffer(renderTargetProperties["__webglColorRenderbuffer"]);
    }
    if (renderTargetProperties["__webglDepthRenderbuffer"] != null) {
      gl.deleteRenderbuffer(renderTargetProperties["__webglDepthRenderbuffer"]);
    }
  }

  if (renderTarget.isWebGLMultipleRenderTargets && texture is GroupTexture) {
    for (int i = 0, il = texture.children.length; i < il; i++) {
      final attachmentProperties = properties.get(texture.children[i]);

      if (attachmentProperties["__webglTexture"] != null) {
        gl.deleteTexture(attachmentProperties["__webglTexture"]);

        info.memory["textures"] = info.memory["textures"]! - 1;
      }

      properties.remove(texture.children[i]);
    }
  }

  properties.remove(texture);
  properties.remove(renderTarget);
}