UNPKG

gl-react-dom

Version:

DOM implementation of gl-react, an universal React library to write and compose WebGL shaders

26 lines (24 loc) 763 B
const getContext = ( canvas: HTMLCanvasElement, opts: any, version: "webgl" | "webgl2" | "auto" ) => { let gl: WebGLRenderingContext | null = null; if (version === "webgl2" || version === "auto") { gl = canvas.getContext("webgl2", opts) as unknown as WebGLRenderingContext | null; } if (!gl && (version === "webgl" || version === "auto")) { gl = (canvas.getContext("webgl", opts) as unknown as WebGLRenderingContext | null) || (canvas.getContext( "webgl-experimental" as any, opts ) as unknown as WebGLRenderingContext | null) || (canvas.getContext( "experimental-webgl" as any, opts ) as unknown as WebGLRenderingContext | null); } return gl; }; export default getContext;