function getWebGLContext(canvas, webglOptions, requestWebgl1) {
  if (typeof WebGLRenderingContext === "undefined") {
    throw new RuntimeError(
      "The browser does not support WebGL.  Visit http://get.webgl.org.",
    );
  }

  // Ensure that WebGL 2 is supported when it is requested. Otherwise, fall back to WebGL 1.
  const webgl2Supported = typeof WebGL2RenderingContext !== "undefined";
  if (!requestWebgl1 && !webgl2Supported) {
    requestWebgl1 = true;
  }

  const contextType = requestWebgl1 ? "webgl" : "webgl2";
  const glContext = canvas.getContext(contextType, webglOptions);

  if (!defined(glContext)) {
    throw new RuntimeError(
      "The browser supports WebGL, but initialization failed.",
    );
  }

  return glContext;
}
@private
@param {HTMLCanvasElement} canvas The canvas element to which the context will be associated
@param {WebGLOptions} webglOptions WebGL options to be passed on to HTMLCanvasElement.getContext()
@param {boolean} requestWebgl1 Whether to request a WebGLRenderingContext or a WebGL2RenderingContext.
@returns {WebGLRenderingContext|WebGL2RenderingContext}