与 iframe and/or window 弹出窗口共享 WebGL 上下文

Sharing a WebGL context with an iframe and/or window popups

我们正在尝试构建一个允许嵌入内容(DOM 或 iFrame)的应用程序 'floated',即。通过 window.open().

移动到单独的 window
  1. WebGL 渲染上下文可以在两者之间共享吗windows?这将避免新 window 必须重建 GPU 上下文:纹理上传、着色器编译等

  2. 额外问题:上下文可以在 iframe 之间共享吗?

  3. 双重奖励:对于Electron场景,渲染进程之间是否可以共享上下文?

Can the WebGL render context be shared between the two windows? This would prevent the new window from having to rebuild the GPU context: texture uploads, shader compilation, etc.

WebGL 上下文只能与单个 canvas 一起使用,因此您可以在另一个 window 中使用该上下文(假设它是由同一页面打开的 window ) 它只能渲染到它最初关联的 canvas。

Bonus question: can the context be shared between iframes?

同上

Double bonus: for an Electron scenario, can the context be shared between render processes?

不,您可以在同一进程中跨 windows 共享。不能跨进程共享。

您可以使用 canvas 2d 将 WebGL canvas 绘制成 2D canvas,这样您就可以使用一个 canvas,在其中渲染 canvas ,然后将其复制到 iframe。

有关示例,请参见 http://greggman.github.io/doodles/webgl_multiple_windows.html 在左上角单击 create new window。每个新的 window 都是同一场景的另一个视图。 windows,包括主要的window,都是通过使用2D canvases和drawImage

渲染的

您可能可以使用 OffscreenCanvas 并通过 transferToImageBitmap.

跨 iframe 呈现多个 canvases