Skip to content

Commit

Permalink
Enable safemode for gpu that do not support webgl2, print gpu details…
Browse files Browse the repository at this point in the history
… in options stage
  • Loading branch information
riccardobl committed Jan 3, 2024
1 parent 478dea0 commit dbb0e3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/js/ui/UI.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,30 @@ import BrowserStore from "../storage/BrowserStore.js";
export default class UI {
static async setSafeMode(v) {
this.safeMode = v;
if (v) console.log("Enable safe mode");
return this.safeMode;
}

async getGPUModel() {
if (!UI.gpuModel) throw "Unknown";
return UI.gpuModel;
}
static async isSafeMode() {
try {
if (typeof this.safeMode !== "undefined") return this.safeMode;
if (!window.WebGLRenderingContext) return this.setSafeMode(true);
if (!window.WebGL2RenderingContext) return this.setSafeMode(true);

const nCores = navigator.hardwareConcurrency;
if (typeof nCores !== "undefined" && nCores > 0 && nCores < 4) return this.setSafeMode(true);
const canvas = document.createElement("canvas");
const gl =
canvas.getContext("webgl", { powerPreference: "high-performance" }) ||
canvas.getContext("experimental-webgl", { powerPreference: "high-performance" });
const gl = canvas.getContext("webgl2");
if (!gl) return this.setSafeMode(true);
const debugInfo = gl.getExtension("WEBGL_debug_renderer_info");
const vendor = gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);
const renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
console.log("GPU", vendor, renderer);
this.gpuModel = renderer + " " + vendor;
} catch (e) {
return this.setSafeMode(true);
}
Expand Down
5 changes: 5 additions & 0 deletions src/js/ui/stages/OptionsStage.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ export default class OptionsStage extends UIStage {
alert("Cache cleared");
window.location.reload();
});
$vsep(optionsEl);
const gpuModel = $text(optionsEl, ["sub"]);
ui.getGPUModel().then((model) => {
gpuModel.setValue(`GPU: ${model}`);
});

ui.getCurrentTheme().then((currentTheme) => {
const themeEl = themeSelector;
Expand Down

0 comments on commit dbb0e3b

Please sign in to comment.