How can I improve my use of WebGL for GPU-based nonrealtime renders?
I'll give more details below but my question is in the title. How can I improve the download feature so that it works more efficiently or reliably? I've been working on an interactive 3D viewer. It renders in real-time but with many artifacts. https://code.sololearn.com/W6e6xWN0T7Jv/#html The download button on the right lets you render with more quality and at a higher resolution but also much slower. It works by following these steps: 1. Render a vertical strip of just a pixel or 2 in WebGL. 2. Draw that strip onto a 2D context in another canvas. 3. Perform a short setTimeout or requestAnimationFrame to let the browser process user input. 4. Go back to step 1 until the whole image is drawn. One weird thing I noticed is that sometimes the step 3 mentioned above is VERY slow as in 10 seconds or more to receive the next timeout or requestAnimationFrame callback specifically on the last strip. I wasn't sure if the WebGL drawing was only blocking when I needed to download the data. I experimented with drawImage on a canvas element within the body and this weird problem disappeared. When I experimented with a document.createElement('canvas') element that was not included in the document, the delay on the last strip would happen again. WebGL is normally used for realtime rendering which means I'm fighting against what it was designed for. That leads to a few specific problems. The WebGL context can be lost if a strip is too wide and therefore takes more than a couple seconds to render.