Skip to content

fix(rendering): use the default clear color for window letterbox margins - #336

Merged
joeykchen merged 1 commit into
goplus:spx4.4.1from
joeykchen:fix/window-letterbox-background
Sep 21, 2026
Merged

joeykchen merged 1 commit into
goplus:spx4.4.1from
joeykchen:fix/window-letterbox-background

Conversation

@joeykchen

Copy link
Copy Markdown

Clear uncovered window regions with the existing default clear color in both GLES3 and RenderingDevice compositors, while keeping margins opaque. Projects can control their margins through default_clear_color or RenderingServer.set_default_clear_color without a new API or changes to viewport layout and input coordinates.

Base: spx4.4.1. This is the engine-side prerequisite for the SPX stage-letterbox branch.

Prior build and runtime validation: Matching Native and Web builds passed. Eight macOS OpenGL3/Metal window scenarios checked white and runtime color changes, horizontal/vertical margins and transparent input colors; Web DPR 1/2 resize samples stayed opaque white with unchanged visible-world bounds.

@fennoai fennoai 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.

Review: Use project background color for uncovered window regions

This is a small, well-scoped fix. Both call sites replace the hardcoded black clear color with texture_storage->get_default_clear_color() (alpha forced to 1.0) so letterbox/uncovered window regions match the project's background color instead of always being black.

No issues found. The change is correct, safe, and consistent with existing usage.

  • Correctness & consistency — The new usage matches how get_default_clear_color() is already used for related purposes elsewhere (window border/letterbox fill in display_server_windows.cpp, early-window clear in display_server.cpp, viewport background in renderer_viewport.cpp). Both paths correctly force alpha to 1.0 to keep regions opaque. The RD call is placed once outside the per-target loop; the GLES3 call stays guarded behind the p_first + letterbox-region check.
  • Performance — get_default_clear_color() is a trivial accessor returning a cached Color field (no allocation, no lock, no settings lookup), so per-frame cost is negligible.
  • Thread safety — Reading the cached clear color on the render thread follows the established pattern already used by several per-frame render-thread call sites; no new concern is introduced. The existing comment about avoiding a DisplayServer window-size query (deadlock in separate-render-thread mode) still holds.
  • Memory safety — texture_storage is created in each constructor and already dereferenced unconditionally in both functions, so the added call introduces no new null-dereference risk.
  • Comments — Both updated/added comments accurately describe the code.

Optional (testing note, not a blocker): get_default_clear_color() returns the raw rendering/environment/defaults/default_clear_color value and is passed directly without an sRGB↔linear conversion — matching the sibling usages. Worth a quick visual confirmation that the letterbox fill matches the actual rendered viewport background across both renderers (and in HDR mode), since scene-render paths may apply the color in linear/sRGB framebuffer contexts. This is an existing engine-wide consideration, not introduced by this PR.

@joeykchen joeykchen changed the title Use the default clear color for window letterbox margins fix(rendering): use the default clear color for window letterbox margins Sep 20, 2026
@joeykchen
joeykchen merged commit f3aedc3 into goplus:spx4.4.1 Sep 21, 2026
18 checks passed
@joeykchen
joeykchen deleted the fix/window-letterbox-background branch September 22, 2026 07:54
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.

2 participants