Skip to content

Verify that webgl2 is supported before using it #3435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion lib/components/term.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,38 @@ const CURSOR_STYLES = {
BLOCK: 'block'
};

const isWebgl2Supported = (() => {
let isSupported = window.WebGL2RenderingContext ? undefined : false;
return () => {
if (isSupported === undefined) {
const canvas = document.createElement('canvas');
const gl = canvas.getContext('webgl2', {depth: false, antialias: false});
isSupported = gl instanceof window.WebGL2RenderingContext;
}
return isSupported;
};
})();

const getTermOptions = props => {
// Set a background color only if it is opaque
const needTransparency = Color(props.backgroundColor).alpha() < 1;
const backgroundColor = needTransparency ? 'transparent' : props.backgroundColor;
const useWebGL = props.webGLRenderer && !needTransparency;

let useWebGL = false;
if (props.webGLRenderer) {
if (needTransparency) {
// eslint-disable-next-line no-console
console.warn(
'WebGL Renderer has been disabled since it does not support transparent backgrounds yet. ' +
'Falling back to canvas-based rendering.'
);
} else if (!isWebgl2Supported()) {
// eslint-disable-next-line no-console
console.warn('WebGL2 is not supported on your machine. Falling back to canvas-based rendering.');
} else {
useWebGL = true;
}
}
return {
macOptionIsMeta: props.modifierKeys.altIsMeta,
scrollback: props.scrollback,
Expand Down