From b7a9ec3e3cd976f49edb2b99b38b982b97b02890 Mon Sep 17 00:00:00 2001 From: Antoine <20756073+antt0n@users.noreply.github.com> Date: Thu, 5 Nov 2026 00:05:11 +0100 Subject: [PATCH] Settings: say whether the card can draw the map without setting it up MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Settings › Map drawing said "This browser cannot" by calling glInit(), so opening Settings on the title screen or in a puzzle, where the map is drawn in 2D, made the WebGL context and its 64 MB atlas. It now says what is known without asking the card (glCan()): a card given up or a browser without WebGL2 cannot; a card not tried yet counts as able. A card that turns out to be the processor's is still named once the game draws its first frame, in Diagnostic info and in Settings. Test in webgl-context-restore. --- src/game/96-map/30-settings.js | 2 +- src/game/96-map/56-webgl.js | 3 +++ tests/webgl-context-restore.test.js | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/game/96-map/30-settings.js b/src/game/96-map/30-settings.js index f3025be..b2874fd 100644 --- a/src/game/96-map/30-settings.js +++ b/src/game/96-map/30-settings.js @@ -30,7 +30,7 @@ function settingsHtml(){const seg=(lab,act,cur,opts,note)=>`
${tr('settings.display_and_sound')} ${seg(tr('common.animations'),'animSet',UI.anim||'auto',[['auto',tr('common.auto')],['on',tr('common.on')],['off',tr('common.off')]],tr('settings.auto_follows_your_device_s_reduce'))} - ${seg(tr('settings.map_drawing'),'mapSet',GLX.want?'auto':'2d',[['auto',tr('common.auto')],['2d',tr('settings.always_2d')]],tr('settings.auto_draws_the_map_with_your')+(GLX.want&&!glInit()?' '+tr('settings.this_browser_cannot_so_the_map'):''))} + ${seg(tr('settings.map_drawing'),'mapSet',GLX.want?'auto':'2d',[['auto',tr('common.auto')],['2d',tr('settings.always_2d')]],tr('settings.auto_draws_the_map_with_your')+(GLX.want&&!glCan()?' '+tr('settings.this_browser_cannot_so_the_map'):''))} ${seg(tr('common.sound'),'soundSet',UI.muted?'off':'on',[['on',tr('common.on')],['off',tr('common.off')]])}
${langPick('langSel')}
${seg(tr('settings.diagnostic_info'),'vpSet',DIAG.on?'on':'off',[['on',tr('common.on')],['off',tr('common.off')]],tr('settings.for_bug_reports_shows_your_screen'))} diff --git a/src/game/96-map/56-webgl.js b/src/game/96-map/56-webgl.js index 26fae66..7f4196d 100644 --- a/src/game/96-map/56-webgl.js +++ b/src/game/96-map/56-webgl.js @@ -13,6 +13,9 @@ try{GLX.want=localStorage.getItem('sot-map')!=='2d';}catch(e){} // Renderers that are the processor pretending to be a graphics card (GLX.soft: use them anyway, for the GPU benchmark). const GL_SOFT=/swiftshader|llvmpipe|softpipe|lavapipe|software|basic render/i; const glOn=()=>GLX.want&&!GLX.dead&&!!S&&!pzOn()&&glInit(); +// Whether the card can draw the map, as far as is known without asking it: Settings says so without making a context +// (on the title screen or in a puzzle that made the 64 MB atlas for a map drawn in 2D). A card not tried yet counts as able. +const glCan=()=>!GLX.dead&&typeof WebGL2RenderingContext!=='undefined'; // Switches the WebGL map on or off: the setting keeps the choice in this browser (keep), the GPU benchmark does not. // Chosen in Settings, Always 2D also lets the card's context go (glSleep()), and Auto takes it back. function mapGl(on,keep=true){GLX.want=!!on;if(keep)try{on?localStorage.removeItem('sot-map'):localStorage.setItem('sot-map','2d');}catch(e){} diff --git a/tests/webgl-context-restore.test.js b/tests/webgl-context-restore.test.js index 734fa03..ea46ea2 100644 --- a/tests/webgl-context-restore.test.js +++ b/tests/webgl-context-restore.test.js @@ -143,3 +143,21 @@ test('a game started with Always 2D never makes a context', () => { assert.equal(ev('__made'), 0); assert.deepEqual(errors, []); }); + +// Settings said whether the card could draw the map by setting it up: opening them on the title screen or in a puzzle +// made the context and its 64 MB atlas for a map drawn in 2D. It now says what is known without asking the card. +test('opening Settings never makes a context, and still says when the card cannot', () => { + const { ev, errors } = open(); + ev('window.WebGL2RenderingContext=function(){};window.__made=0;const c=document.getElementById("mapgl"),gc=c.getContext;c.getContext=t=>{__made++;return gc(t);};'); + const note = () => ev("settingsHtml().includes(tr('settings.this_browser_cannot_so_the_map'))"); + ev('const s=S;S=null;window.__S=s;'); + assert.equal(note(), false, 'title screen: a card not tried yet counts as able'); + ev('S=__S;'); + assert.equal(note(), false); + assert.equal(ev('__made'), 0, 'no context made by Settings'); + ev('glKill(new Error("no graphics card, only SwiftShader"))'); + assert.equal(note(), true, 'a card given up: Settings says so'); + ev('delete window.WebGL2RenderingContext;GLX.dead=false;'); + assert.equal(note(), true, 'no WebGL2 in this browser: Settings says so'); + assert.deepEqual(errors, []); +});