kiss3d icon indicating copy to clipboard operation
kiss3d copied to clipboard

Support multiple WebGL contexts

Open alexkirsz opened this issue 4 years ago • 1 comments

Right now, kiss3d only supports rendering to a single <canvas> element. I have a use case where I'd like to embed multiple instances of kiss3d on the same page (a blog post that goes through implementing a 3d simulation).

I've identified a few blockers:

if e.target()
    .and_then(|target| <CanvasElement>::try_from(target).ok())
    .map_or(true, |canvas| canvas != edata.canvas)
{
    return;
}

EDIT: For the last point, a better solution is to add event listeners to the canvas element directly (except for window resize / mouse up / mouse move (which needs to be modified to support the pointer leaving the canvas).

alexkirsz avatar Jan 14 '20 21:01 alexkirsz

I just realized that the PR #207 I am working on is related to this issue, at least it solves the third point. The first two points however I don't have a need for them yet.

I do have a case of closing the existing Kiss3d window and opening a new window thus reusing the same canvas. It currently works but I do wonder how much memory is leaked from not cleaning up the canvas WebGL context properly. Keeping the context as a part of the Kiss3d canvas would allow for proper cleanup, or at least allow the canvas element to be removed to allow for the context to be garbage-collected.

alvinhochun avatar Feb 27 '20 16:02 alvinhochun