Skip to content

Commit

Permalink
Make gl-react-dom fallback to "webgl" when "webgl2" fails
Browse files Browse the repository at this point in the history
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
gre committed Mar 13, 2021
1 parent 524897f commit 06d5648
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/gl-react-dom/src/GLViewDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export default class GLViewDOM extends Component<
debug
? { ...webglContextAttributes, preserveDrawingBuffer: true }
: webglContextAttributes,
version || "webgl2"
version || "auto"
);
this.webglContextAttributes = webglContextAttributes || {};
return gl;
Expand Down
21 changes: 15 additions & 6 deletions packages/gl-react-dom/src/getContext.js
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;

0 comments on commit 06d5648

Please sign in to comment.