-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathweb.html
56 lines (52 loc) · 1.63 KB
/
web.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>BaseWebGPU</title>
<style>
body { width: 100vw; height: 100vh; overflow: hidden;}
canvas { width: 100%; height: 100%; background-color: black;}
body, canvas { margin: 0px; border: 0px; padding: 0px; };
</style>
</head><body><script type='text/javascript'>
// =====================================
const canvas = document.createElement("canvas");
canvas.setAttribute("id", "canvas");
document.body.appendChild(canvas);
// =======================================
initWebGPU = async () => {
// Check to ensure the user agent supports WebGPU
if (!('gpu' in navigator)) {
const msg = '⚠️ WebGPU is not available on this browser.';
const pre = document.createElement('pre');
pre.style.color = '#f00';
pre.style.textAlign = 'center';
pre.textContent = msg;
document.body.appendChild(pre);
console.error(msg);
return false;
}
// Request an adapter
const adapter = await navigator.gpu.requestAdapter();
if (!adapter) {
console.error('No WebGPU adapters found.');
return false;
}
// Request a device
const device = await adapter.requestDevice();
device.lost.then((info) => {
console.error(`WebGPU device was lost: ${info.message}`);
device = null;
if (info.reason != 'destroyed') {
initWebGPU();
}
});
// Set WebGPU device in Module
Module.preinitializedWebGPUDevice = device;
return true;
}
initWebGPU();
</script>{{{ SCRIPT }}}<script>
Module.onRuntimeInitialized = () => { BaseWebGPU.init(); };
</script></body></html>