* Create a WebGL context for a canvas * Note calling this multiple time on the same canvas does return the same context
(_ref)
| 8958 | * Note calling this multiple time on the same canvas does return the same context |
| 8959 | */ |
| 8960 | function createBrowserContext(_ref) { |
| 8961 | var canvas = _ref.canvas, |
| 8962 | _ref$opts = _ref.opts, |
| 8963 | opts = _ref$opts === void 0 ? {} : _ref$opts, |
| 8964 | _ref$onError = _ref.onError, |
| 8965 | onError = _ref$onError === void 0 ? function (message) { |
| 8966 | return null; |
| 8967 | } : _ref$onError; // Try to extract any extra information about why context creation failed |
| 8968 | |
| 8969 | function onContextCreationError(error) { |
| 8970 | onError("WebGL context: ".concat(error.statusMessage || 'Unknown error')); |
| 8971 | } |
| 8972 | |
| 8973 | canvas.addEventListener('webglcontextcreationerror', onContextCreationError, false); |
| 8974 | var _opts$webgl = opts.webgl1, |
| 8975 | webgl1 = _opts$webgl === void 0 ? true : _opts$webgl, |
| 8976 | _opts$webgl2 = opts.webgl2, |
| 8977 | webgl2 = _opts$webgl2 === void 0 ? true : _opts$webgl2; |
| 8978 | var gl = null; // Prefer webgl2 over webgl1, prefer conformant over experimental |
| 8979 | |
| 8980 | if (webgl2) { |
| 8981 | gl = gl || canvas.getContext('webgl2', opts); |
| 8982 | gl = gl || canvas.getContext('experimental-webgl2', opts); |
| 8983 | } |
| 8984 | |
| 8985 | if (webgl1) { |
| 8986 | gl = gl || canvas.getContext('webgl', opts); |
| 8987 | gl = gl || canvas.getContext('experimental-webgl', opts); |
| 8988 | } |
| 8989 | |
| 8990 | canvas.removeEventListener('webglcontextcreationerror', onContextCreationError, false); |
| 8991 | |
| 8992 | if (!gl) { |
| 8993 | return onError("Failed to create ".concat(webgl2 && !webgl1 ? 'WebGL2' : 'WebGL', " context")); |
| 8994 | } |
| 8995 | |
| 8996 | return gl; |
| 8997 | } |
| 8998 | },{}],"GOH4":[function(require,module,exports) { |
| 8999 | |
| 9000 | "use strict"; |