Skip to content

bgfx: conform to the canonical window + input contracts (epic #386 Phase 3) - #394

Merged
apotema merged 1 commit into
mainfrom
agent/bgfx-window-contract
Jun 28, 2026
Merged

bgfx: conform to the canonical window + input contracts (epic #386 Phase 3)#394
apotema merged 1 commit into
mainfrom
agent/bgfx-window-contract

Conversation

@apotema

@apotema apotema commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

First backend conformed to labelle-core's canonical window contract (v1.21.0) — the user's chosen "canonical rename (unify)" path. bgfx is FP's backend and the Phase-4 GPU-context-gate backend, so it's the highest-leverage one to do first.

Renames (backends/bgfx/src/window.zig)

beginDrawing→beginFrame, endDrawing→endFrame, getScreenWidth→width, getScreenHeight→height, windowShouldClose→shouldQuit. Already-canonical methods (frameDuration/requestQuit/setFullscreen/setVsync/isFullscreen/takeScreenshot/initWindow) unchanged. All call sites updated: android_app.zig, templates/{desktop,android}.txt, example/{main,android_video}.zig.

Collision respected

The render backend's own getScreenWidth/getScreenHeight in gfx/state.zig (the backend_contract required methods, returning the design canvas) are a DIFFERENT contract — untouched. Only the window's (live framebuffer size) were renamed.

Proves conformance

  • comptime core.assertWindow(@This()) in window.zig + comptime core.assertInput(@This()) in input.zig — compile-time gates that fail with a named-decl list if anything's missing. They compile ⇒ bgfx provably satisfies both contracts. bgfx declares shouldQuit ⇒ correctly a loop backend (ownsLoop() true).
  • Wired input's previously-duck-typed "satisfies InputInterface" claim into a real assert.
  • core pin bumped 1.16.1 → 1.21.0 (clean, no unrelated breakage).

Note

width()/height() decls shadowed initWindow's width/height params (Zig 0.16 rejects) → params renamed to w/h (mechanical).

Verified

backends/bgfx zig build + zig build test green (19/19); Android cross-build (-Dtarget=aarch64-linux-android) green; the bgfx example builds. The comptime asserts cross no core types over the engine seam ⇒ no codegen-unification change needed.

Part of epic #386 Phase 3 (window+input contracts → conform backends). sokol already speaks the canonical dialect; raylib (still beginDrawing/getScreenWidth) follows.

Summary by CodeRabbit

  • New Features
    • Unified the bgfx backend’s window and frame handling across desktop and Android, with consistent sizing, frame start/end, and quit behavior.
  • Bug Fixes
    • Improved screenshot capture timing so images are taken at the correct point in the frame.
    • Updated Android backend integration for better compatibility and build reliability.

Rename the bgfx window methods from the raylib dialect to labelle-core's
canonical window-contract names and prove conformance at comptime:

  beginDrawing      -> beginFrame
  endDrawing        -> endFrame
  getScreenWidth    -> width
  getScreenHeight   -> height
  windowShouldClose -> shouldQuit

(frameDuration / requestQuit / setFullscreen / setVsync / isFullscreen /
takeScreenshot were already canonical and are unchanged.) The render
backend's own getScreenWidth/getScreenHeight (gfx.zig / gfx/state.zig) are
the DIFFERENT render contract and are deliberately left untouched.

- Bump labelle_core pin 1.16.1 -> 1.21.0 (carries window_contract.zig).
- window.zig: import labelle-core + comptime core.assertWindow(@this());
  rename the 5 decls + every internal caller/comment; rename the shadowed
  width/height params in initWindow* to w/h (Zig 0.16 rejects a param that
  shadows the new top-level width()/height() decls).
- input.zig: wire the previously duck-typed contract claim into a real
  comptime core.assertInput(@this()).
- build.zig: import labelle-core onto window_mod + input_mod on every
  target (comptime-only asserts, no core type crosses the engine seam, so
  no codegen unification needed beyond the existing Android input override).
- templates/desktop.txt + android.txt and example/main.zig +
  android_video.zig: update the run-loop call sites to canonical names.

Verified: zig build + zig build test green (host and
-Dtarget=aarch64-linux-android); the bgfx example builds.
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d64d74d1-c790-4aac-8248-3b184862c939

📥 Commits

Reviewing files that changed from the base of the PR and between 3d39ece and 1d97919.

📒 Files selected for processing (9)
  • backends/bgfx/build.zig
  • backends/bgfx/build.zig.zon
  • backends/bgfx/example/android_video.zig
  • backends/bgfx/example/main.zig
  • backends/bgfx/src/android_app.zig
  • backends/bgfx/src/input.zig
  • backends/bgfx/src/window.zig
  • backends/bgfx/templates/android.txt
  • backends/bgfx/templates/desktop.txt

📝 Walkthrough

Walkthrough

The bgfx backend's public window API is renamed to match the labelle-core canonical contract (beginFrame/endFrame, width/height, shouldQuit), and comptime assertWindow/assertInput checks are added. The labelle-core dependency is lifted from Android-only to all targets, bumped to v1.21.0, and all examples and code-generation templates are updated to the new names.

Changes

bgfx Window/Input API Rename and Contract Enforcement

Layer / File(s) Summary
labelle-core dependency wiring and version bump
backends/bgfx/build.zig, backends/bgfx/build.zig.zon
core_dep/core_mod are resolved unconditionally and passed to both input_mod and window_mod; pinned labelle_core version bumped from v1.16.1 to v1.21.0.
window.zig: API renames and comptime contract assertion
backends/bgfx/src/window.zig
Imports labelle-core and calls core.assertWindow(@this()) at comptime; renames getScreenWidth/getScreenHeightwidth/height, beginDrawing/endDrawingbeginFrame/endFrame, windowShouldCloseshouldQuit; moves screenshot queue consumption to endFrame; refactors initWindowAndroid to accept w/h.
input.zig: comptime assertInput contract check
backends/bgfx/src/input.zig
Adds labelle-core import and comptime core.assertInput(@this()) call, replacing doc-comment-only conformance claim.
Examples and android_app comment updates
backends/bgfx/example/main.zig, backends/bgfx/example/android_video.zig, backends/bgfx/src/android_app.zig
Propagates renamed APIs to examples (beginFrame/endFrame, width/height, shouldQuit) and updates comments in android_app.zig.
Template propagation
backends/bgfx/templates/android.txt, backends/bgfx/templates/desktop.txt
Updates code-generation templates to use width/height, beginFrame/endFrame, and shouldQuit.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 Hop hop, the names have changed today,
beginFrame leads where beginDrawing once held sway,
shouldQuit now asks if it's time to rest,
width and height pass the contract test.
The core asserts at build — no guessing game,
Every module hops in sync, all the same! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: bgfx is being aligned with the canonical window and input contracts for Phase 3.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/bgfx-window-contract

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the bgfx backend to conform to the canonical window and input contracts defined in labelle-core (v1.21.0). Comptime assertions (core.assertInput and core.assertWindow) have been added to verify contract conformance, and several window API functions have been renamed to match the canonical contract (e.g., getScreenWidth/getScreenHeight to width/height, beginDrawing/endDrawing to beginFrame/endFrame, and windowShouldClose to shouldQuit). There are no review comments, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@apotema
apotema merged commit 89c21d0 into main Jun 28, 2026
6 checks passed
@apotema
apotema deleted the agent/bgfx-window-contract branch June 28, 2026 13:46
apotema added a commit that referenced this pull request Jun 28, 2026
…lete (#395)

gfx.zig's façade already exposed every required render decl (types/draw fns/
colors + the paired isCompressed/uploadCompressed); this adds the compile-time
core.assertBackend(@this()) gate that PROVES it, replacing the old prose
'satisfies Backend(Impl)' doc claim. Wires labelle-core onto gfx_mod (gfx_tests
builds from it). Completes bgfx's contract trifecta: render + window
(assertWindow, #394) + input (assertInput, #394). Build/test/Android cross-build
green. #386 Phase 3.
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