Skip to content

Commit

Permalink
Prefer webgl2
Browse files Browse the repository at this point in the history
Closes #10
  • Loading branch information
GarboMuffin committed Jul 20, 2024
1 parent 208e27a commit a4c2e18
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/RenderWebGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ class RenderWebGL extends EventEmitter {
try {
optCanvas = optCanvas || document.createElement('canvas');
const options = {alpha: false, stencil: true, antialias: false};
// Don't use twgl's getContext here because it will spend a few milliseconds enabling extensions
// on a context that won't get used.
return !!(
optCanvas.getContext('webgl2', options) ||
optCanvas.getContext('webgl', options) ||
optCanvas.getContext('experimental-webgl', options) ||
optCanvas.getContext('webgl2', options)
optCanvas.getContext('experimental-webgl', options)
);
} catch (e) {
return false;
Expand All @@ -145,11 +147,7 @@ class RenderWebGL extends EventEmitter {
antialias: false,
powerPreference: RenderWebGL.powerPreference
};
// getWebGLContext = try WebGL 1.0 only
// getContext = try WebGL 2.0 and if that doesn't work, try WebGL 1.0
// getWebGLContext || getContext = try WebGL 1.0 and if that doesn't work, try WebGL 2.0
return twgl.getWebGLContext(canvas, contextAttribs) ||
twgl.getContext(canvas, contextAttribs);
return twgl.getContext(canvas, contextAttribs);
}

/**
Expand Down

0 comments on commit a4c2e18

Please sign in to comment.