webgl_worker_offscreencanvas.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. <style>
  8. html, body {
  9. height: 100%;
  10. }
  11. body {
  12. background: #ffffff;
  13. padding: 0;
  14. margin: 0;
  15. font-family: Monospace;
  16. font-size: 13px;
  17. overflow: hidden;
  18. }
  19. #info {
  20. top: 0px;
  21. width: 100%;
  22. color: #000000;
  23. margin: 6px 0px;
  24. text-align: center;
  25. }
  26. #message {
  27. color: #ff0000;
  28. display: none;
  29. }
  30. #message > a {
  31. color: #ff0000;
  32. }
  33. #container {
  34. width: 100%;
  35. height: calc(100% - 80px);
  36. }
  37. #ui {
  38. margin-top: 8px;
  39. height: 80px;
  40. text-align: center;
  41. }
  42. #button {
  43. border: 0;
  44. padding: 4px 6px;
  45. background: #dddddd;
  46. outline: none;
  47. }
  48. </style>
  49. </head>
  50. <body>
  51. <div id="info">
  52. <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/>
  53. <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>
  54. </div>
  55. <div id="container">
  56. <canvas id="canvas1" style="width: 50%; height: 100%"></canvas><canvas id="canvas2" style="width: 50%; height: 100%"></canvas>
  57. </div>
  58. <div id="ui">
  59. <button id="button">START JANK</button><br/>
  60. <span id="result"></span>
  61. </div>
  62. <script src="../build/three.js"></script>
  63. <script src="js/offscreen/scene.js"></script>
  64. <script src="js/offscreen/jank.js"></script>
  65. <script>
  66. // onscreen
  67. var width = canvas1.clientWidth;
  68. var height = canvas1.clientHeight;
  69. var pixelRatio = window.devicePixelRatio;
  70. init( canvas1, width, height, pixelRatio, './' );
  71. // offscreen
  72. if ( 'transferControlToOffscreen' in canvas2 ) {
  73. var offscreen = canvas2.transferControlToOffscreen();
  74. var worker = new Worker( 'js/offscreen/offscreen.js' );
  75. worker.postMessage( {
  76. drawingSurface: offscreen,
  77. width: canvas2.clientWidth,
  78. height: canvas2.clientHeight,
  79. pixelRatio: window.devicePixelRatio,
  80. path: '../../'
  81. }, [ offscreen ] );
  82. } else {
  83. document.getElementById( 'message' ).style.display = 'block';
  84. }
  85. </script>
  86. </body>
  87. </html>