Skip to content

feat(windows): embed Bloom in a host window via bloom_attach_hwnd (Perry UI BloomView, #2395)#70

Open
proggeramlug wants to merge 1 commit into
mainfrom
feat/bloomview-embed
Open

feat(windows): embed Bloom in a host window via bloom_attach_hwnd (Perry UI BloomView, #2395)#70
proggeramlug wants to merge 1 commit into
mainfrom
feat/bloomview-embed

Conversation

@proggeramlug

Copy link
Copy Markdown
Contributor

The engine side of the Perry UI BloomView widget (PerryTS/perry#5518) — lets Bloom render into a host-provided window instead of always creating its own top-level window, so it can live as a render view inside a normal Perry UI app (analogous to Flame inside Flutter). Pairs with perry-issue #2395.

Changes

  • native/windows/src/lib.rs: factor the wgpu surface + engine init out of bloom_init_window into init_engine_for_hwnd, shared with a new FFI:
    • bloom_attach_hwnd(hwnd, w, h) — build the surface on a host-provided HWND and classic-subclass it so Bloom still sees WM_SIZE / keyboard / mouse (its own wndproc never runs for a foreign-class window), then chain to the original proc.
    • bloom_resize(physW, physH, logW, logH) — explicit resize.
    • An EMBEDDED flag: bloom_begin_drawing skips its own message pump (the host owns the loop) and bloom_window_should_close reports "stay open".
  • src/core/index.ts: attachToHwnd / resize TS wrappers (re-exported from src/index.ts).
  • package.json: declare bloom_attach_hwnd / bloom_resize in the native-library function manifest so Perry links them.
  • embed-perry/: a demo Perry UI app that embeds a live Bloom 3D scene.

Usage

import { BloomView, bloomViewGetHwnd } from 'perry/ui';
import { attachToHwnd, beginDrawing, endDrawing, clearBackground /* … */ } from 'bloom';

const view = BloomView(820, 480);
let attached = 0;
setInterval(() => {
  if (!attached) { attachToHwnd(bloomViewGetHwnd(view), 820, 480); attached = 1; }
  beginDrawing(); clearBackground({ r: 18, g: 22, b: 34, a: 255 }); /* …draw 3D… */ endDrawing();
}, 16);

The host owns the message loop, so drive frames yourself (don't call runGame, which blocks).

Status

  • Windows only. Per-platform attach (NSView / UIView / GTK4 dmabuf) is a follow-up; the Perry-side BloomView widget already links on all targets.
  • Verified end-to-end: the embed-perry/ demo compiles and renders a live, animating 3D scene inside a Perry UI window, including resize (see embed-perry/bloomFull.png).
  • The demo requires the BloomView Perry build from feat(ui): BloomView — embed the Bloom engine in a Perry UI app (#2395) PerryTS/perry#5518 to compile/run.

🔗 Perry-side PR: PerryTS/perry#5518

…rry UI BloomView, #2395)

Lets Bloom render into a host-provided child window instead of always creating
its own top-level window — the engine side of the Perry UI `BloomView` widget
(PerryTS/perry#5518), analogous to Flame inside Flutter.

- native/windows/src/lib.rs: factor the wgpu surface + engine init out of
  bloom_init_window into init_engine_for_hwnd, shared with a new FFI
  bloom_attach_hwnd(hwnd, w, h). It builds the surface on the host HWND and
  classic-subclasses it (WM_SIZE/keyboard/mouse → engine). Add bloom_resize,
  an EMBEDDED flag (begin_drawing skips its own message pump; should_close
  reports "stay open" since the host owns the loop).
- src/core/index.ts: attachToHwnd / resize TS wrappers (+ src/index.ts export).
- package.json: declare bloom_attach_hwnd / bloom_resize in the native-library
  function manifest.
- embed-perry/: a demo Perry UI app embedding a live Bloom 3D scene (requires
  the BloomView Perry build from PerryTS/perry#5518 to compile/run).

Windows only for now; per-platform attach (NSView/UIView/dmabuf) is a follow-up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant