RenderContextWebGL constructor

RenderContextWebGL(
  1. CanvasElement canvasElement, {
  2. bool alpha = false,
  3. bool antialias = false,
})

Implementation

RenderContextWebGL(CanvasElement canvasElement,
    {bool alpha = false, bool antialias = false})
    : _canvasElement = canvasElement {
  _canvasElement.onWebGlContextLost.listen(_onContextLost);
  _canvasElement.onWebGlContextRestored.listen(_onContextRestored);

  final renderingContext = _canvasElement.getContext3d(
      alpha: alpha, antialias: antialias, depth: false, stencil: true);

  if (renderingContext is! gl.RenderingContext) {
    throw StateError('Failed to get WebGL context.');
  }

  _renderingContext = renderingContext;
  _renderingContext.enable(gl.WebGL.BLEND);
  _renderingContext.disable(gl.WebGL.STENCIL_TEST);
  _renderingContext.disable(gl.WebGL.DEPTH_TEST);
  _renderingContext.disable(gl.WebGL.CULL_FACE);
  _renderingContext.pixelStorei(gl.WebGL.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1);
  _renderingContext.blendFunc(gl.WebGL.ONE, gl.WebGL.ONE_MINUS_SRC_ALPHA);

  _activeRenderProgram = renderProgramSimple;
  _activeRenderProgram.activate(this);

  _contextValid = true;
  _contextIdentifier = ++_globalContextIdentifier;

  reset();
}