WebGLCanvasController constructor

WebGLCanvasController({
  1. double width = 512,
  2. double height = 512,
  3. GLESVersion version = GLESVersion.GLES_20,
})

Implementation

WebGLCanvasController({
  double width = 512,
  double height = 512,
  GLESVersion version = GLESVersion.GLES_20,
}) : super.inherit(GLValue._()) {
  _canvasElement = CanvasElement(
    width: width.toInt(),
    height: height.toInt(),
  );
  String viewId = "gl-canvas-$_viewId";
  dynamic gl;
  switch (version) {
    case GLESVersion.GLES_10:
      throw Exception("gles 1.0 is not supported.");
    case GLESVersion.GLES_20:
      gl = _canvasElement.getContext("webgl");
      break;
    case GLESVersion.GLES_30:
      gl = _canvasElement.getContext("webgl2");
      break;
  }
  value = value._copy(
    viewId: viewId,
    gl: gl,
  );
  _canvasElement.id = viewId;

  ui.platformViewRegistry.registerViewFactory(viewId, (viewId) => _canvasElement);
}