Repository navigation
cvcGL: ViewportManager — N cameras/viewports in one window (PiP core) - #384
Merged
Merged
Conversation
The picture-in-picture path the cvcgl_renderer test documents as unsolvable
with two SceneRenderers over one scene (a second SceneGraph::setRenderer
silently blanks the first view, no diagnostic). ViewportManager owns ONE
vtkRenderWindow — one GL context, the mandatory shape under WASM's single
canvas — and composites N Viewports as SetViewport/SetLayer regions drawn by a
single window->Render().
* Viewport: one rectangle of the window with its OWN vtkRenderer,
CameraController (rooted at "<scene prefix>.viewers.<name>.camera", so a
PiP inset aims/follows independently) and the SceneGraph it draws. Placed
by a normalized region (survives resize) and a composite layer; opaque vs
translucent background controls whether it clears its rect.
* ViewportManager: constructed like a SceneRenderer (main scene + size +
offscreen) and auto-creates a full-screen PRIMARY viewport over that scene,
so the single-view case is a drop-in. addSceneViewport adds an inset over a
DIFFERENT scene; re-attaching an already-drawn scene is now a LOUD error
instead of the silent blank. Keeps the window layer count above the highest
layer in use. render() drains every viewport's scene then composites once;
frameRGB/writePNG capture the whole window.
This is the generalised DBG minimap: alternate views of one scene, or entirely
separate scene graphs, all in one app instance and one WebGL context.
Additive — SceneRenderer is untouched (the SceneRenderer<->facade unification
is a follow-up). New cvcgl_viewport test: a primary + an inset over a second
scene both composite in one offscreen window (each rect shows its own
background hue, each scene's geometry reaches only its own viewport), and the
double-attach / duplicate-name / bad-size guards all fire. Full cvcgl suite
(28 tests) green locally.
This was referenced Sep 21, 2026
transfix
added a commit
that referenced
this pull request
Sep 21, 2026
…p analysis (#389) Concrete defects a gap-analysis pass found in the merged PiP stack (#384/#386/ #387), fixed before the minimap demo exercises them: * Mirror double-drew 2-D overlays: syncMirrorProps copied EVERY prop, so a mirror of a scene with FpsHud/ScreenTextHud drew the HUD a second time on the inset. It now skips vtkActor2D (a window-space overlay, not scene geometry) — matching the shipping wasm PiP. * Mirror rendered flat: syncMirrorProps copied view props but not lights, so a mirror of a StageLighting-rigged scene lost its lighting. It now copies the source's lights (world-space, correct from the mirror's own camera); with none, the mirror falls back to VTK's automatic headlight. * MB::Right was not the no-op the header claims: its button-down latched a drag target and called setActiveViewport, so a right-click silently stole keyboard focus and released the prior viewport's held keys. routeMouseButton now returns immediately for Right. * CameraController::viewportAspect preferred the WINDOW size over the renderer's for the Map/ortho fit, so a PiP inset in Map mode framed to the wrong aspect; it now prefers the viewport (renderer) size, matching the pan scaling, and falls back to the window before the first frame. * Fixed the stale "addMirrorViewport, a follow-up" comment (it shipped in #386). Tests: cvcgl_viewport gains a check that a 2-D actor on the source does NOT reach the mirror while a source light DOES; cvcgl_viewport_input gains a Right-button no-op check (no focus steal, no camera motion). Full cvcgl suite (29) green locally.
transfix
added a commit
that referenced
this pull request
Sep 21, 2026
…ython (#390) Closes the largest gap the PiP work left: the whole ViewportManager/Viewport/ input-router surface (cvcGL #384/#386/#387) was C++-only, so volrover3 and grl-snam — both Python — could not build multi-viewport or minimap layouts. This wraps it, so the Python API mirrors C++: vm = pycvc_gl.ViewportManager(scene, 1024, 768, False, "main") inset = vm.addSceneViewport("inset", scene2, (0.62, 0.05, 0.97, 0.42), 1) mini = vm.addMirrorViewport("mini", "main", (0.62, 0.58, 0.97, 0.95), 2) inset.camera().setMode(pycvc_gl.CameraController.Mode_Fly) # per-viewport vm.routeMouseButton(pycvc_gl.ViewportManager.MouseButton_Left, True, x, y) vp = vm.viewportAt(x, y) # None over the gutter frame = vm.frameRGB() # bytes Binding details, following the existing pycvc_gl patterns: * frameRGB() -> bytes (a scoped typemap, like SceneRenderer's — the SceneRenderer one does not apply to ViewportManager). * region as a Python 4-sequence in (addSceneViewport/addMirrorViewport) and a 4-tuple out (Viewport.region()), via in/argout typemaps. * Viewport has a private ctor -> %nodefaultctor; it is only ever handed out by the manager. renderer()/renderWindow()/mirrorSource() reuse the existing vtkRenderer*/vtkRenderWindow* -> live vtkmodules typemaps. * KEEPALIVE chain mirrors C++ ownership so a live child pins its parent: the manager keeps its scene(s); every handed-out Viewport (primary/viewport/ viewportAt/activeViewport/add*Viewport) keeps the manager; a Viewport's camera() keeps the Viewport. * MouseButton enum -> ViewportManager.MouseButton_Left/Middle/Right. New test_pycvc_gl_viewport.py exercises the surface end to end: auto primary, addSceneViewport over a second scene + addMirrorViewport, viewportAt (layer/ visibility/inputEnabled/gutter), focus-follows-click into cvc::state, the per-viewport camera (its state under the viewer tree), region tuples, and frameRGB bytes — self-skipping without a GL driver, hard-exiting past cvcGL's static-teardown race like the other pycvc_gl tests. Validated locally by SWIG generation (all 24 ViewportManager + 15 Viewport methods, the MouseButton enum, and both typemaps wrap cleanly); the compiled .pyd + this test run in the cvcpkg pycvc-gl recipe, which builds against the python-enabled VTK the module needs.
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.
cvcGL: ViewportManager — N cameras/viewports in one window (PiP core)
First, additive commit of the multi-viewport / picture-in-picture work. It
introduces the core the rest builds on and does not touch
SceneRenderer.Why
cvcgl_renderer's own test documents the gap this closes:The demos want the minimap generalised: dedicated cameras for inset
viewports that show an alternate view of the main scene — or an entirely
separate scene graph — all in one application instance and one WebGL
context (WASM has a single canvas, so multiple windows is not an option).
What
Viewport— one rectangle of the manager's single window: its ownvtkRenderer,CameraController(rooted at"<scene prefix>.viewers.<name>.camera", so a PiP inset aims/followsindependently of the main view) and the
SceneGraphit draws. Placed by anormalized region (survives resize) and a composite layer;
setBackground(…, opaque)chooses whether it clears its rect (opaque inset) or preserves theview under it (translucent overlay). Constructed only by the manager.
ViewportManager— owns ONEvtkRenderWindowand composites NViewports asSetViewport/SetLayerregions in a singlewindow->Render(). Constructed like aSceneRenderer(main scene + size +offscreen flag) and auto-creates a full-screen primary viewport, so the
common single-view case is a drop-in.
addSceneViewport(name, scene, region, layer)adds an inset over a different scene; re-attaching a scene anotherviewport already draws is now a loud
std::invalid_argument— the exactsilent trap above. Keeps the window's layer count above the highest layer in
use;
render()drains each scene's pending graphics events then compositesonce;
frameRGB/writePNGcapture the whole window.Tests
New
cvcgl_viewport(offscreen, headless CI):each rect shows its own background hue, and each scene's geometry reaches
only its own viewport (per-rect frame delta);
fire.
Full
cvcglsuite (28 tests) green locally on Windows/MSVC (built in-tree viacvcpkg deps).
Follow-ups (separate PRs)
draws (per-frame
GetViewPropssync); this is the true minimap.FindPokedRendererso a click/drag targets the viewportunder the cursor.
region/layer/visible+active_viewportunder the existing
.viewers.<name>.*tree.SceneRenderer→ thin facade over a one-viewportViewportManager(back-compat gated).
ChaseCamerashim so volrover3 / grl-snam get thesame multi-viewport surface from Python.