forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebgl_worker_offscreencanvas.html
105 lines (87 loc) · 2.45 KB
/
webgl_worker_offscreencanvas.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - worker - offscreen canvas</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
html, body {
height: 100%;
}
body {
background: #ffffff;
padding: 0;
margin: 0;
font-family: Monospace;
font-size: 13px;
overflow: hidden;
}
#info {
top: 0px;
width: 100%;
color: #000000;
margin: 6px 0px;
text-align: center;
}
#message {
color: #ff0000;
display: none;
}
#message > a {
color: #ff0000;
}
#container {
width: 100%;
height: calc(100% - 80px);
}
#ui {
margin-top: 8px;
height: 80px;
text-align: center;
}
#button {
border: 0;
padding: 4px 6px;
background: #dddddd;
outline: none;
}
</style>
</head>
<body>
<div id="info">
<a href="https://threejs.org" target="_blank" rel="noopener noreferrer">three.js</a> - offscreen canvas (<a href="https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas" target="_blank" rel="noopener noreferrer">about</a>)<br/>
<p id="message">Your browser does not support OffscreenCanvas. Check the browser support <a href="https://caniuse.com/#feat=offscreencanvas" target="_blank" rel="noopener noreferrer">here</a></p>
</div>
<div id="container">
<canvas id="canvas1" style="width: 50%; height: 100%"></canvas><canvas id="canvas2" style="width: 50%; height: 100%"></canvas>
</div>
<div id="ui">
<button id="button">START JANK</button><br/>
<span id="result"></span>
</div>
<script src="../build/three.js"></script>
<script src="js/offscreen/scene.js"></script>
<script src="js/offscreen/jank.js"></script>
<script>
// onscreen
var width = canvas1.clientWidth;
var height = canvas1.clientHeight;
var pixelRatio = window.devicePixelRatio;
init( canvas1, width, height, pixelRatio, './' );
// offscreen
if ( 'transferControlToOffscreen' in canvas2 ) {
var offscreen = canvas2.transferControlToOffscreen();
var worker = new Worker( 'js/offscreen/offscreen.js' );
worker.postMessage( {
drawingSurface: offscreen,
width: canvas2.clientWidth,
height: canvas2.clientHeight,
pixelRatio: window.devicePixelRatio,
path: '../../'
}, [ offscreen ] );
} else {
document.getElementById( 'message' ).style.display = 'block';
}
</script>
</body>
</html>