void activate(RenderContextWebGL renderContext, int textureSlot)

Source

void activate(RenderContextWebGL renderContext, int textureSlot) {

  if (this.contextIdentifier != renderContext.contextIdentifier) {

    var target = gl.TEXTURE_2D;
    var rgba = gl.RGBA;
    var type = gl.UNSIGNED_BYTE;

    _renderContext = renderContext;
    _contextIdentifier = renderContext.contextIdentifier;
    _renderingContext = renderContext.rawContext;
    _texture = _renderingContext.createTexture();

    _renderingContext.activeTexture(textureSlot);
    _renderingContext.bindTexture(target, _texture);

    if (_source != null) {
      _renderingContext.texImage2D(target, 0, rgba, rgba, type, _source);
      _textureSourceWorkaround = _renderingContext.getError() == gl.INVALID_VALUE;
    } else {
      _renderingContext.texImage2D(target, 0, rgba, width, height, 0, rgba, type, null);
    }

    if (_textureSourceWorkaround) {
      // WEBGL11072: INVALID_VALUE: texImage2D: This texture source is not supported
      _canvas = new CanvasElement(width: width, height: height);
      _canvas.context2D.drawImage(_source, 0, 0);
      _renderingContext.texImage2D(target, 0, rgba, rgba, type, _canvas);
    }

    _renderingContext.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
    _renderingContext.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
    _renderingContext.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, _filtering.value);
    _renderingContext.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, _filtering.value);

  } else {

    _renderingContext.activeTexture(textureSlot);
    _renderingContext.bindTexture(gl.TEXTURE_2D, _texture);
  }
}