activate method

void activate(
  1. RenderContextWebGL renderContext
)

Implementation

void activate(RenderContextWebGL renderContext) {
  if (contextIdentifier != renderContext.contextIdentifier) {
    _renderContext = renderContext;
    _contextIdentifier = renderContext.contextIdentifier;
    _renderingContext = renderContext.rawContext;
    _framebuffer = renderContext.rawContext.createFramebuffer();

    if (_renderTexture != null) {
      _renderContext.activateRenderTexture(_renderTexture!);
    }

    if (_renderStencilBuffer != null) {
      _renderContext.activateRenderStencilBuffer(_renderStencilBuffer!);
    }

    const target = gl.WebGL.FRAMEBUFFER;
    const color = gl.WebGL.COLOR_ATTACHMENT0;
    const colorTarget = gl.WebGL.TEXTURE_2D;
    final colorData = _renderTexture!.texture;
    const stencil = gl.WebGL.DEPTH_STENCIL_ATTACHMENT;
    const stencilTarget = gl.WebGL.RENDERBUFFER;
    final stencilData = _renderStencilBuffer!.renderbuffer;

    _renderingContext!.bindFramebuffer(target, _framebuffer);
    _renderingContext!
        .framebufferTexture2D(target, color, colorTarget, colorData, 0);
    _renderingContext!
        .framebufferRenderbuffer(target, stencil, stencilTarget, stencilData);
  } else {
    _renderingContext!.bindFramebuffer(gl.WebGL.FRAMEBUFFER, _framebuffer);
  }
}