gl-react-dom
Version:
DOM implementation of gl-react, an universal React library to write and compose WebGL shaders
20 lines (18 loc) • 486 B
JavaScript
const getContext = (
canvas: HTMLCanvasElement,
opts: any,
version: "webgl" | "webgl2" | "auto"
) => {
let gl;
if (version === "webgl2" || version === "auto") {
gl = canvas.getContext("webgl2", opts);
}
if (!gl && (version === "webgl" || version === "auto")) {
gl =
canvas.getContext("webgl", opts) ||
canvas.getContext("webgl-experimental", opts) ||
canvas.getContext("experimental-webgl", opts);
}
return gl;
};
export default getContext;