Settings: say whether the card can draw the map without setting it up

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.
This commit is contained in:
Antoine 2026-11-05 00:05:11 +01:00
parent 351b3aa522
commit b7a9ec3e3c
No known key found for this signature in database
GPG key ID: 728FF1CE15732B05
3 changed files with 22 additions and 1 deletions

View file

@ -30,7 +30,7 @@ function settingsHtml(){const seg=(lab,act,cur,opts,note)=>`<div class="setline"
${seg(tr('settings.quiet_notifications'),'prefSet',cur('quiet'),onoff('quiet'),tr('settings.only_trouble_and_milestones_pop_up'))}
<h3 class="sub4">${tr('settings.display_and_sound')}</h3>
${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')]])}
<div class="setline"><label for="langSel">${tr('common.language')}</label>${langPick('langSel')}</div>
${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'))}

View file

@ -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){}

View file

@ -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, []);
});