|
5 | 5 | <meta charset="utf-8"> |
6 | 6 | <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"> |
7 | 7 | <style> |
| 8 | + html, body { |
| 9 | + height: 100%; |
| 10 | + } |
| 11 | + |
8 | 12 | body { |
9 | | - background:#000000; |
10 | | - padding:0; |
11 | | - margin:0; |
12 | | - font-weight: bold; |
13 | | - overflow:hidden; |
| 13 | + background: #ffffff; |
| 14 | + padding: 0; |
| 15 | + margin: 0; |
| 16 | + font-family: Monospace; |
| 17 | + font-size: 13px; |
| 18 | + overflow: hidden; |
14 | 19 | } |
15 | 20 |
|
16 | 21 | #info { |
17 | | - position: absolute; |
18 | 22 | top: 0px; |
19 | 23 | width: 100%; |
20 | | - color: #ffffff; |
21 | | - padding: 5px; |
22 | | - font-family:Monospace; |
23 | | - font-size:13px; |
24 | | - text-align:center; |
| 24 | + color: #000000; |
| 25 | + margin: 6px 0px; |
| 26 | + text-align: center; |
25 | 27 | } |
26 | 28 |
|
27 | 29 | #message { |
28 | 30 | color: #ff0000; |
29 | | - font-size:14px; |
30 | 31 | display: none; |
31 | 32 | } |
32 | 33 |
|
33 | 34 | #message > a { |
34 | 35 | color: #ff0000; |
35 | 36 | } |
36 | 37 |
|
37 | | - a { color: #ffffff; } |
| 38 | + #container { |
| 39 | + width: 100%; |
| 40 | + height: calc(100% - 80px); |
| 41 | + } |
| 42 | + |
| 43 | + #ui { |
| 44 | + margin-top: 8px; |
| 45 | + height: 80px; |
| 46 | + text-align: center; |
| 47 | + } |
| 48 | + #button { |
| 49 | + border: 0; |
| 50 | + padding: 4px 6px; |
| 51 | + background: #dddddd; |
| 52 | + outline: none; |
| 53 | + } |
38 | 54 | </style> |
39 | | - <script src="js/WebGL.js"></script> |
40 | 55 | </head> |
41 | 56 | <body> |
42 | 57 | <div id="info"> |
43 | | - <a href="https://threejs.org" target="_blank" rel="noopener noreferrer">three.js</a> offscreen canvas<br/><br/> |
44 | | - three.js runs in a worker and produces asynchronously frames for the canvas element in the main thread. <br/> |
45 | | - This is an <a href="https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas" target="_blank" rel="noopener noreferrer"> experimental feature</a>! |
| 58 | + <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/> |
46 | 59 | <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> |
47 | 60 | </div> |
48 | 61 |
|
49 | | - <canvas id="canvas" style="width: 100%; height: 100%"></canvas> |
50 | | - </body> |
51 | | - <script> |
| 62 | + <div id="container"> |
| 63 | + <canvas id="canvas1" style="width: 50%; height: 100%"></canvas><canvas id="canvas2" style="width: 50%; height: 100%"></canvas> |
| 64 | + </div> |
| 65 | + <div id="ui"> |
| 66 | + <button id="button">START JANK</button><br/> |
| 67 | + <span id="result"></span> |
| 68 | + </div> |
52 | 69 |
|
53 | | - if ( WEBGL.isWebGLAvailable() === false ) { |
| 70 | + <script src="../build/three.js"></script> |
| 71 | + <script src="js/offscreen/scene.js"></script> |
| 72 | + <script src="js/offscreen/jank.js"></script> |
| 73 | + <script> |
54 | 74 |
|
55 | | - document.body.appendChild( WEBGL.getWebGLErrorMessage() ); |
| 75 | + // onscreen |
56 | 76 |
|
57 | | - } |
| 77 | + var width = canvas1.clientWidth; |
| 78 | + var height = canvas1.clientHeight; |
| 79 | + var pixelRatio = window.devicePixelRatio; |
58 | 80 |
|
59 | | - var canvas = document.getElementById( 'canvas' ); |
| 81 | + init( canvas1, width, height, pixelRatio, './' ); |
60 | 82 |
|
61 | | - if ( canvas.transferControlToOffscreen !== undefined ) { |
| 83 | + // offscreen |
62 | 84 |
|
63 | | - var offscreen = canvas.transferControlToOffscreen(); |
64 | | - var worker = new Worker( 'js/workers/OffscreenCanvas.js' ); |
| 85 | + if ( 'transferControlToOffscreen' in canvas2 ) { |
65 | 86 |
|
66 | | - worker.postMessage( { |
67 | | - drawingSurface: offscreen, |
68 | | - width: window.innerWidth, |
69 | | - height: window.innerHeight, |
70 | | - pixelRatio: window.devicePixelRatio |
71 | | - }, [ offscreen ] ); // transfer |
| 87 | + var offscreen = canvas2.transferControlToOffscreen(); |
| 88 | + var worker = new Worker( 'js/offscreen/offscreen.js' ); |
| 89 | + worker.postMessage( { |
| 90 | + drawingSurface: offscreen, |
| 91 | + width: canvas2.clientWidth, |
| 92 | + height: canvas2.clientHeight, |
| 93 | + pixelRatio: window.devicePixelRatio, |
| 94 | + path: '../../' |
| 95 | + }, [ offscreen ] ); |
72 | 96 |
|
73 | | - } else { |
| 97 | + } else { |
74 | 98 |
|
75 | | - document.getElementById( 'message' ).style.display = 'block'; |
| 99 | + document.getElementById( 'message' ).style.display = 'block'; |
76 | 100 |
|
77 | | - } |
| 101 | + } |
78 | 102 |
|
79 | | - </script> |
| 103 | + </script> |
| 104 | + </body> |
80 | 105 | </html> |
0 commit comments