updateMultisampleRenderTarget method

void updateMultisampleRenderTarget(
  1. RenderTarget renderTarget
)

Implementation

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

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

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

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

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

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

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

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

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