2
0

webgl_worker_offscreencanvas.html 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. body {
  9. background:#000000;
  10. padding:0;
  11. margin:0;
  12. font-weight: bold;
  13. overflow:hidden;
  14. }
  15. #info {
  16. position: absolute;
  17. top: 0px;
  18. width: 100%;
  19. color: #ffffff;
  20. padding: 5px;
  21. font-family:Monospace;
  22. font-size:13px;
  23. text-align:center;
  24. }
  25. #message {
  26. color: #ff0000;
  27. font-size:14px;
  28. display: none;
  29. }
  30. #message > a {
  31. color: #ff0000;
  32. }
  33. a {
  34. color: #ffffff;
  35. }
  36. </style>
  37. <script src="js/WebGL.js"></script>
  38. </head>
  39. <body>
  40. <div id="info">
  41. <a href="https://threejs.org" target="_blank" rel="noopener noreferrer">three.js</a> offscreen canvas<br/><br/>
  42. three.js runs in a worker and produces asynchronously frames for the canvas element in the main thread. <br/>
  43. This is an <a href="https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas" target="_blank" rel="noopener noreferrer"> experimental feature</a>!
  44. <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>
  45. </div>
  46. <canvas id="canvas" style="width: 100%; height: 100%"></canvas>
  47. </body>
  48. <script>
  49. if ( WEBGL.isWebGLAvailable() === false ) {
  50. document.body.appendChild( WEBGL.getWebGLErrorMessage() );
  51. }
  52. var canvas = document.getElementById( 'canvas' );
  53. if ( canvas.transferControlToOffscreen !== undefined ) {
  54. var offscreen = canvas.transferControlToOffscreen();
  55. var worker = new Worker( 'js/workers/OffscreenCanvas.js' );
  56. worker.postMessage( {
  57. drawingSurface: offscreen,
  58. width: window.innerWidth,
  59. height: window.innerHeight,
  60. pixelRatio: window.devicePixelRatio
  61. }, [ offscreen ] ); // transfer
  62. } else {
  63. document.getElementById( 'message' ).style.display = 'block';
  64. }
  65. </script>
  66. </html>