Skip to content

Commit 6556fee

Browse files
Warn when HDR canvas is not supported (#451)
1 parent 268c290 commit 6556fee

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
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: 18 additions & 6 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+
hdrFolder.name = getHdrFolderName();
3839
}
3940

4041
const particlesBuffer = device.createBuffer({
@@ -346,13 +347,24 @@ hdrFolder
346347
hdrFolder.add(simulationParams, 'brightnessFactor', 0, 4, 0.1);
347348
hdrFolder.open();
348349
const hdrMediaQuery = window.matchMedia('(dynamic-range: high)');
349-
function updateHdrFolderName() {
350-
hdrFolder.name = `HDR settings ${
351-
hdrMediaQuery.matches ? '' : '⚠️ Your display is not compatible'
352-
}`;
350+
function getHdrFolderName() {
351+
if (!hdrMediaQuery.matches) {
352+
return "HDR settings ⚠️ Display isn't compatible";
353+
}
354+
if (!('getConfiguration' in GPUCanvasContext.prototype)) {
355+
return 'HDR settings';
356+
}
357+
if (
358+
simulationParams.toneMappingMode === 'extended' &&
359+
context.getConfiguration().toneMapping?.mode !== 'extended'
360+
) {
361+
return "HDR settings ⚠️ Browser doesn't support HDR canvas";
362+
}
363+
return 'HDR settings';
353364
}
354-
updateHdrFolderName();
355-
hdrMediaQuery.onchange = updateHdrFolderName;
365+
hdrMediaQuery.onchange = () => {
366+
hdrFolder.name = getHdrFolderName();
367+
};
356368

357369
const computePipeline = device.createComputePipeline({
358370
layout: 'auto',

0 commit comments

Comments
 (0)