Skip to content

Commit 06d5648

Browse files
committed
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.
1 parent 524897f commit 06d5648

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

packages/gl-react-dom/src/GLViewDOM.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export default class GLViewDOM extends Component<
176176
debug
177177
? { ...webglContextAttributes, preserveDrawingBuffer: true }
178178
: webglContextAttributes,
179-
version || "webgl2"
179+
version || "auto"
180180
);
181181
this.webglContextAttributes = webglContextAttributes || {};
182182
return gl;
+15-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
export default (
1+
const getContext = (
22
canvas: HTMLCanvasElement,
33
opts: any,
4-
version: "webgl" | "webgl2"
5-
) =>
6-
version === "webgl2"
7-
? canvas.getContext("webgl2", opts)
8-
: canvas.getContext("webgl", opts) ||
4+
version: "webgl" | "webgl2" | "auto"
5+
) => {
6+
let gl;
7+
if (version === "webgl2" || version === "auto") {
8+
gl = canvas.getContext("webgl2", opts);
9+
}
10+
if (!gl && (version === "webgl" || version === "auto")) {
11+
gl =
12+
canvas.getContext("webgl", opts) ||
913
canvas.getContext("webgl-experimental", opts) ||
1014
canvas.getContext("experimental-webgl", opts);
15+
}
16+
return gl;
17+
};
18+
19+
export default getContext;

0 commit comments

Comments
 (0)