Skip to content

Commit a5be0dc

Browse files
Warn when HDR canvas is not supported
1 parent 268c290 commit a5be0dc

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

package-lock.json

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"@types/showdown": "^2.0.6",
4343
"@types/stats.js": "^0.17.3",
4444
"@typescript-eslint/eslint-plugin": "^7.13.0",
45-
"@webgpu/types": "^0.1.44",
45+
"@webgpu/types": "^0.1.47",
4646
"chokidar": "^3.6.0",
4747
"eslint": "^8.57.0",
4848
"eslint-config-prettier": "^8.10.0",

sample/particles/main.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ function configureContext() {
3535
toneMapping: { mode: simulationParams.toneMappingMode },
3636
alphaMode: 'premultiplied',
3737
});
38+
updateHdrFolderName();
3839
}
3940

4041
const particlesBuffer = device.createBuffer({
@@ -347,11 +348,21 @@ hdrFolder.add(simulationParams, 'brightnessFactor', 0, 4, 0.1);
347348
hdrFolder.open();
348349
const hdrMediaQuery = window.matchMedia('(dynamic-range: high)');
349350
function updateHdrFolderName() {
351+
if (!hdrMediaQuery.matches) {
352+
hdrFolder.name = 'HDR settings ⚠️ Your display is not compatible';
353+
return;
354+
}
355+
if (!('getConfiguration' in GPUCanvasContext.prototype)) {
356+
hdrFolder.name = 'HDR settings';
357+
return;
358+
}
359+
const configuration = context.getConfiguration();
360+
const toneMappingModeMatches =
361+
configuration.toneMapping.mode === simulationParams.toneMappingMode;
350362
hdrFolder.name = `HDR settings ${
351-
hdrMediaQuery.matches ? '' : '⚠️ Your display is not compatible'
363+
toneMappingModeMatches ? '' : '⚠️ Your browser doesn\'t support HDR canvas'
352364
}`;
353365
}
354-
updateHdrFolderName();
355366
hdrMediaQuery.onchange = updateHdrFolderName;
356367

357368
const computePipeline = device.createComputePipeline({

0 commit comments

Comments
 (0)