-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
114 lines (106 loc) · 4.25 KB
/
index.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>test_webgl_webgpu</title>
<style>
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#engine-container-01, #engine-container-02 {
width: 340px;
height: 250px;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<h1>Hello WebGL2 and WebGPU based on WASM!</h1>
<input id="slowCheckbox" type="button" value="Slow things down" onclick="slowDown()">
<div style="display: grid; grid-template-columns: 360px 360px; margin-top: 10px;">
<span>Rendering in UI Thread</span>
<span>Rendering in Worker(using OffscreenCanvas)</span>
<div id="engine-container-01"></div>
<div id="engine-container-02"></div>
</div>
<script>
// This code is from https://doc.babylonjs.com/features/featuresDeepDive/scene/offscreenCanvas
const slowDown = function() {
let count = 0;
setInterval(() => {
for (var index = 0; index < 10000000; index++) {
count += Math.cos(Math.sin(Math.random()));
}
}, 1);
}
</script>
<!-- 使用外部(js中)创建canvas和Module的方式时,“customCanvas”参数必须为true -->
<!-- <script type="module">
import EngineCore from './lib/EngineCore.js'
const canvasId = "xr-dxasf-0ddas-main-canvas";
const container = document.getElementById("engine-container");
const Module = {
canvas: (() => {
const canvas = document.createElement('canvas');
canvas.id = canvasId;
canvas.style.cssText = `
width: ${container.clientWidth}px;
height: ${container.clientHeight}px;
margin: 0;
padding: 0;
`;
canvas.addEventListener("webglcontextlost", (e) => { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
document.getElementById("engine-container").appendChild(canvas);
return canvas;
})(),
};
EngineCore(Module).then(engine => {
engine.startEngine({
containerId: "engine-container",
width: container.clientWidth,
height: container.clientHeight,
backend: "webgpu", // Valid values: webgl2 or webgpu
usingOffscreenCanvas: true,
canvasId: canvasId,
customCanvas: true,
style: "" // A css text, it is only working when "customCanvas" is set to false
});
});
</script> -->
<!-- 使用WASM内部创建canvas和Module的方式 -->
<script type="module">
import EngineCore from './lib/EngineCore.js'
const container1 = document.getElementById("engine-container-01");
EngineCore().then(engine => {
engine.startEngine({
containerId: "engine-container-01",
width: container1.clientWidth,
height: container1.clientHeight,
backend: "webgpu", // Valid values: webgl2 or webgpu
usingOffscreenCanvas: false,
canvasId: 'xr-main-canvas-0x000001',
customCanvas: false,
style: "" // A css text, it is only working when "customCanvas" is set to false
});
});
const container2 = document.getElementById("engine-container-02");
EngineCore().then(engine => {
engine.startEngine({
containerId: "engine-container-02",
width: container2.clientWidth,
height: container2.clientHeight,
backend: "webgpu", // Valid values: webgl2 or webgpu
usingOffscreenCanvas: true,
canvasId: 'xr-main-canvas-0x000002',
customCanvas: false,
style: "" // A css text, it is only working when "customCanvas" is set to false
});
});
</script>
</body>
</html>