updateMultisampleRenderTarget method

void updateMultisampleRenderTarget(
  1. RenderTarget renderTarget
)

Implementation

void updateMultisampleRenderTarget(RenderTarget renderTarget) {
  if ((isWebGL2 && renderTarget.samples > 0) && useMultisampledRenderToTexture(renderTarget) == false) {
    final width = renderTarget.width.toInt();
    final height = renderTarget.height.toInt();
    int mask = WebGL.COLOR_BUFFER_BIT;
    final invalidationArray = [WebGL.COLOR_ATTACHMENT0];
    final depthStyle = renderTarget.stencilBuffer ? WebGL.DEPTH_STENCIL_ATTACHMENT : WebGL.DEPTH_ATTACHMENT;

    if (renderTarget.depthBuffer) {
      invalidationArray.add(depthStyle);
    }

    final renderTargetProperties = properties.get(renderTarget);
    final ignoreDepthValues = (renderTargetProperties["__ignoreDepthValues"] != null)
        ? renderTargetProperties["__ignoreDepthValues"]
        : true;

    if (ignoreDepthValues == false) {
      if (renderTarget.depthBuffer) mask |= WebGL.DEPTH_BUFFER_BIT;
      if (renderTarget.stencilBuffer) mask |= WebGL.STENCIL_BUFFER_BIT;
    }

    state.bindFramebuffer(WebGL.READ_FRAMEBUFFER, renderTargetProperties["__webglMultisampledFramebuffer"]);
    state.bindFramebuffer(WebGL.DRAW_FRAMEBUFFER, renderTargetProperties["__webglFramebuffer"]);

    if (ignoreDepthValues == true) {
      _gl.invalidateFramebuffer(WebGL.READ_FRAMEBUFFER, [depthStyle]);
      _gl.invalidateFramebuffer(WebGL.DRAW_FRAMEBUFFER, [depthStyle]);
    }

    _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, WebGL.NEAREST);

    if (supportsInvalidateFramenbuffer) {
      _gl.invalidateFramebuffer(WebGL.READ_FRAMEBUFFER, invalidationArray);
    }

    state.bindFramebuffer(WebGL.READ_FRAMEBUFFER, null);
    state.bindFramebuffer(WebGL.DRAW_FRAMEBUFFER, renderTargetProperties["__webglMultisampledFramebuffer"]);
  }
}