Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

Implement multi-window support #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

atrosinenko
Copy link

In my port of QEMU to JavaScript I use their SDL2 UI for graphics. Previously, I had to disable every window except one, otherwise the canvas was messed up.

In this PR, SDL2 support for multiple windows is implemented for Emscripten.

This PR relies on window selector from Emscripten runtime (emscripten-core/emscripten#6374) but should work in single-window case when window selector is not supported.

PS: Frankly speaking, I'm not familiar with OpenGL at all, but it seems to work in my QEMU port. Corrections are welcome, of course. You can test it with this kludgy gist.

This commit relies on window selector from Emscripten runtime but should
work in single-window case when window selector is not supported.
@Daft-Freak
Copy link
Member

Not sure I like this approach. It should work fine for software but GL will be a mess (every window will have the same context). I always intended to implement multi-window by mapping multiple windows to multiple canvases, but never had the time actually implement it. My plan was something like this:

  • add emscripten_create_canvas, probably calling something like Module['createCanvas'] for customization. That would return the id of the new canvas.
  • use id strings as the NativeWindowType in EGL for GL support.
  • use the default canvas for the first window and create new canvases for any additional windows. SDL_CreateWindowFrom could be used to target any existing canvases.

@atrosinenko
Copy link
Author

It can probably have the same logic: window switcher, one-window-at-a-time, SHOWN/HIDDEN notifications, but with reworked support from Emscripten, so emscripten_add_window should create separate canvas and EGL support functions should respect from which canvas which renderer should be created.

@Daft-Freak
Copy link
Member

If you have per-canvas visibility events, then it would be up to the shell (switching, side by side or even a simple window manager) and it shouldn't involve that many changes in SDL. I'd try to avoid using window in function names though, that usually refers to the browser window.

@atrosinenko
Copy link
Author

Got it, thank you. I will probably try to modify this PR according to this, but some time later.

@Daft-Freak
Copy link
Member

Not sure how much work is involved for the EGL part though, it was mentioned in one of the other issues that EGL support was getting rewritten: #48 (comment)

@Daft-Freak
Copy link
Member

Did some work on SDL_CreateWindowFrom: https://github.com/emscripten-ports/SDL2/commits/create-window-from. It's enough for software rendering to work. Some events are sill broken(only fire on the first window created).

slightly hacky demo

@Daft-Freak
Copy link
Member

With some EGL work (emscripten-core/emscripten@incoming...Daft-Freak:egl-rewrite), I have the GLES renderer working on multiple canvases.

@kripken
Copy link
Member

kripken commented Jan 17, 2019

Wow, very cool @Daft-Freak! :)

@GuestInCorle
Copy link

GuestInCorle commented Apr 12, 2019

@Daft-Freak your links seems to be presently broken. Can you fix them or upload that files to github? AFAIK your example of rendering on multiple canvases using SDL and GLES is unique.

UPD: Now it's fine. 😁

@GuestInCorle
Copy link

@Daft-Freak Can you please share the source code of your two examples?

Why does the second example show a strong performance decrease?

@Daft-Freak
Copy link
Member

The first was testnative from the branch (possibly modified to force software), the second is this modified version.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants