-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make gl-react-dom fallback to "webgl" when "webgl2" fails
By default, we'll do "auto" compatible mode until Safari supports webgl2. This behavior can be overriden if needed by forcing version="webgl2" or version="webgl" on the Surface. it will implicitly be version="auto" until 100% browser supports webgl2.
- Loading branch information
Showing
2 changed files
with
16 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
export default ( | ||
const getContext = ( | ||
canvas: HTMLCanvasElement, | ||
opts: any, | ||
version: "webgl" | "webgl2" | ||
) => | ||
version === "webgl2" | ||
? canvas.getContext("webgl2", opts) | ||
: canvas.getContext("webgl", opts) || | ||
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; |