webgl_worker_offscreencanvas.html 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - worker - offscreen canvas</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <link type="text/css" rel="stylesheet" href="main.css">
  8. <style>
  9. body {
  10. background-color: #fff;
  11. color: #444;
  12. }
  13. a {
  14. color: #08f;
  15. }
  16. canvas {
  17. display: inline-block;
  18. }
  19. #message {
  20. color: #ff0000;
  21. display: none;
  22. }
  23. #message > a {
  24. color: #ff0000;
  25. }
  26. #container {
  27. position: absolute;
  28. top: 50px;
  29. bottom: 70px;
  30. width: 100%;
  31. }
  32. #ui {
  33. position: absolute;
  34. bottom: 20px;
  35. width: 100%;
  36. text-align: center;
  37. }
  38. #button {
  39. border: 0;
  40. padding: 4px 6px;
  41. background: #dddddd;
  42. outline: none;
  43. }
  44. </style>
  45. </head>
  46. <body>
  47. <div id="info">
  48. <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/>
  49. <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>
  50. </div>
  51. <div id="container">
  52. <canvas id="canvas1" style="width: 50%; height: 100%"></canvas><canvas id="canvas2" style="width: 50%; height: 100%"></canvas>
  53. </div>
  54. <div id="ui">
  55. <button id="button">START JANK</button><br/>
  56. <span id="result"></span>
  57. </div>
  58. <script src="../build/three.js"></script>
  59. <script src="js/offscreen/scene.js"></script>
  60. <script src="js/offscreen/jank.js"></script>
  61. <script>
  62. // onscreen
  63. var width = canvas1.clientWidth;
  64. var height = canvas1.clientHeight;
  65. var pixelRatio = window.devicePixelRatio;
  66. init( canvas1, width, height, pixelRatio, './' );
  67. // offscreen
  68. if ( 'transferControlToOffscreen' in canvas2 ) {
  69. var offscreen = canvas2.transferControlToOffscreen();
  70. var worker = new Worker( 'js/offscreen/offscreen.js' );
  71. worker.postMessage( {
  72. drawingSurface: offscreen,
  73. width: canvas2.clientWidth,
  74. height: canvas2.clientHeight,
  75. pixelRatio: window.devicePixelRatio,
  76. path: '../../'
  77. }, [ offscreen ] );
  78. } else {
  79. document.getElementById( 'message' ).style.display = 'block';
  80. }
  81. </script>
  82. </body>
  83. </html>