Repository navigation
cvcGL: SDL3 owns the browser canvas and its WebGL2 context - #997
Merged
Merged
Conversation
In a browser VTK fits the canvas to its container only when it handles a resize event, and the first one comes from a ResizeObserver after the first frames have drawn at the window's starting size. cyprty starts at arigl's 1024x768, so ImGui placed every window against that, and on a shorter canvas (577-729 px tall in a laptop's browser) windows ran off the bottom: the "opens inside the view" rule (ARIADNE.md 5.8) had moved them in for a view that was not there. ViewportManager now takes the container's size right after the interactor initializes, as VTK's own resize handling would. With the real size from frame 1, the overlay's small-screen rule would start a 1366x768 laptop's browser with its panels hidden (short side under 700). It is a phone's rule, so the line is now 500 logical px, the phone view libcvc#974 uses. cvcgl_imgui_panels_start checks both sides.
Checked in headless Chrome at 1366x768: with the canvas sized before the first frame, the Avatar window was placed in a 597-px stage, and a frame later the stage was 578. The footer is empty until the program first prints, then a line taller. It is one line tall from the start now, in cyprty and the cvcGL demo page, so the canvas keeps the size the windows were placed in. When the overlay hides its panels on a phone, it writes that to its state mirror, as the show/hide button does, so ui.panels_open says what shows. cvcgl_imgui_panels_start renders three frames per window: the overlay's GL backend starts at the first render, so ImGui's first frame is the second.
The first is the window resize event the wasm interactor's Initialize() dispatches, handled at the next processUIEvents(), not a ResizeObserver as the comment (and the first commit's message) said. Checked in Chrome: with the container held at 0 px past that event, the canvas stayed 0 px tall after the container got its height, until a window resize event.
A window opened inside the view (5.8), but if the view got smaller after (a browser window made smaller, a phone turned on its side, fullscreen left), nothing brought it back: on a shorter canvas the windows below its new edge stayed there. Each window now keeps the work area it was last drawn in. When it is drawn in a smaller one, a window that showed in full there moves back in as it opened, no larger than the work area. A window the user left partly outside stays where it is, a view that grows again moves nothing, and the flow places its windows itself, as before. cvcgl_imgui_view_shrink checks it on a bare ImGui context: 1600x900, then 1350x579 (a 1366x768 laptop's browser canvas), 1350x450 and 500x450, then back; and a window dragged past the bottom edge. Against the old ImGuiBackend.cpp 5 of its 11 checks fail.
A window moved in to fit the view, where it opened or when the view got smaller, now keeps its home: the place and size it had without the move. Each frame it heads there as far as the view allows, so a view that grows again returns it, and a page opened in a small browser window and then made larger puts the windows where the document says. It is home again when it gets there. If the user has moved or resized it since it was last put somewhere, where they put it is its place from then on. cvcgl_imgui_view_shrink: back at 1600x900 every window is where its pos: says at its size; a page opened at 1350x579 goes back part way at 1450x700 and all the way at 1600x900; a window the user drags after it was moved in stays there. 16 checks.
#974 (windows as a list of titles on a phone) and this branch both changed where ImGuiBackend::begin_window opens a window. Both stay: a window that does not fit a phone's view opens collapsed in the list, and one moved in anywhere else keeps its home. A window in the list gets no home: one would pull it back out of the list, on the phone and again when the view grows. reset_layout clears the list count, the last views and the homes. cvcgl_imgui_view_shrink gains the case (it fails without the rule), and section 5.8 says a window in a phone's list stays there.
… drag to steer Three things from trying cyprty with mouse look on. A click on a window could take the pointer. The page takes its pointer lock inside the press, and it judged "not on the UI" by a flag the frame loop set from ImGui's hover, a frame or two old: a move onto a window and a click within that time locked the mouse (3 of 5 such clicks in headless Chrome). The overlay now hands the camera the rectangles of the windows it drew (CameraController::setUiRegions, replacing setPointerOverUi), the page tests the press's own position against them, and the overlay keeps a press there from the camera even before ImGui has seen the pointer arrive. After: 0 of 5, and a click on the floor still locks. Looking around was jagged. arigl's browser loop yielded on a 0 ms timer, out of step with the display, so frames stayed up for 0, 1 or 2 refreshes unevenly: in headless Chrome at 60 Hz, 44-58 of ~385 refreshes got two frames (one never shown) and 18-19 none. It now waits for the next animation frame (a 100 ms timer keeps a hidden tab's loop going): 374-375 of ~375 refreshes get exactly one. ?yield=timeout ($CVC_ARIGL_YIELD) is the A/B. The pointer lock also asks for raw motion (unadjustedMovement: no pointer acceleration, none of Chromium's jumps under a lock), and takes the plain lock where a browser has none. In drag to look, a drag on the floor now steers: the avatar faces the point under the pointer as it moves, mouse or finger (CameraController::setPrimaryDragSteers, on in a room; a drag starts past the 4 px click slop). The right button, or two fingers, turns the view instead; the browser's context menu is kept off the canvas. A second finger cancels the first one's press (CameraController::cancelPointer), so a two-finger turn neither steers nor ends as a tap on the floor. Turns from a drag are rate-limited like mouse look's (20 a second to the relay, every frame on screen). The Controls window has the switch: "Drag the floor to face it (right drag / two fingers look around)". Tests: cvcgl_camera gains a drag-to-steer section (slop, right drag, click, cancel, off from state, mouse look); the Controls window test checks the new row. cvcgl_camera*, cvcgl_imgui_*, ari_golden, streaming_overlays 13/13, ariadne_runtime 248/248.
… button for messages
In the browser the conference's chat field took typed letters but not
Enter or Backspace, so nothing could be sent. ImGuiOverlay hands ImGui
the keys the viewer's interactor reports, by name. VTK's own windows
name them as X11 does ("Return", "BackSpace", "Left"); in a browser
VTK's interactor passes the page's KeyboardEvent.key ("Enter",
"Backspace", "ArrowLeft"), which the overlay's table did not know.
Letters arrived anyway, through the CharEvent. Headless Chrome with real
key events: "hellox" then Backspace still read "hellox", and Enter
posted nothing.
The table now has both spellings (arrows, PageUp/PageDown, the
modifiers and " " too). It moves to an internal header,
src/cvcGL/ImGuiKeyNames.h, so cvcgl_imgui_key_names can check both
names for each key without a window or GL.
message_input gains `send:`, the label of a button on the field's right
that sends it as Enter does (ImGui; a terminal has Enter only). The
field narrows to leave the button room. The chat component uses
`send: Send`.
Multi-line already works once Enter does: Shift+Enter (and Ctrl+Enter)
add a line, up to max_lines (4), then it scrolls.
Tests: cvcgl_imgui_key_names (new); cvcgl_imgui_chat_widgets gains a
Send case (inside the window, sends, clears, keeps the focus, ignores an
empty field); the loader test reads `send:`.
…t/cvcgl-sdl-browser
…cvcgl-sdl-browser
…nto feat/cvcgl-sdl-browser
In a browser cvcGL's onscreen window is now SdlGLRenderWindow too, so SDL's events drive VTK's interactor there as they do natively: the camera, ImGui and SdlInput read one input path with one set of key names. - The canvas fills its container as VTK's canvas window styled it, and SDL takes the window's size from the canvas's CSS box when it is made and at every resize. The page sizes it; an app's SetSize is ignored there. - WebGL2 with VTK's attributes: no antialiasing, opaque unless translucent, depth and stencil. Blit to the bound framebuffer; color bits from WebGL. - No swap: Frame() yields where VTK 9.5's canvas window does, so FrameYield keeps its meaning. The current context is checked against WebGL's own. - SDL takes the keys typed into the canvas only, not the page's fields or the system keyboard's input. No window title (it would be the page's). - CameraController's in-press pointer lock and raw motion stay; under the lock the interactor's position stands still. While two fingers are down the mouse SDL makes of the first stays still (TouchGestures' gesture). - Text events drop control characters (a keypress types Enter as "\r"). - $CVCGL_SDL_WINDOW=0 in the page's ENV keeps VTK's canvas window.
A tap's compatibility mousedown focused the canvas right after ImGuiOverlay focused its system-keyboard field, which would put a phone's keyboard away. VTK's touch handlers cancelled touch events, so there was no mousedown or click; SDL reads pointer events and cancels nothing.
…/cvcgl-sdl-browser # Conflicts: # src/cvcGL/ViewportManager.cpp
…/cvcgl-sdl-browser # Conflicts: # src/cvcGL/CameraController.cpp # src/cvcGL/TouchGestures.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#829 made SDL3 own cvcGL's onscreen window and its GL context on the desktop, so SDL's events drive VTK's interactor there. The browser was left on VTK's canvas window and
vtkWebAssemblyRenderWindowInteractor, whose key names are the page'sKeyboardEvent.key(#993 had to teach ImGui those). This makes the browser windowSdlGLRenderWindowwithSdlRenderWindowInteractortoo: one input path and one set of key names everywhere.The WebGL2 context
SDL 3.4's
Emscripten_GLES_CreateContextmakes the context from the SDL GL attributes. WithSDL_GL_ALPHA_SIZE0 (8 only for a translucent window) it is the context VTK's canvas window makes: WebGL2, no antialiasing (VTK resolves its own multisampled framebuffers into it), opaque, premultiplied alpha, depth, stencil, default power preference.What changes under Emscripten (
src/cvcGL/SdlWindow.cpp)sdl_window_enabled()is true in the browser too.ENV.CVCGL_SDL_WINDOW = '0'in the page's preRun keeps VTK's canvas window.SetSizeis ignored once the window exists.SDL_GL_SwapWindow(in the browser it only yields).Frame()yields where VTK 9.5's canvas window does, so FrameYield means the same; arigl's App mode plus requestAnimationFrame wait is unchanged. Blit to the bound framebuffer (BlitToCurrent), color bits from WebGL, as VTK's window does.MakeCurrent,IsCurrent,ReleaseCurrentand the context stack check WebGL's own current context, since SDL skips one it believes current and a VTK canvas window can change it behind SDL."\r").Docs:
docs/CVCGL_WASM.mdgains "The window: SDL's canvas";docs/ARIADNE.md's input note and header comments are brought up to date.Testing
Built the conference client for wasm locally against the cvcpkg wasm prefix (SDL 3.4.12, VTK 9.5, emsdk 5.0.7) and drove it in headless Chrome (ANGLE D3D11) over the DevTools protocol, with trusted input events, against a local relay.
document.pointerLockElement: 400 px of motion turned the avatar 50°, and moving across a window's close button under the lock didn't hover it (it does once released).Input.insertText), Backspace and Enter send.ENV.CVCGL_SDL_WINDOW = '0'runs VTK's canvas window as before (keys, walking).cvcgl_sdl_attach,cvcgl_sdl_inputandcvcgl_viewport_inputamong them. The Ariadne and chat gtests (with CI's exclusions): 727 cases pass in ariadne_bind, doc_fetch, ftxui, host, loader, media, requires, runtime, scene_tf, stream_view, term_graphics and room_chat. 30 cases skip because the local dependency prefixes have no yaml-cpp (the three ari CLI binaries, two loader cases); CI has it. The core suites this branch doesn't touch (nav, physics, state, world) were left to CI. On the desktopSDL_CreateWindowWithPropertiesgets the same propertiesSDL_CreateWindowset.